Commit ab9534cc authored by haoyanbin's avatar haoyanbin

1

parent 6f8d3115
...@@ -251,14 +251,15 @@ func ExportMocDataExcel(c *gin.Context) { ...@@ -251,14 +251,15 @@ func ExportMocDataExcel(c *gin.Context) {
surveyCount := service.GetSurveyUserCount(req) //留资数量 surveyCount := service.GetSurveyUserCount(req) //留资数量
logCountReq := request.GetSurveyLogListReq{ logCountReq := request.GetSurveyLogListReq{
SlPage: 10, SlPage: 10,
MocId: k, MocId: k,
Groupby: " user_id ", StartCreateTime: req.StartCreateTime,
EndCreateTime: req.EndCreateTime,
} }
logCount := service.GetSurveyLogCount(logCountReq) //点击量 logCount := service.GetSurveyLogCount(logCountReq) //点击量
a := strconv.Itoa(k + 1) a := strconv.Itoa(k + 1)
f.SetCellValue(fileName, "A"+a, time.Now().Format("2006/01/02")) f.SetCellValue(fileName, "A"+a, req.StartCreateTime)
f.SetCellValue(fileName, "B"+a, v) f.SetCellValue(fileName, "B"+a, v)
f.SetCellValue(fileName, "C"+a, "短信") f.SetCellValue(fileName, "C"+a, "短信")
f.SetCellValue(fileName, "D"+a, "") f.SetCellValue(fileName, "D"+a, "")
...@@ -283,3 +284,50 @@ func ExportMocDataExcel(c *gin.Context) { ...@@ -283,3 +284,50 @@ func ExportMocDataExcel(c *gin.Context) {
c.File("./" + fileName + ".csv") c.File("./" + fileName + ".csv")
return return
} }
func ExportSurveyLogPageList(c *gin.Context) {
var req request.GetSurveyLogListReq
_ = c.ShouldBindQuery(&req)
list := service.GetSurveyLogPageList(req)
fileName := "点击明细" + time.Now().Format("20060102")
f := excelize.NewFile()
// Create a new sheet.
index := f.NewSheet(fileName)
f.SetCellValue(fileName, "A1", "用户ID")
f.SetCellValue(fileName, "B1", "用户名")
f.SetCellValue(fileName, "C1", "省")
f.SetCellValue(fileName, "D1", "市")
f.SetCellValue(fileName, "E1", "工作人员")
f.SetCellValue(fileName, "F1", "工作人员电话")
f.SetCellValue(fileName, "G1", "数据来源")
f.SetCellValue(fileName, "H1", "访问IP")
f.SetCellValue(fileName, "I1", "访问时间")
for k, v := range list {
a := strconv.Itoa(k + 2)
f.SetCellValue(fileName, "A"+a, v.Id)
f.SetCellValue(fileName, "B"+a, v.UserName)
f.SetCellValue(fileName, "C"+a, v.Region)
f.SetCellValue(fileName, "D"+a, v.City)
f.SetCellValue(fileName, "E"+a, v.WorkerName)
f.SetCellValue(fileName, "F"+a, v.WorkerMobile)
f.SetCellValue(fileName, "G"+a, v.UserSource)
f.SetCellValue(fileName, "H"+a, v.Ip)
f.SetCellValue(fileName, "I"+a, utils.StringToTime(v.CreateTime))
}
// Set active sheet of the workbook.
f.SetActiveSheet(index)
// Save xlsx file by the given path.
if err := f.SaveAs("./" + fileName + ".csv"); err != nil {
fmt.Println(err)
return
}
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "./"+fileName+".csv")) //fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
c.Writer.Header().Add("Content-Type", "application/octet-stream")
c.File("./" + fileName + ".csv")
return
}
...@@ -62,14 +62,14 @@ type GetSurveyUserList struct { ...@@ -62,14 +62,14 @@ type GetSurveyUserList struct {
type GetSurveyLogListReq struct { type GetSurveyLogListReq struct {
PageInfo PageInfo
UserId int `gorm:"type:int(255)" json:"user_id"` UserId int `gorm:"type:int(255)" json:"user_id" form:"user_id"`
MocId int `gorm:"type:int(255)" json:"moc_id"` MocId int `gorm:"type:int(255)" json:"moc_id" form:"moc_id"`
SlPage int `gorm:"type:int(255)" json:"sl_page"` SlPage int `gorm:"type:int(255)" json:"sl_page" form:"sl_page"`
WorkerName string `gorm:"type:string(255)" json:"worker_name"` WorkerName string `gorm:"type:string(255)" json:"worker_name" form:"worker_name"`
WorkerMobile string `gorm:"type:string(255)" json:"worker_mobile"` WorkerMobile string `gorm:"type:string(255)" json:"worker_mobile" form:"worker_mobile"`
Region string `gorm:"type:string(255)" json:"region"` Region string `gorm:"type:string(255)" json:"region" form:"region"`
City string `gorm:"type:string(255)" json:"city"` City string `gorm:"type:string(255)" json:"city" form:"city"`
Zone string `gorm:"type:string(255)" json:"zone"` Zone string `gorm:"type:string(255)" json:"zone" form:"zone"`
StartCreateTime string `json:"start_create_time" form:"start_create_time"` StartCreateTime string `json:"start_create_time" form:"start_create_time"`
EndCreateTime string `json:"end_create_time" form:"end_create_time"` EndCreateTime string `json:"end_create_time" form:"end_create_time"`
Groupby string `json:"groupby" form:"groupby"` Groupby string `json:"groupby" form:"groupby"`
...@@ -91,3 +91,17 @@ type SlData struct { ...@@ -91,3 +91,17 @@ type SlData struct {
Cid int `json:"cid"` Cid int `json:"cid"`
MocId int `json:"moc_id"` MocId int `json:"moc_id"`
} }
type GetSurveyLogPageList struct {
Id int `gorm:"type:int(255)" json:"id"`
UserName string `gorm:"type:string(255)" json:"user_name"`
Region string `gorm:"type:string(255)" json:"region"`
City string `gorm:"type:string(255)" json:"city"`
Zone string `gorm:"type:string(255)" json:"zone"`
Address string `gorm:"type:string(255)" json:"address"`
WorkerName string `gorm:"type:string(255)" json:"worker_name"`
WorkerMobile string `gorm:"type:string(255)" json:"worker_mobile"`
UserSource string `gorm:"type:string(255)" json:"user_source"`
Ip string `gorm:"type:string(255)" json:"ip"`
CreateTime string `gorm:"type:string(255)" json:"create_time"`
}
...@@ -22,5 +22,6 @@ func InitSurveyPublicRouter(Router *gin.RouterGroup) { ...@@ -22,5 +22,6 @@ func InitSurveyPublicRouter(Router *gin.RouterGroup) {
DataVipCommentRouter.POST("createLog", mobile.CreateSurveyLog) DataVipCommentRouter.POST("createLog", mobile.CreateSurveyLog)
DataVipCommentRouter.GET("exportSurveyUserExcel", mobile.ExportSurveyUserExcel) DataVipCommentRouter.GET("exportSurveyUserExcel", mobile.ExportSurveyUserExcel)
DataVipCommentRouter.GET("exportMocDataExcel", mobile.ExportMocDataExcel) DataVipCommentRouter.GET("exportMocDataExcel", mobile.ExportMocDataExcel)
DataVipCommentRouter.GET("exportSurveyLogPageList", mobile.ExportSurveyLogPageList)
} }
} }
...@@ -265,56 +265,103 @@ func GetSurveyUserCount(req request.GetSurveyUserListReq) int64 { ...@@ -265,56 +265,103 @@ func GetSurveyUserCount(req request.GetSurveyUserListReq) int64 {
} }
// 点击量 // 点击量
// SELECT count(sl.page) as cid, sl.moc_id FROM (select moc_id, user_id, page, ip from survey_log where create_time > '2023-09-11 00:00:00' and create_time <= '2023-09-11 23:59:59' AND page = 10 and moc_id != 0 group by ip)sl left join customer_user as cu on sl.user_id = cu.id group by sl.moc_id
func GetSurveyLogCount(req request.GetSurveyLogListReq) map[int]int { func GetSurveyLogCount(req request.GetSurveyLogListReq) map[int]int {
conditions := ""
list := make([]request.SlData, 0) if req.MocId != 0 {
conditions += " AND moc_id = " + strconv.Itoa(req.MocId)
}
if req.SlPage != 0 {
conditions += " AND page = " + strconv.Itoa(req.SlPage)
}
if req.Region != "" {
conditions += " AND region like '%" + req.Region + "%'"
}
if req.City != "" {
conditions += " AND city like '%" + req.City + "%'"
}
table := " (select moc_id, user_id, page from survey_log group by ip)sl " if req.StartCreateTime != "" {
conditions += " AND create_time >'" + req.StartCreateTime + " 00:00:00'"
}
if req.EndCreateTime != "" {
conditions += " AND create_time <='" + req.EndCreateTime + " 23:59:59'"
}
conditions += " and moc_id != 0 "
table := " (select moc_id, user_id, page, ip from survey_log WHERE 1>0 " + conditions + " group by ip)sl "
//table := " survey_log as sl left join customer_user as cu on sl.user_id=cu.id " //table := " survey_log as sl left join customer_user as cu on sl.user_id=cu.id "
field := " count(sl.page) as cid, sl.moc_id " field := " count(sl.page) as cid, sl.moc_id "
list := make([]request.SlData, 0)
sqlStr2 := "SELECT " + field +
" FROM " + table
global.GVA_DB.Raw(sqlStr2).Scan(&list)
if global.GVA_DB.Error != nil {
return nil
}
reply := make(map[int]int, 0)
for _, v := range list {
reply[v.MocId] = v.Cid
}
return reply
}
// 点击列表
// SELECT user_id, user_name, region, city, worker_name, worker_mobile, user_source, ip FROM (select moc_id, user_id, page, ip from survey_log where create_time > '2023-09-11 00:00:00' and create_time <= '2023-09-11 23:59:59' AND moc_id = 1 AND page = 10 group by ip)sl left join customer_user as cu on sl.user_id = cu.id
func GetSurveyLogPageList(req request.GetSurveyLogListReq) []request.GetSurveyLogPageList {
conditions := "" conditions := ""
if req.MocId != 0 { if req.MocId != 0 {
conditions += " AND sl.moc_id = " + strconv.Itoa(req.MocId) conditions += " AND moc_id = " + strconv.Itoa(req.MocId)
} }
if req.SlPage != 0 { if req.SlPage != 0 {
conditions += " AND sl.page = " + strconv.Itoa(req.SlPage) conditions += " AND page = " + strconv.Itoa(req.SlPage)
} }
if req.Region != "" { if req.Region != "" {
conditions += " AND sl.region like '%" + req.Region + "%'" conditions += " AND region like '%" + req.Region + "%'"
} }
if req.City != "" { if req.City != "" {
conditions += " AND sl.city like '%" + req.City + "%'" conditions += " AND city like '%" + req.City + "%'"
} }
if req.StartCreateTime != "" { if req.StartCreateTime != "" {
conditions += " AND sl.create_time >'" + req.StartCreateTime + " 00:00:00'" conditions += " AND create_time >'" + req.StartCreateTime + " 00:00:00'"
} }
if req.EndCreateTime != "" { if req.EndCreateTime != "" {
conditions += " AND sl.create_time <='" + req.EndCreateTime + " 23:59:59'" conditions += " AND create_time <='" + req.EndCreateTime + " 23:59:59'"
} }
conditions += " and moc_id != 0 "
table := " (select moc_id, user_id, page, ip, create_time from survey_log WHERE 1>0 " + conditions + " group by ip order by create_time asc)sl "
table += " left join customer_user as cu on sl.user_id = cu.id "
field := " cu.id, cu.user_name, cu.region, cu.city, cu.worker_name, cu.worker_mobile, cu.user_source" +
", sl.ip, sl.create_time "
list := make([]request.GetSurveyLogPageList, 0)
sqlStr2 := "SELECT " + field + sqlStr2 := "SELECT " + field +
" FROM " + table + " FROM " + table +
" WHERE 1>0 " + conditions " WHERE 1>0 "
if req.Groupby != "" {
sqlStr2 += " GROUP BY sl.moc_id"
}
global.GVA_DB.Raw(sqlStr2).Scan(&list) global.GVA_DB.Raw(sqlStr2).Scan(&list)
if global.GVA_DB.Error != nil { if global.GVA_DB.Error != nil {
return nil return nil
} }
reply := make(map[int]int, 0) return list
for _, v := range list {
reply[v.MocId] = v.Cid
}
return reply
} }
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