This commit is contained in:
duyu 2024-08-21 17:52:35 +08:00
parent 7d666e8021
commit c38248cfc5
2 changed files with 8 additions and 3 deletions

View File

@ -378,6 +378,7 @@ func (m *ordersModel) GetRechargeTimeoutOrder(
sql := "1=1" sql := "1=1"
var args []interface{} var args []interface{}
sql += " and transfer_status = 2" sql += " and transfer_status = 2"
sql += " and (fail_reason = '' or fail_reason IS NULL)"
// sql += " and created_at <= DATE_SUB(NOW(), INTERVAL 3 MINUTE)" // 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)" 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) err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders)

View File

@ -14,8 +14,8 @@ import (
func DoRechargeTimeout() { func DoRechargeTimeout() {
fmt.Println("开始执行周期任务DoTimeout") fmt.Println("开始执行周期任务DoTimeout")
// 创建一个新的Ticker3秒钟触发一次 // 创建一个新的Ticker钟触发一次
ticker := time.NewTicker(3 * time.Second) ticker := time.NewTicker(60 * time.Second)
defer ticker.Stop() // 在函数结束时停止Ticker defer ticker.Stop() // 在函数结束时停止Ticker
for range ticker.C { for range ticker.C {
res, err := models.GetInstance().GetRechargeTimeoutOrder(10) res, err := models.GetInstance().GetRechargeTimeoutOrder(10)
@ -24,12 +24,16 @@ func DoRechargeTimeout() {
continue continue
} }
for i := 0; i < len(res); i++ { for i := 0; i < len(res); i++ {
models.GetInstance().Update(&models.Orders{
Id: res[i].Id,
FailReason: "超时",
})
dingStr := fmt.Sprintf( dingStr := fmt.Sprintf(
` `
系统出现了超时7分钟的订单啦快去后台查看 系统出现了超时7分钟的订单啦快去后台查看
- 异常单号: %s; - 异常单号: %s;
- 充值账号: %s; - 充值账号: %s;
`, `,
res[i].OutTradeNo, res[i].OutTradeNo,
res[i].RechargeAccount, res[i].RechargeAccount,
) )