From 7970f4d34db898271555a2d342a1d3c0ed3fc7bb Mon Sep 17 00:00:00 2001
From: haoyanbin <605649647@qq.com>
Date: Fri, 8 Sep 2023 12:13:20 +0800
Subject: [PATCH] 1

---
 api/mobile/survey.go      | 31 +++++++++++++++++--------------
 api/mobile/user.go        | 29 +++++++++++++++++++++++------
 model/request/survey.go   |  1 +
 model/request/sys_user.go |  2 ++
 model/survey.go           |  3 +++
 router/survey.go          |  1 +
 service/survey.go         |  5 +++++
 7 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/api/mobile/survey.go b/api/mobile/survey.go
index be2e01d..2cf5031 100755
--- a/api/mobile/survey.go
+++ b/api/mobile/survey.go
@@ -57,31 +57,34 @@ func CreateSurveyUser(c *gin.Context) {
 	var req request.CreateSurveyUserReq
 	_ = c.ShouldBindJSON(&req)
 
-	ipData, _ := service.GetIpaddr(c.ClientIP())
-
 	SurveyUser := model.SurveyUser{
-		SurveyId:        1,
-		UserId:          req.UserId,
-		MocId:           req.MocId,
+		Id:              req.Id,
 		Contacts:        req.Contacts,
 		ContactsMobile:  req.ContactsMobile,
 		Reference:       req.Reference,
 		ReferenceMobile: req.ReferenceMobile,
-		CreateTime:      utils.NowTime(),
-		Country:         ipData.Country,
-		Area:            ipData.Area,
-		Region:          ipData.Region,
-		City:            ipData.City,
+		Status:          1,
 	}
 
-	_, 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 {
-		v.SurveyUserId = surveyUserId
+		v.SurveyUserId = req.Id
 		service.CreateSurveyUserData(v)
 	}
-
-	response.OkWithMessage("创建成功", c)
+	response.OkWithMessage("修改成功", c)
 	return
 }
 
diff --git a/api/mobile/user.go b/api/mobile/user.go
index f2b2ecd..ba1b7f2 100644
--- a/api/mobile/user.go
+++ b/api/mobile/user.go
@@ -44,17 +44,34 @@ func SendCode(c *gin.Context) {
 }
 
 func CheckCode(c *gin.Context) {
-	var r request.CheckCodeReq
-	_ = c.ShouldBindJSON(&r)
+	var req request.CheckCodeReq
+	_ = c.ShouldBindJSON(&req)
 
-	data := service.GetMobileCode(r.Mobile)
+	data := service.GetMobileCode(req.Mobile)
 
-	if data.Code == r.Code || r.Code == "999888" {
-		response.OkWithMessage("验证成功", c)
+	if data.Code != req.Code && req.Code != "999888" {
+		response.FailWithMessage("验证码不正确", c)
 		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
 }
 
diff --git a/model/request/survey.go b/model/request/survey.go
index bae813a..f662736 100755
--- a/model/request/survey.go
+++ b/model/request/survey.go
@@ -4,6 +4,7 @@ import "gin-vue-admin/model"
 
 type CreateSurveyUserReq struct {
 	Data            []model.SurveyUserData `json:"data"`
+	Id              int                    `gorm:"type:int(255)" json:"id"`
 	SurveyId        int                    `gorm:"type:int(255)" json:"survey_id"`
 	UserId          int                    `gorm:"type:int(255)" json:"user_id"`
 	MocId           int                    `gorm:"type:int(255)" json:"moc_id"`
diff --git a/model/request/sys_user.go b/model/request/sys_user.go
index 5ce9eab..5857211 100755
--- a/model/request/sys_user.go
+++ b/model/request/sys_user.go
@@ -10,6 +10,8 @@ type SendCodeReq 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"`
 	Code   string `json:"code"`
 }
diff --git a/model/survey.go b/model/survey.go
index cc33acc..2081cc9 100755
--- a/model/survey.go
+++ b/model/survey.go
@@ -6,6 +6,8 @@ type SurveyUser struct {
 	SurveyId        int    `gorm:"type:int(255)" json:"survey_id"`
 	UserId          int    `gorm:"type:int(255)" json:"user_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"`
 	ContactsMobile  string `gorm:"type:string(255)" json:"contacts_mobile"`
 	Reference       string `gorm:"type:string(255)" json:"reference"`
@@ -15,6 +17,7 @@ type SurveyUser struct {
 	Area            string `gorm:"type:string(255)" json:"area"`
 	Region          string `gorm:"type:string(255)" json:"region"`
 	City            string `gorm:"type:string(255)" json:"city"`
+	Status          int    `gorm:"type:int(255)" json:"status"`
 }
 
 type SurveyUserData struct {
diff --git a/router/survey.go b/router/survey.go
index 0c11aa3..f3232cf 100755
--- a/router/survey.go
+++ b/router/survey.go
@@ -18,6 +18,7 @@ func InitSurveyPublicRouter(Router *gin.RouterGroup) {
 	DataVipCommentRouter := Router.Group("survey").Use(middleware.OperationRecord())
 	{
 		DataVipCommentRouter.POST("create", mobile.CreateSurveyUser)
+		DataVipCommentRouter.POST("createData", mobile.CreateSurveyUserData)
 		DataVipCommentRouter.POST("createLog", mobile.CreateSurveyLog)
 		DataVipCommentRouter.GET("exportSurveyUserExcel", mobile.ExportSurveyUserExcel)
 	}
diff --git a/service/survey.go b/service/survey.go
index 19022c7..214b0dc 100755
--- a/service/survey.go
+++ b/service/survey.go
@@ -12,6 +12,11 @@ func CreateSurveyUser(req model.SurveyUser) (error, int) {
 	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 {
 	err := global.GVA_DB.Table("survey_user_data").Create(&req).Error
 	return err
-- 
2.18.1