From afa23e565007c390753d53a2b158d0debf309551 Mon Sep 17 00:00:00 2001
From: haoyanbin <605649647@qq.com>
Date: Sat, 2 Sep 2023 16:42:27 +0800
Subject: [PATCH] 1

---
 api/mobile/survey.go | 18 ++++++++++++++----
 model/survey.go      |  8 ++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/api/mobile/survey.go b/api/mobile/survey.go
index ec9f707..85af11c 100755
--- a/api/mobile/survey.go
+++ b/api/mobile/survey.go
@@ -1,7 +1,6 @@
 package mobile
 
 import (
-	"fmt"
 	"gin-vue-admin/global"
 	"gin-vue-admin/model"
 	"gin-vue-admin/model/request"
@@ -24,12 +23,18 @@ 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,
 		Contacts:       req.Contacts,
 		ContactsMobile: req.ContactsMobile,
 		CreateTime:     utils.NowTime(),
+		Country:        ipData.Country,
+		Area:           ipData.Area,
+		Region:         ipData.Region,
+		City:           ipData.City,
 	}
 
 	_, surveyUserId := service.CreateSurveyUser(SurveyUser)
@@ -47,9 +52,14 @@ func CreateSurveyLog(c *gin.Context) {
 	var req model.SurveyLog
 	_ = c.ShouldBindJSON(&req)
 
-	//ipData, _ := service.GetIpaddr(c.ClientIP())
-	ipData, _ := service.GetIpaddr("125.34.219.138")
-	fmt.Println(ipData)
+	ipData, _ := service.GetIpaddr(c.ClientIP())
+	//ipData, _ := service.GetIpaddr("125.34.219.138")
+	//fmt.Println(ipData)
+
+	req.Country = ipData.Country
+	req.Area = ipData.Area
+	req.Region = ipData.Region
+	req.City = ipData.City
 
 	req.CreateTime = utils.NowTime()
 	if err := service.CreateSurveyLog(req); err != nil {
diff --git a/model/survey.go b/model/survey.go
index 016e2d4..3f11d10 100755
--- a/model/survey.go
+++ b/model/survey.go
@@ -8,6 +8,10 @@ type SurveyUser struct {
 	Contacts       string `gorm:"type:string(255)" json:"contacts"`
 	ContactsMobile string `gorm:"type:string(255)" json:"contacts_mobile"`
 	CreateTime     string `gorm:"type:string(255)" json:"create_time"`
+	Country        string `gorm:"type:string(255)" json:"country"`
+	Area           string `gorm:"type:string(255)" json:"area"`
+	Region         string `gorm:"type:string(255)" json:"region"`
+	City           string `gorm:"type:string(255)" json:"city"`
 }
 
 type SurveyUserData struct {
@@ -24,4 +28,8 @@ type SurveyLog struct {
 	UserId     int    `gorm:"type:int(255)" json:"user_id"`
 	Page       int    `gorm:"type:int(255)" json:"page"`
 	CreateTime string `gorm:"type:string(255)" json:"create_time"`
+	Country    string `gorm:"type:string(255)" json:"country"`
+	Area       string `gorm:"type:string(255)" json:"area"`
+	Region     string `gorm:"type:string(255)" json:"region"`
+	City       string `gorm:"type:string(255)" json:"city"`
 }
-- 
2.18.1