From 1ba7e43412424bd2518024050fda3f4c0ac96352 Mon Sep 17 00:00:00 2001 From: aarongao Date: Mon, 3 Feb 2020 14:43:44 +0800 Subject: [PATCH] .. --- API/Complaint.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ API/Shop.go | 2 +- API/User.go | 43 +++++++++++++++++++++++++++++-------------- DB/db.go | 14 +++++++++----- README.md | 5 +++++ main.go | 1 + 6 files changed, 90 insertions(+), 20 deletions(-) diff --git a/API/Complaint.go b/API/Complaint.go index d15c386..abee3a1 100644 --- a/API/Complaint.go +++ b/API/Complaint.go @@ -5,6 +5,7 @@ import ( "github.com/aarongao/tools" "github.com/gin-gonic/gin" "letu/DB" + "regexp" ) // @Title 增加投诉 @@ -12,6 +13,10 @@ import ( // @Accept json // @Produce json // @Param mobile 18616619599 string true "联系电话" +// @Param name 高先生 string true "姓名" +// @Param code 123456 string true "验证码" +// @Param sex 男 string true "性别" +// @Param scenicid 5e1ed07524e03431008b4572 string true "景区id" // @Param type 1 string true "类型" // @Param content 卫生不干净 string true "投诉内容" // @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) { c.Header("Access-Control-Allow-Credentials","true") + + reg := regexp.MustCompile(Regular) + if !reg.MatchString(c.PostForm("mobile")) { + + c.JSON(200, tools.ResponseError{ + 1, + "手机号格式不正确", + }) + return + } + + if c.PostForm("mobile") == ""{ + c.JSON(200, tools.ResponseError{ + 1, + "手机号为空", + }) + return + } + + + // 检查验证码 + cacheCode := DB.Redis.Get(c.PostForm("mobile")) + if cacheCode != c.PostForm("code") { + + c.JSON(200, tools.ResponseError{ + 1, + "验证码不正确", + }) + return + + } + + + + + + var images []string json.Unmarshal([]byte(c.PostForm("image")), &images) DB.CComplaint.Insert(DB.SComplaint{ c.PostForm("type"), + c.PostForm("scenicid"), c.PostForm("mobile"), + c.PostForm("name"), + c.PostForm("sex"), c.PostForm("content"), images, }) diff --git a/API/Shop.go b/API/Shop.go index ebec828..f63c698 100644 --- a/API/Shop.go +++ b/API/Shop.go @@ -70,7 +70,7 @@ func UpdateCommodity(c *gin.Context) { var Picture []string json.Unmarshal([]byte(c.PostForm("Images")), &Picture) - var TopPhoto []string + var TopPhoto []DB.SPicture json.Unmarshal([]byte(c.PostForm("TopPhoto")), &TopPhoto) //var Location DB.SLocation diff --git a/API/User.go b/API/User.go index a16f816..a1ed1d8 100644 --- a/API/User.go +++ b/API/User.go @@ -137,6 +137,7 @@ func LoginUser(c *gin.Context) { c.PostForm("mobile"), "", token, + "", } DB.CMember.Insert(oUser) //if err == nil { @@ -187,7 +188,6 @@ func UserInfo(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, @@ -216,6 +216,7 @@ func UserInfo(c *gin.Context) { // @Param fullname aarongao string true "全名" // @Param code 12345678 string true "6位验证码" // @Param mobile 18616619599 string true "手机,同用户名" +// @Param sex 男 string true "性别" // @Param openid 12345 string true "微信id" // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" @@ -233,6 +234,15 @@ func UpdateUser(c *gin.Context) { }) return } + + if c.PostForm("mobile") == "" || c.PostForm("password") == "" { + c.JSON(200, tools.ResponseError{ + 1, + "手机号或密码为空", + }) + return + } + if c.PostForm("password") != c.PostForm("confirmpassword") { c.JSON(200, tools.ResponseError{ 1, @@ -251,25 +261,30 @@ func UpdateUser(c *gin.Context) { return } - objectID := bson.NewObjectId() - err := DB.CMember.Insert(DB.SMember{ - &objectID, - c.PostForm("password"), - c.PostForm("birthday"), - c.PostForm("fullname"), - c.PostForm("mobile"), - c.PostForm("openid"), - "", - }) + err := DB.CMember.Update( + bson.M{"Mobile": c.PostForm("mobile")}, + bson.M{"$set": bson.M{ + "Password": c.PostForm("password"), + "Birthday": c.PostForm("birthday"), + "FullName": c.PostForm("fullname"), + "Mobile": c.PostForm("mobile"), + "Sex": c.PostForm("sex"), + }}, + ) + if err == nil { + + var User *DB.SMember + DB.CMember.Find(bson.M{"Mobile": c.PostForm("mobile")}).One(&User) + c.JSON(200, tools.ResponseSeccess{ 0, - "ok", + User, }) } else { c.JSON(200, tools.ResponseError{ - 0, - "此手机号已经注册", + 1, + err.Error(), }) } diff --git a/DB/db.go b/DB/db.go index b13d33a..e42cd34 100644 --- a/DB/db.go +++ b/DB/db.go @@ -75,7 +75,7 @@ type SCommodity struct { ShopName string `bson:"ShopName" json:"ShopName"` ItemId string `bson:"ItemId" json:"ItemId"` //项目id KvPhoto string `bson:"KvPhoto" json:"KvPhoto"` //用于列表页的图片 - TopPhoto []string `bson:"TopPhoto" json:"TopPhoto"` //详情页最上面的轮播图 + TopPhoto []SPicture `bson:"TopPhoto" json:"TopPhoto"` //详情页最上面的轮播图 Images []string `bson:"Images" json:"Images"` //详情页下面的产品详细图 } type SLine struct { @@ -91,10 +91,13 @@ type SLine struct { } type SComplaint struct { - Type string `bson:"Type" json:"Type"` - Mobile string `bson:"Mobile" json:"Mobile"` - Content string `bson:"Content" json:"Content"` - Image []string `bson:"Image" json:"Image"` + Type string `bson:"Type" json:"Type"` + ScenicId string `bson:"ScenicId" json:"ScenicId"` // 景区id + Mobile string `bson:"Mobile" json:"Mobile"` + FullName string `bson:"FullName" json:"FullName"` + Sex string `bson:"Sex" json:"Sex"` + Content string `bson:"Content" json:"Content"` + Image []string `bson:"Image" json:"Image"` } type SInvestigation struct { @@ -110,6 +113,7 @@ type SMember struct { Mobile string `bson:"Mobile" json:"Mobile"` Openid string `bson:"Openid" json:"Openid"` Token string `bson:"Token" json:"Token"` + Sex string `bson:"Sex" json:"Sex"` } type STag struct { diff --git a/README.md b/README.md index 7df5831..b9f4623 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,10 @@ | Param Name | Example | Data Type | Description | Required? | |-----|-----|-----|-----|-----| | mobile | 18616619599 | string | 联系电话 | Yes | +| name | 高先生 | string | 姓名 | Yes | +| code | 123456 | string | 验证码 | Yes | +| sex | 男 | string | 性别 | Yes | +| scenicid | 5e1ed07524e03431008b4572 | string | 景区id | Yes | | type | 1 | string | 类型 | Yes | | content | 卫生不干净 | string | 投诉内容 | Yes | | image | ["http://www.xx.com/123.jpg","http://www.xx.com/123.jpg"] | string | 照片数组 | Yes | @@ -446,6 +450,7 @@ | fullname | aarongao | string | 全名 | Yes | | code | 12345678 | string | 6位验证码 | Yes | | mobile | 18616619599 | string | 手机,同用户名 | Yes | +| sex | 男 | string | 性别 | Yes | | openid | 12345 | string | 微信id | Yes | diff --git a/main.go b/main.go index ba89dd7..0d3f58f 100644 --- a/main.go +++ b/main.go @@ -75,6 +75,7 @@ func main() { r.POST("/CreateComplaint", Api.CreateComplaint) //r.POST("/CreateUser", Api.CreateUser) r.POST("/LoginUser", Api.LoginUser) + r.POST("/UpdateUser", Api.UpdateUser) r.GET("/UserInfo", Api.UserInfo) r.GET("/ScenicInfo", Api.ScenicInfo) r.GET("/LineInfo", Api.LineInfo) -- libgit2 0.21.0