feat(billing): 计费商业化重构(积分制)+ 团队差异化调价

统一计价引擎 apps/billing/pricing.py:1积分=¥0.1,平台成本(¥)与用户价(积分)双记账,
视频按火山真实 usage.total_tokens 结算(true-up,终结¥1/段倒贴)+ 首发×1.5毛利系数。
Team.price_multiplier 差异化调价(jimeng同款):挂牌价×系数两步HALF_UP取整,视频类
按下单时的价格/汇率快照结算(中途改配不影响在途任务)。

BillingConfig 单例(汇率/毛利系数/预留buffer,admin可调即刻生效)。存量数据 ×10 rescale
迁移(RunPython+atomic,MySQL 迁移不可中断重跑)。开户赠送归零(DEFAULT_TRIAL_CREDITS=0,
商业决策)。audit_billing 加 I9(卖亏审计)。271 条测试 + tsc/build 全绿。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
zyc
2026-07-07 10:04:00 +08:00
co-authored by Claude Sonnet 5
parent c1420316c2
commit bf20de956c
46 changed files with 1490 additions and 150 deletions
@@ -0,0 +1,18 @@
# Generated by Django 5.1.15 on 2026-07-03 03:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("ai", "0023_seed_seedance_free_video_models"),
]
operations = [
migrations.AddField(
model_name="aitask",
name="base_cost",
field=models.DecimalField(decimal_places=4, default=0, max_digits=12),
),
]
@@ -0,0 +1,35 @@
"""积分制切换 · 任务计价与模型单价 ×10(与 billing/0004 同窗口)。
- AITask.estimated/actual_cost:历史任务金额转积分语义;
- ModelConfig.unit_price:语义重定义为「积分/次(张)」——¥1→10、¥2→20,恰好等于目标价目;
- **不缩放** AITask.base_cost(¥ 口径)与 ModelConfig.metadata.pricing(火山 ¥ 成本表)。
写法纪律(review 修正):RunPython + atomic 防 MySQL 中断重放 ×100;反向除 10.0 防 sqlite 整数截断。
详见 billing/0004_points_rescale.py 同款说明。
"""
from django.db import migrations, transaction
RESCALE_STATEMENTS = [
"UPDATE ai_aitask SET estimated_cost = estimated_cost * 10, actual_cost = actual_cost * 10",
"UPDATE ai_modelconfig SET unit_price = unit_price * 10",
]
REVERSE_STATEMENTS = [
"UPDATE ai_aitask SET estimated_cost = estimated_cost / 10.0, actual_cost = actual_cost / 10.0",
"UPDATE ai_modelconfig SET unit_price = unit_price / 10.0",
]
def _run(statements):
def apply(apps, schema_editor):
with transaction.atomic(using=schema_editor.connection.alias):
with schema_editor.connection.cursor() as cursor:
for sql in statements:
cursor.execute(sql)
return apply
class Migration(migrations.Migration):
dependencies = [("ai", "0024_aitask_base_cost")]
operations = [migrations.RunPython(_run(RESCALE_STATEMENTS), _run(REVERSE_STATEMENTS))]