This commit is contained in:
2026-02-28 14:49:42 +08:00
parent dedd4a60a4
commit 927b08b871
8 changed files with 56 additions and 22 deletions

View File

@@ -276,6 +276,8 @@ wallet:
default_credit_limit: 50.00 default_credit_limit: 50.00
min_amount: "100.00" # 生产环境最低充值金额 min_amount: "100.00" # 生产环境最低充值金额
max_amount: "100000.00" # 单次最高充值金额 max_amount: "100000.00" # 单次最高充值金额
recharge_bonus_enabled: true # 是否启用充值赠送,设为 false 时仅展示商务洽谈提示
api_store_recharge_tip: "" # 关闭赠送时展示的提示文案,为空则使用默认文案
# 支付宝充值赠送配置 # 支付宝充值赠送配置
alipay_recharge_bonus: alipay_recharge_bonus:
- recharge_amount: 1000.00 # 充值1000元 - recharge_amount: 1000.00 # 充值1000元

View File

@@ -108,6 +108,8 @@ wallet:
default_credit_limit: 0.01 default_credit_limit: 0.01
min_amount: "0.01" # 生产环境最低充值金额 min_amount: "0.01" # 生产环境最低充值金额
max_amount: "100000.00" # 单次最高充值金额 max_amount: "100000.00" # 单次最高充值金额
recharge_bonus_enabled: false # 开发环境可设为 true 测试赠送
api_store_recharge_tip: "尊敬的客户,若您的充值金额较大或有批量调价需求,为获取专属商务优惠方案,请直接联系我司商务团队进行洽谈。感谢您的支持!"
# 支付宝充值赠送配置 # 支付宝充值赠送配置
alipay_recharge_bonus: alipay_recharge_bonus:
- recharge_amount: 0.01 # 充值1000元 - recharge_amount: 0.01 # 充值1000元

View File

@@ -109,7 +109,9 @@ wallet:
default_credit_limit: 50.00 default_credit_limit: 50.00
min_amount: "100.00" # 生产环境最低充值金额 min_amount: "100.00" # 生产环境最低充值金额
max_amount: "100000.00" # 单次最高充值金额 max_amount: "100000.00" # 单次最高充值金额
# 支付宝充值赠送配置 recharge_bonus_enabled: false # 暂不赠送,展示商务洽谈提示
api_store_recharge_tip: "尊敬的客户,若您的充值金额较大或有批量调价需求,为获取专属商务优惠方案,请直接联系我司商务团队进行洽谈。感谢您的支持!"
# 支付宝充值赠送配置recharge_bonus_enabled 为 true 时生效)
alipay_recharge_bonus: alipay_recharge_bonus:
- recharge_amount: 1000.00 # 充值1000元 - recharge_amount: 1000.00 # 充值1000元
bonus_amount: 50.00 # 赠送50元 bonus_amount: 50.00 # 赠送50元

View File

