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,6 +5,7 @@ import ( | ||
| 5 | "github.com/aarongao/tools" | 5 | "github.com/aarongao/tools" |
| 6 | "github.com/gin-gonic/gin" | 6 | "github.com/gin-gonic/gin" |
| 7 | "letu/DB" | 7 | "letu/DB" |
| 8 | + "regexp" | ||
| 8 | ) | 9 | ) |
| 9 | 10 | ||
| 10 | // @Title 增加投诉 | 11 | // @Title 增加投诉 |
| @@ -12,6 +13,10 @@ import ( | @@ -12,6 +13,10 @@ import ( | ||
| 12 | // @Accept json | 13 | // @Accept json |
| 13 | // @Produce json | 14 | // @Produce json |
| 14 | // @Param mobile 18616619599 string true "联系电话" | 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 | // @Param type 1 string true "类型" | 20 | // @Param type 1 string true "类型" |
| 16 | // @Param content 卫生不干净 string true "投诉内容" | 21 | // @Param content 卫生不干净 string true "投诉内容" |
| 17 | // @Param image ["http://www.xx.com/123.jpg","http://www.xx.com/123.jpg"] string true "照片数组" | 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,13 +28,53 @@ func CreateComplaint(c *gin.Context) { | ||
| 23 | c.Header("Access-Control-Allow-Credentials","true") | 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 | var images []string | 68 | var images []string |
| 27 | 69 | ||
| 28 | json.Unmarshal([]byte(c.PostForm("image")), &images) | 70 | json.Unmarshal([]byte(c.PostForm("image")), &images) |
| 29 | 71 | ||
| 30 | DB.CComplaint.Insert(DB.SComplaint{ | 72 | DB.CComplaint.Insert(DB.SComplaint{ |
| 31 | c.PostForm("type"), | 73 | c.PostForm("type"), |
| 74 | + c.PostForm("scenicid"), | ||
| 32 | c.PostForm("mobile"), | 75 | c.PostForm("mobile"), |
| 76 | + c.PostForm("name"), | ||
| 77 | + c.PostForm("sex"), | ||
| 33 | c.PostForm("content"), | 78 | c.PostForm("content"), |
| 34 | images, | 79 | images, |
| 35 | }) | 80 | }) |
API/Shop.go
| @@ -70,7 +70,7 @@ func UpdateCommodity(c *gin.Context) { | @@ -70,7 +70,7 @@ func UpdateCommodity(c *gin.Context) { | ||
| 70 | var Picture []string | 70 | var Picture []string |
| 71 | json.Unmarshal([]byte(c.PostForm("Images")), &Picture) | 71 | json.Unmarshal([]byte(c.PostForm("Images")), &Picture) |
| 72 | 72 | ||
| 73 | - var TopPhoto []string | 73 | + var TopPhoto []DB.SPicture |
| 74 | json.Unmarshal([]byte(c.PostForm("TopPhoto")), &TopPhoto) | 74 | json.Unmarshal([]byte(c.PostForm("TopPhoto")), &TopPhoto) |
| 75 | 75 | ||
| 76 | //var Location DB.SLocation | 76 | //var Location DB.SLocation |
API/User.go
| @@ -137,6 +137,7 @@ func LoginUser(c *gin.Context) { | @@ -137,6 +137,7 @@ func LoginUser(c *gin.Context) { | ||
| 137 | c.PostForm("mobile"), | 137 | c.PostForm("mobile"), |
| 138 | "", | 138 | "", |
| 139 | token, | 139 | token, |
| 140 | + "", | ||
| 140 | } | 141 | } |
| 141 | DB.CMember.Insert(oUser) | 142 | DB.CMember.Insert(oUser) |
| 142 | //if err == nil { | 143 | //if err == nil { |
| @@ -187,7 +188,6 @@ func UserInfo(c *gin.Context) { | @@ -187,7 +188,6 @@ func UserInfo(c *gin.Context) { | ||
| 187 | c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | 188 | c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) |
| 188 | c.Header("Access-Control-Allow-Credentials", "true") | 189 | c.Header("Access-Control-Allow-Credentials", "true") |
| 189 | 190 | ||
| 190 | - | ||
| 191 | if c.Query("id") == "" { | 191 | if c.Query("id") == "" { |
| 192 | c.JSON(200, tools.ResponseError{ | 192 | c.JSON(200, tools.ResponseError{ |
| 193 | 1, | 193 | 1, |
| @@ -216,6 +216,7 @@ func UserInfo(c *gin.Context) { | @@ -216,6 +216,7 @@ func UserInfo(c *gin.Context) { | ||
| 216 | // @Param fullname aarongao string true "全名" | 216 | // @Param fullname aarongao string true "全名" |
| 217 | // @Param code 12345678 string true "6位验证码" | 217 | // @Param code 12345678 string true "6位验证码" |
| 218 | // @Param mobile 18616619599 string true "手机,同用户名" | 218 | // @Param mobile 18616619599 string true "手机,同用户名" |
| 219 | +// @Param sex 男 string true "性别" | ||
| 219 | // @Param openid 12345 string true "微信id" | 220 | // @Param openid 12345 string true "微信id" |
| 220 | // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" | 221 | // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" |
| 221 | // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | 222 | // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" |
| @@ -233,6 +234,15 @@ func UpdateUser(c *gin.Context) { | @@ -233,6 +234,15 @@ func UpdateUser(c *gin.Context) { | ||
| 233 | }) | 234 | }) |
| 234 | return | 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 | if c.PostForm("password") != c.PostForm("confirmpassword") { | 246 | if c.PostForm("password") != c.PostForm("confirmpassword") { |
| 237 | c.JSON(200, tools.ResponseError{ | 247 | c.JSON(200, tools.ResponseError{ |
| 238 | 1, | 248 | 1, |
| @@ -251,25 +261,30 @@ func UpdateUser(c *gin.Context) { | @@ -251,25 +261,30 @@ func UpdateUser(c *gin.Context) { | ||
| 251 | return | 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 | if err == nil { | 275 | if err == nil { |
| 276 | + | ||
| 277 | + var User *DB.SMember | ||
| 278 | + DB.CMember.Find(bson.M{"Mobile": c.PostForm("mobile")}).One(&User) | ||
| 279 | + | ||
| 265 | c.JSON(200, tools.ResponseSeccess{ | 280 | c.JSON(200, tools.ResponseSeccess{ |
| 266 | 0, | 281 | 0, |
| 267 | - "ok", | 282 | + User, |
| 268 | }) | 283 | }) |
| 269 | } else { | 284 | } else { |
| 270 | c.JSON(200, tools.ResponseError{ | 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,7 +75,7 @@ type SCommodity struct { | ||
| 75 | ShopName string `bson:"ShopName" json:"ShopName"` | 75 | ShopName string `bson:"ShopName" json:"ShopName"` |
| 76 | ItemId string `bson:"ItemId" json:"ItemId"` //项目id | 76 | ItemId string `bson:"ItemId" json:"ItemId"` //项目id |
| 77 | KvPhoto string `bson:"KvPhoto" json:"KvPhoto"` //用于列表页的图片 | 77 | KvPhoto string `bson:"KvPhoto" json:"KvPhoto"` //用于列表页的图片 |
| 78 | - TopPhoto []string `bson:"TopPhoto" json:"TopPhoto"` //详情页最上面的轮播图 | 78 | + TopPhoto []SPicture `bson:"TopPhoto" json:"TopPhoto"` //详情页最上面的轮播图 |
| 79 | Images []string `bson:"Images" json:"Images"` //详情页下面的产品详细图 | 79 | Images []string `bson:"Images" json:"Images"` //详情页下面的产品详细图 |
| 80 | } | 80 | } |
| 81 | type SLine struct { | 81 | type SLine struct { |
| @@ -91,10 +91,13 @@ type SLine struct { | @@ -91,10 +91,13 @@ type SLine struct { | ||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | type SComplaint struct { | 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 | type SInvestigation struct { | 103 | type SInvestigation struct { |
| @@ -110,6 +113,7 @@ type SMember struct { | @@ -110,6 +113,7 @@ type SMember struct { | ||
| 110 | Mobile string `bson:"Mobile" json:"Mobile"` | 113 | Mobile string `bson:"Mobile" json:"Mobile"` |
| 111 | Openid string `bson:"Openid" json:"Openid"` | 114 | Openid string `bson:"Openid" json:"Openid"` |
| 112 | Token string `bson:"Token" json:"Token"` | 115 | Token string `bson:"Token" json:"Token"` |
| 116 | + Sex string `bson:"Sex" json:"Sex"` | ||
| 113 | } | 117 | } |
| 114 | 118 | ||
| 115 | type STag struct { | 119 | type STag struct { |
README.md
| @@ -146,6 +146,10 @@ | @@ -146,6 +146,10 @@ | ||
| 146 | | Param Name | Example | Data Type | Description | Required? | | 146 | | Param Name | Example | Data Type | Description | Required? | |
| 147 | |-----|-----|-----|-----|-----| | 147 | |-----|-----|-----|-----|-----| |
| 148 | | mobile | 18616619599 | string | 联系电话 | Yes | | 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 | | type | 1 | string | 类型 | Yes | | 153 | | type | 1 | string | 类型 | Yes | |
| 150 | | content | 卫生不干净 | string | 投诉内容 | Yes | | 154 | | content | 卫生不干净 | string | 投诉内容 | Yes | |
| 151 | | image | ["http://www.xx.com/123.jpg","http://www.xx.com/123.jpg"] | string | 照片数组 | Yes | | 155 | | image | ["http://www.xx.com/123.jpg","http://www.xx.com/123.jpg"] | string | 照片数组 | Yes | |
| @@ -446,6 +450,7 @@ | @@ -446,6 +450,7 @@ | ||
| 446 | | fullname | aarongao | string | 全名 | Yes | | 450 | | fullname | aarongao | string | 全名 | Yes | |
| 447 | | code | 12345678 | string | 6位验证码 | Yes | | 451 | | code | 12345678 | string | 6位验证码 | Yes | |
| 448 | | mobile | 18616619599 | string | 手机,同用户名 | Yes | | 452 | | mobile | 18616619599 | string | 手机,同用户名 | Yes | |
| 453 | +| sex | 男 | string | 性别 | Yes | | ||
| 449 | | openid | 12345 | string | 微信id | Yes | | 454 | | openid | 12345 | string | 微信id | Yes | |
| 450 | 455 | ||
| 451 | 456 |
main.go
| @@ -75,6 +75,7 @@ func main() { | @@ -75,6 +75,7 @@ func main() { | ||
| 75 | r.POST("/CreateComplaint", Api.CreateComplaint) | 75 | r.POST("/CreateComplaint", Api.CreateComplaint) |
| 76 | //r.POST("/CreateUser", Api.CreateUser) | 76 | //r.POST("/CreateUser", Api.CreateUser) |
| 77 | r.POST("/LoginUser", Api.LoginUser) | 77 | r.POST("/LoginUser", Api.LoginUser) |
| 78 | + r.POST("/UpdateUser", Api.UpdateUser) | ||
| 78 | r.GET("/UserInfo", Api.UserInfo) | 79 | r.GET("/UserInfo", Api.UserInfo) |
| 79 | r.GET("/ScenicInfo", Api.ScenicInfo) | 80 | r.GET("/ScenicInfo", Api.ScenicInfo) |
| 80 | r.GET("/LineInfo", Api.LineInfo) | 81 | r.GET("/LineInfo", Api.LineInfo) |