diff --git a/config.yaml b/config.yaml index 04fcb45..364e8ac 100644 --- a/config.yaml +++ b/config.yaml @@ -276,6 +276,8 @@ wallet: default_credit_limit: 50.00 min_amount: "100.00" # 生产环境最低充值金额 max_amount: "100000.00" # 单次最高充值金额 + recharge_bonus_enabled: true # 是否启用充值赠送,设为 false 时仅展示商务洽谈提示 + api_store_recharge_tip: "" # 关闭赠送时展示的提示文案,为空则使用默认文案 # 支付宝充值赠送配置 alipay_recharge_bonus: - recharge_amount: 1000.00 # 充值1000元 diff --git a/configs/env.development.yaml b/configs/env.development.yaml index 2c5f9ad..a35c4b2 100644 --- a/configs/env.development.yaml +++ b/configs/env.development.yaml @@ -108,6 +108,8 @@ wallet: default_credit_limit: 0.01 min_amount: "0.01" # 生产环境最低充值金额 max_amount: "100000.00" # 单次最高充值金额 + recharge_bonus_enabled: false # 开发环境可设为 true 测试赠送 + api_store_recharge_tip: "尊敬的客户,若您的充值金额较大或有批量调价需求,为获取专属商务优惠方案,请直接联系我司商务团队进行洽谈。感谢您的支持!" # 支付宝充值赠送配置 alipay_recharge_bonus: - recharge_amount: 0.01 # 充值1000元 diff --git a/configs/env.production.yaml b/configs/env.production.yaml index 3159cdb..198eba5 100644 --- a/configs/env.production.yaml +++ b/configs/env.production.yaml @@ -109,7 +109,9 @@ wallet: default_credit_limit: 50.00 min_amount: "100.00" # 生产环境最低充值金额 max_amount: "100000.00" # 单次最高充值金额 - # 支付宝充值赠送配置 + recharge_bonus_enabled: false # 暂不赠送,展示商务洽谈提示 + api_store_recharge_tip: "尊敬的客户,若您的充值金额较大或有批量调价需求,为获取专属商务优惠方案,请直接联系我司商务团队进行洽谈。感谢您的支持!" + # 支付宝充值赠送配置(recharge_bonus_enabled 为 true 时生效) alipay_recharge_bonus: - recharge_amount: 1000.00 # 充值1000元 bonus_amount: 50.00 # 赠送50元 diff --git a/internal/application/finance/dto/responses/finance_responses.go b/internal/application/finance/dto/responses/finance_responses.go index 556bd35..34a2262 100644 --- a/internal/application/finance/dto/responses/finance_responses.go +++ b/internal/application/finance/dto/responses/finance_responses.go @@ -108,8 +108,10 @@ type AlipayRechargeOrderResponse struct { // RechargeConfigResponse 充值配置响应 type RechargeConfigResponse struct { - MinAmount string `json:"min_amount"` // 最低充值金额 - MaxAmount string `json:"max_amount"` // 最高充值金额 + MinAmount string `json:"min_amount"` // 最低充值金额 + MaxAmount string `json:"max_amount"` // 最高充值金额 + RechargeBonusEnabled bool `json:"recharge_bonus_enabled"` // 是否启用充值赠送 + ApiStoreRechargeTip string `json:"api_store_recharge_tip"` // API 商店充值提示(大额/批量联系商务) AlipayRechargeBonus []AlipayRechargeBonusRuleResponse `json:"alipay_recharge_bonus"` } diff --git a/internal/application/finance/finance_application_service_impl.go b/internal/application/finance/finance_application_service_impl.go index 2b8eab2..d5d6d52 100644 --- a/internal/application/finance/finance_application_service_impl.go +++ b/internal/application/finance/finance_application_service_impl.go @@ -1337,17 +1337,26 @@ func (s *FinanceApplicationServiceImpl) GetAdminRechargeRecords(ctx context.Cont // GetRechargeConfig 获取充值配置 func (s *FinanceApplicationServiceImpl) GetRechargeConfig(ctx context.Context) (*responses.RechargeConfigResponse, error) { - bonus := make([]responses.AlipayRechargeBonusRuleResponse, 0, len(s.config.Wallet.AliPayRechargeBonus)) - for _, rule := range s.config.Wallet.AliPayRechargeBonus { - bonus = append(bonus, responses.AlipayRechargeBonusRuleResponse{ - RechargeAmount: rule.RechargeAmount, - BonusAmount: rule.BonusAmount, - }) + bonus := make([]responses.AlipayRechargeBonusRuleResponse, 0) + if s.config.Wallet.RechargeBonusEnabled && len(s.config.Wallet.AliPayRechargeBonus) > 0 { + bonus = make([]responses.AlipayRechargeBonusRuleResponse, 0, len(s.config.Wallet.AliPayRechargeBonus)) + for _, rule := range s.config.Wallet.AliPayRechargeBonus { + bonus = append(bonus, responses.AlipayRechargeBonusRuleResponse{ + RechargeAmount: rule.RechargeAmount, + BonusAmount: rule.BonusAmount, + }) + } + } + tip := s.config.Wallet.ApiStoreRechargeTip + if tip == "" && !s.config.Wallet.RechargeBonusEnabled { + tip = "尊敬的客户,若您的充值金额较大或有批量调价需求,为获取专属商务优惠方案,请直接联系我司商务团队进行洽谈。感谢您的支持!" } return &responses.RechargeConfigResponse{ - MinAmount: s.config.Wallet.MinAmount, - MaxAmount: s.config.Wallet.MaxAmount, - AlipayRechargeBonus: bonus, + MinAmount: s.config.Wallet.MinAmount, + MaxAmount: s.config.Wallet.MaxAmount, + RechargeBonusEnabled: s.config.Wallet.RechargeBonusEnabled, + ApiStoreRechargeTip: tip, + AlipayRechargeBonus: bonus, }, nil } @@ -1651,9 +1660,9 @@ func (s *FinanceApplicationServiceImpl) processWechatPaymentSuccess(ctx context. return nil } - // 计算充值赠送金额(复用支付宝的赠送逻辑) + // 计算充值赠送金额(复用支付宝的赠送逻辑,受 recharge_bonus_enabled 开关控制) bonusAmount := decimal.Zero - if len(s.config.Wallet.AliPayRechargeBonus) > 0 { + if s.config.Wallet.RechargeBonusEnabled && len(s.config.Wallet.AliPayRechargeBonus) > 0 { for i := len(s.config.Wallet.AliPayRechargeBonus) - 1; i >= 0; i-- { rule := s.config.Wallet.AliPayRechargeBonus[i] if amount.GreaterThanOrEqual(decimal.NewFromFloat(rule.RechargeAmount)) { diff --git a/internal/config/config.go b/internal/config/config.go index 61739ec..e865834 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -331,11 +331,13 @@ type SignConfig struct { // WalletConfig 钱包配置 type WalletConfig struct { - DefaultCreditLimit float64 `mapstructure:"default_credit_limit"` - MinAmount string `mapstructure:"min_amount"` // 最低充值金额 - MaxAmount string `mapstructure:"max_amount"` // 最高充值金额 - AliPayRechargeBonus []AliPayRechargeBonusRule `mapstructure:"alipay_recharge_bonus"` - BalanceAlert BalanceAlertConfig `mapstructure:"balance_alert"` + DefaultCreditLimit float64 `mapstructure:"default_credit_limit"` + MinAmount string `mapstructure:"min_amount"` // 最低充值金额 + MaxAmount string `mapstructure:"max_amount"` // 最高充值金额 + RechargeBonusEnabled bool `mapstructure:"recharge_bonus_enabled"` // 是否启用充值赠送,关闭后仅展示商务洽谈提示 + ApiStoreRechargeTip string `mapstructure:"api_store_recharge_tip"` // API 商店充值提示文案(大额/批量需求联系商务) + AliPayRechargeBonus []AliPayRechargeBonusRule `mapstructure:"alipay_recharge_bonus"` + BalanceAlert BalanceAlertConfig `mapstructure:"balance_alert"` } // BalanceAlertConfig 余额预警配置 diff --git a/internal/domains/finance/services/recharge_record_service.go b/internal/domains/finance/services/recharge_record_service.go index e69a8c1..1657d94 100644 --- a/internal/domains/finance/services/recharge_record_service.go +++ b/internal/domains/finance/services/recharge_record_service.go @@ -15,9 +15,9 @@ import ( "tyapi-server/internal/shared/interfaces" ) -// calculateAlipayRechargeBonus 计算支付宝充值赠送金额 +// calculateAlipayRechargeBonus 计算支付宝充值赠送金额(受 recharge_bonus_enabled 开关控制) func calculateAlipayRechargeBonus(rechargeAmount decimal.Decimal, walletConfig *config.WalletConfig) decimal.Decimal { - if walletConfig == nil || len(walletConfig.AliPayRechargeBonus) == 0 { + if walletConfig == nil || !walletConfig.RechargeBonusEnabled || len(walletConfig.AliPayRechargeBonus) == 0 { return decimal.Zero } diff --git a/internal/domains/finance/services/recharge_record_service_test.go b/internal/domains/finance/services/recharge_record_service_test.go index 489f322..64dbaa7 100644 --- a/internal/domains/finance/services/recharge_record_service_test.go +++ b/internal/domains/finance/services/recharge_record_service_test.go @@ -10,8 +10,9 @@ import ( ) func TestCalculateAlipayRechargeBonus(t *testing.T) { - // 创建测试配置 + // 创建测试配置(开启赠送) walletConfig := &config.WalletConfig{ + RechargeBonusEnabled: true, AliPayRechargeBonus: []config.AliPayRechargeBonusRule{ {RechargeAmount: 1000.00, BonusAmount: 50.00}, // 充1000送50 {RechargeAmount: 5000.00, BonusAmount: 300.00}, // 充5000送300 @@ -74,6 +75,7 @@ func TestCalculateAlipayRechargeBonus(t *testing.T) { func TestCalculateAlipayRechargeBonus_EmptyConfig(t *testing.T) { // 测试空配置 walletConfig := &config.WalletConfig{ + RechargeBonusEnabled: true, AliPayRechargeBonus: []config.AliPayRechargeBonusRule{}, } @@ -85,4 +87,17 @@ func TestCalculateAlipayRechargeBonus_EmptyConfig(t *testing.T) { assert.True(t, bonus.Equal(decimal.Zero), "nil配置应该返回零赠送金额") } +func TestCalculateAlipayRechargeBonus_Disabled(t *testing.T) { + // 关闭赠送时,任意金额均不赠送 + walletConfig := &config.WalletConfig{ + RechargeBonusEnabled: false, + AliPayRechargeBonus: []config.AliPayRechargeBonusRule{ + {RechargeAmount: 1000.00, BonusAmount: 50.00}, + {RechargeAmount: 10000.00, BonusAmount: 800.00}, + }, + } + bonus := calculateAlipayRechargeBonus(decimal.NewFromFloat(10000.00), walletConfig) + assert.True(t, bonus.Equal(decimal.Zero), "关闭赠送时应返回零") +} + \ No newline at end of file