57 lines
1.7 KiB
Go
57 lines
1.7 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 Pay(c *gin.Context) {
|
|
req := controllers.GetRequest(c).(*front.PayReqs)
|
|
appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
|
|
check := thirdpay.ThirdPayCheck(c.Request.Context(), req, appCheckInfo, c.ClientIP())
|
|
if check.CheckCode != errorcode.Success {
|
|
if check.CheckCode == errorcode.OrdersExist {
|
|
//订单已存在,直接返回订单信息
|
|
controllers.ApiRes(c, thirdpay.PayCallBack(check.OldOrder, false), errorcode.Success)
|
|
return
|
|
}
|
|
controllers.ApiRes(c, nil, check.CheckCode)
|
|
return
|
|
}
|
|
payInfo := thirdpay.ThirdPayWeb(check)
|
|
if payInfo.PayCode != errorcode.Success {
|
|
controllers.ApiRes(c, nil, payInfo.PayCode)
|
|
return
|
|
}
|
|
controllers.ApiRes(c, thirdpay.PayCallBack(payInfo.Order, true), errorcode.Success)
|
|
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, order, code)
|
|
return
|
|
}
|
|
data := front.OrdersResponse{}
|
|
data.ResponseFromDb(order)
|
|
controllers.ApiRes(c, data, errorcode.Success)
|
|
}
|