@@ -108,8 +108,10 @@ type AlipayRechargeOrderResponse struct {
// RechargeConfigResponse 充值配置响应 // RechargeConfigResponse 充值配置响应
type RechargeConfigResponse struct { type RechargeConfigResponse struct {
MinAmount string `json:"min_amount"` // 最低充值金额 MinAmount string `json:"min_amount"` // 最低充值金额
MaxAmount string `json:"max_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"` AlipayRechargeBonus []AlipayRechargeBonusRuleResponse `json:"alipay_recharge_bonus"`
} }

View File

@@ -1337,17 +1337,26 @@ func (s *FinanceApplicationServiceImpl) GetAdminRechargeRecords(ctx context.Cont
// GetRechargeConfig 获取充值配置 // GetRechargeConfig 获取充值配置
func (s *FinanceApplicationServiceImpl) GetRechargeConfig(ctx context.Context) (*responses.RechargeConfigResponse, error) { func (s *FinanceApplicationServiceImpl) GetRechargeConfig(ctx context.Context) (*responses.RechargeConfigResponse, error) {
bonus := make([]responses.AlipayRechargeBonusRuleResponse, 0, len(s.config.Wallet.AliPayRechargeBonus)) bonus := make([]responses.AlipayRechargeBonusRuleResponse, 0)
for _, rule := range s.config.Wallet.AliPayRechargeBonus { if s.config.Wallet.RechargeBonusEnabled && len(s.config.Wallet.AliPayRechargeBonus) > 0 {
bonus = append(bonus, responses.AlipayRechargeBonusRuleResponse{ bonus = make([]responses.AlipayRechargeBonusRuleResponse, 0, len(s.config.Wallet.AliPayRechargeBonus))
RechargeAmount: rule.RechargeAmount, for _, rule := range s.config.Wallet.AliPayRechargeBonus {
BonusAmount: rule.BonusAmount, 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{ return &responses.RechargeConfigResponse{
MinAmount: s.config.Wallet.MinAmount, MinAmount: s.config.Wallet.MinAmount,
MaxAmount: s.config.Wallet.MaxAmount, MaxAmount: s.config.Wallet.MaxAmount,
AlipayRechargeBonus: bonus, RechargeBonusEnabled: s.config.Wallet.RechargeBonusEnabled,
ApiStoreRechargeTip: tip,
AlipayRechargeBonus: bonus,
}, nil }, nil
} }
@@ -1651,9 +1660,9 @@ func (s *FinanceApplicationServiceImpl) processWechatPaymentSuccess(ctx context.
return nil return nil
} }
// 计算充值赠送金额(复用支付宝的赠送逻辑) // 计算充值赠送金额(复用支付宝的赠送逻辑,受 recharge_bonus_enabled 开关控制
bonusAmount := decimal.Zero 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-- { for i := len(s.config.Wallet.AliPayRechargeBonus) - 1; i >= 0; i-- {
rule := s.config.Wallet.AliPayRechargeBonus[i] rule := s.config.Wallet.AliPayRechargeBonus[i]
if amount.GreaterThanOrEqual(decimal.NewFromFloat(rule.RechargeAmount)) { if amount.GreaterThanOrEqual(decimal.NewFromFloat(rule.RechargeAmount)) {

View File

@@ -331,11 +331,13 @@ type SignConfig struct {
// WalletConfig 钱包配置 // WalletConfig 钱包配置
type WalletConfig struct { type WalletConfig struct {
DefaultCreditLimit float64 `mapstructure:"default_credit_limit"` DefaultCreditLimit float64 `mapstructure:"default_credit_limit"`
MinAmount string `mapstructure:"min_amount"` // 最低充值金额 MinAmount string `mapstructure:"min_amount"` // 最低充值金额
MaxAmount string `mapstructure:"max_amount"` // 最高充值金额 MaxAmount string `mapstructure:"max_amount"` // 最高充值金额
AliPayRechargeBonus []AliPayRechargeBonusRule `mapstructure:"alipay_recharge_bonus"` RechargeBonusEnabled bool `mapstructure:"recharge_bonus_enabled"` // 是否启用充值赠送,关闭后仅展示商务洽谈提示
BalanceAlert BalanceAlertConfig `mapstructure:"balance_alert"` ApiStoreRechargeTip string `mapstructure:"api_store_recharge_tip"` // API 商店充值提示文案(大额/批量需求联系商务)
AliPayRechargeBonus []AliPayRechargeBonusRule `mapstructure:"alipay_recharge_bonus"`
BalanceAlert BalanceAlertConfig `mapstructure:"balance_alert"`
} }
// BalanceAlertConfig 余额预警配置 // BalanceAlertConfig 余额预警配置

View File

@@ -15,9 +15,9 @@ import (
"tyapi-server/internal/shared/interfaces" "tyapi-server/internal/shared/interfaces"
) )
// calculateAlipayRechargeBonus 计算支付宝充值赠送金额 // calculateAlipayRechargeBonus 计算支付宝充值赠送金额(受 recharge_bonus_enabled 开关控制)
func calculateAlipayRechargeBonus(rechargeAmount decimal.Decimal, walletConfig *config.WalletConfig) decimal.Decimal { 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 return decimal.Zero
} }

View File

@@ -10,8 +10,9 @@ import (
) )
func TestCalculateAlipayRechargeBonus(t *testing.T) { func TestCalculateAlipayRechargeBonus(t *testing.T) {
// 创建测试配置 // 创建测试配置(开启赠送)
walletConfig := &config.WalletConfig{ walletConfig := &config.WalletConfig{
RechargeBonusEnabled: true,
AliPayRechargeBonus: []config.AliPayRechargeBonusRule{ AliPayRechargeBonus: []config.AliPayRechargeBonusRule{
{RechargeAmount: 1000.00, BonusAmount: 50.00}, // 充1000送50 {RechargeAmount: 1000.00, BonusAmount: 50.00}, // 充1000送50
{RechargeAmount: 5000.00, BonusAmount: 300.00}, // 充5000送300 {RechargeAmount: 5000.00, BonusAmount: 300.00}, // 充5000送300
@@ -74,6 +75,7 @@ func TestCalculateAlipayRechargeBonus(t *testing.T) {
func TestCalculateAlipayRechargeBonus_EmptyConfig(t *testing.T) { func TestCalculateAlipayRechargeBonus_EmptyConfig(t *testing.T) {
// 测试空配置 // 测试空配置
walletConfig := &config.WalletConfig{ walletConfig := &config.WalletConfig{
RechargeBonusEnabled: true,
AliPayRechargeBonus: []config.AliPayRechargeBonusRule{}, AliPayRechargeBonus: []config.AliPayRechargeBonusRule{},
} }
@@ -85,4 +87,17 @@ func TestCalculateAlipayRechargeBonus_EmptyConfig(t *testing.T) {
assert.True(t, bonus.Equal(decimal.Zero), "nil配置应该返回零赠送金额") 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), "关闭赠送时应返回零")
}