-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathorder_check.go
98 lines (93 loc) · 2.88 KB
/
order_check.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
package unipay
import (
"das_sub_account/notify"
"das_sub_account/tables"
"fmt"
"github.com/dotbitHQ/das-lib/http_api"
"time"
)
func (t *ToolUniPay) RunOrderCheck() {
tickerOrder := time.NewTicker(time.Minute)
t.Wg.Add(1)
go func() {
defer http_api.RecoverPanic()
for {
select {
case <-tickerOrder.C:
log.Info("RunOrderCheck start ...")
if err := t.doOrderCheck(); err != nil {
log.Error("doOrderCheck err:", err.Error())
notify.SendLarkErrNotify("doOrderCheck", err.Error())
}
log.Info("RunOrderCheck end ...")
case <-t.Ctx.Done():
log.Info("RunOrderCheck done")
t.Wg.Done()
return
}
}
}()
}
func (t *ToolUniPay) doOrderCheck() error {
list, err := t.DbDao.GetNeedCheckOrderList()
if err != nil {
return fmt.Errorf("GetNeedCheckOrderList err: %s", err.Error())
}
for _, v := range list {
switch v.ActionType {
case tables.ActionTypeMint:
smtRecord, err := t.DbDao.GetSmtRecordByOrderId(v.OrderId)
if err != nil {
return fmt.Errorf("GetSmtRecordByOrderId err: %s", err.Error())
}
acc, err := t.DbDao.GetAccountInfoByAccountId(v.AccountId)
if err != nil {
return fmt.Errorf("GetAccountInfoByAccountId err: %s", err.Error())
} else if acc.Id == 0 {
if smtRecord.Id == 0 {
continue
} else if smtRecord.RecordType == tables.RecordTypeClosed {
notify.SendLarkErrNotify("doOrderCheck", v.OrderId)
}
} else {
newStatus := tables.OrderStatusSuccess
if smtRecord.Id == 0 || smtRecord.RecordType == tables.RecordTypeClosed {
newStatus = tables.OrderStatusFail
}
if err := t.DbDao.UpdateOrderStatusForCheckMint(v.OrderId, tables.OrderStatusDefault, newStatus); err != nil {
return fmt.Errorf("UpdateOrderStatusForCheckMint err: %s[%s]", err.Error(), v.OrderId)
}
}
case tables.ActionTypeRenew:
acc, err := t.DbDao.GetAccountInfoByAccountId(v.AccountId)
if err != nil {
return fmt.Errorf("GetAccountInfoByAccountId err: %s", err.Error())
}
if acc.Id == 0 {
notify.SendLarkErrNotify("doRenewOrderCheck", fmt.Sprintf("[%s][%s]", v.OrderId, v.AccountId))
continue
}
smtRecord, err := t.DbDao.GetSmtRecordByOrderId(v.OrderId)
if err != nil {
return fmt.Errorf("GetSmtRecordByOrderId err: %s", err.Error())
}
if smtRecord.Id == 0 {
continue
}
if smtRecord.RecordType == tables.RecordTypeDefault {
continue
}
newStatus := tables.OrderStatusSuccess
if smtRecord.RecordType == tables.RecordTypeClosed {
newStatus = tables.OrderStatusFail
}
if err := t.DbDao.UpdateOrderStatusForCheckRenew(v.OrderId, tables.OrderStatusDefault, newStatus); err != nil {
return fmt.Errorf("UpdateOrderStatusForCheckRenew err: %s[%s]", err.Error(), v.OrderId)
}
case tables.ActionTypeCouponCreate:
default:
notify.SendLarkErrNotify("doOrderCheck", fmt.Sprintf("doOrderCheck unsupport action %d", v.ActionType))
}
}
return nil
}