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
200
201
202
203
204
205
206
207
package service
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/utils"
"strconv"
"time"
)
func GetVipUser(userId int) (error, model.VipUser) {
data := new(model.VipUser)
table := " vip_user "
field := " id, maturity_time, vip_level "
sqlStr := "SELECT " + field +
" FROM " + table +
" WHERE delflag=0 AND user_id =?"
global.GVA_DB.Raw(sqlStr, userId).Find(&data)
if global.GVA_DB.Error != nil {
return global.GVA_DB.Error, model.VipUser{}
}
return nil, *data
}
func CreateVipUser(req model.VipUser) error {
sqlStr := "INSERT INTO vip_user(user_id, maturity_time, vip_level) VALUE(?,?,?)"
global.GVA_DB.Exec(sqlStr, req.UserId, req.MaturityTime, req.VipLevel)
return global.GVA_DB.Error
}
func UpdateVipUser(req model.VipUser, userId int) error {
sqlStr := "UPDATE vip_user SET maturity_time='" + utils.Time2Str(req.MaturityTime) + "', vip_level=? WHERE user_id=?"
global.GVA_DB.Exec(sqlStr, req.VipLevel, userId)
return global.GVA_DB.Error
}
func IsVipUser(userId int) int64 {
var totalItem int64 = 0
sqlStr := "SELECT count(id) as totalItem FROM vip_user where user_id=?"
global.GVA_DB.Raw(sqlStr, userId).Count(&totalItem) //获取总条数
return totalItem
}
func IsNewUser(userId int) int64 {
//now := time.Now().Format("2006-01-02 15:04:05")
var totalItem int64 = 0
sqlStr := "SELECT count(id) as totalItem FROM vip_order where user_id='" + strconv.Itoa(userId) + "' and status = 2 "
global.GVA_DB.Raw(sqlStr).Count(&totalItem) //获取总条数
return totalItem
}
func GetVipConf(id int) (error, *model.VipConf) {
data := new(model.VipConf)
table := " vip_conf "
field := " id, title, content, vip_level, vip_money, vip_day, vip_type, remark "
sqlStr := "SELECT " + field +
" FROM " + table +
" WHERE delflag=0 AND id =?"
global.GVA_DB.Raw(sqlStr, id).Find(&data)
if global.GVA_DB.Error != nil {
return global.GVA_DB.Error, nil
}
return nil, data
}
func GetVipConfList(req request.GetVipConfListReq) (error, []model.VipConf, int64) {
pagesize := 10
page := 1
currentpage := pagesize * (page - 1)
field := " id, title, content, vip_money, vip_day, vip_type, remark "
table := " vip_conf"
conditions := " AND delflag=0 AND is_show=1"
orderby := ""
orderby += " sort asc"
if req.IsNewUser != 1 {
conditions += " AND vip_type != 2 "
}
list := make([]model.VipConf, 0)
//@@总条数,总页数
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)
return nil, list, totalItem
}
func CreateVipOrder(req model.VipOrder) error {
sqlStr := "INSERT INTO vip_order(order_no, user_id, vip_conf_id, vip_day, vip_level, vip_money, pay_money, status, is_points, points_num, remark) VALUE(?,?,?,?,?,?,?,?,?,?,?)"
global.GVA_DB.Exec(sqlStr, req.OrderNo, req.UserId, req.VipConfId, req.VipDay, req.VipLevel, req.VipMoney, req.PayMoney, req.Status, req.IsPoints, req.PointsNum, req.Remark)
return global.GVA_DB.Error
}
func UpdateVipOrder(req request.CallBackReq) error {
payTime := time.Now().Format("2006-01-02 15:04:05")
sqlStr := "UPDATE vip_order SET status=2, pay_time='" + payTime + "', out_trade_no=?, transaction_id=? WHERE order_no=?"
global.GVA_DB.Exec(sqlStr, req.OutTradeNo, req.TransactionId, req.AttachInfo)
return global.GVA_DB.Error
}
func GetVipOrder(orderNo string) (error, model.VipOrder) {
data := new(model.VipOrder)
table := " vip_order "
field := " id, user_id, vip_level, vip_day, status, is_points, points_num "
sqlStr := "SELECT " + field +
" FROM " + table +
" WHERE delflag=0 AND order_no =?"
global.GVA_DB.Raw(sqlStr, orderNo).Find(&data)
if global.GVA_DB.Error != nil {
return global.GVA_DB.Error, model.VipOrder{}
}
return nil, *data
}
func GetVipOrderList(req request.GetVipOrderListReq) (error, []request.VipOrderList, 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.VipOrderList, 0)
field := " vo.id, vo.vip_money, vo.pay_money, vo.vip_level, vo.is_points" +
", vo.points_num, vo.create_time, vo.remark, vo.vip_day " +
", su.mobile, su.nick_name, sua.name"
table := " vip_order as vo " +
" left join sys_users as su on vo.user_id=su.id " +
" left join sys_user_authe as sua on su.id = sua.user_id and sua.delflag=0 "
conditions := " AND vo.delflag = 0 AND vo.status = 2 "
orderby := " create_time desc "
if req.Mobile != "" {
conditions += " AND su.mobile like '%" + req.Mobile + "%'"
}
if req.UserType != "" {
conditions += " AND su.user_type = " + req.UserType
}
if req.StartCreateTime != "" {
conditions += " AND vo.create_time >'" + req.StartCreateTime + "'"
}
if req.EndCreateTime != "" {
conditions += " AND vo.create_time <='" + req.EndCreateTime + "'"
}
if req.VipLevel != "" {
conditions += " AND vo.vip_level in (" + req.VipLevel + ")"
}
//@@总条数,总页数
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)
fmt.Println(sqlStr2)
global.GVA_DB.Raw(sqlStr2).Scan(&list)
if global.GVA_DB.Error != nil {
return global.GVA_DB.Error, nil, 0
}
return nil, list, totalItem
}