feat(tenant): 按租户隔离支付退款与商户配置
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
@@ -125,8 +126,12 @@ func (r *Repository) StartMohongRefund(ctx context.Context, orderID uint64, refu
|
||||
|
||||
func (r *Repository) findOriginalMohongPayment(ctx context.Context, orderID uint64) (model.PaymentOrder, error) {
|
||||
var originalPayment model.PaymentOrder
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("order_id = ? AND status = 'paid' AND biz_type = ?", orderID, bizTypeMohongPay).
|
||||
query := r.db.WithContext(ctx).
|
||||
Where("order_id = ? AND status = 'paid' AND biz_type = ?", orderID, bizTypeMohongPay)
|
||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||
query = query.Where("tenant_id = ?", tenantID)
|
||||
}
|
||||
if err := query.
|
||||
Order("id DESC").
|
||||
First(&originalPayment).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
@@ -158,7 +163,7 @@ func (r *Repository) prepareMohongRefundOrder(ctx context.Context, originalPayme
|
||||
|
||||
var existingRefund model.PaymentOrder
|
||||
err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).
|
||||
Where("order_id = ? AND biz_type = ?", originalPayment.OrderID, bizTypeMohongRefund).
|
||||
Where("order_id = ? AND biz_type = ? AND tenant_id = ?", originalPayment.OrderID, bizTypeMohongRefund, originalPayment.TenantID).
|
||||
Order("id DESC").
|
||||
First(&existingRefund).Error
|
||||
if err == nil {
|
||||
@@ -176,6 +181,7 @@ func (r *Repository) prepareMohongRefundOrder(ctx context.Context, originalPayme
|
||||
}
|
||||
merchantRefundID := "REF" + paymentNo[3:]
|
||||
refundOrder := model.PaymentOrder{
|
||||
TenantID: originalPayment.TenantID,
|
||||
PaymentNo: paymentNo,
|
||||
OrderID: originalPayment.OrderID,
|
||||
OrderNo: originalPayment.OrderNo,
|
||||
|
||||
Reference in New Issue
Block a user