-
Notifications
You must be signed in to change notification settings - Fork 0
/
mission_get.go
244 lines (232 loc) · 7.75 KB
/
mission_get.go
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package TMSUserRunning
import (
"errors"
"fmt"
CoreFilter "github.com/fotomxq/weeekj_core/v5/core/filter"
CoreSQL "github.com/fotomxq/weeekj_core/v5/core/sql"
CoreSQLPages "github.com/fotomxq/weeekj_core/v5/core/sql/pages"
Router2SystemConfig "github.com/fotomxq/weeekj_core/v5/router2/system_config"
)
// ArgsGetMissionList 获取任务列表参数
type ArgsGetMissionList struct {
//分页
Pages CoreSQLPages.ArgsDataList `json:"pages"`
//跑腿单类型
// 0 帮我送 ; 1 帮我买; 2 帮我取
RunType int `db:"run_type" json:"runType" check:"intThan0" empty:"true"`
//关联组织
OrgID int64 `db:"org_id" json:"orgID" check:"id" empty:"true"`
//用户ID
// 允许为0,则该信息不属于任何用户,或不和任何用户关联
UserID int64 `db:"user_id" json:"userID" check:"id" empty:"true"`
//是否完成取货
NeedIsTake bool `json:"needIsTake" check:"bool"`
IsTake bool `json:"isTake" check:"bool"`
//是否完成
NeedIsFinish bool `json:"needIsFinish" check:"bool"`
IsFinish bool `json:"isFinish" check:"bool"`
//关联订单ID
// 可能没有关联订单
OrderID int64 `db:"order_id" json:"orderID" check:"id" empty:"true"`
//履约跑腿员
// 用户角色ID
RoleID int64 `db:"role_id" json:"roleID" check:"id" empty:"true"`
//是否支付跑腿费
// 当前费用部分
NeedIsRunPay bool `json:"needIsRunPay" check:"bool"`
IsRunPay bool `json:"isRunPay" check:"bool"`
//是否已经支付过跑腿费
// 存在支付过的费用
NeedHaveRunPay bool `json:"needHaveRunPay" check:"bool"`
HaveRunPay bool `json:"haveRunPay" check:"bool"`
//是否被删除
IsRemove bool `db:"is_remove" json:"isRemove" check:"bool" empty:"true"`
//搜索
Search string `json:"search" check:"search" empty:"true"`
}
// GetMissionList 获取任务列表
func GetMissionList(args *ArgsGetMissionList) (dataList []FieldsMission, dataCount int64, err error) {
where := ""
maps := map[string]interface{}{}
where = CoreSQL.GetDeleteSQL(args.IsRemove, where)
if args.RunType > -1 {
where = where + " AND run_type = :run_type"
maps["run_type"] = args.RunType
}
if args.OrgID > -1 {
where = where + " AND org_id = :org_id"
maps["org_id"] = args.OrgID
}
if args.UserID > -1 {
where = where + " AND user_id = :user_id"
maps["user_id"] = args.UserID
}
if args.UserID > -1 {
where = where + " AND user_id = :user_id"
maps["user_id"] = args.UserID
}
if args.NeedIsTake {
if args.IsTake {
where = where + " AND take_at > to_timestamp(1000000)"
} else {
where = where + " AND take_at <= to_timestamp(1000000)"
}
}
if args.NeedIsFinish {
if args.IsFinish {
where = where + " AND finish_at > to_timestamp(1000000)"
} else {
where = where + " AND finish_at <= to_timestamp(1000000)"
}
}
if args.OrderID > -1 {
where = where + " AND order_id = :order_id"
maps["order_id"] = args.OrderID
}
if args.RoleID > -1 {
where = where + " AND role_id = :role_id"
maps["role_id"] = args.RoleID
}
if args.NeedIsRunPay {
if args.IsRunPay {
where = where + " AND run_pay_at > to_timestamp(1000000)"
} else {
where = where + " AND run_pay_at <= to_timestamp(1000000)"
}
}
if args.NeedHaveRunPay {
if args.HaveRunPay {
where = where + " AND run_price > 0"
} else {
where = where + " AND run_price <= 0"
}
}
if args.Search != "" {
where = where + " AND (order_wait_price ILIKE '%' || :search || '%' OR des ILIKE '%' || :search || '%' OR order_des ILIKE '%' || :search || '%' OR from_address ->> 'address' ILIKE '%' || :search || '%' OR from_address ->> 'name' ILIKE '%' || :search || '%' OR from_address ->> 'phone' ILIKE '%' || :search || '%' OR to_address ->> 'address' ILIKE '%' || :search || '%' OR to_address ->> 'name' ILIKE '%' || :search || '%' OR to_address ->> 'phone' ILIKE '%' || :search || '%')"
maps["search"] = args.Search
}
tableName := "tms_user_running_mission"
var rawList []FieldsMission
dataCount, err = CoreSQL.GetListPageAndCount(
Router2SystemConfig.MainDB.DB,
&rawList,
tableName,
"id",
"SELECT id "+"FROM "+tableName+" WHERE "+where,
where,
maps,
&args.Pages,
[]string{"id", "create_at", "update_at", "delete_at", "take_at", "finish_at"},
)
if err != nil || len(rawList) < 1 {
err = errors.New("no data")
return
}
for _, v := range rawList {
vData := getMissionID(v.ID)
if vData.ID < 1 {
continue
}
vData.TakeCode = ""
dataList = append(dataList, vData)
}
return
}
// ArgsGetMissionID 获取指定任务信息参数
type ArgsGetMissionID struct {
//ID
ID int64 `db:"id" json:"id" check:"id"`
//关联组织
OrgID int64 `db:"org_id" json:"orgID" check:"id" empty:"true"`
//关联用户
UserID int64 `db:"user_id" json:"userID" check:"id" empty:"true"`
//履约跑腿员
// 用户角色ID
RoleID int64 `db:"role_id" json:"roleID" check:"id" empty:"true"`
}
// GetMissionID 获取指定任务信息
func GetMissionID(args *ArgsGetMissionID) (data FieldsMission, err error) {
data = getMissionID(args.ID)
if data.ID < 1 {
err = errors.New("no data")
return
}
if !CoreFilter.EqID2(args.OrgID, data.OrgID) || !CoreFilter.EqID2(args.UserID, data.UserID) || !CoreFilter.EqID2(args.RoleID, data.RoleID) {
err = errors.New("no data")
return
}
data.TakeCode = ""
return
}
func getMissionID(id int64) (data FieldsMission) {
cacheMark := getMissionCacheMark(id)
if err := Router2SystemConfig.MainCache.GetStruct(cacheMark, &data); err == nil && data.ID > 0 {
return
}
err := Router2SystemConfig.MainDB.Get(&data, "SELECT id, create_at, update_at, delete_at, wait_at, good_type, take_at, finish_at, take_code, run_type, org_id, user_id, order_id, role_id, run_pay_at, run_pay_id, run_price, run_wait_price, run_pay_list, run_pay_after, order_pay_after, order_wait_price, order_price, order_pay_at, order_pay_id, des, order_des_files, order_des, good_widget, from_address, to_address, logs, params FROM tms_user_running_mission WHERE id = $1", id)
if err != nil || data.ID < 1 {
err = errors.New("no data")
return
}
Router2SystemConfig.MainCache.SetStruct(cacheMark, data, cacheTime)
return
}
// GetMissionAllInfoID 获取指定任务全部信息
func GetMissionAllInfoID(args *ArgsGetMissionID) (data FieldsMission, err error) {
data = getMissionID(args.ID)
if data.ID < 1 {
err = errors.New("no data")
return
}
if !CoreFilter.EqID2(args.OrgID, data.OrgID) || !CoreFilter.EqID2(args.UserID, data.UserID) || !CoreFilter.EqID2(args.RoleID, data.RoleID) {
err = errors.New("no data")
return
}
return
}
// GetMissionTakeCodeByID 获取任务领取代码
func GetMissionTakeCodeByID(args *ArgsGetMissionID) (code string, err error) {
var data FieldsMission
data = getMissionID(args.ID)
if data.ID < 1 {
err = errors.New("no data")
return
}
if data.TakeCode == "" {
err = errors.New("no data")
return
}
code = data.TakeCode
return
}
// 获取关联订单数据集
func getMissionListByOrderID(orderID int64) (dataList []FieldsMission, err error) {
err = Router2SystemConfig.MainDB.Select(&dataList, "SELECT id FROM tms_user_running_mission WHERE order_id = $1 AND delete_at < to_timestamp(1000000)", orderID)
if err != nil {
return
}
for k, v := range dataList {
dataList[k] = getMissionID(v.ID)
}
return
}
// 获取支付ID的相关任务
func getMissionListByPayID(payID int64) (dataList []FieldsMission, err error) {
err = Router2SystemConfig.MainDB.Select(&dataList, "SELECT id FROM tms_user_running_mission WHERE (order_pay_id = $1 OR run_pay_id = $1) AND delete_at < to_timestamp(1000000)", payID)
if err != nil {
return
}
for k, v := range dataList {
dataList[k] = getMissionID(v.ID)
}
return
}
// 获取缓冲名称
func getMissionCacheMark(id int64) string {
return fmt.Sprint("tms:user:running:id:", id)
}
// 删除缓冲
func deleteMissionCache(id int64) {
cacheMark := getMissionCacheMark(id)
Router2SystemConfig.MainCache.DeleteMark(cacheMark)
}