com.snow.auto_monitor/app/services/transfersys/transfersys_recharge_timeou...

53 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-08-21 17:35:28 +08:00
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() {
2024-08-21 18:54:34 +08:00
fmt.Println("开始执行周期任务DoRechargeTimeout")
2024-08-21 17:35:28 +08:00
2024-08-21 17:52:35 +08:00
// 创建一个新的Ticker每分钟触发一次
2024-08-21 18:54:34 +08:00
ticker := time.NewTicker(3 * time.Second)
2024-08-21 17:35:28 +08:00
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++ {
2024-08-21 18:54:34 +08:00
models.GetInstance().Update(&models.Orders{
2024-08-21 17:52:35 +08:00
Id: res[i].Id,
FailReason: "超时",
})
2024-08-21 18:54:34 +08:00
logger.Info(context.TODO(), "order recharge timeout", "orderId: "+strconv.FormatInt(res[i].Id, 10))
}
if len(res) > 0 {
2024-08-21 17:35:28 +08:00
dingStr := fmt.Sprintf(
`
系统出现了超时7分钟的订单啦快去后台查看
- 异常单号: %s;
- 充值账号: %s;
2024-08-21 17:52:35 +08:00
`,
2024-08-21 18:54:34 +08:00
res[0].OutTradeNo,
res[0].RechargeAccount,
2024-08-21 17:35:28 +08:00
)
2024-08-21 18:54:34 +08:00
err = dingServ.DingSend("订单超时", dingStr, true)
fmt.Println(err)
2024-08-21 17:35:28 +08:00
}
}
}
func init() {
2024-09-10 18:38:06 +08:00
go DoRechargeTimeout()
2024-08-21 17:35:28 +08:00
}