diff --git a/README.md b/README.md index 1e48e5c..6713d5c 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ | Feature | Description | | ------- | ----------- | | 💰 **Native CNY billing** | Quota is displayed in CNY: top-up amount equals RMB paid, credited quota = amount ÷ Price × QuotaPerUnit. No exchange-rate conversion in the wallet; applies to all top-up channels such as Epay and Waffo (`controller/topup.go`, `model/topup.go`) | +| 🎉 **Recharge bonus (pay 1 get 2)** | New uniform top-up bonus: set `payment_setting.amount_bonus` to `1.0` and every ¥1 paid credits ¥2 of quota ("充多少送多少"). Backend multiplies credited quota in `model/topupQuotaFromAmount` (covers Epay/Waffo/pancake/补单 paths) and `controller/getTopUpQuota` keeps validation consistent; bonus ratio is exposed via `/api/user/topup/info`. The wallet recharge card shows a 100%-bonus banner, per-preset credited amounts ("到账 ¥2"), custom-amount credited line, and a credited amount row in the payment confirm dialog — all hardcoded Chinese for the zh audience | +| 🈷️ **Chinese-first i18n** | Recharge UI texts are written directly in Chinese (banner, "支付"/"到账", placeholders). Site language no longer follows the browser locale: it defaults to Chinese (fallback `zhCN`) and honors a user's manual switch only; old language caches are reset via a new storage key | | 🎁 **Daily check-in + header button** | New `CheckinButton` component in both authenticated and public headers, with Turnstile support; guides anonymous visitors to sign up | | 📦 **Subscription plans page `/subscribe`** | Public plan listing (reads a `plans.json` snapshot when logged out, system API when logged in), supports Alipay purchase, balance payment, and free claims; auto group upgrade on purchase, periodic quota reset, auto downgrade on expiry | | 📖 **Built-in usage docs `/docs`** | A brand-new 12-section beginner guide (intro, quick start, check-in, top-up, group explanation, API keys, pricing, Playground, third-party clients, API examples, FAQ) with sticky anchor navigation | @@ -74,6 +76,25 @@ > [!TIP] > Try it live at : get ¥0.1 on sign-up and ¥0.5 per daily check-in — no deposit needed to try 30+ models including GLM, DeepSeek, and Kimi. +### 🗒️ 更新日志(Latest update — 充值优惠上线) + +**2026-09-24 · v"充值优惠"(RC42)** + +1. **充值优惠「充 1 元到账 2 元」** + - 后端新增统一赠送比例 `payment_setting.amount_bonus`:`1` = 充多少送多少(¥1 实到 ¥2),`0` = 关闭;改数据库一行再重启即可调整,无需改代码 + - 到账额度统一在 `topupQuotaFromAmount` / `getTopUpQuota` 乘以 `(1 + bonus)`,覆盖易支付、Waffo、Pancake、管理员补单全部到账路径;Stripe/Creem 保持原有逻辑 + - 携带回归测试 `TestTopUpQuotaAppliesAmountBonus`(含赠送关闭恢复原状) +2. **充值页展示优惠**(位置:控制台 → 钱包) + - 顶部绿色横幅:「充值优惠:充值 1 元实际到账 2 元,以此类推,充多少送多少。」 + - 每个金额档显示「到账 ¥x」(绿色)+「支付 ¥x · 已省 ¥x」 + - 自定义金额旁显示「待支付金额」+「到账金额」两行;输入框占位符改「最低充值 N」 + - 支付确认弹窗新增「到账金额」绿色行 +3. **文档页 `/docs`** 第 05 节「充值与包月套餐」加入优惠说明框(¥10→¥20、¥100→¥200 举例) +4. **关于页**(后台可编辑的 HTML 内容)新增「🎁 充值优惠 · 充 1 元到账 2 元」小节,含 ¥1/¥10/¥100 到账价格卡片 +5. **默认中文**:i18n 不再跟随浏览器语言,默认中文;充值页关键文案直接中文写死,避免英文浏览器显示英文 + +> 配置入口:数据库 `options` 表 `payment_setting.amount_bonus`(如改回 `0` 即取消优惠)。关于页优惠小节保存在 `options` 表的 `About` 键中,可在后台 系统设置 → 导航 内容里继续编辑。 + --- ## 📝 Project Description diff --git a/controller/topup.go b/controller/topup.go index be658fc..db7c476 100644 --- a/controller/topup.go +++ b/controller/topup.go @@ -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) } diff --git a/controller/topup_quota_limit_test.go b/controller/topup_quota_limit_test.go index 710e87a..757f94e 100644 --- a/controller/topup_quota_limit_test.go +++ b/controller/topup_quota_limit_test.go @@ -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 diff --git a/model/topup.go b/model/topup.go index d6eecb9..762ce34 100644 --- a/model/topup.go +++ b/model/topup.go @@ -15,6 +15,8 @@ import ( // topupQuotaFromAmount 将充值记录的 Amount 换算为到账 quota。 // CNY 展示模式下 Amount 为人民币金额,需先除以 Price 再乘 QuotaPerUnit。 +// 充值赠送比例(payment_setting.amount_bonus)在所有换算路径统一叠加, +// 例如 amount_bonus=1.0 时充值 1 元实际到账 2 元。 func topupQuotaFromAmount(amount int64) decimal.Decimal { d := decimal.NewFromInt(amount) if operation_setting.GetQuotaDisplayType() == operation_setting.QuotaDisplayTypeCNY { @@ -23,6 +25,7 @@ func topupQuotaFromAmount(amount int64) decimal.Decimal { d = d.Div(dPrice) } } + d = d.Mul(decimal.NewFromFloat(1 + operation_setting.GetTopupBonusRatio())) return d.Mul(decimal.NewFromFloat(common.QuotaPerUnit)) } diff --git a/setting/operation_setting/payment_setting.go b/setting/operation_setting/payment_setting.go index b08d466..7be55b7 100644 --- a/setting/operation_setting/payment_setting.go +++ b/setting/operation_setting/payment_setting.go @@ -5,6 +5,7 @@ import "github.com/QuantumNous/new-api/setting/config" type PaymentSetting struct { AmountOptions []int `json:"amount_options"` AmountDiscount map[int]float64 `json:"amount_discount"` // 充值金额对应的折扣,例如 100 元 0.9 表示 100 元充值享受 9 折优惠 + AmountBonus float64 `json:"amount_bonus"` // 统一赠送比例:1.0 表示充值多少到账双倍(充1到2),0 表示无赠送 ComplianceConfirmed bool `json:"compliance_confirmed"` ComplianceTermsVersion string `json:"compliance_terms_version"` @@ -30,6 +31,14 @@ func GetPaymentSetting() *PaymentSetting { return &paymentSetting } +// GetTopupBonusRatio 返回充值赠送比例(负值视为 0,0 表示无赠送,1.0 表示到账翻倍) +func GetTopupBonusRatio() float64 { + if paymentSetting.AmountBonus > 0 { + return paymentSetting.AmountBonus + } + return 0 +} + func IsPaymentComplianceConfirmed() bool { return paymentSetting.ComplianceConfirmed && paymentSetting.ComplianceTermsVersion == CurrentComplianceTermsVersion diff --git a/web/src/features/docs/index.tsx b/web/src/features/docs/index.tsx index 6fad59f..c03423f 100644 --- a/web/src/features/docs/index.tsx +++ b/web/src/features/docs/index.tsx @@ -216,6 +216,11 @@ export function Docs() { ,页面会自动跳回本站 +
+ 🎉 充值优惠:充值 ¥1 实际到账 ¥2 + ,以此类推——充多少送多少(100% 赠送)。例如支付 ¥10 到账 ¥20 + ,支付 ¥100 到账 ¥200,到账额度可用于全部模型与套餐。 +

