From 7d666e8021064a62fe7585816c1b39d9559a0a86 Mon Sep 17 00:00:00 2001 From: duyu Date: Wed, 21 Aug 2024 17:35:28 +0800 Subject: [PATCH] test --- app/models/orders/orders.go | 13 ++++++ .../transfersys_recharge_timeout.go | 44 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 app/services/transfersys/transfersys_recharge_timeout.go diff --git a/app/models/orders/orders.go b/app/models/orders/orders.go index 62455cf..4111027 100644 --- a/app/models/orders/orders.go +++ b/app/models/orders/orders.go @@ -371,6 +371,19 @@ func (m *ordersModel) GetTimeoutOrder( return } +func (m *ordersModel) GetRechargeTimeoutOrder( + limit int, +) (orders []*Orders, err error) { + orders = make([]*Orders, 0) + sql := "1=1" + var args []interface{} + sql += " and transfer_status = 2" + // sql += " and created_at <= DATE_SUB(NOW(), INTERVAL 3 MINUTE)" + sql += " and created_at <= DATE_SUB(DATE_ADD(NOW(),INTERVAL 8 HOUR), INTERVAL 7 MINUTE)" + err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders) + return +} + func (m *ordersModel) SetOrderMobile(orders *Orders) (affected int64, err error) { session := m.GetDb().NewSession() defer session.Close() diff --git a/app/services/transfersys/transfersys_recharge_timeout.go b/app/services/transfersys/transfersys_recharge_timeout.go new file mode 100644 index 0000000..e6332a6 --- /dev/null +++ b/app/services/transfersys/transfersys_recharge_timeout.go @@ -0,0 +1,44 @@ +package transfersys + +import ( + "context" + "fmt" + "strconv" + "time" + + models "com.snow.auto_monitor/app/models/orders" + dingServ "com.snow.auto_monitor/app/services/dingding" + "github.com/qit-team/snow-core/log/logger" +) + +func DoRechargeTimeout() { + fmt.Println("开始执行周期任务:DoTimeout") + + // 创建一个新的Ticker,每3秒钟触发一次 + ticker := time.NewTicker(3 * time.Second) + defer ticker.Stop() // 在函数结束时停止Ticker + for range ticker.C { + res, err := models.GetInstance().GetRechargeTimeoutOrder(10) + if err != nil { + fmt.Println(err.Error()) + continue + } + for i := 0; i < len(res); i++ { + dingStr := fmt.Sprintf( + ` + 系统出现了超时7分钟的订单啦,快去后台查看! + - 异常单号: %s; + - 充值账号: %s; + `, + res[i].OutTradeNo, + res[i].RechargeAccount, + ) + dingServ.DingSend("订单超时", dingStr, true) + logger.Info(context.TODO(), "order recharge timeout", "orderId: "+strconv.FormatInt(res[i].Id, 10)) + } + } +} + +func init() { + go DoRechargeTimeout() +}