Commit 1ba7e43412424bd2518024050fda3f4c0ac96352
1 parent
7cce0d4a
Exists in
v1.2
and in
2 other branches
..
Showing
6 changed files
with
90 additions
and
20 deletions
Show diff stats
API/Complaint.go
... | ... | @@ -5,6 +5,7 @@ import ( |
5 | 5 | "github.com/aarongao/tools" |
6 | 6 | "github.com/gin-gonic/gin" |
7 | 7 | "letu/DB" |
8 | + "regexp" | |
8 | 9 | ) |
9 | 10 | |
10 | 11 | // @Title 增加投诉 |
... | ... | @@ -12,6 +13,10 @@ import ( |
12 | 13 | // @Accept json |
13 | 14 | // @Produce json |
14 | 15 | // @Param mobile 18616619599 string true "联系电话" |
16 | +// @Param name 高先生 string true "姓名" | |
17 | +// @Param code 123456 string true "验证码" | |
18 | +// @Param sex 男 string true "性别" | |
19 | +// @Param scenicid 5e1ed07524e03431008b4572 string true "景区id" | |
15 | 20 | // @Param type 1 string true "类型" |
16 | 21 | // @Param content 卫生不干净 string true "投诉内容" |
17 | 22 | // @Param image ["http://www.xx.com/123.jpg","http://www.xx.com/123.jpg"] string true "照片数组" |
... | ... | @@ -23,13 +28,53 @@ func CreateComplaint(c *gin.Context) { |
23 | 28 | c.Header("Access-Control-Allow-Credentials","true") |
24 | 29 | |
25 | 30 | |
31 | + | |
32 | + reg := regexp.MustCompile(Regular) | |
33 | + if !reg.MatchString(c.PostForm("mobile")) { | |
34 | + | |
35 | + c.JSON(200, tools.ResponseError{ | |
36 | + 1, | |
37 | + "手机号格式不正确", | |
38 | + }) | |
39 | + return | |
40 | + } | |
41 | + | |
42 | + if c.PostForm("mobile") == ""{ | |
43 | + c.JSON(200, tools.ResponseError{ | |
44 | + 1, | |
45 | + "手机号为空", | |
46 | + }) | |
47 | + return | |
48 | + } | |
49 | + | |
50 | + | |
51 | + // 检查验证码 | |
52 | + cacheCode := DB.Redis.Get(c.PostForm("mobile")) | |
53 | + if cacheCode != c.PostForm("code") { | |
54 | + | |
55 | + c.JSON(200, tools.ResponseError{ | |
56 | + 1, | |
57 | + "验证码不正确", | |
58 | + }) | |
59 | + return | |
60 | + | |
61 | + } | |
62 | + | |
63 | + | |
64 | + | |
65 | + | |
66 | + | |
67 | + | |
26 | 68 | var images []string |
27 | 69 | |
28 | 70 | json.Unmarshal([]byte(c.PostForm("image")), &images) |
29 | 71 | |
30 | 72 | DB.CComplaint.Insert(DB.SComplaint{ |
31 | 73 | c.PostForm("type"), |
74 | + c.PostForm("scenicid"), | |
32 | 75 | c.PostForm("mobile"), |
76 | + c.PostForm("name"), | |
77 | + c.PostForm("sex"), | |
33 | 78 | c.PostForm("content"), |
34 | 79 | images, |
35 | 80 | }) | ... | ... |
API/Shop.go
... | ... | @@ -70,7 +70,7 @@ func UpdateCommodity(c *gin.Context) { |
70 | 70 | var Picture []string |
71 | 71 | json.Unmarshal([]byte(c.PostForm("Images")), &Picture) |
72 | 72 | |
73 | - var TopPhoto []string | |
73 | + var TopPhoto []DB.SPicture | |
74 | 74 | json.Unmarshal([]byte(c.PostForm("TopPhoto")), &TopPhoto) |
75 | 75 | |
76 | 76 | //var Location DB.SLocation | ... | ... |
API/User.go
... | ... | @@ -137,6 +137,7 @@ func LoginUser(c *gin.Context) { |
137 | 137 | c.PostForm("mobile"), |
138 | 138 | "", |
139 | 139 | token, |
140 | + "", | |
140 | 141 | } |
141 | 142 | DB.CMember.Insert(oUser) |
142 | 143 | //if err == nil { |
... | ... | @@ -187,7 +188,6 @@ func UserInfo(c *gin.Context) { |
187 | 188 | c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) |
188 | 189 | c.Header("Access-Control-Allow-Credentials", "true") |
189 | 190 | |
190 | - | |
191 | 191 | if c.Query("id") == "" { |
192 | 192 | c.JSON(200, tools.ResponseError{ |
193 | 193 | 1, |
... | ... | @@ -216,6 +216,7 @@ func UserInfo(c *gin.Context) { |
216 | 216 | // @Param fullname aarongao string true "全名" |
217 | 217 | // @Param code 12345678 string true "6位验证码" |
218 | 218 | // @Param mobile 18616619599 string true "手机,同用户名" |
219 | +// @Param sex 男 string true "性别" | |
219 | 220 | // @Param openid 12345 string true "微信id" |
220 | 221 | // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" |
221 | 222 | // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" |
... | ... | @@ -233,6 +234,15 @@ func UpdateUser(c *gin.Context) { |
233 | 234 | }) |
234 | 235 | return |
235 | 236 | } |
237 | + | |
238 | + if c.PostForm("mobile") == "" || c.PostForm("password") == "" { | |
239 | + c.JSON(200, tools.ResponseError{ | |
240 | + 1, | |
241 | + "手机号或密码为空", | |
242 | + }) | |
243 | + return | |
244 | + } | |
245 | + | |
236 | 246 | if c.PostForm("password") != c.PostForm("confirmpassword") { |
237 | 247 | c.JSON(200, tools.ResponseError{ |
238 | 248 | 1, |
... | ... | @@ -251,25 +261,30 @@ func UpdateUser(c *gin.Context) { |
251 | 261 | return |
252 | 262 | } |
253 | 263 | |
254 | - objectID := bson.NewObjectId() | |
255 | - err := DB.CMember.Insert(DB.SMember{ | |
256 | - &objectID, | |
257 | - c.PostForm("password"), | |
258 | - c.PostForm("birthday"), | |
259 | - c.PostForm("fullname"), | |
260 | - c.PostForm("mobile"), | |
261 | - c.PostForm("openid"), | |
262 | - "", | |
263 | - }) | |
264 | + err := DB.CMember.Update( | |
265 | + bson.M{"Mobile": c.PostForm("mobile")}, | |
266 | + bson.M{"$set": bson.M{ | |
267 | + "Password": c.PostForm("password"), | |
268 | + "Birthday": c.PostForm("birthday"), | |
269 | + "FullName": c.PostForm("fullname"), | |
270 | + "Mobile": c.PostForm("mobile"), | |
271 | + "Sex": c.PostForm("sex"), | |
272 | + }}, | |
273 | + ) | |
274 | + | |
264 | 275 | if err == nil { |
276 | + | |
277 | + var User *DB.SMember | |
278 | + DB.CMember.Find(bson.M{"Mobile": c.PostForm("mobile")}).One(&User) | |
279 | + | |
265 | 280 | c.JSON(200, tools.ResponseSeccess{ |
266 | 281 | 0, |
267 | - "ok", | |
282 | + User, | |
268 | 283 | }) |
269 | 284 | } else { |
270 | 285 | c.JSON(200, tools.ResponseError{ |
271 | - 0, | |
272 | - "此手机号已经注册", | |
286 | + 1, | |
287 | + err.Error(), | |
273 | 288 | }) |
274 | 289 | } |
275 | 290 | ... | ... |
DB/db.go
... | ... | @@ -75,7 +75,7 @@ type SCommodity struct { |
75 | 75 | ShopName string `bson:"ShopName" json:"ShopName"` |
76 | 76 | ItemId string `bson:"ItemId" json:"ItemId"` //项目id |
77 | 77 | KvPhoto string `bson:"KvPhoto" json:"KvPhoto"` //用于列表页的图片 |
78 | - TopPhoto []string `bson:"TopPhoto" json:"TopPhoto"` //详情页最上面的轮播图 | |
78 | + TopPhoto []SPicture `bson:"TopPhoto" json:"TopPhoto"` //详情页最上面的轮播图 | |
79 | 79 | Images []string `bson:"Images" json:"Images"` //详情页下面的产品详细图 |
80 | 80 | } |
81 | 81 | type SLine struct { |
... | ... | @@ -91,10 +91,13 @@ type SLine struct { |
91 | 91 | } |
92 | 92 | |
93 | 93 | type SComplaint struct { |
94 | - Type string `bson:"Type" json:"Type"` | |
95 | - Mobile string `bson:"Mobile" json:"Mobile"` | |
96 | - Content string `bson:"Content" json:"Content"` | |
97 | - Image []string `bson:"Image" json:"Image"` | |
94 | + Type string `bson:"Type" json:"Type"` | |
95 | + ScenicId string `bson:"ScenicId" json:"ScenicId"` // 景区id | |
96 | + Mobile string `bson:"Mobile" json:"Mobile"` | |
97 | + FullName string `bson:"FullName" json:"FullName"` | |
98 | + Sex string `bson:"Sex" json:"Sex"` | |
99 | + Content string `bson:"Content" json:"Content"` | |
100 | + Image []string `bson:"Image" json:"Image"` | |
98 | 101 | } |
99 | 102 | |
100 | 103 | type SInvestigation struct { |
... | ... | @@ -110,6 +113,7 @@ type SMember struct { |
110 | 113 | Mobile string `bson:"Mobile" json:"Mobile"` |
111 | 114 | Openid string `bson:"Openid" json:"Openid"` |
112 | 115 | Token string `bson:"Token" json:"Token"` |
116 | + Sex string `bson:"Sex" json:"Sex"` | |
113 | 117 | } |
114 | 118 | |
115 | 119 | type STag struct { | ... | ... |
README.md
... | ... | @@ -146,6 +146,10 @@ |
146 | 146 | | Param Name | Example | Data Type | Description | Required? | |
147 | 147 | |-----|-----|-----|-----|-----| |
148 | 148 | | mobile | 18616619599 | string | 联系电话 | Yes | |
149 | +| name | 高先生 | string | 姓名 | Yes | | |
150 | +| code | 123456 | string | 验证码 | Yes | | |
151 | +| sex | 男 | string | 性别 | Yes | | |
152 | +| scenicid | 5e1ed07524e03431008b4572 | string | 景区id | Yes | | |
149 | 153 | | type | 1 | string | 类型 | Yes | |
150 | 154 | | content | 卫生不干净 | string | 投诉内容 | Yes | |
151 | 155 | | image | ["http://www.xx.com/123.jpg","http://www.xx.com/123.jpg"] | string | 照片数组 | Yes | |
... | ... | @@ -446,6 +450,7 @@ |
446 | 450 | | fullname | aarongao | string | 全名 | Yes | |
447 | 451 | | code | 12345678 | string | 6位验证码 | Yes | |
448 | 452 | | mobile | 18616619599 | string | 手机,同用户名 | Yes | |
453 | +| sex | 男 | string | 性别 | Yes | | |
449 | 454 | | openid | 12345 | string | 微信id | Yes | |
450 | 455 | |
451 | 456 | ... | ... |
main.go
... | ... | @@ -75,6 +75,7 @@ func main() { |
75 | 75 | r.POST("/CreateComplaint", Api.CreateComplaint) |
76 | 76 | //r.POST("/CreateUser", Api.CreateUser) |
77 | 77 | r.POST("/LoginUser", Api.LoginUser) |
78 | + r.POST("/UpdateUser", Api.UpdateUser) | |
78 | 79 | r.GET("/UserInfo", Api.UserInfo) |
79 | 80 | r.GET("/ScenicInfo", Api.ScenicInfo) |
80 | 81 | r.GET("/LineInfo", Api.LineInfo) | ... | ... |