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
@@ -13,7 +13,7 @@ import (
// IncrementUsage 增加使用统计
func (r *Repository) IncrementUsage(ctx context.Context, id uint64, amountCent int64) error {
now := time.Now()
return r.db.WithContext(ctx).Model(&model.PaymentMerchantConfig{}).Where("id = ?", id).Updates(map[string]any{
return applyOwnerTenantScope(r.db.WithContext(ctx).Model(&model.PaymentMerchantConfig{}), ctx).Where("id = ?", id).Updates(map[string]any{
"total_transactions": gorm.Expr("total_transactions + ?", 1),
"total_amount_cent": gorm.Expr("total_amount_cent + ?", amountCent),
"last_used_at": now,
@@ -23,7 +23,7 @@ func (r *Repository) IncrementUsage(ctx context.Context, id uint64, amountCent i
// RecordUsage 记录支付配置命中情况,同一个支付单只记录一次。
// RecordUsage 记录支付配置命中情况,同一个支付单只记录一次。
func (r *Repository) RecordUsage(ctx context.Context, configID uint64, paymentOrderID uint64, provider string, merchantID string, amountCent int64, bizType string) error {
func (r *Repository) RecordUsage(ctx context.Context, tenantID uint64, configID uint64, paymentOrderID uint64, provider string, merchantID string, amountCent int64, bizType string) error {
if configID == 0 || paymentOrderID == 0 {
return nil
}
@@ -37,6 +37,7 @@ func (r *Repository) RecordUsage(ctx context.Context, configID uint64, paymentOr
return err
}
log := model.PaymentConfigUsageLog{
TenantID: tenantID,
ConfigID: configID,
PaymentOrderID: paymentOrderID,
Provider: provider,
@@ -48,11 +49,13 @@ func (r *Repository) RecordUsage(ctx context.Context, configID uint64, paymentOr
return err
}
now := time.Now()
return tx.Model(&model.PaymentMerchantConfig{}).Where("id = ?", configID).Updates(map[string]any{
"total_transactions": gorm.Expr("total_transactions + ?", 1),
"total_amount_cent": gorm.Expr("total_amount_cent + ?", amountCent),
"last_used_at": now,
}).Error
return tx.Model(&model.PaymentMerchantConfig{}).
Where("id = ? AND owner_tenant_id = ?", configID, tenantID).
Updates(map[string]any{
"total_transactions": gorm.Expr("total_transactions + ?", 1),
"total_amount_cent": gorm.Expr("total_amount_cent + ?", amountCent),
"last_used_at": now,
}).Error
})
}