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

112 lines
2.4 KiB
Go

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"
)
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"),
)
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
}