From 4670c706fc89519d9355be6ac6fc6876df7c960c Mon Sep 17 00:00:00 2001 From: duyu Date: Mon, 26 Aug 2024 18:04:49 +0800 Subject: [PATCH] fix --- app/models/orders/orders.go | 5 +++ app/services/transfersys/transfersys.go | 59 ++++++++++++++----------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/app/models/orders/orders.go b/app/models/orders/orders.go index 70f1d9d..628af93 100644 --- a/app/models/orders/orders.go +++ b/app/models/orders/orders.go @@ -222,6 +222,11 @@ func (m *ordersModel) CountAll( return } +func (m *ordersModel) CountErrHour() (res int64, err error) { + res, err = m.GetDb().Where("(transfer_status = 4 or transfer_status = 5) and created_at >= NOW() + INTERVAL 7 HOUR").Table("orders").Count() + return +} + func (m *ordersModel) Create(orders *Orders) (affected int64, err error) { orders.CreatedAt = time.Now() affected, err = m.GetDb().Insert(orders) diff --git a/app/services/transfersys/transfersys.go b/app/services/transfersys/transfersys.go index 7b1be07..2057a67 100644 --- a/app/services/transfersys/transfersys.go +++ b/app/services/transfersys/transfersys.go @@ -2,13 +2,11 @@ package transfersys import ( "errors" - "fmt" "time" mermod "com.snow.auto_monitor/app/models/merchant" models "com.snow.auto_monitor/app/models/orders" promod "com.snow.auto_monitor/app/models/product" - "com.snow.auto_monitor/app/services/device" dingServ "com.snow.auto_monitor/app/services/dingding" "com.snow.auto_monitor/app/utils/rdbdq" ) @@ -45,35 +43,42 @@ func FinishOrder(orders *models.Orders) (affected int64, err error) { if orders.TransferStatus == 4 || orders.TransferStatus == 5 { orders.Status = orders.TransferStatus - 1 - device, err := device.Search(0, orders.DeviceNo, "", 0, "", "", 1, 1) + // device, err := device.Search(0, orders.DeviceNo, "", 0, "", "", 1, 1) + // if err != nil { + // return 0, err + // } + // orderDetail, _, err := models.GetInstance().GetById(orders.Id) + // if err != nil { + // return 0, err + // } + // var deviceNumber int64 = -1 + // if device != nil { + // deviceNumber = device[0].Code + // } + // dingStr := fmt.Sprintf( + // ` + // - 异常设备: %d 号机; + // - 异常单号: %s; + // - 充值账号: %s; + // - 产品号: %d; + // - 失败原因: %s; + // - 失败时间: %s; + // `, + // deviceNumber, + // orderDetail.OutTradeNo, + // orderDetail.RechargeAccount, + // orders.ProductId, + // orders.FailReason, + // orderDetail.CreatedAt.Format("2006-01-02 15:04:05"), + // ) + count, err := models.GetInstance().CountErrHour() if err != nil { return 0, err } - orderDetail, _, err := models.GetInstance().GetById(orders.Id) - if err != nil { - return 0, err + if count > 5 { + dingStr := "新的设备异常提醒,一小时内有超过5台设备异常啦!快去监控系统查看(已处理请忽略本条信息) " + dingServ.DingSend("订单异常", dingStr, true) } - var deviceNumber int64 = -1 - if device != nil { - deviceNumber = device[0].Code - } - dingStr := fmt.Sprintf( - ` - - 异常设备: %d 号机; - - 异常单号: %s; - - 充值账号: %s; - - 产品号: %d; - - 失败原因: %s; - - 失败时间: %s; - `, - deviceNumber, - orderDetail.OutTradeNo, - orderDetail.RechargeAccount, - orders.ProductId, - orders.FailReason, - orderDetail.CreatedAt.Format("2006-01-02 15:04:05"), - ) - dingServ.DingSend("订单异常", dingStr, true) } affected, err = models.GetInstance().SetDealingOrder(orders)