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
package service
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/utils"
"strconv"
"time"
)
func GetPointsLogList(req request.GetPointsLogListReq) (error, []model.PointsLog, int64) {
pagesize := 10
page := 1
if req.PageSize != 0 {
pagesize = req.PageSize
}
if req.Page != 0 {
page = req.Page
}
currentpage := pagesize * (page - 1)
field := " id, change_type, change_time, change_num, now_points_num, remark, other_no, source "
table := " points_log "
conditions := " AND delflag=0 "
orderby := ""
orderby += " create_time desc"
if req.UserId != 0 {
conditions += " AND user_id = " + strconv.Itoa(req.UserId)
}
if req.Source != 0 {
conditions += " AND source = " + strconv.Itoa(req.Source)
}
if req.ChangeType != 0 {
conditions += " AND change_type = " + strconv.Itoa(req.ChangeType)
}
list := make([]model.PointsLog, 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 GetPointsData(userId int, changeType int) int {
table := " points_log "
conditions := " AND delflag=0 "
if userId != 0 {
conditions += " AND user_id = " + strconv.Itoa(userId)
}
if changeType != 0 {
conditions += " AND change_type = " + strconv.Itoa(changeType)
}
//@@总条数,总页数
var totalItem int64 = 0
sqlStr := "SELECT sum(change_num) as totalItem FROM " + table + " where 1=1 " + conditions
global.GVA_DB.Raw(sqlStr).Count(&totalItem) //获取总条数
return int(totalItem)
}
func GetPointsLog(id int) (error, model.PointsLog) {
data := new(model.PointsLog)
table := " points_log "
field := " id, maturity_time, vip_level "
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, model.PointsLog{}
}
return nil, *data
}
func CreatePointsLog(req model.PointsLog) error {
err := global.GVA_DB.Table("points_log").Create(&req).Error
return err
}
func IsPointsLog(otherNo string) int64 {
var totalItem int64 = 0
sqlStr := "SELECT count(id) as totalItem FROM points_log where other_no=? and source=1"
global.GVA_DB.Raw(sqlStr, otherNo).Count(&totalItem) //获取总条数
return totalItem
}
func GetPointsOrder(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 GetPointsOrderList(req request.GetPointsOrderListReq) (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 CreatePointsOrder(req model.PointsOrder) error {
sqlStr := "INSERT INTO points_order(user_id, pay_status, pay_type, points_no, points_num, other_no, remark) VALUE(?,?,?,?,?,?,?)"
global.GVA_DB.Exec(sqlStr, req.UserId, req.PayStatus, req.PayType, req.PointsNo, req.PointsNum, req.OtherNo, req.Remark)
return global.GVA_DB.Error
}
func UpdatePointsOrderForOtherNo(otherNo string) error {
payTime := time.Now().Format("2006-01-02 15:04:05")
sqlStr := "UPDATE points_order SET pay_status=2, pay_time='" + payTime + "' WHERE other_no=?"
global.GVA_DB.Exec(sqlStr, otherNo)
return global.GVA_DB.Error
}
func GetPointsOrderForNo(orderNo string) (error, model.VipOrder) {
data := new(model.VipOrder)
table := " vip_order "
field := " id, user_id, vip_level, vip_day, status "
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 GetPointsLogNum(hospitalCode string, userId int) (int64, int64) {
start, _ := utils.GetMonthStartEnd(time.Now())
var totalItem int64 = 0
sqlStr := "SELECT count(id) as totalItem FROM points_log where hospital_code=? and change_type = 2 and source=1 and change_time > ?"
global.GVA_DB.Raw(sqlStr, hospitalCode, start).Count(&totalItem) //获取总条数
var totalItem2 int64 = 0
sqlStr2 := "SELECT count(id) as totalItem FROM points_log where user_id=? and change_type = 2 and source=1 and change_time > ?"
global.GVA_DB.Raw(sqlStr2, userId, start).Count(&totalItem2) //获取总条数
return totalItem, totalItem2
}