Scenic.go
9.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
package Api
import (
"encoding/json"
"github.com/aarongao/tools"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
"letu/Lib/Auth"
"strconv"
)
// @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=首桢图片);InvestigationUrl问券调查的url;RangeLocation景区范围(多个坐标点)ZoomForIOS地图的缩放大小(IOS);ZoomForAndroidMin地图的缩放大小(Android最小);ZoomForAndroidMax地图的缩放大小(Android最大);Rotation旋转角度;OpenTiles否开启地图切片;ColorTiles切片底色(#FFFFFF)"
// @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
objID, _ := primitive.ObjectIDFromHex(c.Query("id"))
DB.CScenic.FindOne(tools.GetContext(), bson.M{"_id": objID}).Decode(&Scenic)
c.JSON(200, tools.ResponseSeccess{
0,
Scenic,
})
}
// @Title 更新景区基础信息
// @Description 更新景区基础信息
// @Accept json
// @Produce json
// @Param id 5dfb03070a9ac17ac7a82054 string true "景区id"
// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "Name名称;Describe介绍;OpenHours营业时间;Picture最上面图片;ShopAdPicture商城列表页图片;ItemScenicPicture项目场次照片;ActivityPicture活动照片;VideoList视频(VideoPicture=首桢图片);InvestigationUrl问券调查的url;"
// @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")
_user, _ := c.Get("UserInfo")
user := _user.(*DB.SMember)
err := Auth.CheckScenicAuth(c.PostForm("id"), user)
if err != nil {
c.JSON(200, tools.ResponseError{
401,
"没有权限",
})
return
}
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 primitive.ObjectID
if pid := c.PostForm("id"); pid == "null" {
if user.UserType != "root" {
c.JSON(200, tools.ResponseError{
401,
"没有权限",
})
return
}
id = primitive.NewObjectID()
// 新景区,初始化
initScenic(id.Hex())
} else {
id, _ = primitive.ObjectIDFromHex(pid)
}
upsert := true
DB.CScenic.FindOneAndUpdate(tools.GetContext(),
bson.M{"_id": id},
bson.M{"$set": bson.M{
"Name": c.PostForm("Name"),
"Describe": c.PostForm("Describe"),
"OpenHours": c.PostForm("OpenHours"),
"Mobile": c.PostForm("Mobile"),
"Address": c.PostForm("Address"),
"InvestigationUrl": c.PostForm("InvestigationUrl"),
"Picture": Picture,
"ShopAdPicture": ShopAdPicture,
"ItemScenicPicture": ItemScenicPicture,
"ActivityPicture": ActivityPicture,
"VideoList": VideoList,
}}, &options.FindOneAndUpdateOptions{
Upsert: &upsert,
},
)
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
})
}
// @Title 更新景区基础信息-高级
// @Description 更新景区基础信息-高级
// @Accept json
// @Produce json
// @Param id 5dfb03070a9ac17ac7a82054 string true "景区id"
// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "RangeLocation景区范围(多个坐标点)ZoomForIOS地图的缩放大小(IOS);ZoomForAndroidMin地图的缩放大小(Android最小);ZoomForAndroidMax地图的缩放大小(Android最大);Rotation旋转角度;OpenTiles否开启地图切片;ColorTiles切片底色(#FFFFFF)"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /UpdateScenicSenior? [post]
func UpdateScenicSenior(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
_user, _ := c.Get("UserInfo")
user := _user.(*DB.SMember)
err := Auth.CheckScenicAuth(c.PostForm("id"), user)
if err != nil {
c.JSON(200, tools.ResponseError{
401,
"没有权限",
})
return
}
var Location DB.SLocation
json.Unmarshal([]byte(c.PostForm("Location")), &Location)
var RangeLocation []DB.SLocation
json.Unmarshal([]byte(c.PostForm("RangeLocation")), &RangeLocation)
var ZoomForIOS DB.SRange
json.Unmarshal([]byte(c.PostForm("ZoomForIOS")), &ZoomForIOS)
var ZoomForAndroidMin []DB.SLocation
json.Unmarshal([]byte(c.PostForm("ZoomForAndroidMin")), &ZoomForAndroidMin)
var ZoomForAndroidMax []DB.SLocation
json.Unmarshal([]byte(c.PostForm("ZoomForAndroidMax")), &ZoomForAndroidMax)
var id primitive.ObjectID
if pid := c.PostForm("id"); pid == "null" {
if user.UserType != "root" {
c.JSON(200, tools.ResponseError{
401,
"没有权限",
})
return
}
id = primitive.NewObjectID()
// 新景区,初始化
initScenic(id.Hex())
} else {
id, _ = primitive.ObjectIDFromHex(pid)
}
Rotation, err := strconv.ParseFloat(c.PostForm("Rotation"), 64)
OpenTiles, err := strconv.ParseBool(c.PostForm("OpenTiles"))
Display, _ := strconv.ParseBool(c.PostForm("Display"))
upsert := true
DB.CScenic.FindOneAndUpdate(tools.GetContext(),
bson.M{"_id": id},
bson.M{"$set": bson.M{
"Location": Location,
"RangeLocation": RangeLocation,
"ZoomForIOS": ZoomForIOS,
"ZoomForAndroidMin": ZoomForAndroidMin,
"ZoomForAndroidMax": ZoomForAndroidMax,
"Rotation": Rotation,
"OpenTiles": OpenTiles,
"ColorTiles": c.PostForm("ColorTiles"),
"Display": Display,
"Remove": false,
}}, &options.FindOneAndUpdateOptions{
Upsert: &upsert,
},
)
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
})
}
func initScenic(id string) {
var dba []interface{}
dba = append(dba, DB.STag{
id,
"type",
"服务设施",
})
dba = append(dba, DB.STag{
id,
"type",
"普通",
})
dba = append(dba, DB.STag{
id,
"type",
"演出",
})
dba = append(dba, DB.STag{
id,
"type",
"购物",
})
dba = append(dba, DB.STag{
id,
"type",
"餐饮",
})
dba = append(dba, DB.STag{
id,
"type",
"游乐设施",
})
dba = append(dba, DB.STag{
id,
"age",
"儿童",
})
dba = append(dba, DB.STag{
id,
"age",
"成人",
})
dba = append(dba, DB.STag{
id,
"age",
"青少年",
})
dba = append(dba, DB.STag{
id,
"food",
"海鲜",
})
dba = append(dba, DB.STag{
id,
"food",
"团餐",
})
dba = append(dba, DB.STag{
id,
"food",
"烧烤",
})
dba = append(dba, DB.STag{
id,
"food",
"小吃",
})
dba = append(dba, DB.STag{
id,
"recommend",
"必玩",
})
dba = append(dba, DB.STag{
id,
"shop",
"纪念品",
})
dba = append(dba, DB.STag{
id,
"shop",
"收藏品",
})
dba = append(dba, DB.STag{
id,
"shop",
"玩具",
})
dba = append(dba, DB.STag{
id,
"thrilling",
"刺激",
})
dba = append(dba, DB.STag{
id,
"thrilling",
"放松",
})
DB.CTags.InsertMany(tools.GetContext(), dba[1:])
}
// @Title 所有景区基础信息
// @Description 所有景区基础信息
// @Accept json
// @Produce json
// @Param Display true string true "true=显示隐藏数据"
// @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")
_select := bson.M{"Display": true}
if c.Query("Display") == "all"{
_select = bson.M{}
}
var Scenic []DB.SScenic
cur, err := DB.CScenic.Find(tools.GetContext(), _select)
defer cur.Close(tools.GetContext())
if err == nil {
for cur.Next(tools.GetContext()) {
var e DB.SScenic
cur.Decode(&e)
Scenic = append(Scenic, e)
}
}
if Scenic == nil {
Scenic = []DB.SScenic{}
}
c.JSON(200, tools.ResponseSeccess{
0,
Scenic,
})
}