73 lines
2.0 KiB
Go
73 lines
2.0 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"
|
|
"PaymentCenter/app/services/thirdpay/api"
|
|
"github.com/gin-gonic/gin"
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
func PayUrl(c *gin.Context) {
|
|
var res front.PayUrlResp
|
|
req := controllers.GetRequest(c).(*front.PayReqs)
|
|
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.CheckOrder()
|
|
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
|
|
}
|
|
data := thirdpay.NewOrdersResp(pay.Order)
|
|
encryptData, errCode := api.EnCrypt(appCheckInfo.App, data)
|
|
|
|
if errCode != errorcode.Success {
|
|
controllers.ApiRes(c, nil, pay.PayCode)
|
|
return
|
|
}
|
|
res.Order = string(encryptData)
|
|
res.Url = pay.Url
|
|
controllers.ApiRes(c, res, pay.PayCode)
|
|
return
|
|
}
|
|
|
|
// 查询订单
|
|
func QueryOrder(c *gin.Context) {
|
|
req := controllers.GetRequest(c).(*front.QueryReqs)
|
|
|
|
appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
|
|
// 查询订单表
|
|
order := ordersmodel.Orders{
|
|
OutTreadNo: req.OutTradeNo,
|
|
AppId: req.AppId,
|
|
MerchantId: appCheckInfo.App.MerchantId,
|
|
}
|
|
cond := builder.NewCond()
|
|
cond = cond.And(builder.Eq{"out_tread_no": order.OutTreadNo}, builder.Eq{"app_id": order.AppId})
|
|
_, code := services.OrderFindOne(&order, cond)
|
|
if code != errorcode.OrdersExist {
|
|
controllers.ApiRes(c, nil, code)
|
|
return
|
|
}
|
|
data := thirdpay.NewOrdersResp(&order)
|
|
encryptData, errCode := api.EnCrypt(appCheckInfo.App, data)
|
|
if errCode != errorcode.Success {
|
|
controllers.ApiRes(c, nil, errCode)
|
|
return
|
|
}
|
|
controllers.ApiRes(c, encryptData, errorcode.Success)
|
|
}
|