Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dt_analysis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoyanbin
dt_analysis
Commits
20d48647
Commit
20d48647
authored
Sep 08, 2023
by
haoyanbin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
b156edf0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
188 additions
and
2 deletions
+188
-2
survey.go
api/mobile/survey.go
+60
-0
survey.go
model/request/survey.go
+8
-0
survey.go
router/survey.go
+1
-0
survey.go
service/survey.go
+119
-2
No files found.
api/mobile/survey.go
View file @
20d48647
...
...
@@ -212,3 +212,63 @@ func ExportSurveyUserExcel(c *gin.Context) {
c
.
File
(
"./"
+
fileName
+
".csv"
)
return
}
func
ExportMocDataExcel
(
c
*
gin
.
Context
)
{
var
req
request
.
GetSurveyUserListReq
_
=
c
.
ShouldBindQuery
(
&
req
)
req
.
Status
=
1
//req.IsReference = 1
req
.
MocId
=
1
surveyCount
:=
service
.
GetSurveyUserCount
(
req
)
//留资数量
logCountReq
:=
request
.
GetSurveyLogListReq
{
SlPage
:
10
,
MocId
:
req
.
MocId
,
}
logCount
:=
service
.
GetSurveyLogCount
(
logCountReq
)
//点击量
fmt
.
Println
(
logCount
)
fileName
:=
"数据统计"
+
time
.
Now
()
.
Format
(
"20060102"
)
f
:=
excelize
.
NewFile
()
// Create a new sheet.
index
:=
f
.
NewSheet
(
fileName
)
f
.
SetCellValue
(
fileName
,
"A1"
,
"日期"
)
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"
,
"点击率"
)
f
.
SetCellValue
(
fileName
,
"I1"
,
"留资数量"
)
f
.
SetCellValue
(
fileName
,
"J1"
,
"留资率"
)
f
.
SetCellValue
(
fileName
,
"K1"
,
"获客单价"
)
f
.
SetCellValue
(
fileName
,
"A2"
,
time
.
Now
()
.
Format
(
"2006/01/02"
))
f
.
SetCellValue
(
fileName
,
"B2"
,
"直接留资"
)
f
.
SetCellValue
(
fileName
,
"C2"
,
"短信"
)
f
.
SetCellValue
(
fileName
,
"D2"
,
""
)
f
.
SetCellValue
(
fileName
,
"E2"
,
""
)
f
.
SetCellValue
(
fileName
,
"F2"
,
""
)
f
.
SetCellValue
(
fileName
,
"G2"
,
logCount
[
0
]
.
Cid
)
f
.
SetCellValue
(
fileName
,
"H2"
,
""
)
f
.
SetCellValue
(
fileName
,
"I2"
,
surveyCount
)
f
.
SetCellValue
(
fileName
,
"J2"
,
""
)
f
.
SetCellValue
(
fileName
,
"K2"
,
""
)
// 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
}
model/request/survey.go
View file @
20d48647
...
...
@@ -28,6 +28,7 @@ type GetSurveyUserListReq struct {
StartCreateTime
string
`json:"start_create_time" form:"start_create_time"`
EndCreateTime
string
`json:"end_create_time" form:"end_create_time"`
Status
int
`gorm:"type:int(255)" json:"status"`
IsReference
int
`gorm:"-" json:"isReference"`
}
type
GetSurveyUserListReply
struct
{
...
...
@@ -58,6 +59,7 @@ type GetSurveyLogListReq struct {
PageInfo
UserId
int
`gorm:"type:int(255)" json:"user_id"`
MocId
int
`gorm:"type:int(255)" json:"moc_id"`
SlPage
int
`gorm:"type:int(255)" json:"sl_page"`
WorkerName
string
`gorm:"type:string(255)" json:"worker_name"`
WorkerMobile
string
`gorm:"type:string(255)" json:"worker_mobile"`
Region
string
`gorm:"type:string(255)" json:"region"`
...
...
@@ -65,6 +67,7 @@ type GetSurveyLogListReq struct {
Zone
string
`gorm:"type:string(255)" json:"zone"`
StartCreateTime
string
`json:"start_create_time" form:"start_create_time"`
EndCreateTime
string
`json:"end_create_time" form:"end_create_time"`
Groupby
string
`json:"groupby" form:"groupby"`
}
type
GetSurveyLogListReply
struct
{
...
...
@@ -78,3 +81,8 @@ type GetSurveyLogList struct {
WorkerName
string
`gorm:"type:string(255)" json:"worker_name"`
WorkerMobile
string
`gorm:"type:string(255)" json:"worker_mobile"`
}
type
SlData
struct
{
Cid
int
`json:"cid"`
Page
int
`json:"page"`
}
router/survey.go
View file @
20d48647
...
...
@@ -21,5 +21,6 @@ func InitSurveyPublicRouter(Router *gin.RouterGroup) {
DataVipCommentRouter
.
POST
(
"createData"
,
mobile
.
CreateSurveyUserData
)
DataVipCommentRouter
.
POST
(
"createLog"
,
mobile
.
CreateSurveyLog
)
DataVipCommentRouter
.
GET
(
"exportSurveyUserExcel"
,
mobile
.
ExportSurveyUserExcel
)
DataVipCommentRouter
.
GET
(
"exportMocDataExcel"
,
mobile
.
ExportMocDataExcel
)
}
}
service/survey.go
View file @
20d48647
...
...
@@ -87,11 +87,11 @@ func GetSurveyUserList(req request.GetSurveyUserListReq) (error, []request.GetSu
}
if
req
.
StartCreateTime
!=
""
{
conditions
+=
" AND sur.create_time >'"
+
req
.
StartCreateTime
+
"'"
conditions
+=
" AND sur.create_time >'"
+
req
.
StartCreateTime
+
"
00:00:00
'"
}
if
req
.
EndCreateTime
!=
""
{
conditions
+=
" AND sur.create_time <='"
+
req
.
EndCreateTime
+
"'"
conditions
+=
" AND sur.create_time <='"
+
req
.
EndCreateTime
+
"
23:59:59
'"
}
//@@总条数,总页数
...
...
@@ -197,3 +197,120 @@ func GetSurveyLogList(req request.GetSurveyLogListReq) (error, []request.GetSurv
}
return
nil
,
list
,
totalItem
}
// 留资数量
func
GetSurveyUserCount
(
req
request
.
GetSurveyUserListReq
)
int64
{
table
:=
" survey_user as sur "
+
" left join customer_user as cu on sur.user_id=cu.id "
+
" left join vcode as vc on sur.user_id=vc.user_id and sur.moc_id = vc.moc_id "
conditions
:=
""
if
req
.
MocId
!=
0
{
conditions
+=
" AND sur.moc_id = "
+
strconv
.
Itoa
(
req
.
MocId
)
}
if
req
.
Status
!=
0
{
conditions
+=
" AND sur.status = "
+
strconv
.
Itoa
(
req
.
Status
)
}
if
req
.
Region
!=
""
{
conditions
+=
" AND sur.region like '%"
+
req
.
Region
+
"%'"
}
if
req
.
City
!=
""
{
conditions
+=
" AND sur.city like '%"
+
req
.
City
+
"%'"
}
if
req
.
Contacts
!=
""
{
conditions
+=
" AND sur.contacts like '%"
+
req
.
Contacts
+
"%'"
}
if
req
.
ContactsMobile
!=
""
{
conditions
+=
" AND sur.contacts_mobile like '%"
+
req
.
ContactsMobile
+
"%'"
}
if
req
.
Reference
!=
""
{
conditions
+=
" AND sur.reference like '%"
+
req
.
Reference
+
"%'"
}
if
req
.
ReferenceMobile
!=
""
{
conditions
+=
" AND sur.reference_mobile like '%"
+
req
.
ReferenceMobile
+
"%'"
}
if
req
.
StartCreateTime
!=
""
{
conditions
+=
" AND sur.create_time >'"
+
req
.
StartCreateTime
+
" 00:00:00'"
}
if
req
.
EndCreateTime
!=
""
{
conditions
+=
" AND sur.create_time <='"
+
req
.
EndCreateTime
+
" 23:59:59'"
}
if
req
.
IsReference
==
1
{
conditions
+=
" AND sur.contacts = cu.worker_mobile "
}
else
if
req
.
IsReference
==
2
{
conditions
+=
" AND sur.contacts != cu.worker_mobile "
}
//@@总条数,总页数
var
totalItem
int64
=
0
sqlStr
:=
"SELECT count(sur.id) as totalItem FROM "
+
table
+
" where 1=1 "
+
conditions
global
.
GVA_DB
.
Raw
(
sqlStr
)
.
Count
(
&
totalItem
)
//获取总条数
if
global
.
GVA_DB
.
Error
!=
nil
{
return
0
}
return
totalItem
}
// 点击量
func
GetSurveyLogCount
(
req
request
.
GetSurveyLogListReq
)
[]
request
.
SlData
{
list
:=
make
([]
request
.
SlData
,
0
)
table
:=
" survey_log as sl "
+
" left join customer_user as cu on sl.user_id=cu.id "
field
:=
" count(sl.id) as cid, sl.page "
conditions
:=
""
if
req
.
MocId
!=
0
{
conditions
+=
" AND sl.moc_id = "
+
strconv
.
Itoa
(
req
.
MocId
)
}
if
req
.
SlPage
!=
0
{
conditions
+=
" AND sl.page = "
+
strconv
.
Itoa
(
req
.
SlPage
)
}
if
req
.
Region
!=
""
{
conditions
+=
" AND sl.region like '%"
+
req
.
Region
+
"%'"
}
if
req
.
City
!=
""
{
conditions
+=
" AND sl.city like '%"
+
req
.
City
+
"%'"
}
if
req
.
StartCreateTime
!=
""
{
conditions
+=
" AND sl.create_time >'"
+
req
.
StartCreateTime
+
" 00:00:00'"
}
if
req
.
EndCreateTime
!=
""
{
conditions
+=
" AND sl.create_time <='"
+
req
.
EndCreateTime
+
" 23:59:59'"
}
sqlStr2
:=
"SELECT "
+
field
+
" FROM "
+
table
+
" WHERE 1>0 "
+
conditions
if
req
.
Groupby
!=
""
{
sqlStr2
+=
" GROUP BY "
+
req
.
Groupby
}
global
.
GVA_DB
.
Raw
(
sqlStr2
)
.
Scan
(
&
list
)
if
global
.
GVA_DB
.
Error
!=
nil
{
return
nil
}
return
list
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment