修复(履约绑定): 禁止预检同对抢跑并补齐角色绑定与日志表格展示
This commit is contained in:
@@ -669,6 +669,9 @@ def _apply_binding_qr_display(
|
||||
def _same_pair_reuse_role(
|
||||
result: dict[str, Any] | None,
|
||||
account: Account | None,
|
||||
*,
|
||||
customer_role_name: str = "",
|
||||
task_status: str = "",
|
||||
) -> str:
|
||||
"""本次扫码角色已经绑在当前账号上:同一对,直接复用。
|
||||
|
||||
@@ -678,11 +681,21 @@ def _same_pair_reuse_role(
|
||||
"""
|
||||
if not isinstance(result, dict) or account is None:
|
||||
return ""
|
||||
# 发码预检/轮询未变化阶段绝不复用账号历史角色,必须等扫码完成或观测到扫码变化。
|
||||
if task_status and task_status != "success" and not bool(
|
||||
result.get("bind_poll_legacy_observed_change")
|
||||
):
|
||||
return ""
|
||||
if str(account.role_bind_status or "") != "bound":
|
||||
return ""
|
||||
current = str(account.game_name or "").strip()
|
||||
if not current:
|
||||
return ""
|
||||
customer_role = str(customer_role_name or "").strip()
|
||||
if bool(result.get("expected_role_required")) and not customer_role:
|
||||
return ""
|
||||
if customer_role and not role_names_match(current, customer_role):
|
||||
return ""
|
||||
raw_aliases = result.get("action_act_aliases")
|
||||
action_aliases = (
|
||||
[str(value).strip() for value in raw_aliases if str(value).strip()]
|
||||
@@ -978,7 +991,12 @@ def _apply_binding_task(
|
||||
|
||||
account = db.get(Account, int(task.account_id))
|
||||
if str(source.task_type or "") == "get_bind_qr" and phase != "confirming":
|
||||
reused_role = _same_pair_reuse_role(source.result, account)
|
||||
reused_role = _same_pair_reuse_role(
|
||||
source.result,
|
||||
account,
|
||||
customer_role_name=str(task.customer_role_name or ""),
|
||||
task_status=str(source.status or ""),
|
||||
)
|
||||
if reused_role:
|
||||
return _mark_reused_pair(
|
||||
db,
|
||||
@@ -1370,6 +1388,87 @@ def sync_task_from_binding_runner(db: Session, *, douyu_task_id: int) -> int:
|
||||
return changed
|
||||
|
||||
|
||||
def _revert_false_same_pair_reuse(
|
||||
db: Session,
|
||||
*,
|
||||
limit: int = 500,
|
||||
) -> int:
|
||||
"""纠偏被预检同对复用误锁为 bound 的未履约订单(未完成兑换且绑定角色 != 客户目标)。"""
|
||||
rows = (
|
||||
db.query(PlatformFulfillmentTask)
|
||||
.filter(
|
||||
PlatformFulfillmentTask.scope == "elite",
|
||||
PlatformFulfillmentTask.account_id.isnot(None),
|
||||
PlatformFulfillmentTask.bind_task_id.isnot(None),
|
||||
PlatformFulfillmentTask.binding_status == "bound",
|
||||
PlatformFulfillmentTask.execution_status.notin_(
|
||||
("completed", "cancelled")
|
||||
),
|
||||
PlatformFulfillmentTask.exchange_status.notin_(
|
||||
("succeeded", "locked", "submitting")
|
||||
),
|
||||
PlatformFulfillmentTask.customer_role_name != "",
|
||||
)
|
||||
.order_by(PlatformFulfillmentTask.id.desc())
|
||||
.limit(max(1, min(limit, 1000)))
|
||||
.all()
|
||||
)
|
||||
reverted = 0
|
||||
for task in rows:
|
||||
bind_task = db.get(DouyuTask, int(task.bind_task_id))
|
||||
if bind_task is None or str(bind_task.task_type or "") != "get_bind_qr":
|
||||
continue
|
||||
result = bind_task.result if isinstance(bind_task.result, dict) else {}
|
||||
if bool(result.get("bind_confirmed")) or bool(result.get("manual_confirmed")):
|
||||
continue
|
||||
reuse_event = (
|
||||
db.query(PlatformFulfillmentEvent)
|
||||
.filter(
|
||||
PlatformFulfillmentEvent.task_id == int(task.id),
|
||||
PlatformFulfillmentEvent.event_type == "binding_reused_existing_pair",
|
||||
)
|
||||
.order_by(PlatformFulfillmentEvent.id.desc())
|
||||
.first()
|
||||
)
|
||||
if reuse_event is None:
|
||||
continue
|
||||
reused_role = str(
|
||||
(reuse_event.detail_json or {}).get("roleName") or ""
|
||||
).strip()
|
||||
customer_role = str(task.customer_role_name or "").strip()
|
||||
if not customer_role or (
|
||||
reused_role and role_names_match(reused_role, customer_role)
|
||||
):
|
||||
continue
|
||||
lease = _lease_for_task(db, task)
|
||||
task.binding_status = "qr_pending"
|
||||
task.execution_status = "waiting_bind"
|
||||
task.issue_code = ""
|
||||
task.last_error = ""
|
||||
task.updated_at = _now()
|
||||
_append_event(
|
||||
db,
|
||||
task.id,
|
||||
"binding_false_reuse_reverted",
|
||||
detail={
|
||||
"bindTaskId": int(bind_task.id),
|
||||
"reusedRoleName": reused_role[:128],
|
||||
"customerRoleName": customer_role[:128],
|
||||
},
|
||||
)
|
||||
applied = _apply_binding_task(
|
||||
db,
|
||||
task,
|
||||
bind_task,
|
||||
owned=bind_task.platform_task_id is not None,
|
||||
)
|
||||
if not applied:
|
||||
_apply_task_lease_policy(db, task, lease=lease)
|
||||
_emit_order_site_binding_state(db, task.id)
|
||||
reverted += 1
|
||||
return reverted
|
||||
|
||||
|
||||
def reconcile_binding_observations(
|
||||
db: Session,
|
||||
*,
|
||||
@@ -1380,6 +1479,7 @@ def reconcile_binding_observations(
|
||||
只处理订单自己的证据(``platform_task_id``)和兼容路径的旧待确认任务;
|
||||
账号上的查询任务不再参与订单结算。
|
||||
"""
|
||||
reconciled = _revert_false_same_pair_reuse(db, limit=limit)
|
||||
tasks = (
|
||||
db.query(PlatformFulfillmentTask)
|
||||
.filter(
|
||||
@@ -1401,7 +1501,6 @@ def reconcile_binding_observations(
|
||||
.limit(max(1, min(limit, 2000)))
|
||||
.all()
|
||||
)
|
||||
reconciled = 0
|
||||
for task in tasks:
|
||||
if _frozen(task):
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user