From 7aca21290e25ceb40e2fba0b17fc23f4d1d29d61 Mon Sep 17 00:00:00 2001 From: aarongao Date: Mon, 13 Jan 2020 17:22:22 +0800 Subject: [PATCH] 增加调查和短信接口 --- API/Investigation.go | 38 ++++++++++++++++++++++++++++++++++++++ API/Sms.go | 6 ++++-- DB/db.go | 3 +++ main.go | 3 ++- 4 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 API/Investigation.go diff --git a/API/Investigation.go b/API/Investigation.go new file mode 100644 index 0000000..41335da --- /dev/null +++ b/API/Investigation.go @@ -0,0 +1,38 @@ +package Api + +import ( + "encoding/json" + "github.com/aarongao/tools" + "github.com/gin-gonic/gin" + "letu/DB" +) + +// @Title 增加调查 +// @Description 增加调查 +// @Accept json +// @Produce json +// @Param UserId 1111111 string true "UserId" +// @Param Mobile 18616619599 string true "联系电话" +// @Param type 1 string true "类型" +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" +// @Router /Investigation/Save? [post] +func Save(c *gin.Context) { + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) + c.Header("Access-Control-Allow-Credentials", "true") + + var Data map[string]interface{} + json.Unmarshal([]byte(c.PostForm("Data")), &Data) + + DB.CInvestigation.Insert(DB.SInvestigation{ + c.PostForm("UserId"), + c.PostForm("Mobile"), + Data, + }) + + c.JSON(200, tools.ResponseSeccess{ + 0, + "ok", + }) + +} diff --git a/API/Sms.go b/API/Sms.go index 6ee5b50..e472a5f 100644 --- a/API/Sms.go +++ b/API/Sms.go @@ -65,8 +65,10 @@ func Send(c *gin.Context) { println(err.Error()) reserr = err.Error() } else { - reserr = "" - DB.Redis.Set(c.PostForm("Mobile"), code, time.Second*60*3) + reserr = response.Code + if response.Code == "OK" { + DB.Redis.Set(c.PostForm("Mobile"), code, time.Second*60*3) + } } var Location DB.SLocation diff --git a/DB/db.go b/DB/db.go index 565a8a9..98c05ba 100644 --- a/DB/db.go +++ b/DB/db.go @@ -92,6 +92,9 @@ type SComplaint struct { } type SInvestigation struct { + UserId string `bson:"UserId" json:"UserId"` // 用户ID + Mobile string `bson:"Mobile" json:"Mobile"` //手机号 + Data interface{} `bson:"Data" json:"Data"` } type SMember struct { Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` diff --git a/main.go b/main.go index 7548292..525ef6d 100644 --- a/main.go +++ b/main.go @@ -42,7 +42,6 @@ func main() { 0, }) - //设置模式 DB.DBSession.SetMode(mgo.Monotonic, true) //获取文档集 @@ -57,6 +56,7 @@ func main() { DB.CLine = DB.DB.C("Line") DB.CAccessLog = DB.DB.C("AccessLog") DB.CActionLog = DB.DB.C("ActionLog") + DB.CInvestigation = DB.DB.C("Investigation") r := gin.Default() //r.Static("/.well-known", "./.well-known/") @@ -84,6 +84,7 @@ func main() { r.POST("/AccessLog", Api.AccessLog) r.GET("/AccessLog", Api.AccessLog) r.POST("/Sms/Send", Api.Send) + r.POST("/Investigation/Save", Api.Save) //r.GET("/ws", Api.WsPage) r.Static("/Upload", "./Upload") -- libgit2 0.21.0