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:
@@ -0,0 +1,17 @@
|
||||
/** Format CNY cents-per-1k-tokens as readable yuan string. */
|
||||
export function formatYuanPer1kTokens(centsPer1k: number) {
|
||||
const yuan = centsPer1k / 100;
|
||||
if (yuan >= 0.01) return `¥${yuan.toFixed(2)}/1k`;
|
||||
return `¥${yuan.toFixed(3)}/1k`;
|
||||
}
|
||||
|
||||
/** Approximate yuan per million tokens from cents-per-1k rate. */
|
||||
export function formatYuanPerMillionTokens(centsPer1k: number) {
|
||||
const yuanPerM = (centsPer1k / 100) * 1000;
|
||||
if (yuanPerM >= 1) return `约 ¥${yuanPerM.toFixed(1).replace(/\.0$/, '')}/百万`;
|
||||
return `约 ¥${yuanPerM.toFixed(2)}/百万`;
|
||||
}
|
||||
|
||||
export function formatBillingRates(inputCentsPer1k: number, outputCentsPer1k: number) {
|
||||
return `输入 ${formatYuanPer1kTokens(inputCentsPer1k)}(${formatYuanPerMillionTokens(inputCentsPer1k)}),输出 ${formatYuanPer1kTokens(outputCentsPer1k)}(${formatYuanPerMillionTokens(outputCentsPer1k)})`;
|
||||
}
|
||||
Reference in New Issue
Block a user