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

117 lines
2.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package transfersys
import (
"errors"
"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"
dingServ "com.snow.auto_monitor/app/services/dingding"
"com.snow.auto_monitor/app/utils/rdbdq"
)
func GetOrder() (res *models.Orders, err error) {
res, _, err = models.GetInstance().GetIdleOrder()
return
}
func FinishOrder(orders *models.Orders) (affected int64, err error) {
//验证商户是否存在
_, has, err := mermod.GetInstance().GetById(orders.MerchantId)
if err != nil {
return
}
if !has {
err = errors.New("商户不存在")
return
}
//验证产品是否存在
_, has, err = promod.GetInstance().GetById(orders.ProductId)
if err != nil {
return
}
if !has {
err = errors.New("产品不存在")
return
}
if orders.TransferStatus == 1 {
orders.Status = 1
}
if orders.TransferStatus == 4 || orders.TransferStatus == 5 {
orders.Status = orders.TransferStatus - 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
}
if count > 5 {
dingStr := "新的设备异常提醒一小时内有超过5台设备异常啦快去监控系统查看已处理请忽略本条信息 "
dingServ.DingSend("订单异常", dingStr, true)
}
}
affected, err = models.GetInstance().SetDealingOrder(orders)
return
}
func AddCallback(order_id string) (err error) {
err = rdbdq.WriteOne("1_"+order_id, time.Now().Add(1*time.Second).Unix())
return
}
func SetOrderMobile(orders *models.Orders) (affected int64, err error) {
//验证商户是否存在
_, has, err := mermod.GetInstance().GetById(orders.MerchantId)
if err != nil {
return
}
if !has {
err = errors.New("商户不存在")
return
}
//验证产品是否存在
_, has, err = promod.GetInstance().GetById(orders.ProductId)
if err != nil {
return
}
if !has {
err = errors.New("产品不存在")
return
}
affected, err = models.GetInstance().SetOrderMobile(orders)
return
}