1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package service
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"strconv"
)
func CreateSurveyUser(req model.SurveyUser) (error, int) {
err := global.GVA_DB.Table("survey_user").Create(&req).Error
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
}
func CreateSurveyLog(req model.SurveyLog) error {
err := global.GVA_DB.Table("survey_log").Create(&req).Error
return err
}
func GetSurveyUserList(req request.GetSurveyUserListReq) (error, []request.GetSurveyUserList, int64) {
pagesize := 10
page := 1
if req.PageSize != 0 {
pagesize = req.PageSize
}
if req.Page != 0 {
page = req.Page
}
currentpage := pagesize * (page - 1)
list := make([]request.GetSurveyUserList, 0)
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 "
field := " sur.id, sur.user_id, sur.moc_id, sur.code_mobile, sur.code, sur.contacts, sur.contacts_mobile" +
", sur.reference, sur.reference_mobile, sur.create_time" +
", sur.country, sur.area, sur.region, sur.city" +
", cu.worker_name, cu.worker_mobile " +
", vc.code as vcode "
conditions := ""
orderby := " sur.create_time desc "
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 + "'"
}
if req.EndCreateTime != "" {
conditions += " AND sur.create_time <='" + req.EndCreateTime + "'"
}
//@@总条数,总页数
var totalItem int64 = 0
sqlStr := "SELECT count(sur.id) as totalItem FROM " + table + " where 1=1 " + conditions
global.GVA_DB.Raw(sqlStr).Count(&totalItem) //获取总条数
sqlStr2 := "SELECT " + field +
" FROM " + table +
" WHERE 1>0 " + conditions +
" ORDER BY " + orderby +
" LIMIT " + strconv.Itoa(currentpage) + "," + strconv.Itoa(pagesize)
global.GVA_DB.Raw(sqlStr2).Scan(&list)
if global.GVA_DB.Error != nil {
return global.GVA_DB.Error, nil, 0
}
return nil, list, totalItem
}
func GetSurveyUserDataList(id int) []model.SurveyUserData {
list := make([]model.SurveyUserData, 0)
table := " survey_user_data "
field := " survey_user_id, `option`, option_value, option_num, price "
conditions := " AND survey_user_id = " + strconv.Itoa(id)
sqlStr2 := "SELECT " + field +
" FROM " + table +
" WHERE 1>0 " + conditions
global.GVA_DB.Raw(sqlStr2).Scan(&list)
if global.GVA_DB.Error != nil {
return []model.SurveyUserData{}
}
return list
}
func GetSurveyLogList(req request.GetSurveyLogListReq) (error, []request.GetSurveyLogList, int64) {
pagesize := 10
page := 1
if req.PageSize != 0 {
pagesize = req.PageSize
}
if req.Page != 0 {
page = req.Page
}
currentpage := pagesize * (page - 1)
list := make([]request.GetSurveyLogList, 0)
table := " survey_log as sl " +
" left join customer_user as cu on sur.user_id=cu.id "
field := " sur.id, sur.user_id, sur.moc_id, sur.contacts, sur.contacts_mobile" +
", sur.reference, sur.reference_mobile, sur.create_time" +
", sur.country, sur.area, sur.region, sur.city" +
", cu.worker_name, cu.worker_mobile "
conditions := ""
orderby := " sur.create_time desc "
if req.MocId != 0 {
conditions += " AND sur.moc_id = " + strconv.Itoa(currentpage)
}
if req.Region != "" {
conditions += " AND region like '%" + req.Region + "%'"
}
if req.City != "" {
conditions += " AND city like '%" + req.City + "%'"
}
if req.StartCreateTime != "" {
conditions += " AND sur.create_time >'" + req.StartCreateTime + "'"
}
if req.EndCreateTime != "" {
conditions += " AND sur.create_time <='" + req.EndCreateTime + "'"
}
//@@总条数,总页数
var totalItem int64 = 0
sqlStr := "SELECT count(vo.id) as totalItem FROM " + table + " where 1=1 " + conditions
global.GVA_DB.Raw(sqlStr).Count(&totalItem) //获取总条数
sqlStr2 := "SELECT " + field +
" FROM " + table +
" WHERE 1>0 " + conditions +
" ORDER BY " + orderby +
" LIMIT " + strconv.Itoa(currentpage) + "," + strconv.Itoa(pagesize)
global.GVA_DB.Raw(sqlStr2).Scan(&list)
if global.GVA_DB.Error != nil {
return global.GVA_DB.Error, nil, 0
}
return nil, list, totalItem
}