package orders import ( common "com.snow.auto_monitor/app/http/controllers" zhilianEnt "com.snow.auto_monitor/app/http/entities/zhiliansys" orderMod "com.snow.auto_monitor/app/models/orders" zhilianServ "com.snow.auto_monitor/app/services/zhiliansys" "github.com/gin-gonic/gin" ) func GetByOutTradeNo(c *gin.Context) { request := new(zhilianEnt.GetByOutTradeNoReq) err := common.GenRequest(c, request) if err != nil { common.Error(c, 400, err.Error()) return } item, err := zhilianServ.GetByOutTradeNo(request.OutTradeNo, request.MerchantId) if err != nil { common.Error(c, 400, err.Error()) return } var response *zhilianEnt.GetByOutTradeNoResp = nil if item != nil { response = &zhilianEnt.GetByOutTradeNoResp{ OutTradeNo: item.OutTradeNo, Status: item.Status, } } common.Success(c, response) } func CreateOrder(c *gin.Context) { request := new(zhilianEnt.CreateOrderReq) err := common.GenRequest(c, request) if err != nil { common.Error(c, 400, err.Error()) return } item, err := zhilianServ.GetByOutTradeNo(request.OutTradeNo, request.MerchantId) if err != nil { common.Error(c, 400, err.Error()) return } if item != nil { common.Error(c, 400, "订单已存在") return } orders := &orderMod.Orders{ OutTradeNo: request.OutTradeNo, ProductId: request.ProductId, RechargeAccount: request.RechargeAccount, AccountType: *request.AccountType, Number: request.Number, NotifyUrl: request.NotifyUrl, ExtendParameter: request.ExtendParameter, MerchantId: request.MerchantId, } affected, err := zhilianServ.CreateOrder(orders) if err != nil || affected == 0 { common.Error(c, 400, "创建订单失败") return } response := &zhilianEnt.CreateOrderResp{ OutTradeNo: orders.OutTradeNo, } common.Success(c, response) }