Commit 74de40c645cb8e31b4d04889d6ce48224b35c5df
0 parents
Exists in
v1.2
and in
2 other branches
init
Showing
15 changed files
with
1159 additions
and
0 deletions
Show diff stats
1 | +++ a/API/Complaint.go | ||
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +package Api | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "github.com/aarongao/tools" | ||
6 | + "github.com/gin-gonic/gin" | ||
7 | + "letu/DB" | ||
8 | +) | ||
9 | + | ||
10 | +// @Title 增加投诉 | ||
11 | +// @Description 增加投诉 | ||
12 | +// @Accept json | ||
13 | +// @Produce json | ||
14 | +// @Param mobile 18616619599 string true "联系电话" | ||
15 | +// @Param type 1 string true "类型" | ||
16 | +// @Param content 卫生不干净 string true "投诉内容" | ||
17 | +// @Param image ["http://www.xx.com/123.jpg","http://www.xx.com/123.jpg"] string true "照片数组" | ||
18 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" | ||
19 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
20 | +// @Router /CreateComplaint? [post] | ||
21 | +func CreateComplaint(c *gin.Context) { | ||
22 | + c.Header("Access-Control-Allow-Origin",c.Request.Header.Get("Origin")) | ||
23 | + c.Header("Access-Control-Allow-Credentials","true") | ||
24 | + | ||
25 | + | ||
26 | + var images []string | ||
27 | + | ||
28 | + json.Unmarshal([]byte(c.PostForm("image")), &images) | ||
29 | + | ||
30 | + DB.CComplaint.Insert(DB.SComplaint{ | ||
31 | + c.PostForm("type"), | ||
32 | + c.PostForm("mobile"), | ||
33 | + c.PostForm("content"), | ||
34 | + images, | ||
35 | + }) | ||
36 | + | ||
37 | + c.JSON(200, tools.ResponseSeccess{ | ||
38 | + 0, | ||
39 | + "ok", | ||
40 | + }) | ||
41 | + | ||
42 | + | ||
43 | +} |
1 | +++ a/API/Item.go | ||
@@ -0,0 +1,157 @@ | @@ -0,0 +1,157 @@ | ||
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 | +) | ||
10 | + | ||
11 | +// @Title 查询设备信息 | ||
12 | +// @Description 查询设备信息 | ||
13 | +// @Accept json | ||
14 | +// @Produce json | ||
15 | +// @Param id 5dfb03070a9ac17ac7a82054 string true "设备id" | ||
16 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Name":"名称","Describe":"介绍","OpenHours":"开放时间","Mobile":"电话","Address":"地址","SLocation":{"Latitude":0,"Longitude":0},"Picture":["照片1","照片2"]}}" | ||
17 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
18 | +// @Router /ScenicInfo? [get] | ||
19 | +func ItemInfo(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 | + if c.Query("id") == "" { | ||
24 | + c.JSON(200, tools.ResponseError{ | ||
25 | + 1, | ||
26 | + "空", | ||
27 | + }) | ||
28 | + return | ||
29 | + } | ||
30 | + | ||
31 | + var SItem *DB.SItem | ||
32 | + DB.CItem.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&SItem) | ||
33 | + | ||
34 | + if SItem == nil { | ||
35 | + | ||
36 | + c.JSON(200, tools.ResponseError{ | ||
37 | + 1, | ||
38 | + "空", | ||
39 | + }) | ||
40 | + } else { | ||
41 | + | ||
42 | + c.JSON(200, tools.ResponseSeccess{ | ||
43 | + 0, | ||
44 | + SItem, | ||
45 | + }) | ||
46 | + } | ||
47 | + | ||
48 | +} | ||
49 | + | ||
50 | +// @Title 查询所有游玩项目 | ||
51 | +// @Description 查询所有游玩项目 | ||
52 | +// @Accept json | ||
53 | +// @Produce json | ||
54 | +// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单" | ||
55 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
56 | +// @Router /AllItems? [get] | ||
57 | +func AllItems(c *gin.Context) { | ||
58 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
59 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
60 | + | ||
61 | + var aItems []DB.SItem | ||
62 | + DB.CItem.Find(bson.M{}).All(&aItems) | ||
63 | + | ||
64 | + c.JSON(200, aItems) | ||
65 | + | ||
66 | +} | ||
67 | + | ||
68 | +// @Title 更新设施 | ||
69 | +// @Description 更新设施 | ||
70 | +// @Accept json | ||
71 | +// @Produce json | ||
72 | +// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单" | ||
73 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
74 | +// @Router /UpdateItem? [post] | ||
75 | +func UpdateItem(c *gin.Context) { | ||
76 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
77 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
78 | + | ||
79 | + var Location DB.SLocation | ||
80 | + json.Unmarshal([]byte(c.PostForm("Location")), &Location) | ||
81 | + | ||
82 | + var Tags []DB.STag | ||
83 | + json.Unmarshal([]byte(c.PostForm("Tags")), &Tags) | ||
84 | + | ||
85 | + var Picture []string | ||
86 | + json.Unmarshal([]byte(c.PostForm("Picture")), &Picture) | ||
87 | + | ||
88 | + var id bson.ObjectId | ||
89 | + if pid := c.PostForm("id"); pid == "null" { | ||
90 | + id = bson.NewObjectId() | ||
91 | + } else { | ||
92 | + id = bson.ObjectIdHex(pid) | ||
93 | + } | ||
94 | + | ||
95 | + DB.CItem.UpsertId( | ||
96 | + id, | ||
97 | + bson.M{"$set": bson.M{ | ||
98 | + "Name": c.PostForm("Name"), | ||
99 | + "SubName": c.PostForm("SubName"), | ||
100 | + "Location": Location, | ||
101 | + "Icon": c.PostForm("Icon"), | ||
102 | + "LimitHeight": c.PostForm("LimitHeight"), | ||
103 | + "PlayDuration": c.PostForm("PlayDuration"), | ||
104 | + "SceneTime": c.PostForm("SceneTime"), | ||
105 | + "Picture": Picture, | ||
106 | + "Voice": c.PostForm("Voice"), | ||
107 | + "Tel": c.PostForm("Tel"), | ||
108 | + "AverageConsumption": c.PostForm("AverageConsumption"), | ||
109 | + "Menu": c.PostForm("Menu"), | ||
110 | + "Tags": Tags, | ||
111 | + }}, | ||
112 | + ) | ||
113 | + | ||
114 | + c.JSON(200, tools.ResponseSeccess{ | ||
115 | + 0, | ||
116 | + "ok", | ||
117 | + }) | ||
118 | + | ||
119 | +} | ||
120 | + | ||
121 | +type ItemTime struct { | ||
122 | + Id string `json:"id"` | ||
123 | + Time string `json:"time"` | ||
124 | +} | ||
125 | + | ||
126 | + | ||
127 | +// @Title 更新等待时间 | ||
128 | +// @Description 更新等待时间 | ||
129 | +// @Accept json | ||
130 | +// @Produce json | ||
131 | +// @Param item [{"id":"5df864740a9ac17ac7a7feb8","time":"20"},{"id":"5df8660924e03417008b4567","time":"33"}] string true "设备列表" | ||
132 | +// @Success 200 {object} tools.ResponseSeccess "{errcode: 0, result: "ok"}" | ||
133 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
134 | +// @Router /UpdateItemTime? [post] | ||
135 | +func UpdateItemTime(c *gin.Context) { | ||
136 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
137 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
138 | + | ||
139 | + var ItemTime []ItemTime | ||
140 | + json.Unmarshal([]byte(c.PostForm("items")), &ItemTime) | ||
141 | + | ||
142 | + for _, v := range ItemTime { | ||
143 | + | ||
144 | + DB.CItem.Update( | ||
145 | + bson.M{"_id": bson.ObjectIdHex(v.Id)}, | ||
146 | + bson.M{"$set": bson.M{ | ||
147 | + "Time": v.Time, | ||
148 | + }}, | ||
149 | + ) | ||
150 | + } | ||
151 | + | ||
152 | + c.JSON(200, tools.ResponseSeccess{ | ||
153 | + 0, | ||
154 | + "ok", | ||
155 | + }) | ||
156 | + | ||
157 | +} |
1 | +++ a/API/Line.go | ||
@@ -0,0 +1,110 @@ | @@ -0,0 +1,110 @@ | ||
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 | +) | ||
10 | + | ||
11 | +// @Title 查询线路信息 | ||
12 | +// @Description 查询线路信息 | ||
13 | +// @Accept json | ||
14 | +// @Produce json | ||
15 | +// @Param id 5dfb03070a9ac17ac7a82054 string true "id" | ||
16 | +// @Success 200 {object} tools.ResponseSeccess "Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id" | ||
17 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
18 | +// @Router /LineInfo? [get] | ||
19 | +func LineInfo(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 | + if c.Query("id") == "" { | ||
24 | + c.JSON(200, tools.ResponseError{ | ||
25 | + 1, | ||
26 | + "空", | ||
27 | + }) | ||
28 | + return | ||
29 | + } | ||
30 | + | ||
31 | + var SLine *DB.SLine | ||
32 | + DB.CLine.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&SLine) | ||
33 | + | ||
34 | + if SLine == nil { | ||
35 | + | ||
36 | + c.JSON(200, tools.ResponseError{ | ||
37 | + 1, | ||
38 | + "空", | ||
39 | + }) | ||
40 | + } else { | ||
41 | + | ||
42 | + c.JSON(200, tools.ResponseSeccess{ | ||
43 | + 0, | ||
44 | + SLine, | ||
45 | + }) | ||
46 | + } | ||
47 | + | ||
48 | +} | ||
49 | + | ||
50 | +// @Title 查询所有线路 | ||
51 | +// @Description 查询所有线路 | ||
52 | +// @Accept json | ||
53 | +// @Produce json | ||
54 | +// @Success 200 {object} tools.ResponseSeccess "Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id" | ||
55 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
56 | +// @Router /AllLine? [get] | ||
57 | +func AllLine(c *gin.Context) { | ||
58 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
59 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
60 | + | ||
61 | + var aLine []DB.SLine | ||
62 | + DB.CLine.Find(bson.M{}).All(&aLine) | ||
63 | + | ||
64 | + c.JSON(200, aLine) | ||
65 | + | ||
66 | +} | ||
67 | + | ||
68 | +// @Title 更新线路 | ||
69 | +// @Description 更新线路 | ||
70 | +// @Accept json | ||
71 | +// @Produce json | ||
72 | +// @Success 200 {object} tools.ResponseSeccess "" | ||
73 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
74 | +// @Router /UpdateLine? [post] | ||
75 | +func UpdateLine(c *gin.Context) { | ||
76 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
77 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
78 | + | ||
79 | + var Location []DB.SLocation | ||
80 | + json.Unmarshal([]byte(c.PostForm("Location")), &Location) | ||
81 | + | ||
82 | + var Annotations []string | ||
83 | + json.Unmarshal([]byte(c.PostForm("Annotations")), &Annotations) | ||
84 | + | ||
85 | + var id bson.ObjectId | ||
86 | + if pid := c.PostForm("id"); pid == "null" { | ||
87 | + id = bson.NewObjectId() | ||
88 | + } else { | ||
89 | + id = bson.ObjectIdHex(pid) | ||
90 | + } | ||
91 | + | ||
92 | + DB.CLine.UpsertId( | ||
93 | + id, | ||
94 | + bson.M{"$set": bson.M{ | ||
95 | + "Name": c.PostForm("Name"), | ||
96 | + "SubName": c.PostForm("SubName"), | ||
97 | + "PlayDuration": c.PostForm("PlayDuration"), | ||
98 | + "Suitable": c.PostForm("Suitable"), | ||
99 | + "Content": c.PostForm("Content"), | ||
100 | + "Annotations": Annotations, | ||
101 | + "Location": Location, | ||
102 | + }}, | ||
103 | + ) | ||
104 | + | ||
105 | + c.JSON(200, tools.ResponseSeccess{ | ||
106 | + 0, | ||
107 | + "ok", | ||
108 | + }) | ||
109 | + | ||
110 | +} |
1 | +++ a/API/Scenic.go | ||
@@ -0,0 +1,123 @@ | @@ -0,0 +1,123 @@ | ||
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 | +) | ||
10 | + | ||
11 | +// @Title 返回景区基础信息 | ||
12 | +// @Description 基础信息 | ||
13 | +// @Accept json | ||
14 | +// @Produce json | ||
15 | +// @Param id 5dfb03070a9ac17ac7a82054 string true "景区id" | ||
16 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Name":"名称","Describe":"介绍","OpenHours":"开放时间","Mobile":"电话","Address":"地址","SLocation":{"Latitude":0,"Longitude":0},"Picture":["照片1","照片2"]}}" | ||
17 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
18 | +// @Router /ScenicInfo? [get] | ||
19 | +func ScenicInfo(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 | + if c.Query("id") == "" { | ||
24 | + c.JSON(200, tools.ResponseError{ | ||
25 | + 1, | ||
26 | + "空", | ||
27 | + }) | ||
28 | + return | ||
29 | + } | ||
30 | + | ||
31 | + var Scenic *DB.SScenic | ||
32 | + DB.CScenic.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&Scenic) | ||
33 | + | ||
34 | + if Scenic == nil { | ||
35 | + | ||
36 | + c.JSON(200, tools.ResponseError{ | ||
37 | + 1, | ||
38 | + "空", | ||
39 | + }) | ||
40 | + } else { | ||
41 | + | ||
42 | + c.JSON(200, tools.ResponseSeccess{ | ||
43 | + 0, | ||
44 | + Scenic, | ||
45 | + }) | ||
46 | + } | ||
47 | + | ||
48 | +} | ||
49 | + | ||
50 | +// @Title 更新景区基础信息 | ||
51 | +// @Description 更新景区基础信息 | ||
52 | +// @Accept json | ||
53 | +// @Produce json | ||
54 | +// @Param id 5dfb03070a9ac17ac7a82054 string true "景区id" | ||
55 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Name":"名称","Describe":"介绍","OpenHours":"开放时间","Mobile":"电话","Address":"地址","SLocation":{"Latitude":0,"Longitude":0},"Picture":["照片1","照片2"]}}" | ||
56 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
57 | +// @Router /UpdateScenic? [post] | ||
58 | +func UpdateScenic(c *gin.Context) { | ||
59 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
60 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
61 | + | ||
62 | + var Location DB.SLocation | ||
63 | + json.Unmarshal([]byte(c.PostForm("Location")), &Location) | ||
64 | + | ||
65 | + var Picture []string | ||
66 | + json.Unmarshal([]byte(c.PostForm("Picture")), &Picture) | ||
67 | + | ||
68 | + var id bson.ObjectId | ||
69 | + if pid := c.PostForm("id"); pid == "null" { | ||
70 | + id = bson.NewObjectId() | ||
71 | + } else { | ||
72 | + id = bson.ObjectIdHex(pid) | ||
73 | + } | ||
74 | + | ||
75 | + DB.CScenic.UpsertId( | ||
76 | + id, | ||
77 | + bson.M{"$set": bson.M{ | ||
78 | + "Name": c.PostForm("Name"), | ||
79 | + "Describe": c.PostForm("Describe"), | ||
80 | + "Location": Location, | ||
81 | + "OpenHours": c.PostForm("OpenHours"), | ||
82 | + "Mobile": c.PostForm("Mobile"), | ||
83 | + "Address": c.PostForm("Address"), | ||
84 | + "Picture": Picture, | ||
85 | + }}, | ||
86 | + ) | ||
87 | + | ||
88 | + c.JSON(200, tools.ResponseSeccess{ | ||
89 | + 0, | ||
90 | + "ok", | ||
91 | + }) | ||
92 | + | ||
93 | +} | ||
94 | + | ||
95 | +// @Title 所有景区基础信息 | ||
96 | +// @Description 所有景区基础信息 | ||
97 | +// @Accept json | ||
98 | +// @Produce json | ||
99 | +// @Success 200 {object} tools.ResponseSeccess "" | ||
100 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
101 | +// @Router /AllScenic? [get] | ||
102 | +func AllScenic(c *gin.Context) { | ||
103 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
104 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
105 | + | ||
106 | + var Scenic []*DB.SScenic | ||
107 | + DB.CScenic.Find(bson.M{}).All(&Scenic) | ||
108 | + | ||
109 | + if Scenic == nil { | ||
110 | + | ||
111 | + c.JSON(200, tools.ResponseError{ | ||
112 | + 1, | ||
113 | + "空", | ||
114 | + }) | ||
115 | + } else { | ||
116 | + | ||
117 | + c.JSON(200, tools.ResponseSeccess{ | ||
118 | + 0, | ||
119 | + Scenic, | ||
120 | + }) | ||
121 | + } | ||
122 | + | ||
123 | +} |
1 | +++ a/API/Shop.go | ||
@@ -0,0 +1,113 @@ | @@ -0,0 +1,113 @@ | ||
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 | +) | ||
10 | + | ||
11 | +// @Title 查询商品信息 | ||
12 | +// @Description 查询商品信息 | ||
13 | +// @Accept json | ||
14 | +// @Produce json | ||
15 | +// @Param id 5dfb03070a9ac17ac7a82054 string true "id" | ||
16 | +// @Success 200 {object} tools.ResponseSeccess "Price=价格;ShopName=店铺名称;KvPhoto用于列表页的图片;TopPhoto详情页最上面的轮播图;Images详情页下面的产品详细图" | ||
17 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
18 | +// @Router /CommodityInfo? [get] | ||
19 | +func CommodityInfo(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 | + if c.Query("id") == "" { | ||
24 | + c.JSON(200, tools.ResponseError{ | ||
25 | + 1, | ||
26 | + "空", | ||
27 | + }) | ||
28 | + return | ||
29 | + } | ||
30 | + | ||
31 | + var SCommodity *DB.SCommodity | ||
32 | + DB.CCommodity.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&SCommodity) | ||
33 | + | ||
34 | + if SCommodity == nil { | ||
35 | + | ||
36 | + c.JSON(200, tools.ResponseError{ | ||
37 | + 1, | ||
38 | + "空", | ||
39 | + }) | ||
40 | + } else { | ||
41 | + | ||
42 | + c.JSON(200, tools.ResponseSeccess{ | ||
43 | + 0, | ||
44 | + SCommodity, | ||
45 | + }) | ||
46 | + } | ||
47 | + | ||
48 | +} | ||
49 | + | ||
50 | +// @Title 查询所有商品 | ||
51 | +// @Description 查询所有商品 | ||
52 | +// @Accept json | ||
53 | +// @Produce json | ||
54 | +// @Success 200 {object} tools.ResponseSeccess "Price=价格;ShopName=店铺名称;KvPhoto用于列表页的图片;TopPhoto详情页最上面的轮播图;Images详情页下面的产品详细图" | ||
55 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
56 | +// @Router /AllCommodity? [get] | ||
57 | +func AllCommodity(c *gin.Context) { | ||
58 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
59 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
60 | + | ||
61 | + var aCommoditys []DB.SCommodity | ||
62 | + DB.CCommodity.Find(bson.M{}).All(&aCommoditys) | ||
63 | + | ||
64 | + c.JSON(200, aCommoditys) | ||
65 | + | ||
66 | +} | ||
67 | + | ||
68 | +// @Title 更新商品 | ||
69 | +// @Description 更新商品 | ||
70 | +// @Accept json | ||
71 | +// @Produce json | ||
72 | +// @Success 200 {object} tools.ResponseSeccess "" | ||
73 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
74 | +// @Router /UpdateCommodity? [post] | ||
75 | +func UpdateCommodity(c *gin.Context) { | ||
76 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
77 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
78 | + | ||
79 | + var Picture []string | ||
80 | + json.Unmarshal([]byte(c.PostForm("Images")), &Picture) | ||
81 | + | ||
82 | + var TopPhoto []string | ||
83 | + json.Unmarshal([]byte(c.PostForm("TopPhoto")), &TopPhoto) | ||
84 | + | ||
85 | + var Location DB.SLocation | ||
86 | + json.Unmarshal([]byte(c.PostForm("Location")), &Location) | ||
87 | + | ||
88 | + var id bson.ObjectId | ||
89 | + if pid := c.PostForm("id"); pid == "null" { | ||
90 | + id = bson.NewObjectId() | ||
91 | + } else { | ||
92 | + id = bson.ObjectIdHex(pid) | ||
93 | + } | ||
94 | + | ||
95 | + DB.CCommodity.UpsertId( | ||
96 | + id, | ||
97 | + bson.M{"$set": bson.M{ | ||
98 | + "Name": c.PostForm("Name"), | ||
99 | + "Price": c.PostForm("Price"), | ||
100 | + "ShopName": c.PostForm("ShopName"), | ||
101 | + "KvPhoto": c.PostForm("KvPhoto"), | ||
102 | + "TopPhoto": TopPhoto, | ||
103 | + "Location": Location, | ||
104 | + "Images": Picture, | ||
105 | + }}, | ||
106 | + ) | ||
107 | + | ||
108 | + c.JSON(200, tools.ResponseSeccess{ | ||
109 | + 0, | ||
110 | + "ok", | ||
111 | + }) | ||
112 | + | ||
113 | +} |
1 | +++ a/API/Tag.go | ||
@@ -0,0 +1,105 @@ | @@ -0,0 +1,105 @@ | ||
1 | +package Api | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/aarongao/tools" | ||
5 | + "github.com/gin-gonic/gin" | ||
6 | + "gopkg.in/mgo.v2/bson" | ||
7 | + "letu/DB" | ||
8 | +) | ||
9 | + | ||
10 | +// @Title 标签列表 | ||
11 | +// @Description 标签列表 | ||
12 | +// @Accept json | ||
13 | +// @Produce json | ||
14 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Type":"menu","Name":"服务设施"},{"Type":"normal","Name":"不错"},{"Type":"thrilling","Name":"刺激"},{"Type":"recommend","Name":"必玩"}]}" | ||
15 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
16 | +// @Router /Tags? [get] | ||
17 | +func AllTag(c *gin.Context) { | ||
18 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
19 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
20 | + | ||
21 | + | ||
22 | + var Stags []*DB.STag | ||
23 | + DB.CTags.Find(bson.M{}).All(&Stags) | ||
24 | + | ||
25 | + if Stags == nil { | ||
26 | + | ||
27 | + c.JSON(200, tools.ResponseError{ | ||
28 | + 1, | ||
29 | + "空", | ||
30 | + }) | ||
31 | + } else { | ||
32 | + | ||
33 | + | ||
34 | + c.JSON(200, tools.ResponseSeccess{ | ||
35 | + 0, | ||
36 | + Stags, | ||
37 | + }) | ||
38 | + } | ||
39 | + | ||
40 | +} | ||
41 | + | ||
42 | +// @Title 创建标签 | ||
43 | +// @Description 创建标签 | ||
44 | +// @Accept json | ||
45 | +// @Produce json | ||
46 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Type":"menu","Name":"服务设施"},{"Type":"normal","Name":"不错"},{"Type":"thrilling","Name":"刺激"},{"Type":"recommend","Name":"必玩"}]}" | ||
47 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
48 | +// @Router /CreateTag? [post] | ||
49 | +func CreateTag(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 | + | ||
54 | + var Stags []*DB.STag | ||
55 | + DB.CTags.Find(bson.M{}).All(&Stags) | ||
56 | + | ||
57 | + if Stags == nil { | ||
58 | + | ||
59 | + c.JSON(200, tools.ResponseError{ | ||
60 | + 1, | ||
61 | + "空", | ||
62 | + }) | ||
63 | + } else { | ||
64 | + | ||
65 | + | ||
66 | + c.JSON(200, tools.ResponseSeccess{ | ||
67 | + 0, | ||
68 | + Stags, | ||
69 | + }) | ||
70 | + } | ||
71 | + | ||
72 | +} | ||
73 | + | ||
74 | + | ||
75 | +// @Title 更新标签 | ||
76 | +// @Description 更新标签 | ||
77 | +// @Accept json | ||
78 | +// @Produce json | ||
79 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":[{"Type":"menu","Name":"服务设施"},{"Type":"normal","Name":"不错"},{"Type":"thrilling","Name":"刺激"},{"Type":"recommend","Name":"必玩"}]}" | ||
80 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
81 | +// @Router /UpdateTag? [post] | ||
82 | +func UpdateTag(c *gin.Context) { | ||
83 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
84 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
85 | + | ||
86 | + | ||
87 | + var Stags []*DB.STag | ||
88 | + DB.CTags.Find(bson.M{}).All(&Stags) | ||
89 | + | ||
90 | + if Stags == nil { | ||
91 | + | ||
92 | + c.JSON(200, tools.ResponseError{ | ||
93 | + 1, | ||
94 | + "空", | ||
95 | + }) | ||
96 | + } else { | ||
97 | + | ||
98 | + | ||
99 | + c.JSON(200, tools.ResponseSeccess{ | ||
100 | + 0, | ||
101 | + Stags, | ||
102 | + }) | ||
103 | + } | ||
104 | + | ||
105 | +} |
1 | +++ a/API/Upload.go | ||
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | +package Api | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/aarongao/tools" | ||
6 | + "github.com/gin-gonic/gin" | ||
7 | + "path" | ||
8 | + "strconv" | ||
9 | + "time" | ||
10 | +) | ||
11 | + | ||
12 | +// @Title 上传文件 | ||
13 | +// @Description 上传 | ||
14 | +// @Accept json | ||
15 | +// @Produce json | ||
16 | +// @Param file 1 file true "文件" | ||
17 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"图片地址"}" | ||
18 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
19 | +// @Router /Upload? [post] | ||
20 | +func Upload(c *gin.Context) { | ||
21 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
22 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
23 | + | ||
24 | + file, err := c.FormFile("file") | ||
25 | + if err != nil { | ||
26 | + c.JSON(200, tools.ResponseError{ | ||
27 | + 1, | ||
28 | + "a Bad request", | ||
29 | + }) | ||
30 | + return | ||
31 | + } | ||
32 | + | ||
33 | + fileName := file.Filename | ||
34 | + fileExt := path.Ext(fileName) | ||
35 | + filePath := "Upload/" + strconv.Itoa(int(time.Now().UnixNano())) + fileExt | ||
36 | + | ||
37 | + if err := c.SaveUploadedFile(file, filePath); err != nil { | ||
38 | + fmt.Println(err) | ||
39 | + c.JSON(200, tools.ResponseError{ | ||
40 | + 1, | ||
41 | + "upload file err", | ||
42 | + }) | ||
43 | + return | ||
44 | + } | ||
45 | + c.JSON(200, tools.ResponseSeccess{ | ||
46 | + 0, | ||
47 | + "/" + filePath, | ||
48 | + }) | ||
49 | +} |
1 | +++ a/API/User.go | ||
@@ -0,0 +1,147 @@ | @@ -0,0 +1,147 @@ | ||
1 | +package Api | ||
2 | + | ||
3 | +import ( | ||
4 | + "crypto/sha256" | ||
5 | + "encoding/hex" | ||
6 | + "github.com/aarongao/tools" | ||
7 | + "github.com/gin-gonic/gin" | ||
8 | + "gopkg.in/mgo.v2/bson" | ||
9 | + "letu/DB" | ||
10 | + "strconv" | ||
11 | + "time" | ||
12 | +) | ||
13 | + | ||
14 | +// @Title 创建用户 | ||
15 | +// @Description 用户注册 | ||
16 | +// @Accept json | ||
17 | +// @Produce json | ||
18 | +// @Param password 1 string true "密码" | ||
19 | +// @Param confirmpassword 1 string true "确认密码" | ||
20 | +// @Param birthday 2010.10.10 string true "生日" | ||
21 | +// @Param fullname aarongao string true "全名" | ||
22 | +// @Param mobile 18616619599 string true "手机,同用户名" | ||
23 | +// @Param openid 12345 string true "微信id" | ||
24 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" | ||
25 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
26 | +// @Router /CreateUser? [post] | ||
27 | +func CreateUser(c *gin.Context) { | ||
28 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
29 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
30 | + | ||
31 | + if c.PostForm("mobile") == "" || c.PostForm("password") != c.PostForm("confirmpassword") { | ||
32 | + c.JSON(200, tools.ResponseError{ | ||
33 | + 1, | ||
34 | + "密码错误", | ||
35 | + }) | ||
36 | + return | ||
37 | + } | ||
38 | + | ||
39 | + objectID := bson.NewObjectId() | ||
40 | + DB.CMember.Insert(DB.SMember{ | ||
41 | + &objectID, | ||
42 | + c.PostForm("password"), | ||
43 | + c.PostForm("birthday"), | ||
44 | + c.PostForm("fullname"), | ||
45 | + c.PostForm("mobile"), | ||
46 | + c.PostForm("openid"), | ||
47 | + "", | ||
48 | + }) | ||
49 | + | ||
50 | + c.JSON(200, tools.ResponseSeccess{ | ||
51 | + 0, | ||
52 | + "ok", | ||
53 | + }) | ||
54 | + | ||
55 | +} | ||
56 | + | ||
57 | +// @Title 登录 | ||
58 | +// @Description 用户登录 | ||
59 | +// @Accept json | ||
60 | +// @Produce json | ||
61 | +// @Param mobile aaron string true "用户名" | ||
62 | +// @Param password 1 string true "密码" | ||
63 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Username":"admin","Password":"123","Birthday":"","FullName":"","Mobile":"","Openid":"","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}} 调用其它需要登陆的接口时携带token,有过期时间" | ||
64 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
65 | +// @Router /LoginUser? [post] | ||
66 | +func LoginUser(c *gin.Context) { | ||
67 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
68 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
69 | + | ||
70 | + if c.PostForm("mobile") == "" || c.PostForm("password") == "" { | ||
71 | + c.JSON(200, tools.ResponseError{ | ||
72 | + 1, | ||
73 | + "空", | ||
74 | + }) | ||
75 | + return | ||
76 | + } | ||
77 | + | ||
78 | + var User *DB.SMember | ||
79 | + DB.CMember.Find(bson.M{"Mobile": c.PostForm("mobile"), "Password": c.PostForm("password")}).One(&User) | ||
80 | + | ||
81 | + if User == nil { | ||
82 | + | ||
83 | + c.JSON(200, tools.ResponseError{ | ||
84 | + 1, | ||
85 | + "空", | ||
86 | + }) | ||
87 | + } else { | ||
88 | + | ||
89 | + // 生成token | ||
90 | + tokenunit8 := sha256.Sum256([]byte(c.PostForm("mobile") + c.PostForm("password") + strconv.FormatInt(time.Now().UnixNano(), 10))) | ||
91 | + token := hex.EncodeToString(tokenunit8[:32]) | ||
92 | + // 更新用户信息 | ||
93 | + DB.CMember.Update( | ||
94 | + bson.M{"_id": User.Id}, | ||
95 | + bson.M{"$set": bson.M{"Token": token}}, | ||
96 | + ) | ||
97 | + | ||
98 | + User.Token = token | ||
99 | + c.JSON(200, tools.ResponseSeccess{ | ||
100 | + 0, | ||
101 | + User, | ||
102 | + }) | ||
103 | + } | ||
104 | + | ||
105 | +} | ||
106 | + | ||
107 | + | ||
108 | + | ||
109 | +// @Title 用户信息 | ||
110 | +// @Description 获取用户信息 | ||
111 | +// @Accept json | ||
112 | +// @Produce json | ||
113 | +// @Param id aaron string true "用户id" | ||
114 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Username":"admin","Password":"123","Birthday":"","FullName":"","Mobile":"","Openid":"","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}}" | ||
115 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | ||
116 | +// @Router /UserInfo? [get] | ||
117 | +func UserInfo(c *gin.Context) { | ||
118 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
119 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
120 | + | ||
121 | + if c.Query("id") == ""{ | ||
122 | + c.JSON(200, tools.ResponseError{ | ||
123 | + 1, | ||
124 | + "空", | ||
125 | + }) | ||
126 | + return | ||
127 | + } | ||
128 | + | ||
129 | + var User *DB.SMember | ||
130 | + DB.CMember.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&User) | ||
131 | + | ||
132 | + if User == nil { | ||
133 | + | ||
134 | + c.JSON(200, tools.ResponseError{ | ||
135 | + 1, | ||
136 | + "空", | ||
137 | + }) | ||
138 | + } else { | ||
139 | + | ||
140 | + | ||
141 | + c.JSON(200, tools.ResponseSeccess{ | ||
142 | + 0, | ||
143 | + User, | ||
144 | + }) | ||
145 | + } | ||
146 | + | ||
147 | +} |
1 | +++ a/API/Ws.go | ||
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +package Api | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/gin-gonic/gin" | ||
6 | + "github.com/gorilla/websocket" | ||
7 | + uuid "github.com/satori/go.uuid" | ||
8 | + "letu/Lib/Ws" | ||
9 | +) | ||
10 | + | ||
11 | +var wsupgrader = websocket.Upgrader{ | ||
12 | + ReadBufferSize: 1024, | ||
13 | + WriteBufferSize: 1024, | ||
14 | +} | ||
15 | + | ||
16 | +func WsPage(c *gin.Context) { | ||
17 | + | ||
18 | + conn, err := wsupgrader.Upgrade(c.Writer, c.Request, nil) | ||
19 | + if err != nil { | ||
20 | + fmt.Println("Failed to set websocket upgrade: %+v", err) | ||
21 | + return | ||
22 | + } | ||
23 | + | ||
24 | + // websocket connect | ||
25 | + _uuid, _ := uuid.NewV4() | ||
26 | + client := &Ws.Client{ | ||
27 | + _uuid.String(), | ||
28 | + conn, | ||
29 | + } | ||
30 | + | ||
31 | + Ws.Manager.Register <- client | ||
32 | + | ||
33 | + for { | ||
34 | + _, msg, err := conn.ReadMessage() | ||
35 | + if err != nil { | ||
36 | + println(err.Error()) | ||
37 | + Ws.Manager.Unregister <- client | ||
38 | + client.Socket.Close() | ||
39 | + break | ||
40 | + } | ||
41 | + | ||
42 | + sMsg := string(msg) | ||
43 | + println("收到消息:", sMsg) | ||
44 | + | ||
45 | + switch sMsg { | ||
46 | + case "test": | ||
47 | + client.Send([]byte("hahaha")) | ||
48 | + case "test2": | ||
49 | + client.Send([]byte("hahaha2")) | ||
50 | + | ||
51 | + | ||
52 | + } | ||
53 | + | ||
54 | + | ||
55 | + | ||
56 | + } | ||
57 | + | ||
58 | +} |
1 | +++ a/DB/db.go | ||
@@ -0,0 +1,93 @@ | @@ -0,0 +1,93 @@ | ||
1 | +package DB | ||
2 | + | ||
3 | +import ( | ||
4 | + "gopkg.in/mgo.v2" | ||
5 | + "gopkg.in/mgo.v2/bson" | ||
6 | +) | ||
7 | + | ||
8 | +var DBSession *mgo.Session | ||
9 | +var CItem *mgo.Collection //所有游玩项目内容 | ||
10 | +var CComplaint *mgo.Collection //投诉 | ||
11 | +var CInvestigation *mgo.Collection //调查 | ||
12 | +var CMember *mgo.Collection //会员 | ||
13 | +var CCommodity *mgo.Collection //商城 | ||
14 | +var CTags *mgo.Collection //标签 | ||
15 | +var CScenic *mgo.Collection //景区 | ||
16 | +var CLine *mgo.Collection //推荐线路 | ||
17 | +var DB *mgo.Database | ||
18 | + | ||
19 | +type SItem struct { | ||
20 | + Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` | ||
21 | + Name string `bson:"Name" json:"Name"` | ||
22 | + SubName string `bson:"SubName" json:"SubName"` | ||
23 | + Location SLocation `bson:"Location" json:"Location"` | ||
24 | + Tags []STag `bson:"Tags" json:"Tags"` | ||
25 | + Icon string `bson:"Icon" json:"Icon"` | ||
26 | + LimitHeight string `bson:"LimitHeight" json:"LimitHeight"` | ||
27 | + PlayDuration string `bson:"PlayDuration" json:"PlayDuration"` | ||
28 | + SceneTime string `bson:"SceneTime" json:"SceneTime"` | ||
29 | + Picture []string `bson:"Picture" json:"Picture"` | ||
30 | + Voice string `bson:"Voice" json:"Voice"` | ||
31 | + Tel string `bson:"Tel" json:"Tel"` | ||
32 | + AverageConsumption string `bson:"AverageConsumption" json:"AverageConsumption"` | ||
33 | + Menu string `bson:"Menu" json:"Menu"` | ||
34 | + Time string `bson:"Time" json:"Time"` | ||
35 | +} | ||
36 | +type SLocation struct { | ||
37 | + Latitude float64 `bson:"Latitude" json:"Latitude"` | ||
38 | + Longitude float64 `bson:"Longitude" json:"Longitude"` | ||
39 | +} | ||
40 | +type SCommodity struct { | ||
41 | + Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` | ||
42 | + Name string `bson:"Name" json:"Name"` | ||
43 | + Price string `bson:"Price" json:"Price"` | ||
44 | + ShopName string `bson:"ShopName" json:"ShopName"` | ||
45 | + Location SLocation `bson:"Location" json:"Location"` | ||
46 | + KvPhoto string `bson:"KvPhoto" json:"KvPhoto"` | ||
47 | + TopPhoto []string `bson:"TopPhoto" json:"TopPhoto"` | ||
48 | + Images []string `bson:"Images" json:"Images"` | ||
49 | +} | ||
50 | +type SLine struct { | ||
51 | + Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` | ||
52 | + Name string `bson:"Name" json:"Name"` | ||
53 | + SubName string `bson:"SubName" json:"SubName"` | ||
54 | + Location []SLocation `bson:"Location" json:"Location"` | ||
55 | + PlayDuration string `bson:"PlayDuration" json:"PlayDuration"` | ||
56 | + Suitable string `bson:"Suitable" json:"Suitable"` | ||
57 | + Content string `bson:"Content" json:"Content"` | ||
58 | + Annotations []string `bson:"Annotations" json:"Annotations"` | ||
59 | +} | ||
60 | + | ||
61 | +type SComplaint struct { | ||
62 | + Type string `bson:"Type" json:"Type"` | ||
63 | + Mobile string `bson:"Mobile" json:"Mobile"` | ||
64 | + Content string `bson:"Content" json:"Content"` | ||
65 | + Image []string `bson:"Image" json:"Image"` | ||
66 | +} | ||
67 | + | ||
68 | +type SInvestigation struct { | ||
69 | +} | ||
70 | +type SMember struct { | ||
71 | + Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` | ||
72 | + Password string `bson:"Password" json:"Password"` | ||
73 | + Birthday string `bson:"Birthday" json:"Birthday"` | ||
74 | + FullName string `bson:"FullName" json:"FullName"` | ||
75 | + Mobile string `bson:"Mobile" json:"Mobile"` | ||
76 | + Openid string `bson:"Openid" json:"Openid"` | ||
77 | + Token string `bson:"Token" json:"Token"` | ||
78 | +} | ||
79 | + | ||
80 | +type STag struct { | ||
81 | + Type string `bson:"Type" json:"Type"` | ||
82 | + Name string `bson:"Name" json:"Name"` | ||
83 | +} | ||
84 | +type SScenic struct { | ||
85 | + Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` | ||
86 | + Name string `bson:"Name" json:"Name"` | ||
87 | + Describe string `bson:"Describe" json:"Describe"` | ||
88 | + OpenHours string `bson:"OpenHours" json:"OpenHours"` | ||
89 | + Mobile string `bson:"Mobile" json:"Mobile"` | ||
90 | + Address string `bson:"Address" json:"Address"` | ||
91 | + Location SLocation `bson:"Location" json:"Location"` | ||
92 | + Picture []string `bson:"Picture" json:"Picture"` | ||
93 | +} |
1 | +++ a/Lib/Ws/Ws.go | ||
@@ -0,0 +1,71 @@ | @@ -0,0 +1,71 @@ | ||
1 | +package Ws | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "github.com/gorilla/websocket" | ||
6 | +) | ||
7 | + | ||
8 | +// ClientManager is a websocket manager | ||
9 | +type ClientManager struct { | ||
10 | + Clients map[*Client]bool | ||
11 | + Broadcast chan []byte | ||
12 | + Register chan *Client | ||
13 | + Unregister chan *Client | ||
14 | +} | ||
15 | + | ||
16 | +// Client is a websocket client | ||
17 | +type Client struct { | ||
18 | + ID string | ||
19 | + Socket *websocket.Conn | ||
20 | +} | ||
21 | + | ||
22 | +// Message is an object for websocket message which is mapped to json type | ||
23 | +type Message struct { | ||
24 | + Sender string `json:"sender,omitempty"` | ||
25 | + Recipient string `json:"recipient,omitempty"` | ||
26 | + Content string `json:"content,omitempty"` | ||
27 | +} | ||
28 | + | ||
29 | +// Manager define a ws server manager | ||
30 | +var Manager = ClientManager{ | ||
31 | + Broadcast: make(chan []byte), | ||
32 | + Register: make(chan *Client), | ||
33 | + Unregister: make(chan *Client), | ||
34 | + Clients: make(map[*Client]bool), | ||
35 | +} | ||
36 | + | ||
37 | +// Start is to start a ws server | ||
38 | +func (manager *ClientManager) Start() { | ||
39 | + for { | ||
40 | + select { | ||
41 | + case conn := <-manager.Register: | ||
42 | + manager.Clients[conn] = true | ||
43 | + jsonMessage, _ := json.Marshal(&Message{Content: "/A new socket has connected."}) | ||
44 | + manager.Send(jsonMessage, conn) | ||
45 | + case conn := <-manager.Unregister: | ||
46 | + if _, ok := manager.Clients[conn]; ok { | ||
47 | + delete(manager.Clients, conn) | ||
48 | + jsonMessage, _ := json.Marshal(&Message{Content: "/A socket has disconnected."}) | ||
49 | + manager.Send(jsonMessage, conn) | ||
50 | + } | ||
51 | + case message := <-manager.Broadcast: | ||
52 | + for conn := range manager.Clients { | ||
53 | + conn.Socket.WriteMessage(1, message) | ||
54 | + } | ||
55 | + } | ||
56 | + } | ||
57 | +} | ||
58 | + | ||
59 | +// Send is to send ws message to ws client | ||
60 | +func (manager *ClientManager) Send(message []byte, ignore *Client) { | ||
61 | + for conn := range manager.Clients { | ||
62 | + if conn != ignore { | ||
63 | + conn.Socket.WriteMessage(1, message) | ||
64 | + } | ||
65 | + } | ||
66 | +} | ||
67 | + | ||
68 | + | ||
69 | +func (c *Client) Send(message []byte) { | ||
70 | + c.Socket.WriteMessage(websocket.TextMessage, message) | ||
71 | +} | ||
0 | \ No newline at end of file | 72 | \ No newline at end of file |
1 | +++ a/main.go | ||
@@ -0,0 +1,76 @@ | @@ -0,0 +1,76 @@ | ||
1 | +package main | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "github.com/aarongao/tools" | ||
6 | + "github.com/gin-gonic/gin" | ||
7 | + "gopkg.in/mgo.v2" | ||
8 | + "letu/Api" | ||
9 | + "letu/Config" | ||
10 | + "letu/DB" | ||
11 | + "letu/Lib/Ws" | ||
12 | + "os" | ||
13 | +) | ||
14 | + | ||
15 | +// @APIVersion 1.0.0 | ||
16 | +// @APITitle 乐游图后端接口文档 | ||
17 | +// @BasePath https://letu.api.imagchina.com | ||
18 | +func main() { | ||
19 | + | ||
20 | + // 读取配置文件 | ||
21 | + dir, _ := os.Getwd() | ||
22 | + //println(dir) | ||
23 | + file, _ := os.Open(dir + "/Config/config.json") | ||
24 | + defer file.Close() | ||
25 | + decoder := json.NewDecoder(file) | ||
26 | + conf := Config.Config{} | ||
27 | + err := decoder.Decode(&conf) | ||
28 | + tools.CheckError(err) | ||
29 | + | ||
30 | + // 连接数据库 | ||
31 | + DB.DBSession, err = mgo.Dial(conf.DbPath) | ||
32 | + defer DB.DBSession.Close() | ||
33 | + //设置模式 | ||
34 | + DB.DBSession.SetMode(mgo.Monotonic, true) | ||
35 | + //获取文档集 | ||
36 | + DB.DB = DB.DBSession.DB("LeYouTu") | ||
37 | + DB.CItem = DB.DB.C("Item") | ||
38 | + DB.CComplaint = DB.DB.C("Complaint") | ||
39 | + DB.CInvestigation = DB.DB.C("Investigation") | ||
40 | + DB.CMember = DB.DB.C("Member") | ||
41 | + DB.CCommodity = DB.DB.C("Commodity") | ||
42 | + DB.CTags = DB.DB.C("Tags") | ||
43 | + DB.CScenic = DB.DB.C("Scenic") | ||
44 | + DB.CLine = DB.DB.C("Line") | ||
45 | + | ||
46 | + r := gin.Default() | ||
47 | + //r.Static("/.well-known", "./.well-known/") | ||
48 | + r.Static("/tiles", dir+"/tiles") | ||
49 | + r.GET("/AllItems", Api.AllItems) | ||
50 | + r.GET("/AllCommodity", Api.AllCommodity) | ||
51 | + r.GET("/AllLine", Api.AllLine) | ||
52 | + r.GET("/ItemInfo", Api.ItemInfo) | ||
53 | + r.GET("/CommodityInfo", Api.CommodityInfo) | ||
54 | + r.POST("/CreateComplaint", Api.CreateComplaint) | ||
55 | + r.POST("/CreateUser", Api.CreateUser) | ||
56 | + r.POST("/LoginUser", Api.LoginUser) | ||
57 | + r.GET("/UserInfo", Api.UserInfo) | ||
58 | + r.GET("/ScenicInfo", Api.ScenicInfo) | ||
59 | + r.GET("/LineInfo", Api.LineInfo) | ||
60 | + r.GET("/AllTag", Api.AllTag) | ||
61 | + r.POST("/CreateTag", Api.CreateTag) | ||
62 | + r.POST("/UpdateTag", Api.UpdateTag) | ||
63 | + r.POST("/Upload", Api.Upload) | ||
64 | + r.POST("/UpdateItem", Api.UpdateItem) | ||
65 | + r.POST("/UpdateCommodity", Api.UpdateCommodity) | ||
66 | + r.POST("/UpdateLine", Api.UpdateLine) | ||
67 | + r.POST("/UpdateScenic", Api.UpdateScenic) | ||
68 | + r.POST("/UpdateItemTime", Api.UpdateItemTime) | ||
69 | + r.GET("/AllScenic", Api.AllScenic) | ||
70 | + //r.GET("/ws", Api.WsPage) | ||
71 | + | ||
72 | + r.Static("/Upload", "./Upload") | ||
73 | + r.Static("/Console", "./Console") | ||
74 | + go Ws.Manager.Start() | ||
75 | + r.Run(":8080") | ||
76 | +} |