/
recharge_expiration.go
57 lines (51 loc) · 1.45 KB
/
recharge_expiration.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
package handle
import (
"context"
"github.com/buyaobilian1/autobuytgvip-saas/btp-saas/dao/query"
"github.com/buyaobilian1/autobuytgvip-saas/btp-saas/global"
"github.com/buyaobilian1/autobuytgvip-saas/btp-saas/pkg/proxy"
"github.com/hibiken/asynq"
tele "gopkg.in/telebot.v3"
)
const RechargeExpirationPattern = "recharge:expiration"
func NewRechargeExpirationTask(orderNo string) (*asynq.Task, error) {
return asynq.NewTask(RechargeExpirationPattern, []byte(orderNo)), nil
}
func RechargeExpirationHandler(ctx context.Context, t *asynq.Task) error {
var r, u = query.Recharge, query.User
orderNo := string(t.Payload())
dbRecharge, err := r.Where(r.OrderNo.Eq(orderNo)).First()
if err != nil {
return err
}
if dbRecharge.Status == 1 {
_, err = r.Where(r.OrderNo.Eq(orderNo)).Update(r.Status, 3)
} else {
return nil
}
// 通知机器人
type Result struct {
BotToken string
}
res := Result{}
_ = u.Select(u.BotToken).LeftJoin(r, u.BotID.EqCol(r.BotID)).Where(r.OrderNo.Eq(orderNo)).Scan(&res)
opt := tele.Settings{
Token: res.BotToken,
Offline: true,
}
if global.Conf.AppConf.ProxyUrl != "" {
opt.Client = proxy.NewProxyHttpClient(global.Conf.AppConf.ProxyUrl)
}
tgBot, _ := tele.NewBot(opt)
_ = tgBot.Delete(&tele.Message{
ID: int(dbRecharge.TgMsgID),
Chat: &tele.Chat{
ID: dbRecharge.TgChatID,
},
})
user := &tele.User{
ID: dbRecharge.TgChatID,
}
_, _ = tgBot.Send(user, "🚫支付超时,订单已取消")
return nil
}