com.snow.auto_monitor/app/http/controllers/zhiliansys/zhiliansys.go

80 lines
1.8 KiB
Go
Raw Normal View History

2024-07-12 18:11:21 +08:00
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
}
2024-07-18 11:16:52 +08:00
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
}
2024-07-12 18:11:21 +08:00
orders := &orderMod.Orders{
OutTradeNo: request.OutTradeNo,
ProductId: request.ProductId,
RechargeAccount: request.RechargeAccount,
2024-07-29 16:36:41 +08:00
AccountType: *request.AccountType,
2024-07-12 18:11:21 +08:00
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)
}