63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package services
|
|
|
|
import (
|
|
"PaymentCenter/app/constants/errorcode"
|
|
"PaymentCenter/app/data"
|
|
"PaymentCenter/app/http/entities/front"
|
|
"PaymentCenter/app/models/merchantmodel"
|
|
"PaymentCenter/app/models/orderrequestlogmodel"
|
|
"PaymentCenter/app/models/ordersmodel"
|
|
"PaymentCenter/app/models/paychannelmodel"
|
|
"github.com/bytedance/sonic"
|
|
)
|
|
|
|
type WebPay struct {
|
|
WebPayReqs *front.PayWebReqs
|
|
AppCheck *AppCheck
|
|
Order *data.OrderRepo
|
|
PayCode int
|
|
}
|
|
|
|
func NewWebPay(resp *front.PayWebReqs, appCheck *AppCheck) *WebPay {
|
|
if appCheck == nil {
|
|
appCheck = AppGetAndCheck(&AppCheck{
|
|
AppId: resp.AppId,
|
|
Code: errorcode.Success,
|
|
})
|
|
}
|
|
return &WebPay{
|
|
WebPayReqs: resp,
|
|
AppCheck: appCheck,
|
|
PayCode: appCheck.Code,
|
|
}
|
|
}
|
|
|
|
func (w *WebPay) AddPayLog() {
|
|
requestJson, err := sonic.Marshal(w.WebPayReqs)
|
|
if err != nil {
|
|
w.PayCode = errorcode.RequestLogErrors
|
|
return
|
|
}
|
|
code := RequestLogCreate(&orderrequestlogmodel.OrderRequestLog{
|
|
IpAddress: w.AppCheck.Ip,
|
|
MerchantRequest: string(requestJson),
|
|
})
|
|
w.PayCode = code
|
|
return
|
|
}
|
|
|
|
func (w *WebPay) CheckMerchant() {
|
|
w.PayCode = GetAndCheckPayChannel(&paychannelmodel.PayChannel{Id: w.WebPayReqs.PayChannelId}, nil)
|
|
}
|
|
|
|
func (w *WebPay) CheckPayChannel() {
|
|
w.PayCode = GetAndCheckMerchant(&merchantmodel.Merchant{Id: w.AppCheck.App.MerchantId}, nil)
|
|
}
|
|
|
|
func (w *WebPay) CheckOrder() {
|
|
exist, code := HadSameValueOrder(&ordersmodel.Orders{OutTreadNo: w.WebPayReqs.OutTradeNo})
|
|
if exist {
|
|
w.PayCode = code
|
|
}
|
|
}
|