<feat>解除pay和paycheck之间的强关联性

This commit is contained in:
Rzy 2024-08-09 10:43:00 +08:00
parent 50ef2fd13a
commit 1630304f3d
3 changed files with 56 additions and 34 deletions

View File

@ -7,25 +7,47 @@ import (
"PaymentCenter/app/models/paychannelmodel"
"PaymentCenter/app/services"
"PaymentCenter/app/third/paymentService/payCommon"
"context"
"PaymentCenter/app/models/ordersmodel"
"PaymentCenter/app/third/paymentService"
)
type Pay struct {
Merchant *merchantmodel.Merchant
Channel *paychannelmodel.PayChannel
paycheck *PayCheck
Order *ordersmodel.Orders
PayCode int
Url string
type PayParam struct {
Merchant *merchantmodel.Merchant
Channel *paychannelmodel.PayChannel
App_id int64
OutTradeNo string
Amount int
ExtJson string
Desc string
ClientIp string
}
func NewPay(paycheck *PayCheck) *Pay {
type Pay struct {
ctx *context.Context
PayParam *PayParam
RelationOrder *ordersmodel.Orders
Order *ordersmodel.Orders
PayCode int
Url string
}
func NewPayWithPayCheck(paycheck *PayCheck) *Pay {
return &Pay{
paycheck: paycheck,
PayCode: errorcode.Success,
ctx: paycheck.ctx,
PayParam: &PayParam{
Merchant: paycheck.Merchant,
Channel: paycheck.Channel,
App_id: paycheck.Reqs.AppId,
OutTradeNo: paycheck.Reqs.OutTradeNo,
Amount: paycheck.Reqs.Amount,
ExtJson: paycheck.Reqs.ExtJson,
Desc: paycheck.Reqs.Desc,
ClientIp: paycheck.AppCheck.Ip,
},
RelationOrder: paycheck.OldOrder,
PayCode: errorcode.Success,
}
}
@ -35,14 +57,14 @@ func (w *Pay) CreateOrder(order_type int) {
return
}
w.Order, w.PayCode = services.OrderCreate(&ordersmodel.Orders{
MerchantId: w.paycheck.Merchant.Id,
PayChannelId: w.paycheck.Channel.Id,
AppId: w.paycheck.Reqs.AppId,
OutTreadNo: w.paycheck.Reqs.OutTradeNo,
MerchantId: w.PayParam.Merchant.Id,
PayChannelId: w.PayParam.Channel.Id,
AppId: w.PayParam.App_id,
OutTreadNo: w.PayParam.OutTradeNo,
OrderType: order_type,
Amount: w.paycheck.Reqs.Amount,
ExtJson: w.paycheck.Reqs.ExtJson,
Desc: w.paycheck.Reqs.Desc,
Amount: w.PayParam.Amount,
ExtJson: w.PayParam.ExtJson,
Desc: w.PayParam.Desc,
Status: common.ORDER_STATUS_WAITPAY,
},
)
@ -54,23 +76,23 @@ func (w *Pay) PayUrl() (url string) {
ok bool
)
thirdPay := &paymentService.PayOrderRequest{
PayChannelId: w.paycheck.Reqs.PayChannelId,
PayChannelId: w.PayParam.Channel.Id,
OrderId: w.Order.Id,
ChannelType: w.paycheck.Channel.ChannelType,
ChannelType: w.PayParam.Channel.ChannelType,
Description: w.Order.Desc,
Amount: w.Order.Amount,
PayerClientIp: w.paycheck.AppCheck.Ip,
PayerClientIp: w.PayParam.ClientIp,
}
if payFunc, ok = PayWayList[w.paycheck.Channel.ChannelType]; !ok {
if payFunc, ok = PayWayList[w.PayParam.Channel.ChannelType]; !ok {
w.PayCode = errorcode.PayChannelNotBuild
return
}
err := payFunc(thirdPay, w.paycheck.Channel)
err := payFunc(thirdPay, w.PayParam.Channel)
if err != nil {
w.PayCode = errorcode.PayChannelExtJsonError
return
}
res := paymentService.PaymentService(*w.paycheck.ctx, *thirdPay)
res := paymentService.PaymentService(*w.ctx, *thirdPay)
if res.Code == payCommon.PAY_SUCCESS_CODE {
w.Order.Status = common.ORDER_STATUS_PAYING
@ -93,21 +115,21 @@ func (w *Pay) Refund() {
)
thirdPayRefund := &paymentService.OrderRefundRequest{
OrderId: w.Order.Id,
RefundOrderId: w.paycheck.OldOrder.Id,
RefundReason: w.paycheck.Reqs.Desc,
RefundAmount: int64(w.paycheck.Reqs.Amount),
PayChannel: w.paycheck.Channel.ChannelType,
RefundOrderId: w.RelationOrder.Id,
RefundReason: w.PayParam.Desc,
RefundAmount: int64(w.PayParam.Amount),
PayChannel: w.PayParam.Channel.ChannelType,
}
if refundFunc, ok = RefundWayList[w.paycheck.Channel.ChannelType]; !ok {
if refundFunc, ok = RefundWayList[w.PayParam.Channel.ChannelType]; !ok {
w.PayCode = errorcode.PayChannelNotBuild
return
}
err := refundFunc(thirdPayRefund, w.paycheck.Channel)
err := refundFunc(thirdPayRefund, w.PayParam.Channel)
if err != nil {
w.PayCode = errorcode.PayChannelExtJsonError
return
}
res := paymentService.OrderRefund(*w.paycheck.ctx, *thirdPayRefund)
res := paymentService.OrderRefund(*w.ctx, *thirdPayRefund)
if res.Code == payCommon.PAY_SUCCESS_CODE {
w.Order.Status = common.ORDER_STATUS_PAYING
code := services.OrderUpdate(w.Order, "status")

View File

@ -104,7 +104,7 @@ func (w *PayCheck) GetOrder() {
w.CheckCode = code
return
}
if code == errorcode.OrdersExist {
if code == errorcode.Success {
w.OldOrder = order
}

View File

@ -58,14 +58,14 @@ func ThirdPayRefund(ctx context.Context, refundReq *front.RefundReqs, appCheck *
if check.CheckCode != errorcode.Success {
return
}
refund = thirdpay.NewPay(check)
refund = thirdpay.NewPayWithPayCheck(check)
refund.CreateOrder(common.ORDER_TYPE_REFUND)
refund.Refund()
return
}
func ThirdPay(check *thirdpay.PayCheck) (pay *thirdpay.Pay) {
pay = thirdpay.NewPay(check)
pay = thirdpay.NewPayWithPayCheck(check)
// 创建订单
if &check.OldOrder != nil {
pay.CreateOrder(common.ORDER_TYPE_PAY)