方式二:包月套餐(推荐)

前往{' '} diff --git a/web/src/features/wallet/components/dialogs/payment-confirm-dialog.tsx b/web/src/features/wallet/components/dialogs/payment-confirm-dialog.tsx index 30fd955..1e63639 100644 --- a/web/src/features/wallet/components/dialogs/payment-confirm-dialog.tsx +++ b/web/src/features/wallet/components/dialogs/payment-confirm-dialog.tsx @@ -47,6 +47,7 @@ interface PaymentConfirmDialogProps { processing: boolean discountRate?: number usdExchangeRate?: number + amountBonus?: number } export function PaymentConfirmDialog({ @@ -60,11 +61,13 @@ export function PaymentConfirmDialog({ processing, discountRate = DEFAULT_DISCOUNT_RATE, usdExchangeRate = 1, + amountBonus = 0, }: PaymentConfirmDialogProps) { const { t } = useTranslation() const hasDiscount = discountRate > 0 && discountRate < 1 && paymentAmount > 0 const originalAmount = hasDiscount ? paymentAmount / discountRate : 0 const discountAmount = hasDiscount ? originalAmount - paymentAmount : 0 + const creditedAmount = topupAmount * usdExchangeRate * (1 + amountBonus) return ( @@ -92,6 +95,21 @@ export function PaymentConfirmDialog({ + {amountBonus > 0 && ( +

+ + 到账金额 + + + {formatLocalCurrencyAmount(creditedAmount, { + digitsLarge: 2, + digitsSmall: 2, + abbreviate: false, + })} + +
+ )} +
{t('You Pay')} diff --git a/web/src/features/wallet/components/recharge-form-card.tsx b/web/src/features/wallet/components/recharge-form-card.tsx index 95f3663..af37aca 100644 --- a/web/src/features/wallet/components/recharge-form-card.tsx +++ b/web/src/features/wallet/components/recharge-form-card.tsx @@ -72,6 +72,7 @@ interface RechargeFormCardProps { loading?: boolean priceRatio?: number usdExchangeRate?: number + amountBonus?: number onOpenBilling?: () => void creemProducts?: CreemProduct[] enableCreemTopup?: boolean @@ -102,6 +103,7 @@ export function RechargeFormCard({ loading, priceRatio = 1, usdExchangeRate = 1, + amountBonus = 0, onOpenBilling, creemProducts, enableCreemTopup, @@ -219,6 +221,12 @@ export function RechargeFormCard({ {/* Online Topup Section */} {hasAnyTopup ? (
+ {hasConfigurableTopup && amountBonus > 0 && ( +
+
+ )} {hasConfigurableTopup && ( <> {presetAmounts.length > 0 && ( @@ -266,11 +274,17 @@ export function RechargeFormCard({ )}
- Pay {formatCurrency(actualPrice)} + {amountBonus > 0 && ( + + {`到账 ${formatNumber(displayValue * (1 + amountBonus))}`} + {' · '} + + )} + {`支付 ${formatCurrency(actualPrice)}`} {hasDiscount && savedAmount > 0 && ( {' '} - • Save {formatCurrency(savedAmount)} + {`· 已省 ${formatCurrency(savedAmount)}`} )}
@@ -295,19 +309,33 @@ export function RechargeFormCard({ value={localAmount} onChange={(e) => handleAmountChange(e.target.value)} min={minTopup} - placeholder={`Minimum ${minTopup}`} + placeholder={`最低充值 ${minTopup}`} className='h-9 text-base sm:h-10 sm:text-lg' /> -
- - {t('Amount to pay:')} - - {calculating ? ( - - ) : ( - - {formatCurrency(paymentAmount)} +
+
+ + 待支付金额: + {calculating ? ( + + ) : ( + + {formatCurrency(paymentAmount)} + + )} +
+ {amountBonus > 0 && ( +
+ + 到账金额 + + + {formatNumber( + topupAmount * usdExchangeRate * (1 + amountBonus) + )} + +
)}
diff --git a/web/src/features/wallet/hooks/use-topup-info.ts b/web/src/features/wallet/hooks/use-topup-info.ts index 8fb4b1a..4ed2498 100644 --- a/web/src/features/wallet/hooks/use-topup-info.ts +++ b/web/src/features/wallet/hooks/use-topup-info.ts @@ -188,6 +188,10 @@ export function useTopupInfo() { ), amount_options: parseAmountOptions(response.data.amount_options), discount: parseDiscountMap(response.data.discount), + amount_bonus: Math.max( + Number(response.data.amount_bonus) || 0, + 0 + ), creem_products: parseCreemProducts(response.data.creem_products), waffo_pay_methods: parseWaffoPayMethods( response.data.waffo_pay_methods diff --git a/web/src/features/wallet/index.tsx b/web/src/features/wallet/index.tsx index 0e1fa2c..54db7e2 100644 --- a/web/src/features/wallet/index.tsx +++ b/web/src/features/wallet/index.tsx @@ -323,6 +323,7 @@ export function Wallet(props: WalletProps) { : (status?.price as number) || 1 } usdExchangeRate={effectiveUsdExchangeRate} + amountBonus={topupInfo?.amount_bonus ?? 0} onOpenBilling={() => setBillingDialogOpen(true)} creemProducts={topupInfo?.creem_products} enableCreemTopup={topupInfo?.enable_creem_topup} @@ -369,6 +370,7 @@ export function Wallet(props: WalletProps) { processing={processing || waffoProcessing || pancakeProcessing} discountRate={getDiscountRate()} usdExchangeRate={effectiveUsdExchangeRate} + amountBonus={topupInfo?.amount_bonus ?? 0} /> + /** Uniform credited bonus ratio (1 = pay 1 get 2), 0 means no bonus */ + amount_bonus: number /** Optional topup link for purchasing codes */ topup_link?: string /** Whether Creem topup is enabled */ diff --git a/web/src/i18n/config.ts b/web/src/i18n/config.ts index b060375..038e8e3 100644 --- a/web/src/i18n/config.ts +++ b/web/src/i18n/config.ts @@ -44,7 +44,8 @@ i18n .use(initReactI18next) .init({ resources, - fallbackLng: 'en', + // 站点面向中文用户:无语言偏好缓存时默认中文,同时支持在界面上手动切换语言 + fallbackLng: 'zhCN', supportedLngs: ['en', 'zhCN', 'fr', 'ru', 'ja', 'vi', 'zhTW'], load: 'currentOnly', nsSeparator: false, // Allow literal colons in keys (e.g., URLs, labels) @@ -53,7 +54,10 @@ i18n escapeValue: false, // not needed for react as it escapes by default }, detection: { - order: ['localStorage', 'navigator'], + // 仅信任已保存的语言偏好,不再跟随浏览器语言,避免英文环境误显示英文 + order: ['localStorage'], + // 使用新的存储键名:丢弃旧版本残留的浏览器语言缓存(如曾识别为 en 的用户) + lookupLocalStorage: 'i18nextLngV2', caches: ['localStorage'], // Browsers report `zh-CN`/`zh-TW`/`zh`; map them onto our `zhCN`/`zhTW` // codes (non-Chinese codes pass through for normal supportedLngs matching). diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index 024cb46..b289eb7 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -6145,5 +6145,8 @@ "Zhipu": "Zhipu", "Zhipu V4": "Zhipu V4", "Zoom": "Zoom" - } + }, + "Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "Recharge bonus: pay ¥{{pay}}, get ¥{{credit}} credited — the more you top up, the more you get.", + "Credited amount": "Credited amount", + "Credited {{amount}}": "Credited {{amount}}" } diff --git a/web/src/i18n/locales/fr.json b/web/src/i18n/locales/fr.json index 2c232f6..8799f87 100644 --- a/web/src/i18n/locales/fr.json +++ b/web/src/i18n/locales/fr.json @@ -6145,5 +6145,8 @@ "Zhipu": "Zhipu", "Zhipu V4": "Zhipu V4", "Zoom": "Zoom" - } + }, + "Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "Bonus de recharge : payez ¥{{pay}} et recevez ¥{{credit}} — plus vous rechargez, plus vous gagnez.", + "Credited amount": "Montant crédité", + "Credited {{amount}}": "Crédité {{amount}}" } diff --git a/web/src/i18n/locales/ja.json b/web/src/i18n/locales/ja.json index c69e085..7f1ca4a 100644 --- a/web/src/i18n/locales/ja.json +++ b/web/src/i18n/locales/ja.json @@ -6145,5 +6145,8 @@ "Zhipu": "Zhipu", "Zhipu V4": "Zhipu V 4", "Zoom": "ズーム" - } + }, + "Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "チャージ特典:{{pay}}元の支払いで{{credit}}元が付与されます。金額が多いほどお得です。", + "Credited amount": "付与額", + "Credited {{amount}}": "付与 {{amount}}" } diff --git a/web/src/i18n/locales/ru.json b/web/src/i18n/locales/ru.json index 51c5654..7e70293 100644 --- a/web/src/i18n/locales/ru.json +++ b/web/src/i18n/locales/ru.json @@ -6145,5 +6145,8 @@ "Zhipu": "Zhipu", "Zhipu V4": "Zhipu V4", "Zoom": "Zoom" - } + }, + "Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "Бонус за пополнение: платите ¥{{pay}} — получаете ¥{{credit}}. Чем больше пополнение, тем больше бонус.", + "Credited amount": "Начислено", + "Credited {{amount}}": "Начислено {{amount}}" } diff --git a/web/src/i18n/locales/vi.json b/web/src/i18n/locales/vi.json index 84c0c42..b92930c 100644 --- a/web/src/i18n/locales/vi.json +++ b/web/src/i18n/locales/vi.json @@ -6145,5 +6145,8 @@ "Zhipu": "Zhipu", "Zhipu V4": "Zhipu V4", "Zoom": "Zoom" - } + }, + "Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "Ưu đãi nạp tiền: nạp {{pay}} nhận {{credit}} — nạp càng nhiều nhận càng nhiều.", + "Credited amount": "Số tiền nhận được", + "Credited {{amount}}": "Nhận {{amount}}" } diff --git a/web/src/i18n/locales/zh-TW.json b/web/src/i18n/locales/zh-TW.json index 4d8ef1d..ad35cfa 100644 --- a/web/src/i18n/locales/zh-TW.json +++ b/web/src/i18n/locales/zh-TW.json @@ -6145,5 +6145,8 @@ "Zhipu": "智譜", "Zhipu V4": "智譜 V4", "Zoom": "縮放" - } + }, + "Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "儲值優惠:儲值 {{pay}} 元實際入帳 {{credit}} 元,以此類推,儲多少送多少。", + "Credited amount": "入帳金額", + "Credited {{amount}}": "入帳 {{amount}}" } diff --git a/web/src/i18n/locales/zh.json b/web/src/i18n/locales/zh.json index 9af19bc..aef0d44 100644 --- a/web/src/i18n/locales/zh.json +++ b/web/src/i18n/locales/zh.json @@ -6145,5 +6145,8 @@ "Zhipu": "智谱", "Zhipu V4": "智谱 V4", "Zoom": "缩放" - } + }, + "Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "充值优惠:充值 {{pay}} 元实际到账 {{credit}} 元,以此类推,充多少送多少。", + "Credited amount": "到账金额", + "Credited {{amount}}": "到账 {{amount}}" }