fix(douyu): 完善协作状态回写并锁定构建镜像
This commit is contained in:
@@ -650,9 +650,16 @@ def _sync_order_lease(
|
||||
*,
|
||||
reason: str,
|
||||
force_active: bool = False,
|
||||
reuse_active_lease: bool = False,
|
||||
commit: bool = False,
|
||||
) -> AccountLease | None:
|
||||
if force_active or _order_occupies_account(order):
|
||||
if reuse_active_lease:
|
||||
# 纯状态回写允许沿用平台履约或其他业务的有效占用,不抢占、不转换。
|
||||
lease = active_lease_for_account(db, order.account_id)
|
||||
if lease is not None:
|
||||
return lease
|
||||
# 没有任何有效占用的历史异常行仍需补建协作租约,避免自动分配选中。
|
||||
return _ensure_order_account_lease(
|
||||
db,
|
||||
current,
|
||||
@@ -1578,7 +1585,12 @@ def _status_audit_target(order: DouyuExternalOrder) -> str:
|
||||
return f"douyu_external_order:{order.id}"
|
||||
|
||||
|
||||
def _assert_ready_for_recharge(order: DouyuExternalOrder) -> None:
|
||||
def _assert_ready_for_recharge(
|
||||
order: DouyuExternalOrder,
|
||||
*,
|
||||
entering_waiting: bool,
|
||||
allow_missing_role: bool = False,
|
||||
) -> None:
|
||||
missing: list[str] = []
|
||||
if not order.account_id or not order.account_username:
|
||||
missing.append("斗鱼账号")
|
||||
@@ -1586,11 +1598,12 @@ def _assert_ready_for_recharge(order: DouyuExternalOrder) -> None:
|
||||
missing.append("礼包")
|
||||
if not order.home_images:
|
||||
missing.append("主页截图")
|
||||
if not order.bind_game_role:
|
||||
if not allow_missing_role and not order.bind_game_role:
|
||||
missing.append("绑定角色(先校验账号)")
|
||||
if missing:
|
||||
action = "进入待充值前" if entering_waiting else "更新充值状态前"
|
||||
raise CollabError(
|
||||
f"进入待充值前还缺:{'、'.join(missing)}",
|
||||
f"{action}还缺:{'、'.join(missing)}",
|
||||
code="recharge_precondition",
|
||||
)
|
||||
|
||||
@@ -1616,9 +1629,11 @@ def _restore_void_status(
|
||||
|
||||
target_index = STAGE_INDEX.get(target)
|
||||
if target_index is not None and target_index >= STAGE_INDEX[STATUS_TO_RECHARGE]:
|
||||
_assert_ready_for_recharge(order)
|
||||
if target in COLLAB_LEASE_STATUSES:
|
||||
_ensure_order_account_lease(db, current, order, force_active=True)
|
||||
_assert_ready_for_recharge(
|
||||
order,
|
||||
entering_waiting=target == STATUS_TO_RECHARGE,
|
||||
allow_missing_role=target == STATUS_RECHARGED,
|
||||
)
|
||||
|
||||
old_void_reason = order.void_reason or ""
|
||||
# 取消作废等于重新进入状态机:先清空旧流程时间,再按目标状态补当前时间。
|
||||
@@ -1705,6 +1720,7 @@ def set_status(
|
||||
current,
|
||||
order,
|
||||
reason="douyu_collab_void",
|
||||
reuse_active_lease=True,
|
||||
)
|
||||
if commit:
|
||||
db.commit()
|
||||
@@ -1727,6 +1743,7 @@ def set_status(
|
||||
current,
|
||||
order,
|
||||
reason="douyu_collab_failed",
|
||||
reuse_active_lease=True,
|
||||
)
|
||||
if commit:
|
||||
db.commit()
|
||||
@@ -1749,6 +1766,7 @@ def set_status(
|
||||
current,
|
||||
order,
|
||||
reason="douyu_collab_points_error",
|
||||
reuse_active_lease=True,
|
||||
)
|
||||
if commit:
|
||||
db.commit()
|
||||
@@ -1771,6 +1789,7 @@ def set_status(
|
||||
current,
|
||||
order,
|
||||
reason="douyu_collab_role_error",
|
||||
reuse_active_lease=True,
|
||||
)
|
||||
if commit:
|
||||
db.commit()
|
||||
@@ -1793,7 +1812,11 @@ def set_status(
|
||||
if target_index < current_index and not rollback:
|
||||
raise CollabError("回退状态必须显式确认", code="rollback_required")
|
||||
if target_index >= STAGE_INDEX[STATUS_TO_RECHARGE]:
|
||||
_assert_ready_for_recharge(order)
|
||||
_assert_ready_for_recharge(
|
||||
order,
|
||||
entering_waiting=target == STATUS_TO_RECHARGE,
|
||||
allow_missing_role=target == STATUS_RECHARGED,
|
||||
)
|
||||
|
||||
if rollback:
|
||||
for name, field in STATUS_TIMESTAMP_FIELDS.items():
|
||||
@@ -1822,6 +1845,7 @@ def set_status(
|
||||
db,
|
||||
current,
|
||||
order,
|
||||
reuse_active_lease=True,
|
||||
reason=(
|
||||
"douyu_collab_done"
|
||||
if target == STATUS_DONE
|
||||
|
||||
Reference in New Issue
Block a user