feat(custom): recharge bonus pay-1-get-2, topup page & docs & about promo display, Chinese-first i18n
- payment_setting.amount_bonus: uniform top-up bonus (1 = pay ¥1 credit ¥2), applied to credited quota in model/topupQuotaFromAmount and controller/getTopUpQuota (epay/waffo/pancake/manual paths), exposed via /api/user/topup/info; regression test TestTopUpQuotaAppliesAmountBonus - wallet recharge card: bonus banner, credited amount per preset, custom-amount credited line, credited row in payment confirm dialog; hardcoded Chinese copy (支付/到账/最低充值) - list locale defaults: Chinese-first, browser locale no longer auto-selects English; new localStorage key resets stale language caches - /docs top-up section: bonus notice box - README: record the recharge-bonus update in 'About This Custom Fork'
This commit is contained in:
1 parent
14a9acd368
commit
cf06cd72be
19 files changed
+172
-22
No files matched your search
+3
-1
@@ -119,6 +119,7 @@ func GetTopUpInfo(c *gin.Context) {
|
||||
"waffo_pancake_min_topup": setting.WaffoPancakeMinTopUp,
|
||||
"amount_options": operation_setting.GetPaymentSetting().AmountOptions,
|
||||
"discount": operation_setting.GetPaymentSetting().AmountDiscount,
|
||||
"amount_bonus": operation_setting.GetTopupBonusRatio(),
|
||||
"topup_link": common.TopUpLink,
|
||||
}
|
||||
common.ApiSuccess(c, data)
|
||||
@@ -210,7 +211,6 @@ func getMinTopup() int64 {
|
||||
|
||||
func getTopUpQuota(amount int64) (int, error) {
|
||||
quota := decimal.NewFromInt(amount)
|
||||
// CNY 模式:amount 为人民币金额,到账额度 = 人民币 / Price × QuotaPerUnit(换算为美元额度)
|
||||
if operation_setting.GetQuotaDisplayType() == operation_setting.QuotaDisplayTypeCNY {
|
||||
dPrice := decimal.NewFromFloat(operation_setting.Price)
|
||||
if dPrice.IsPositive() {
|
||||
@@ -223,6 +223,8 @@ func getTopUpQuota(amount int64) (int, error) {
|
||||
} else {
|
||||
quota = quota.Mul(decimal.NewFromFloat(common.QuotaPerUnit))
|
||||
}
|
||||
// 到账额度同样叠加统一赠送比例,确保校验与实际到账一致(如充值 1 元到账 2 元)
|
||||
quota = quota.Mul(decimal.NewFromFloat(1 + operation_setting.GetTopupBonusRatio()))
|
||||
return common.WalletQuotaFromDecimalStrict(quota)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
@@ -74,6 +75,36 @@ func TestTopUpQuotaValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTopUpQuotaAppliesAmountBonus(t *testing.T) {
|
||||
oldQuotaPerUnit := common.QuotaPerUnit
|
||||
oldDisplayType := operation_setting.GetGeneralSetting().QuotaDisplayType
|
||||
oldPrice := operation_setting.Price
|
||||
oldBonus := operation_setting.GetPaymentSetting().AmountBonus
|
||||
common.QuotaPerUnit = 500000
|
||||
operation_setting.GetGeneralSetting().QuotaDisplayType = operation_setting.QuotaDisplayTypeCNY
|
||||
operation_setting.Price = 7.1
|
||||
// 1.0 = 充值多少到账翻倍(充 1 元到账 2 元)
|
||||
operation_setting.GetPaymentSetting().AmountBonus = 1.0
|
||||
t.Cleanup(func() {
|
||||
common.QuotaPerUnit = oldQuotaPerUnit
|
||||
operation_setting.GetGeneralSetting().QuotaDisplayType = oldDisplayType
|
||||
operation_setting.Price = oldPrice
|
||||
operation_setting.GetPaymentSetting().AmountBonus = oldBonus
|
||||
})
|
||||
|
||||
quota, err := getTopUpQuota(1)
|
||||
require.NoError(t, err)
|
||||
// 到账 = round(1 / 7.1 × 500000) × (1 + 1),即充值 1 元实际到账 2 元
|
||||
expectedBase := int(math.Round(1 / 7.1 * 500000))
|
||||
assert.Equal(t, expectedBase*2, quota)
|
||||
|
||||
// bonus=0 恢复无赠送行为
|
||||
operation_setting.GetPaymentSetting().AmountBonus = 0
|
||||
quota, err = getTopUpQuota(1)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expectedBase, quota)
|
||||
}
|
||||
|
||||
func TestValidateTopUpQuotaReturnsMaximumAmount(t *testing.T) {
|
||||
oldQuotaPerUnit := common.QuotaPerUnit
|
||||
oldDisplayType := operation_setting.GetGeneralSetting().QuotaDisplayType
|
||||
|
||||
Reference in new issue
Block a user