From e2bd32c96c7d076ece09de3ce966274a9cbbf71b Mon Sep 17 00:00:00 2001 From: duyu Date: Wed, 21 Aug 2024 18:54:34 +0800 Subject: [PATCH] fix --- app/models/orders/orders.go | 4 ++-- app/services/dingding/dingding.go | 2 +- .../transfersys_recharge_timeout.go | 19 +++++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/models/orders/orders.go b/app/models/orders/orders.go index d45c7b2..087f741 100644 --- a/app/models/orders/orders.go +++ b/app/models/orders/orders.go @@ -379,8 +379,8 @@ func (m *ordersModel) GetRechargeTimeoutOrder( var args []interface{} 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(DATE_ADD(NOW(),INTERVAL 8 HOUR), INTERVAL 7 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)" err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders) return } diff --git a/app/services/dingding/dingding.go b/app/services/dingding/dingding.go index 702b8cb..e5bdd67 100644 --- a/app/services/dingding/dingding.go +++ b/app/services/dingding/dingding.go @@ -137,10 +137,10 @@ func DingSend(title string, content string, retry bool) (err error) { logger.Error(context.TODO(), "dingding", err) return } - // fmt.Println("响应状态码:", resp.StatusCode) // fmt.Println("响应内容:", string(body)) + // fmt.Println("参数:", data) if resp.StatusCode != 200 { logger.Error(context.TODO(), "dingding", "钉钉发送公告失败") logger.Error(context.TODO(), "dingding", string(body)) diff --git a/app/services/transfersys/transfersys_recharge_timeout.go b/app/services/transfersys/transfersys_recharge_timeout.go index b77b76f..ed9b0fe 100644 --- a/app/services/transfersys/transfersys_recharge_timeout.go +++ b/app/services/transfersys/transfersys_recharge_timeout.go @@ -8,15 +8,14 @@ import ( models "com.snow.auto_monitor/app/models/orders" dingServ "com.snow.auto_monitor/app/services/dingding" - orderServ "com.snow.auto_monitor/app/services/orders" "github.com/qit-team/snow-core/log/logger" ) func DoRechargeTimeout() { - fmt.Println("开始执行周期任务:DoTimeout") + fmt.Println("开始执行周期任务:DoRechargeTimeout") // 创建一个新的Ticker,每分钟触发一次 - ticker := time.NewTicker(60 * time.Second) + ticker := time.NewTicker(3 * time.Second) defer ticker.Stop() // 在函数结束时停止Ticker for range ticker.C { res, err := models.GetInstance().GetRechargeTimeoutOrder(10) @@ -25,21 +24,25 @@ func DoRechargeTimeout() { continue } for i := 0; i < len(res); i++ { - orderServ.Update(&models.Orders{ + models.GetInstance().Update(&models.Orders{ Id: res[i].Id, FailReason: "超时", }) + logger.Info(context.TODO(), "order recharge timeout", "orderId: "+strconv.FormatInt(res[i].Id, 10)) + } + if len(res) > 0 { dingStr := fmt.Sprintf( ` 系统出现了超时7分钟的订单啦,快去后台查看! - 异常单号: %s; - 充值账号: %s; `, - res[i].OutTradeNo, - res[i].RechargeAccount, + res[0].OutTradeNo, + res[0].RechargeAccount, ) - dingServ.DingSend("订单超时", dingStr, true) - logger.Info(context.TODO(), "order recharge timeout", "orderId: "+strconv.FormatInt(res[i].Id, 10)) + err = dingServ.DingSend("订单超时", dingStr, true) + fmt.Println(err) + } } }