Commit 7970f4d3 authored by haoyanbin's avatar haoyanbin

1

parent ebfe0db7
...@@ -57,31 +57,34 @@ func CreateSurveyUser(c *gin.Context) { ...@@ -57,31 +57,34 @@ func CreateSurveyUser(c *gin.Context) {
var req request.CreateSurveyUserReq var req request.CreateSurveyUserReq
_ = c.ShouldBindJSON(&req) _ = c.ShouldBindJSON(&req)
ipData, _ := service.GetIpaddr(c.ClientIP())
SurveyUser := model.SurveyUser{ SurveyUser := model.SurveyUser{
SurveyId: 1, Id: req.Id,
UserId: req.UserId,
MocId: req.MocId,
Contacts: req.Contacts, Contacts: req.Contacts,
ContactsMobile: req.ContactsMobile, ContactsMobile: req.ContactsMobile,
Reference: req.Reference, Reference: req.Reference,
ReferenceMobile: req.ReferenceMobile, ReferenceMobile: req.ReferenceMobile,
CreateTime: utils.NowTime(), Status: 1,
Country: ipData.Country,
Area: ipData.Area,
Region: ipData.Region,
City: ipData.City,
} }
_, surveyUserId := service.CreateSurveyUser(SurveyUser) service.UpdateSurveyUser(SurveyUser)
//for _, v := range req.Data {
// v.SurveyUserId = surveyUserId
// service.CreateSurveyUserData(v)
//}
response.OkWithMessage("修改成功", c)
return
}
func CreateSurveyUserData(c *gin.Context) {
var req request.CreateSurveyUserReq
_ = c.ShouldBindJSON(&req)
for _, v := range req.Data { for _, v := range req.Data {
v.SurveyUserId = surveyUserId v.SurveyUserId = req.Id
service.CreateSurveyUserData(v) service.CreateSurveyUserData(v)
} }
response.OkWithMessage("修改成功", c)
response.OkWithMessage("创建成功", c)
return return
} }
......
...@@ -44,17 +44,34 @@ func SendCode(c *gin.Context) { ...@@ -44,17 +44,34 @@ func SendCode(c *gin.Context) {
} }
func CheckCode(c *gin.Context) { func CheckCode(c *gin.Context) {
var r request.CheckCodeReq var req request.CheckCodeReq
_ = c.ShouldBindJSON(&r) _ = c.ShouldBindJSON(&req)
data := service.GetMobileCode(r.Mobile) data := service.GetMobileCode(req.Mobile)
if data.Code == r.Code || r.Code == "999888" { if data.Code != req.Code && req.Code != "999888" {
response.OkWithMessage("验证成功", c) response.FailWithMessage("验证码不正确", c)
return return
} }
response.FailWithMessage("验证失败", c) ipData, _ := service.GetIpaddr(c.ClientIP())
SurveyUser := model.SurveyUser{
SurveyId: 1,
UserId: req.UserId,
MocId: req.MocId,
CodeMobile: req.Mobile,
Code: req.Code,
CreateTime: utils.NowTime(),
Country: ipData.Country,
Area: ipData.Area,
Region: ipData.Region,
City: ipData.City,
}
_, surveyUserId := service.CreateSurveyUser(SurveyUser)
response.OkWithData(map[string]int{"id": surveyUserId}, c)
return return
} }
......
...@@ -4,6 +4,7 @@ import "gin-vue-admin/model" ...@@ -4,6 +4,7 @@ import "gin-vue-admin/model"
type CreateSurveyUserReq struct { type CreateSurveyUserReq struct {
Data []model.SurveyUserData `json:"data"` Data []model.SurveyUserData `json:"data"`
Id int `gorm:"type:int(255)" json:"id"`
SurveyId int `gorm:"type:int(255)" json:"survey_id"` SurveyId int `gorm:"type:int(255)" json:"survey_id"`
UserId int `gorm:"type:int(255)" json:"user_id"` UserId int `gorm:"type:int(255)" json:"user_id"`
MocId int `gorm:"type:int(255)" json:"moc_id"` MocId int `gorm:"type:int(255)" json:"moc_id"`
......
...@@ -10,6 +10,8 @@ type SendCodeReq struct { ...@@ -10,6 +10,8 @@ type SendCodeReq struct {
} }
type CheckCodeReq struct { type CheckCodeReq struct {
UserId int `gorm:"type:int(255)" json:"user_id"`
MocId int `gorm:"type:int(255)" json:"moc_id"`
Mobile string `json:"mobile"` Mobile string `json:"mobile"`
Code string `json:"code"` Code string `json:"code"`
} }
......
...@@ -6,6 +6,8 @@ type SurveyUser struct { ...@@ -6,6 +6,8 @@ type SurveyUser struct {
SurveyId int `gorm:"type:int(255)" json:"survey_id"` SurveyId int `gorm:"type:int(255)" json:"survey_id"`
UserId int `gorm:"type:int(255)" json:"user_id"` UserId int `gorm:"type:int(255)" json:"user_id"`
MocId int `gorm:"type:int(255)" json:"moc_id"` MocId int `gorm:"type:int(255)" json:"moc_id"`
CodeMobile string `gorm:"type:string(255)" json:"code_mobile"`
Code string `gorm:"type:string(255)" json:"code"`
Contacts string `gorm:"type:string(255)" json:"contacts"` Contacts string `gorm:"type:string(255)" json:"contacts"`
ContactsMobile string `gorm:"type:string(255)" json:"contacts_mobile"` ContactsMobile string `gorm:"type:string(255)" json:"contacts_mobile"`
Reference string `gorm:"type:string(255)" json:"reference"` Reference string `gorm:"type:string(255)" json:"reference"`
...@@ -15,6 +17,7 @@ type SurveyUser struct { ...@@ -15,6 +17,7 @@ type SurveyUser struct {
Area string `gorm:"type:string(255)" json:"area"` Area string `gorm:"type:string(255)" json:"area"`
Region string `gorm:"type:string(255)" json:"region"` Region string `gorm:"type:string(255)" json:"region"`
City string `gorm:"type:string(255)" json:"city"` City string `gorm:"type:string(255)" json:"city"`
Status int `gorm:"type:int(255)" json:"status"`
} }
type SurveyUserData struct { type SurveyUserData struct {
......
...@@ -18,6 +18,7 @@ func InitSurveyPublicRouter(Router *gin.RouterGroup) { ...@@ -18,6 +18,7 @@ func InitSurveyPublicRouter(Router *gin.RouterGroup) {
DataVipCommentRouter := Router.Group("survey").Use(middleware.OperationRecord()) DataVipCommentRouter := Router.Group("survey").Use(middleware.OperationRecord())
{ {
DataVipCommentRouter.POST("create", mobile.CreateSurveyUser) DataVipCommentRouter.POST("create", mobile.CreateSurveyUser)
DataVipCommentRouter.POST("createData", mobile.CreateSurveyUserData)
DataVipCommentRouter.POST("createLog", mobile.CreateSurveyLog) DataVipCommentRouter.POST("createLog", mobile.CreateSurveyLog)
DataVipCommentRouter.GET("exportSurveyUserExcel", mobile.ExportSurveyUserExcel) DataVipCommentRouter.GET("exportSurveyUserExcel", mobile.ExportSurveyUserExcel)
} }
......
...@@ -12,6 +12,11 @@ func CreateSurveyUser(req model.SurveyUser) (error, int) { ...@@ -12,6 +12,11 @@ func CreateSurveyUser(req model.SurveyUser) (error, int) {
return err, req.Id return err, req.Id
} }
func UpdateSurveyUser(req model.SurveyUser) (error, int) {
err := global.GVA_DB.Table("survey_user").Where("id=?", req.Id).Updates(&req).Error
return err, req.Id
}
func CreateSurveyUserData(req model.SurveyUserData) error { func CreateSurveyUserData(req model.SurveyUserData) error {
err := global.GVA_DB.Table("survey_user_data").Create(&req).Error err := global.GVA_DB.Table("survey_user_data").Create(&req).Error
return err return err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment