84 lines
2.3 KiB
Go
84 lines
2.3 KiB
Go
package front
|
|
|
|
import (
|
|
"PaymentCenter/app/constants/errorcode"
|
|
"PaymentCenter/app/http/controllers"
|
|
"PaymentCenter/app/http/entities/front"
|
|
"PaymentCenter/app/models/ordersmodel"
|
|
"PaymentCenter/app/services"
|
|
"PaymentCenter/app/services/thirdpay"
|
|
"github.com/gin-gonic/gin"
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
func PayUrl(c *gin.Context) {
|
|
var res front.ApiResponse
|
|
req := controllers.GetRequest(c).(*front.PayReqs)
|
|
c.Set("OutTradeNo", req.OutTradeNo)
|
|
|
|
appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
|
|
check := thirdpay.ThirdPayInfoCheck(c.Request.Context(), req, appCheckInfo, c.ClientIP())
|
|
if check.CheckCode != errorcode.Success {
|
|
controllers.ApiRes(c, nil, check.CheckCode)
|
|
return
|
|
}
|
|
check.CheckOrderPay()
|
|
if check.CheckCode != errorcode.Success {
|
|
controllers.ApiRes(c, nil, check.CheckCode)
|
|
return
|
|
}
|
|
pay := thirdpay.ThirdPayUrl(check)
|
|
if pay.PayCode != errorcode.Success {
|
|
controllers.ApiRes(c, nil, pay.PayCode)
|
|
return
|
|
}
|
|
|
|
res.Order = thirdpay.NewOrdersResp(pay.Order)
|
|
res.Url = pay.Url
|
|
controllers.ApiRes(c, res, pay.PayCode)
|
|
return
|
|
}
|
|
|
|
func Refund(c *gin.Context) {
|
|
req := controllers.GetRequest(c).(*front.RefundReqs)
|
|
c.Set("OutTradeNo", req.OutTradeNo)
|
|
|
|
appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
|
|
refund := thirdpay.ThirdPayRefund(c.Request.Context(), req, appCheckInfo, c.ClientIP())
|
|
if refund.PayCode != errorcode.Success {
|
|
controllers.ApiRes(c, nil, refund.PayCode)
|
|
return
|
|
}
|
|
data := thirdpay.NewOrdersResp(refund.Order)
|
|
var res front.ApiResponse
|
|
res.Order = data
|
|
controllers.ApiRes(c, res, refund.PayCode)
|
|
return
|
|
|
|
}
|
|
|
|
// 查询订单
|
|
func QueryOrder(c *gin.Context) {
|
|
req := controllers.GetRequest(c).(*front.QueryReqs)
|
|
c.Set("OutTradeNo", req.OutTradeNo)
|
|
|
|
appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
|
|
// 查询订单表
|
|
order := ordersmodel.Orders{
|
|
OutTradeNo: req.OutTradeNo,
|
|
AppId: req.AppId,
|
|
MerchantId: appCheckInfo.App.MerchantId,
|
|
}
|
|
cond := builder.NewCond()
|
|
cond = cond.And(builder.Eq{"out_trade_no": order.OutTradeNo}, builder.Eq{"app_id": order.AppId})
|
|
_, code := services.OrderFindOne(&order, cond)
|
|
if code != errorcode.Success {
|
|
controllers.ApiRes(c, nil, code)
|
|
return
|
|
}
|
|
data := thirdpay.NewOrdersResp(&order)
|
|
var res front.ApiResponse
|
|
res.Order = data
|
|
controllers.ApiRes(c, res, errorcode.Success)
|
|
}
|