package Api import ( "encoding/json" "github.com/aarongao/tools" "github.com/gin-gonic/gin" "gopkg.in/mgo.v2/bson" "letu/DB" ) // @Title 返回景区基础信息 // @Description 返回景区基础信息 // @Accept json // @Produce json // @Param id 5dfb03070a9ac17ac7a82054 string true "景区id" // @Success 200 {object} tools.ResponseSeccess "Name名称;Describe介绍;OpenHours营业时间;Picture最上面图片;ShopAdPicture商城列表页图片;ItemScenicPicture项目场次照片;ActivityPicture活动照片;VideoList视频(VideoPicture=首桢图片)" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /ScenicInfo? [get] func ScenicInfo(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") if c.Query("id") == "" { c.JSON(200, tools.ResponseError{ 1, "空", }) return } var Scenic *DB.SScenic DB.CScenic.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&Scenic) c.JSON(200, tools.ResponseSeccess{ 0, Scenic, }) } // @Title 更新景区基础信息 // @Description 更新景区基础信息 // @Accept json // @Produce json // @Param id 5dfb03070a9ac17ac7a82054 string true "景区id" // @Success 200 {object} tools.ResponseSeccess "Name名称;Describe介绍;OpenHours营业时间;Picture最上面图片;ShopAdPicture商城列表页图片;ItemScenicPicture项目场次照片;ActivityPicture活动照片;VideoList视频(VideoPicture=首桢图片)" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /UpdateScenic? [post] func UpdateScenic(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") var Location DB.SLocation json.Unmarshal([]byte(c.PostForm("Location")), &Location) var Picture []DB.SPicture json.Unmarshal([]byte(c.PostForm("Picture")), &Picture) var ShopAdPicture []DB.SPicture json.Unmarshal([]byte(c.PostForm("ShopAdPicture")), &ShopAdPicture) var ItemScenicPicture []DB.SPicture json.Unmarshal([]byte(c.PostForm("ItemScenicPicture")), &ItemScenicPicture) var ActivityPicture []DB.SPicture json.Unmarshal([]byte(c.PostForm("ActivityPicture")), &ActivityPicture) var VideoList []DB.SVideo json.Unmarshal([]byte(c.PostForm("VideoList")), &VideoList) var id bson.ObjectId if pid := c.PostForm("id"); pid == "null" { id = bson.NewObjectId() } else { id = bson.ObjectIdHex(pid) } DB.CScenic.UpsertId( id, bson.M{"$set": bson.M{ "Name": c.PostForm("Name"), "Describe": c.PostForm("Describe"), "Location": Location, "OpenHours": c.PostForm("OpenHours"), "Mobile": c.PostForm("Mobile"), "Address": c.PostForm("Address"), "Picture": Picture, "ShopAdPicture": ShopAdPicture, "ItemScenicPicture": ItemScenicPicture, "ActivityPicture": ActivityPicture, "VideoList": VideoList, }}, ) c.JSON(200, tools.ResponseSeccess{ 0, "ok", }) } // @Title 所有景区基础信息 // @Description 所有景区基础信息 // @Accept json // @Produce json // @Success 200 {object} tools.ResponseSeccess "" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /AllScenic? [get] func AllScenic(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") var Scenic []*DB.SScenic DB.CScenic.Find(bson.M{}).All(&Scenic) if Scenic == nil { Scenic = []*DB.SScenic{} } c.JSON(200, tools.ResponseSeccess{ 0, Scenic, }) }