From 7cce0d4a22fb99185af34939851db57a04ac1310 Mon Sep 17 00:00:00 2001 From: aarongao Date: Tue, 21 Jan 2020 14:31:36 +0800 Subject: [PATCH] .. --- API/DealyMessage.go | 16 +++++----------- API/Item.go | 19 +++++-------------- API/Line.go | 19 +++++-------------- API/Scenic.go | 45 ++++++++++++++++----------------------------- API/Shop.go | 25 ++++++++----------------- API/Tag.go | 18 ++++++------------ API/User.go | 19 +++++-------------- DB/db.go | 17 +++++++++++------ 8 files changed, 61 insertions(+), 117 deletions(-) diff --git a/API/DealyMessage.go b/API/DealyMessage.go index 6c223ed..3f7494f 100644 --- a/API/DealyMessage.go +++ b/API/DealyMessage.go @@ -23,18 +23,12 @@ func DealyMessageInfo(c *gin.Context) { DelayMessage.CDelayMessage.Find(bson.M{"UserId": c.Query("userid")}).All(&aDelayMessage) if aDelayMessage == nil { - - c.JSON(200, tools.ResponseError{ - 1, - "空", - }) - } else { - - c.JSON(200, tools.ResponseSeccess{ - 0, - aDelayMessage, - }) + aDelayMessage = []DelayMessage.Message{} } + c.JSON(200, tools.ResponseSeccess{ + 0, + aDelayMessage, + }) } // @Title 创建提醒 diff --git a/API/Item.go b/API/Item.go index 457e9f9..6c7f790 100644 --- a/API/Item.go +++ b/API/Item.go @@ -28,22 +28,14 @@ func ItemInfo(c *gin.Context) { return } - var SItem *DB.SItem + var SItem DB.SItem DB.CItem.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&SItem) - if SItem == nil { - - c.JSON(200, tools.ResponseError{ - 1, - "空", - }) - } else { + c.JSON(200, tools.ResponseSeccess{ + 0, + SItem, + }) - c.JSON(200, tools.ResponseSeccess{ - 0, - SItem, - }) - } } // @Title 查询所有游玩项目 @@ -122,7 +114,6 @@ type ItemTime struct { Time string `json:"time"` } - // @Title 更新等待时间 // @Description 更新等待时间 // @Accept json diff --git a/API/Line.go b/API/Line.go index 068b61f..7d8c3a1 100644 --- a/API/Line.go +++ b/API/Line.go @@ -28,22 +28,13 @@ func LineInfo(c *gin.Context) { return } - var SLine *DB.SLine + var SLine DB.SLine DB.CLine.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&SLine) - if SLine == nil { - - c.JSON(200, tools.ResponseError{ - 1, - "空", - }) - } else { - - c.JSON(200, tools.ResponseSeccess{ - 0, - SLine, - }) - } + c.JSON(200, tools.ResponseSeccess{ + 0, + SLine, + }) } diff --git a/API/Scenic.go b/API/Scenic.go index fccf278..610579e 100644 --- a/API/Scenic.go +++ b/API/Scenic.go @@ -31,19 +31,10 @@ func ScenicInfo(c *gin.Context) { var Scenic *DB.SScenic DB.CScenic.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&Scenic) - if Scenic == nil { - - c.JSON(200, tools.ResponseError{ - 1, - "空", - }) - } else { - - c.JSON(200, tools.ResponseSeccess{ - 0, - Scenic, - }) - } + c.JSON(200, tools.ResponseSeccess{ + 0, + Scenic, + }) } @@ -62,21 +53,22 @@ func UpdateScenic(c *gin.Context) { var Location DB.SLocation json.Unmarshal([]byte(c.PostForm("Location")), &Location) - var Picture []string + var Picture []DB.SPicture json.Unmarshal([]byte(c.PostForm("Picture")), &Picture) - var ShopAdPicture []string + var ShopAdPicture []DB.SPicture json.Unmarshal([]byte(c.PostForm("ShopAdPicture")), &ShopAdPicture) - var ItemScenicPicture []string + var ItemScenicPicture []DB.SPicture json.Unmarshal([]byte(c.PostForm("ItemScenicPicture")), &ItemScenicPicture) - var ActivityPicture []string + var ActivityPicture []DB.SPicture json.Unmarshal([]byte(c.PostForm("ActivityPicture")), &ActivityPicture) - var VideoList []string + var VideoList []DB.SPicture json.Unmarshal([]byte(c.PostForm("VideoList")), &VideoList) + var id bson.ObjectId if pid := c.PostForm("id"); pid == "null" { id = bson.NewObjectId() @@ -123,17 +115,12 @@ func AllScenic(c *gin.Context) { DB.CScenic.Find(bson.M{}).All(&Scenic) if Scenic == nil { - - c.JSON(200, tools.ResponseError{ - 1, - "空", - }) - } else { - - c.JSON(200, tools.ResponseSeccess{ - 0, - Scenic, - }) + Scenic = []*DB.SScenic{} } + c.JSON(200, tools.ResponseSeccess{ + 0, + Scenic, + }) + } diff --git a/API/Shop.go b/API/Shop.go index ccf30c1..ebec828 100644 --- a/API/Shop.go +++ b/API/Shop.go @@ -28,22 +28,13 @@ func CommodityInfo(c *gin.Context) { return } - var SCommodity *DB.SCommodity + var SCommodity DB.SCommodity DB.CCommodity.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&SCommodity) - if SCommodity == nil { - - c.JSON(200, tools.ResponseError{ - 1, - "空", - }) - } else { - - c.JSON(200, tools.ResponseSeccess{ - 0, - SCommodity, - }) - } + c.JSON(200, tools.ResponseSeccess{ + 0, + SCommodity, + }) } @@ -82,8 +73,8 @@ func UpdateCommodity(c *gin.Context) { var TopPhoto []string json.Unmarshal([]byte(c.PostForm("TopPhoto")), &TopPhoto) - var Location DB.SLocation - json.Unmarshal([]byte(c.PostForm("Location")), &Location) + //var Location DB.SLocation + //json.Unmarshal([]byte(c.PostForm("Location")), &Location) var id bson.ObjectId if pid := c.PostForm("id"); pid == "null" { @@ -100,7 +91,7 @@ func UpdateCommodity(c *gin.Context) { "ShopName": c.PostForm("ShopName"), "KvPhoto": c.PostForm("KvPhoto"), "TopPhoto": TopPhoto, - "Location": Location, + "ItemId": c.PostForm("ItemId"), "Images": Picture, }}, ) diff --git a/API/Tag.go b/API/Tag.go index 7a0bc0f..76a10bd 100644 --- a/API/Tag.go +++ b/API/Tag.go @@ -18,22 +18,16 @@ func AllTag(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") - var Stags []*DB.STag DB.CTags.Find(bson.M{}).All(&Stags) if Stags == nil { - - c.JSON(200, tools.ResponseError{ - 1, - "空", - }) - } else { - - c.JSON(200, tools.ResponseSeccess{ - 0, - Stags, - }) + Stags = []*DB.STag{} } + c.JSON(200, tools.ResponseSeccess{ + 0, + Stags, + }) + } diff --git a/API/User.go b/API/User.go index aae6db5..a16f816 100644 --- a/API/User.go +++ b/API/User.go @@ -196,22 +196,13 @@ func UserInfo(c *gin.Context) { return } - var User *DB.SMember + var User DB.SMember DB.CMember.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&User) - if User == nil { - - c.JSON(200, tools.ResponseError{ - 1, - "空", - }) - } else { - - c.JSON(200, tools.ResponseSeccess{ - 0, - User, - }) - } + c.JSON(200, tools.ResponseSeccess{ + 0, + User, + }) } diff --git a/DB/db.go b/DB/db.go index 26860b5..b13d33a 100644 --- a/DB/db.go +++ b/DB/db.go @@ -73,7 +73,7 @@ type SCommodity struct { Name string `bson:"Name" json:"Name"` Price string `bson:"Price" json:"Price"` ShopName string `bson:"ShopName" json:"ShopName"` - Location SLocation `bson:"Location" json:"Location"` + ItemId string `bson:"ItemId" json:"ItemId"` //项目id KvPhoto string `bson:"KvPhoto" json:"KvPhoto"` //用于列表页的图片 TopPhoto []string `bson:"TopPhoto" json:"TopPhoto"` //详情页最上面的轮播图 Images []string `bson:"Images" json:"Images"` //详情页下面的产品详细图 @@ -116,6 +116,11 @@ type STag struct { Type string `bson:"Type" json:"Type"` Name string `bson:"Name" json:"Name"` } + +type SPicture struct { + Src string `bson:"Src" json:"Src"` + Link string `bson:"Link" json:"Link"` +} type SScenic struct { Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` Name string `bson:"Name" json:"Name"` @@ -124,9 +129,9 @@ type SScenic struct { Mobile string `bson:"Mobile" json:"Mobile"` Address string `bson:"Address" json:"Address"` Location SLocation `bson:"Location" json:"Location"` - Picture []string `bson:"Picture" json:"Picture"` - ShopAdPicture []string `bson:"ShopAdPicture" json:"ShopAdPicture"` //商城列表页图片 - ItemScenicPicture []string `bson:"ItemScenicPicture" json:"ItemScenicPicture"` //项目场次照片 - ActivityPicture []string `bson:"ActivityPicture" json:"ActivityPicture"` //活动照片 - VideoList []string `bson:"VideoList" json:"VideoList"` + Picture []SPicture `bson:"Picture" json:"Picture"` + ShopAdPicture []SPicture `bson:"ShopAdPicture" json:"ShopAdPicture"` //商城列表页图片 + ItemScenicPicture []SPicture `bson:"ItemScenicPicture" json:"ItemScenicPicture"` //项目场次照片 + ActivityPicture []SPicture `bson:"ActivityPicture" json:"ActivityPicture"` //活动照片 + VideoList []SPicture `bson:"VideoList" json:"VideoList"` } -- libgit2 0.21.0