feat(计费): 支持账号计费倍率快照与统计展示
- 新增 accounts.rate_multiplier(默认 1.0,允许 0) - 使用 usage_logs.account_rate_multiplier 记录倍率快照,避免历史回算 - 统计/导出/管理端展示账号口径费用(total_cost * account_rate_multiplier)
This commit is contained in:
14
backend/migrations/037_add_account_rate_multiplier.sql
Normal file
14
backend/migrations/037_add_account_rate_multiplier.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Add account billing rate multiplier and per-usage snapshot.
|
||||
--
|
||||
-- accounts.rate_multiplier: 账号计费倍率(>=0,允许 0 表示该账号计费为 0)。
|
||||
-- usage_logs.account_rate_multiplier: 每条 usage log 的账号倍率快照,用于实现
|
||||
-- “倍率调整仅影响之后请求”,并支持同一天分段倍率加权统计。
|
||||
--
|
||||
-- 注意:usage_logs.account_rate_multiplier 不做回填、不设置 NOT NULL。
|
||||
-- 老数据为 NULL 时,统计口径按 1.0 处理(COALESCE)。
|
||||
|
||||
ALTER TABLE IF EXISTS accounts
|
||||
ADD COLUMN IF NOT EXISTS rate_multiplier DECIMAL(10,4) NOT NULL DEFAULT 1.0;
|
||||
|
||||
ALTER TABLE IF EXISTS usage_logs
|
||||
ADD COLUMN IF NOT EXISTS account_rate_multiplier DECIMAL(10,4);
|
||||
Reference in New Issue
Block a user