Commit 5ce75bb40cfddfa0ce92dee1602171053ba386b4
1 parent
d633d4d0
Exists in
v1.2
and in
2 other branches
..
Showing
5 changed files
with
137 additions
and
0 deletions
Show diff stats
API/Tag.go
... | ... | @@ -133,6 +133,14 @@ func CreateTag(c *gin.Context) { |
133 | 133 | } |
134 | 134 | |
135 | 135 | |
136 | + if c.PostForm("TagGroup") == "type" { | |
137 | + c.JSON(200, tools.ResponseError{ | |
138 | + 1, | |
139 | + "此类型只能加不能加", | |
140 | + }) | |
141 | + return | |
142 | + } | |
143 | + | |
136 | 144 | DB.CTags.Insert(DB.STag{ |
137 | 145 | ScenicId, |
138 | 146 | c.PostForm("TagGroup"), | ... | ... |
... | ... | @@ -0,0 +1,90 @@ |
1 | +package Api | |
2 | + | |
3 | +import ( | |
4 | + "encoding/json" | |
5 | + "github.com/aarongao/tools" | |
6 | + "github.com/gin-gonic/gin" | |
7 | + "gopkg.in/mgo.v2/bson" | |
8 | + "letu/DB" | |
9 | + "letu/Lib/LeYouTu" | |
10 | +) | |
11 | + | |
12 | +// @Title 查询所有菜单 | |
13 | +// @Description 菜单管理 - 查询所有菜单 | |
14 | +// @Accept json | |
15 | +// @Produce json | |
16 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Id":"","ScenicId":"","Title":"玩水","Tags":["玩水"]},{"Id":"","ScenicId":"","Title":"设施","Tags":["服务设施","游玩项目"]}]}" | |
17 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | |
18 | +// @Router /TopMenus/All? [get] | |
19 | +func AllTopMenus(c *gin.Context) { | |
20 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | |
21 | + c.Header("Access-Control-Allow-Credentials", "true") | |
22 | + | |
23 | + ScenicId, err := LeYouTu.GetScenicId(c) | |
24 | + if err != nil { | |
25 | + return | |
26 | + } | |
27 | + | |
28 | + var STopMenus []*DB.STopMenus | |
29 | + DB.CTopMenus.Find(bson.M{"ScenicId": ScenicId}).All(&STopMenus) | |
30 | + | |
31 | + if STopMenus == nil { | |
32 | + STopMenus = []*DB.STopMenus{} | |
33 | + } | |
34 | + | |
35 | + c.JSON(200, tools.ResponseSeccess{ | |
36 | + 0, | |
37 | + STopMenus, | |
38 | + }) | |
39 | + | |
40 | +} | |
41 | + | |
42 | +// @Title 更新菜单 | |
43 | +// @Description 菜单管理 - 更新菜单 | |
44 | +// @Accept json | |
45 | +// @Produce json | |
46 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Id":"","ScenicId":"","Title":"玩水","Tags":["玩水"]},{"Id":"","ScenicId":"","Title":"设施","Tags":["服务设施","游玩项目"]}]}" | |
47 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | |
48 | +// @Router /TopMenus/Update? [post] | |
49 | +func UpdateTopMenus(c *gin.Context) { | |
50 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | |
51 | + c.Header("Access-Control-Allow-Credentials", "true") | |
52 | + | |
53 | + ScenicId, err := LeYouTu.GetScenicId(c) | |
54 | + if err != nil { | |
55 | + return | |
56 | + } | |
57 | + | |
58 | + if c.PostForm("Tags") == "" { | |
59 | + c.JSON(200, tools.ResponseError{ | |
60 | + 1, | |
61 | + "标签不能为空", | |
62 | + }) | |
63 | + return | |
64 | + } | |
65 | + | |
66 | + var Tags []string | |
67 | + json.Unmarshal([]byte(c.PostForm("Tags")), &Tags) | |
68 | + | |
69 | + var id bson.ObjectId | |
70 | + if pid := c.PostForm("id"); pid == "null" { | |
71 | + id = bson.NewObjectId() | |
72 | + } else { | |
73 | + id = bson.ObjectIdHex(pid) | |
74 | + } | |
75 | + | |
76 | + DB.CTopMenus.UpsertId( | |
77 | + id, | |
78 | + bson.M{"$set": bson.M{ | |
79 | + "ScenicId": ScenicId, | |
80 | + "Title": c.PostForm("Title"), | |
81 | + "Tags": Tags, | |
82 | + }}, | |
83 | + ) | |
84 | + | |
85 | + c.JSON(200, tools.ResponseSeccess{ | |
86 | + 0, | |
87 | + "ok", | |
88 | + }) | |
89 | + | |
90 | +} | ... | ... |
DB/db.go
... | ... | @@ -21,6 +21,7 @@ var CUserLog *mgo.Collection //用户行为记录 |
21 | 21 | var CSystemLog *mgo.Collection //操作记录 |
22 | 22 | var CTrajectory *mgo.Collection //移动轨迹 |
23 | 23 | var CIcons *mgo.Collection //图标信息 |
24 | +var CTopMenus *mgo.Collection //菜单 | |
24 | 25 | var DB *mgo.Database |
25 | 26 | |
26 | 27 | type SItem struct { |
... | ... | @@ -59,6 +60,12 @@ type SLocation struct { |
59 | 60 | Latitude float64 `bson:"Latitude" json:"Latitude"` //纬度 |
60 | 61 | Longitude float64 `bson:"Longitude" json:"Longitude"` //经度 |
61 | 62 | } |
63 | +type STopMenus struct { | |
64 | + Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` | |
65 | + ScenicId string `bson:"ScenicId" json:"ScenicId"` | |
66 | + Title string `bson:"Title" json:"Title"` //菜单标题 | |
67 | + Tags []string `bson:"Tags" json:"Tags"` //标签 | |
68 | +} | |
62 | 69 | |
63 | 70 | type SDevice struct { |
64 | 71 | DeviceId string `bson:"DeviceId" json:"DeviceId"` | ... | ... |
README.md
... | ... | @@ -34,6 +34,8 @@ |
34 | 34 | 1. [发送短信验证码](#sms-send-post) |
35 | 35 | 1. [标签 - 增加标签](#tag-create-post) |
36 | 36 | 1. [标签 - 删除标签](#tag-remove-post) |
37 | +1. [菜单管理 - 查询所有菜单](#topmenus-all-get) | |
38 | +1. [菜单管理 - 更新菜单](#topmenus-update-post) | |
37 | 39 | 1. [保存用户移动轨迹(5分钟提交一次)](#trajectory-save-post) |
38 | 40 | 1. [更新商品](#updatecommodity-post) |
39 | 41 | 1. [设备管理 - 更新设施](#updateitem-post) |
... | ... | @@ -534,6 +536,33 @@ |
534 | 536 | |
535 | 537 | |
536 | 538 | |
539 | +<a name="topmenus-all-get"></a> | |
540 | + | |
541 | +#### /TopMenus/All (GET) | |
542 | + | |
543 | + | |
544 | +菜单管理 - 查询所有菜单 | |
545 | + | |
546 | +| Code | Type | Model | Message | | |
547 | +|-----|-----|-----|-----| | |
548 | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":[{"Id":"","ScenicId":"","Title":"玩水","Tags":["玩水"]},{"Id":"","ScenicId":"","Title":"设施","Tags":["服务设施","游玩项目"]}]} | | |
549 | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | | |
550 | + | |
551 | + | |
552 | +<a name="topmenus-update-post"></a> | |
553 | + | |
554 | +#### /TopMenus/Update (POST) | |
555 | + | |
556 | + | |
557 | +菜单管理 - 更新菜单 | |
558 | + | |
559 | +| Code | Type | Model | Message | | |
560 | +|-----|-----|-----|-----| | |
561 | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":[{"Id":"","ScenicId":"","Title":"玩水","Tags":["玩水"]},{"Id":"","ScenicId":"","Title":"设施","Tags":["服务设施","游玩项目"]}]} | | |
562 | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | | |
563 | + | |
564 | + | |
565 | + | |
537 | 566 | <a name="trajectory-save-post"></a> |
538 | 567 | |
539 | 568 | #### /Trajectory/Save (POST) | ... | ... |
main.go
... | ... | @@ -64,6 +64,7 @@ func main() { |
64 | 64 | DB.CInvestigation = DB.DB.C("Investigation") |
65 | 65 | DB.CTrajectory = DB.DB.C("Trajectory") |
66 | 66 | DB.CIcons = DB.DB.C("Icons") |
67 | + DB.CTopMenus = DB.DB.C("TopMenus") | |
67 | 68 | DelayMessage.CDelayMessage = DB.DB.C("DelayMessage") |
68 | 69 | DelayMessage.CDelayErrorLog = DB.DB.C("DelayErrorLog") |
69 | 70 | |
... | ... | @@ -113,6 +114,8 @@ func main() { |
113 | 114 | r.GET("/Icon/Info", Api.IconInfo) |
114 | 115 | r.POST("/CheckToken", Api.CheckToken) |
115 | 116 | r.GET("/Tiles", Api.Tiles) |
117 | + r.POST("/TopMenus/Update", Api.UpdateTopMenus) | |
118 | + r.GET("/TopMenus/All", Api.AllTopMenus) | |
116 | 119 | //r.GET("/ws", Api.WsPage) |
117 | 120 | |
118 | 121 | r.Static("/Upload", "./Upload") | ... | ... |