大量优化修改扣积分规则
This commit is contained in:
@@ -23,7 +23,7 @@ from django.utils import timezone
|
||||
|
||||
from apps.assets.models import Asset, Model
|
||||
from apps.billing.models import CreditAccount
|
||||
from apps.billing.pricing import quote_video_estimate, video_reserve_amount
|
||||
from apps.billing.pricing import quote_video_estimate, settle_video_from_payload, video_quote_payload, video_reserve_amount
|
||||
from apps.products.models import Product
|
||||
|
||||
from .free_video import (
|
||||
@@ -1053,7 +1053,7 @@ def _legacy_start_pending_replace_shots(task):
|
||||
references=built["snapshots"],
|
||||
team=task.team,
|
||||
)
|
||||
reserve_amount = video_reserve_amount(quote.points)
|
||||
reserve_amount = video_reserve_amount(quote.points, rule=quote.meta.get("rule"))
|
||||
|
||||
with transaction.atomic():
|
||||
locked = (
|
||||
@@ -1083,6 +1083,7 @@ def _legacy_start_pending_replace_shots(task):
|
||||
next_payload["estimated_tokens"] = tokens
|
||||
next_payload["review_pending"] = False
|
||||
next_payload["duration"] = billed_duration
|
||||
next_payload.update(video_quote_payload(quote))
|
||||
locked.request_payload = next_payload
|
||||
locked.estimated_cost = quote.points
|
||||
locked.status = AITask.Status.RESERVED
|
||||
@@ -1262,7 +1263,6 @@ def complete_replace_shots(task):
|
||||
"""全部镜头出完:下载 → ffmpeg 拼接 → 转存 TOS → 按 tokens 合计结算。"""
|
||||
from decimal import Decimal
|
||||
|
||||
from apps.billing.pricing import quote_video_actual
|
||||
from apps.billing.services.ledger import charge_reserved_credit, release_credit
|
||||
|
||||
from .free_video import _notify_failure, _store_free_video_media
|
||||
@@ -1289,18 +1289,18 @@ def complete_replace_shots(task):
|
||||
total_tokens += int(item.get("tokens") or 0)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
resolution = payload.get("resolution") or "720p"
|
||||
if total_tokens > 0:
|
||||
settle = quote_video_actual(
|
||||
locked.model_config, tokens=total_tokens, with_video_ref=True,
|
||||
resolution=resolution, multiplier=Decimal(str(payload.get("price_multiplier") or "1")),
|
||||
)
|
||||
# 挂牌秒价按快照扣;无挂牌才按 tokens true-up
|
||||
if "with_ref_video" not in payload:
|
||||
payload["with_ref_video"] = True # 替换片默认带视频参考
|
||||
settle = settle_video_from_payload(locked.model_config, payload=payload, tokens=total_tokens)
|
||||
if settle.meta.get("rule") == "missing_usage":
|
||||
actual, base_cost = locked.estimated_cost, locked.base_cost
|
||||
else:
|
||||
actual, base_cost = settle.points, settle.base_cost_yuan
|
||||
payload["actual_tokens"] = total_tokens
|
||||
if total_tokens > 0:
|
||||
payload["actual_tokens"] = total_tokens
|
||||
if settle.meta.get("rate"):
|
||||
payload["points_per_yuan_snapshot"] = settle.meta["rate"]
|
||||
else:
|
||||
actual, base_cost = locked.estimated_cost, locked.base_cost
|
||||
with transaction.atomic():
|
||||
locked = AITask.objects.select_for_update().get(id=locked.id)
|
||||
if locked.status != AITask.Status.POSTPROCESSING:
|
||||
@@ -1584,7 +1584,7 @@ def _create_reviewing_task(*, team, user, params: dict, digest_pending: bool = F
|
||||
references=references,
|
||||
team=team,
|
||||
)
|
||||
reserve_amount = video_reserve_amount(quote.points)
|
||||
reserve_amount = video_reserve_amount(quote.points, rule=quote.meta.get("rule"))
|
||||
account = CreditAccount.objects.filter(team=team).first()
|
||||
available = (account.balance - account.reserved_balance) if account else Decimal("0")
|
||||
if available < reserve_amount:
|
||||
@@ -1610,8 +1610,7 @@ def _create_reviewing_task(*, team, user, params: dict, digest_pending: bool = F
|
||||
"generate_audio": True,
|
||||
"search_mode": "off",
|
||||
"estimated_tokens": tokens,
|
||||
"price_multiplier": quote.meta.get("price_multiplier", "1"),
|
||||
"points_per_yuan_snapshot": quote.meta.get("rate", ""),
|
||||
**video_quote_payload(quote),
|
||||
"references": references,
|
||||
"model_routing_v1": True,
|
||||
"review_pending": True,
|
||||
|
||||
Reference in New Issue
Block a user