fix: 修复总Token消耗USD计算与模型统计不一致的问题

- 修正Redis key匹配模式从 'usage:model:*:*' 到 'usage:model:*:*:*'
- 更新正则表达式以支持hourly统计数据
- 确保所有模型都使用正确的价格计算费用

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
shaw
2025-07-20 21:18:39 +08:00
parent 262ca74d19
commit ff554d7c70

View File

@@ -1191,7 +1191,7 @@ router.get('/usage-costs', authenticateAdmin, async (req, res) => {
pattern = `usage:model:monthly:*:${currentMonth}`;
} else {
// 全部时间先尝试从Redis获取所有历史模型统计数据
const allModelKeys = await client.keys('usage:model:*:*');
const allModelKeys = await client.keys('usage:model:*:*:*');
logger.info(`💰 Total period calculation: found ${allModelKeys.length} model keys`);
if (allModelKeys.length > 0) {
@@ -1200,7 +1200,7 @@ router.get('/usage-costs', authenticateAdmin, async (req, res) => {
for (const key of allModelKeys) {
// 解析模型名称
let modelMatch = key.match(/usage:model:(?:daily|monthly):(.+):\d{4}-\d{2}(?:-\d{2})?$/);
let modelMatch = key.match(/usage:model:(?:daily|monthly|hourly):(.+):(\d{4}-\d{2}(?:-\d{2})?(?::\d{2})?)$/);
if (!modelMatch) continue;
const model = modelMatch[1];