feat(tenant): 按租户隔离支付退款与商户配置

This commit is contained in:
yml
2026-11-15 16:06:30 +08:00
parent 6d2affa15f
commit c7dacfa025
33 changed files with 767 additions and 233 deletions
@@ -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,