新增撞车订单人工退款
This commit is contained in:
@@ -264,13 +264,13 @@ func (r *Repository) prepareRefundOrder(ctx context.Context, originalPayment mod
|
||||
}
|
||||
func (r *Repository) syncRefundPayment(ctx context.Context, payment *model.PaymentOrder, queryTerminal bool) (*model.PaymentOrder, error) {
|
||||
if payment.Status == "refunded" && !queryTerminal {
|
||||
if err := r.updateOrderRefundStatus(ctx, payment.OrderID, payment.AmountCent, payment.BizType); err != nil {
|
||||
if err := r.updateRefundedOrderStatus(ctx, payment.OrderID, payment.AmountCent, payment.BizType); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return payment, nil
|
||||
}
|
||||
if payment.Status == "failed" && !queryTerminal {
|
||||
if err := r.markOrderRefundFailed(ctx, payment.OrderID, payment.AmountCent); err != nil {
|
||||
if err := r.markRefundFailedOrderStatus(ctx, payment.OrderID, payment.AmountCent, payment.BizType); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return payment, nil
|
||||
@@ -290,7 +290,7 @@ func (r *Repository) syncRefundPayment(ctx context.Context, payment *model.Payme
|
||||
if runtimeConfig.Channel == nil {
|
||||
return nil, ErrPaymentUnavailable
|
||||
}
|
||||
originalPayment, err := r.findOriginalPayment(ctx, payment.OrderID)
|
||||
originalPayment, err := r.findOriginalPaymentForRefund(ctx, payment)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -362,11 +362,11 @@ func (r *Repository) applyRefundChannelStatus(ctx context.Context, payment *mode
|
||||
}
|
||||
switch status {
|
||||
case "refunded":
|
||||
return r.updateOrderRefundStatus(ctx, payment.OrderID, payment.AmountCent, payment.BizType)
|
||||
return r.updateRefundedOrderStatus(ctx, payment.OrderID, payment.AmountCent, payment.BizType)
|
||||
case "failed":
|
||||
return r.markOrderRefundFailed(ctx, payment.OrderID, payment.AmountCent)
|
||||
return r.markRefundFailedOrderStatus(ctx, payment.OrderID, payment.AmountCent, payment.BizType)
|
||||
default:
|
||||
return r.markOrderRefunding(ctx, payment.OrderID, payment.AmountCent)
|
||||
return r.markRefundingOrderStatus(ctx, payment.OrderID, payment.AmountCent, payment.BizType)
|
||||
}
|
||||
}
|
||||
func isRefundBizType(bizType string) bool {
|
||||
@@ -385,6 +385,35 @@ func refundQueryRequest(payment model.PaymentOrder, originalPayment model.Paymen
|
||||
ProviderRefundID: payment.ProviderOrderID,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Repository) findOriginalPaymentForRefund(ctx context.Context, payment *model.PaymentOrder) (model.PaymentOrder, error) {
|
||||
if payment != nil && isMohongRefundBizType(payment.BizType) {
|
||||
return r.findOriginalMohongPayment(ctx, payment.OrderID)
|
||||
}
|
||||
return r.findOriginalPayment(ctx, payment.OrderID)
|
||||
}
|
||||
|
||||
func (r *Repository) updateRefundedOrderStatus(ctx context.Context, orderID uint64, refundAmountCent int64, bizType string) error {
|
||||
if isMohongRefundBizType(bizType) {
|
||||
return r.updateMohongOrderRefundStatus(ctx, orderID)
|
||||
}
|
||||
return r.updateOrderRefundStatus(ctx, orderID, refundAmountCent, bizType)
|
||||
}
|
||||
|
||||
func (r *Repository) markRefundingOrderStatus(ctx context.Context, orderID uint64, refundAmountCent int64, bizType string) error {
|
||||
if isMohongRefundBizType(bizType) {
|
||||
return nil
|
||||
}
|
||||
return r.markOrderRefunding(ctx, orderID, refundAmountCent)
|
||||
}
|
||||
|
||||
func (r *Repository) markRefundFailedOrderStatus(ctx context.Context, orderID uint64, refundAmountCent int64, bizType string) error {
|
||||
if isMohongRefundBizType(bizType) {
|
||||
return nil
|
||||
}
|
||||
return r.markOrderRefundFailed(ctx, orderID, refundAmountCent)
|
||||
}
|
||||
|
||||
func (r *Repository) updateOrderRefundStatus(ctx context.Context, orderID uint64, refundAmountCent int64, bizType string) error {
|
||||
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var order model.RentalOrder
|
||||
|
||||
Reference in New Issue
Block a user