2024-07-12 18:11:21 +08:00
|
|
|
package transfersys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-08-21 10:18:34 +08:00
|
|
|
"fmt"
|
2024-07-26 10:52:53 +08:00
|
|
|
"time"
|
2024-07-12 18:11:21 +08:00
|
|
|
|
|
|
|
mermod "com.snow.auto_monitor/app/models/merchant"
|
|
|
|
models "com.snow.auto_monitor/app/models/orders"
|
|
|
|
promod "com.snow.auto_monitor/app/models/product"
|
2024-08-21 10:18:34 +08:00
|
|
|
"com.snow.auto_monitor/app/services/device"
|
|
|
|
dingServ "com.snow.auto_monitor/app/services/dingding"
|
2024-07-26 10:52:53 +08:00
|
|
|
"com.snow.auto_monitor/app/utils/rdbdq"
|
2024-07-12 18:11:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-07-16 11:05:28 +08:00
|
|
|
if orders.TransferStatus == 1 {
|
|
|
|
orders.Status = 1
|
|
|
|
}
|
2024-08-21 10:18:34 +08:00
|
|
|
|
2024-07-16 11:05:28 +08:00
|
|
|
if orders.TransferStatus == 4 || orders.TransferStatus == 5 {
|
|
|
|
orders.Status = orders.TransferStatus - 1
|
2024-08-21 10:18:34 +08:00
|
|
|
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)
|
2024-07-16 11:05:28 +08:00
|
|
|
}
|
|
|
|
|
2024-07-12 18:11:21 +08:00
|
|
|
affected, err = models.GetInstance().SetDealingOrder(orders)
|
|
|
|
return
|
|
|
|
}
|
2024-07-26 10:52:53 +08:00
|
|
|
|
|
|
|
func AddCallback(order_id string) (err error) {
|
|
|
|
err = rdbdq.WriteOne("1_"+order_id, time.Now().Add(1*time.Second).Unix())
|
|
|
|
return
|
|
|
|
}
|
2024-08-15 09:13:51 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|