Fix duplicate session billing and align pricing with DeepSeek ×3.
Serialize billSessionUsage with row locks, expose rates on recharge, add compensation script and admin usage views. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import crypto from 'node:crypto';
|
||||
import { loadBillingConfig } from './billing.mjs';
|
||||
|
||||
export function loadRechargeConfig() {
|
||||
const tiers = (process.env.H5_RECHARGE_TIERS_CENTS ?? '500,1000,3000,5000,10000,20000')
|
||||
@@ -8,8 +9,8 @@ export function loadRechargeConfig() {
|
||||
return {
|
||||
tiersCents: tiers.length ? tiers : [500, 1000, 3000, 5000, 10000, 20000],
|
||||
minRechargeCents: Number(process.env.H5_MIN_RECHARGE_CENTS ?? 500),
|
||||
orderTtlMs: Number(process.env.H5_RECHARGE_ORDER_TTL_MS ?? 15 * 60 * 1000),
|
||||
maxPendingOrders: Number(process.env.H5_RECHARGE_MAX_PENDING ?? 3),
|
||||
orderTtlMs: Number(process.env.H5_RECHARGE_ORDER_TTL_MS ?? 3 * 60 * 1000),
|
||||
maxPendingOrders: Number(process.env.H5_RECHARGE_MAX_PENDING ?? 5),
|
||||
dailyLimitCents: Number(process.env.H5_RECHARGE_DAILY_LIMIT_CENTS ?? 200_000),
|
||||
};
|
||||
}
|
||||
@@ -104,11 +105,14 @@ export function createRechargeService(pool, { userAuth, wechatPay, config = load
|
||||
|
||||
const getBillingConfig = async (userId) => {
|
||||
const user = await userAuth.getUserById(userId);
|
||||
const billing = loadBillingConfig();
|
||||
return {
|
||||
wechatEnabled: Boolean(wechatPay?.enabled),
|
||||
tiersCents: config.tiersCents,
|
||||
minRechargeCents: config.minRechargeCents,
|
||||
balanceCents: user ? Number(user.balance_cents ?? 0) : 0,
|
||||
inputCentsPer1k: billing.inputCentsPer1k,
|
||||
outputCentsPer1k: billing.outputCentsPer1k,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user