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:
@@ -0,0 +1,38 @@
|
||||
"""积分制切换 · 限额字段 ×10(与 billing/0004 同窗口)。
|
||||
|
||||
- TeamMember 三档限额:0=不限,0×10=0 语义不变;
|
||||
- Team.monthly_credit_limit:**-1 是「不限」哨兵,乘 10 变 -10 会破坏前端 === -1 判断**,
|
||||
必须 WHERE > 0 才乘(0 保持不动);NULL 自然跳过;
|
||||
- Invitation.monthly_credit_limit:join_team 邀请码会把它落到新成员限额,漏乘会发 1/10 限额。
|
||||
|
||||
写法纪律(review 修正):RunPython + atomic 防 MySQL 中断重放 ×100;反向除 10.0 防 sqlite 整数截断。
|
||||
详见 billing/0004_points_rescale.py 同款说明。
|
||||
"""
|
||||
from django.db import migrations, transaction
|
||||
|
||||
RESCALE_STATEMENTS = [
|
||||
"UPDATE accounts_teammember SET daily_credit_limit = daily_credit_limit * 10, monthly_credit_limit = monthly_credit_limit * 10, total_credit_limit = total_credit_limit * 10",
|
||||
"UPDATE accounts_team SET monthly_credit_limit = monthly_credit_limit * 10 WHERE monthly_credit_limit > 0",
|
||||
"UPDATE accounts_invitation SET monthly_credit_limit = monthly_credit_limit * 10",
|
||||
]
|
||||
|
||||
REVERSE_STATEMENTS = [
|
||||
"UPDATE accounts_teammember SET daily_credit_limit = daily_credit_limit / 10.0, monthly_credit_limit = monthly_credit_limit / 10.0, total_credit_limit = total_credit_limit / 10.0",
|
||||
"UPDATE accounts_team SET monthly_credit_limit = monthly_credit_limit / 10.0 WHERE monthly_credit_limit > 0",
|
||||
"UPDATE accounts_invitation SET monthly_credit_limit = monthly_credit_limit / 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 = [("accounts", "0007_team_monthly_credit_limit")]
|
||||
operations = [migrations.RunPython(_run(RESCALE_STATEMENTS), _run(REVERSE_STATEMENTS))]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.15 on 2026-07-03 07:41
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("accounts", "0008_points_rescale"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="team",
|
||||
name="price_multiplier",
|
||||
field=models.DecimalField(decimal_places=2, default=1, max_digits=5),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user