fix(fulfillment): 修复历史账号绑定覆盖当前待确认角色
This commit is contained in:
@@ -57,6 +57,13 @@ BINDING_SYNC_TASK_TYPES = frozenset(
|
||||
"confirm_xpd_bind",
|
||||
}
|
||||
)
|
||||
ACCOUNT_CONFIRMATION_TASK_TYPES = frozenset(
|
||||
{
|
||||
"confirm_bind",
|
||||
"confirm_esports_bind",
|
||||
"confirm_xpd_bind",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def start_binding_sync(
|
||||
@@ -294,6 +301,15 @@ def sync_task_from_binding_runner(db: Session, *, douyu_task_id: int) -> int:
|
||||
douyu_task = db.get(DouyuTask, int(douyu_task_id))
|
||||
if douyu_task is None or douyu_task.task_type not in BINDING_SYNC_TASK_TYPES:
|
||||
return len(task_ids)
|
||||
result = douyu_task.result or {}
|
||||
if (
|
||||
douyu_task.task_type not in ACCOUNT_CONFIRMATION_TASK_TYPES
|
||||
or result.get("bind_confirmed") is not True
|
||||
):
|
||||
# 查询/出码任务只能证明“账号历史绑定是什么”,不能证明本次订单已经确认。
|
||||
# 只有明确执行成功并回查到 bind_confirmed 的确认任务,才允许把账号权威
|
||||
# 绑定投影到履约任务。
|
||||
return len(task_ids)
|
||||
return len(task_ids) + sync_active_task_from_account_binding(
|
||||
db,
|
||||
account_id=int(douyu_task.account_id),
|
||||
@@ -317,6 +333,17 @@ def sync_active_task_from_account_binding(
|
||||
"""
|
||||
if scope != "elite":
|
||||
return 0
|
||||
source_task = (
|
||||
db.get(DouyuTask, int(source_task_id))
|
||||
if source_task_id is not None
|
||||
else None
|
||||
)
|
||||
if (
|
||||
source_task is None
|
||||
or source_task.task_type not in ACCOUNT_CONFIRMATION_TASK_TYPES
|
||||
or (source_task.result or {}).get("bind_confirmed") is not True
|
||||
):
|
||||
return 0
|
||||
account = db.get(Account, int(account_id))
|
||||
if account is None or account.role_bind_status != "bound":
|
||||
return 0
|
||||
@@ -341,6 +368,7 @@ def sync_active_task_from_account_binding(
|
||||
)
|
||||
if task is None:
|
||||
return 0
|
||||
task.bind_task_id = int(source_task.id)
|
||||
task.binding_status = "bound"
|
||||
task.execution_status = "bound"
|
||||
task.issue_code = ""
|
||||
|
||||
@@ -362,8 +362,11 @@ def _task_out(
|
||||
)
|
||||
collab_order = resolved.collab_orders.get(int(task.id))
|
||||
bind_result = (bind_task.result or {}) if bind_task else {}
|
||||
bind_result_confirmed = bool(bind_result.get("bind_confirmed"))
|
||||
account_binding_confirmed = bool(
|
||||
account is not None and account.role_bind_status == "bound"
|
||||
bind_result_confirmed
|
||||
and account is not None
|
||||
and account.role_bind_status == "bound"
|
||||
)
|
||||
effective_issue = _effective_binding_issue(task, bind_task, bind_result)
|
||||
effective_last_error = _effective_task_message(task, effective_issue)
|
||||
@@ -635,8 +638,11 @@ def customer_binding_out(db: Session, task_id: int) -> dict[str, Any]:
|
||||
)
|
||||
bind_result = (bind_task.result or {}) if bind_task else {}
|
||||
account = db.get(Account, int(task.account_id)) if task.account_id else None
|
||||
bind_result_confirmed = bool(bind_result.get("bind_confirmed"))
|
||||
account_binding_confirmed = bool(
|
||||
account is not None and account.role_bind_status == "bound"
|
||||
bind_result_confirmed
|
||||
and account is not None
|
||||
and account.role_bind_status == "bound"
|
||||
)
|
||||
pending_role = (
|
||||
""
|
||||
|
||||
Reference in New Issue
Block a user