feat: 支付手续费功能

- 支持提供商级别和渠道级别手续费率配置(FEE_RATE_PROVIDER_* / FEE_RATE_*)
- 用户多付手续费,到账金额不变(充值 ¥100 + 1.6% = 实付 ¥101.60)
- 前端显示手续费明细和实付金额
- 退款时按实付金额退款,余额扣减到账金额
This commit is contained in:
erio
2026-03-03 22:00:44 +08:00
parent 1a44e94bb5
commit 5be0616e78
14 changed files with 197 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
import { prisma } from '@/lib/db';
import { getEnv } from '@/lib/config';
import { initPaymentProviders, paymentRegistry } from '@/lib/payment';
import { getMethodFeeRate } from './fee';
/**
* 获取指定支付渠道的每日全平台限额0 = 不限制)。
@@ -55,6 +56,8 @@ export interface MethodLimitStatus {
available: boolean;
/** 单笔限额0 = 使用全局配置 MAX_RECHARGE_AMOUNT */
singleMax: number;
/** 手续费率百分比0 = 无手续费 */
feeRate: number;
}
/**
@@ -85,6 +88,7 @@ export async function queryMethodLimits(
for (const type of paymentTypes) {
const dailyLimit = getMethodDailyLimit(type);
const singleMax = getMethodSingleLimit(type);
const feeRate = getMethodFeeRate(type);
const used = usageMap[type] ?? 0;
const remaining = dailyLimit > 0 ? Math.max(0, dailyLimit - used) : null;
result[type] = {
@@ -93,6 +97,7 @@ export async function queryMethodLimits(
remaining,
available: dailyLimit === 0 || used < dailyLimit,
singleMax,
feeRate,
};
}
return result;