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

44 lines
1.1 KiB
Go

package orders
import (
"errors"
models "com.snow.auto_monitor/app/models/orders"
promod "com.snow.auto_monitor/app/models/product"
"github.com/google/uuid"
)
func GetByOutTradeNo(out_trade_no string, merchant_id int64) (res *models.Orders, err error) {
res, _, err = models.GetInstance().GetByOutTradeNo(out_trade_no, merchant_id)
return
}
func CreateOrder(orders *models.Orders) (affected int64, err error) {
//验证商户是否存在
// _, has, err := mermod.GetInstance().GetById(orders.MerchantId)
// if err != nil {
// return
// }
// if !has {
// err = errors.New("商户不存在")
// return
// }
//验证产品是否存在
product, has, err := promod.GetInstance().GetById(orders.ProductId)
if err != nil {
return
}
if !has {
err = errors.New("产品不存在")
return
}
//创建订单
orders.OrderNo = uuid.New().String()
orders.Status = 2 // 1.成功 2.充值中 3.充值失败 4.异常需要人工处理
orders.TransferStatus = 3 // 1.成功 2.充值中 3. 等待充值 4.充值失败 5.异常需要人工处理
orders.QueueNo = product.QueueNo.Int64
affected, err = models.GetInstance().Create(orders)
return
}