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
package service
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model/request"
"strconv"
)
func GetCustomerUserList(req request.GetCustomerUserListReq) (error, []request.GetCustomerUserList, 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.GetCustomerUserList, 0)
table := " customer_user"
field := " id, user_name, region, city, zone, address, contacts, contacts_mobile" +
", worker_position, worker_name, worker_mobile, user_source, user_type, create_time "
conditions := ""
orderby := " id asc "
if req.UserName != "" {
conditions += " AND user_name like '%" + req.UserName + "%'"
}
if req.Region != "" {
conditions += " AND region like '%" + req.Region + "%'"
}
if req.City != "" {
conditions += " AND city like '%" + req.City + "%'"
}
if req.Zone != "" {
conditions += " AND zone like '%" + req.Zone + "%'"
}
if req.WorkerName != "" {
conditions += " AND worker_name like '%" + req.WorkerName + "%'"
}
if req.WorkerMobile != "" {
conditions += " AND worker_mobile like '%" + req.WorkerMobile + "%'"
}
//@@总条数,总页数
var totalItem int64 = 0
sqlStr := "SELECT count(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 {
fmt.Println(sqlStr2)
return global.GVA_DB.Error, nil, 0
}
return nil, list, totalItem
}