会员积分改版V1

This commit is contained in:
2026-08-11 09:24:18 +08:00
parent fe24e51b97
commit b9fd07f293
111 changed files with 9355 additions and 3900 deletions
@@ -9,7 +9,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.config import settings
from app.enums.celery_queue import CeleryQueue
from app.enums.llm_billing import LlmBillingConfigKey, LlmBillingLedgerState
from app.enums.llm_billing import LlmBillingLedgerState
from app.enums.shot_replicate import ShotSplitStatusEnum
from app.models.shot_replicate_segment import ShotReplicateSegment
from app.models.shot_replicate_task_set import ShotReplicateTaskSet
@@ -19,7 +19,6 @@ from app.services.shot_replicate_taskset_service import (
refresh_task_set_split_summaries,
)
from app.services.llm_billing import get_llm_ledger_states
from app.services.llm_billing.config import get_llm_billing_policy
from app.services.celery_runtime.runtime_service import runtime_lock_values
from app.tasks.celery_app import celery_app
@@ -230,15 +229,11 @@ async def recover_shot_analysis_tasks_once(db: AsyncSession) -> dict[str, Any]:
)
segments = list(segment_result.scalars().all())
billing_policy = await get_llm_billing_policy(
db,
config_key=LlmBillingConfigKey.HOLD_SHOT_VIDEO_ANALYSIS.value,
)
billing_contexts = [
*(build_task_set_analysis_billing_context(item) for item in task_sets),
*(build_segment_analysis_billing_context(item) for item in segments),
]
# 配置关闭后仍需识别并继续处理已存在的 active HOLD;只有 missing 流水才按 bypass
# 固定预扣配置变更后仍需识别并继续处理已存在的有效预扣;缺少预扣记录时禁止恢复
billing_states = await get_llm_ledger_states(db, billing_contexts)
lock_keys: list[str] = []
@@ -264,13 +259,10 @@ async def recover_shot_analysis_tasks_once(db: AsyncSession) -> dict[str, Any]:
results["skip_live_task_set_lock"] = results.get("skip_live_task_set_lock", 0) + 1
continue
context = build_task_set_analysis_billing_context(item)
validation = billing_states.get(context.hold_biz_key)
validation = billing_states.get(context.pre_deduct_biz_key)
can_execute = bool(validation and validation.can_execute)
state = validation.state.value if validation else LlmBillingLedgerState.MISSING.value
if validation and validation.state == LlmBillingLedgerState.MISSING and billing_policy.bypassed:
can_execute = True
state = LlmBillingLedgerState.BILLING_BYPASSED.value
elif validation and validation.state == LlmBillingLedgerState.MISSING and not billing_policy.valid:
if validation and validation.state == LlmBillingLedgerState.MISSING:
state = LlmBillingLedgerState.INVALID.value
if not can_execute:
item.analysis_status = ShotAnalysisStatusEnum.FAILED.value
@@ -297,13 +289,10 @@ async def recover_shot_analysis_tasks_once(db: AsyncSession) -> dict[str, Any]:
results["skip_live_segment_lock"] = results.get("skip_live_segment_lock", 0) + 1
continue
context = build_segment_analysis_billing_context(item)
validation = billing_states.get(context.hold_biz_key)
validation = billing_states.get(context.pre_deduct_biz_key)
can_execute = bool(validation and validation.can_execute)
state = validation.state.value if validation else LlmBillingLedgerState.MISSING.value
if validation and validation.state == LlmBillingLedgerState.MISSING and billing_policy.bypassed:
can_execute = True
state = LlmBillingLedgerState.BILLING_BYPASSED.value
elif validation and validation.state == LlmBillingLedgerState.MISSING and not billing_policy.valid:
if validation and validation.state == LlmBillingLedgerState.MISSING:
state = LlmBillingLedgerState.INVALID.value
if not can_execute:
item.analysis_status = ShotSegmentAnalysisStatusEnum.FAILED.value