fix(fulfillment): 恢复 cjm 新角色客户确认
- 回滚 QYOOB-only 门禁,扫到新角色即进入 role_ready - 客户页 readiness 与平台任务 role_ready 对齐,避免确认接口 409 - 绑定证据 baseline 不再冒充本次扫码 - 新增人工确认绑定接口与按钮(角色、备注、操作人事件) - 补充客户确认、证据口径和人工确认回归测试
This commit is contained in:
@@ -246,37 +246,10 @@ def _lease_for_task(
|
||||
return fulfillment_lease_for_task(db, task)
|
||||
|
||||
|
||||
def _actionable_pending_role(
|
||||
result: dict[str, Any] | None,
|
||||
role_name: str,
|
||||
) -> str:
|
||||
"""只有动作 alias 上的 pending 才能作为订单目标。
|
||||
|
||||
cjm/legacy 上先出现的角色只能提示,不能直接确认;否则 actBind 会对
|
||||
QYOOB 调一个未生效的 pending(11.22 抓包 -200001 的根因)。
|
||||
"""
|
||||
role = str(role_name or "").strip()
|
||||
if not role or not isinstance(result, dict):
|
||||
return ""
|
||||
raw_aliases = result.get("action_act_aliases")
|
||||
action_aliases = (
|
||||
[str(value).strip() for value in raw_aliases if str(value).strip()]
|
||||
if isinstance(raw_aliases, (list, tuple))
|
||||
else []
|
||||
)
|
||||
selected_alias = str(result.get("act_alias") or "").strip()
|
||||
if action_aliases and selected_alias and selected_alias not in action_aliases:
|
||||
return ""
|
||||
return role
|
||||
|
||||
|
||||
def _pending_role_of(task: DouyuTask | None) -> str:
|
||||
if task is None or not isinstance(task.result, dict):
|
||||
return ""
|
||||
return _actionable_pending_role(
|
||||
task.result,
|
||||
pending_binding_role_from_result(task.result),
|
||||
)
|
||||
return pending_binding_role_from_result(task.result)
|
||||
|
||||
|
||||
def _owned_binding_tasks(
|
||||
@@ -625,6 +598,99 @@ def _mark_reused_pair(
|
||||
return True
|
||||
|
||||
|
||||
def manual_confirm_binding_sync(
|
||||
db: Session,
|
||||
*,
|
||||
task_id: int,
|
||||
current: User,
|
||||
role_name: str = "",
|
||||
note: str = "",
|
||||
) -> dict[str, Any]:
|
||||
"""运营人工确认绑定:不依赖本次扫码/actBind,直接落订单绑定事实。
|
||||
|
||||
用于客户已在别处完成绑定、或账号当前角色就是客户角色,但履约工作台没有
|
||||
本次扫码证据的场景。必须由运营确认角色并记录操作人/备注;不做自动复用。
|
||||
"""
|
||||
task = _load_task_for_update(db, task_id)
|
||||
if _frozen(task):
|
||||
# 已 bound / completed / cancelled:幂等返回,不重复写事件。
|
||||
return get_task_detail(db, task.id)
|
||||
if not task.account_id or not task.lease_id:
|
||||
raise HTTPException(status_code=409, detail="请先分配账号")
|
||||
lease = db.query(AccountLease).filter(AccountLease.id == task.lease_id).first()
|
||||
if lease is None or lease.status != "active":
|
||||
raise HTTPException(status_code=409, detail="账号租约已失效,请重新分配")
|
||||
account = db.get(Account, int(task.account_id))
|
||||
if account is None:
|
||||
raise HTTPException(status_code=409, detail="账号不存在")
|
||||
confirmed_role = str(role_name or account.game_name or "").strip()
|
||||
if not confirmed_role:
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail="账号没有可确认的角色,请先查询角色或填写确认角色",
|
||||
)
|
||||
note = str(note or "").strip()[:500]
|
||||
previous_binding = str(task.binding_status or "")
|
||||
previous_execution = str(task.execution_status or "")
|
||||
|
||||
bind_task = (
|
||||
db.query(DouyuTask).filter(DouyuTask.id == int(task.bind_task_id)).first()
|
||||
if task.bind_task_id
|
||||
else None
|
||||
)
|
||||
if bind_task is not None and str(bind_task.status or "") in {
|
||||
"planned",
|
||||
"pending",
|
||||
"running",
|
||||
}:
|
||||
result = dict(bind_task.result or {})
|
||||
result.update(
|
||||
{
|
||||
"manual_confirmed": True,
|
||||
"manual_confirmed_role": confirmed_role,
|
||||
"manual_confirmed_by": int(current.id),
|
||||
"manual_confirm_note": note,
|
||||
"bind_phase": "manual_confirmed",
|
||||
"bind_polling": False,
|
||||
"bind_ready_for_confirm": False,
|
||||
}
|
||||
)
|
||||
bind_task.status = "stopped"
|
||||
bind_task.message = f"人工确认绑定: {confirmed_role}"[:512]
|
||||
bind_task.finished_at = _now()
|
||||
bind_task.result = result
|
||||
|
||||
task.binding_status = "bound"
|
||||
task.execution_status = "bound"
|
||||
task.issue_code = ""
|
||||
task.last_error = ""
|
||||
task.operator_id = int(current.id)
|
||||
task.updated_at = _now()
|
||||
_append_event(
|
||||
db,
|
||||
task.id,
|
||||
"binding_manually_confirmed",
|
||||
actor_type="user",
|
||||
actor_id=str(current.id),
|
||||
detail={
|
||||
"roleName": confirmed_role[:128],
|
||||
"accountId": int(task.account_id),
|
||||
"accountName": (account.nickname or account.username),
|
||||
"operatorId": int(current.id),
|
||||
"note": note,
|
||||
"sourceTaskId": int(bind_task.id) if bind_task is not None else None,
|
||||
"sourceTaskStatus": str(bind_task.status or "") if bind_task else "",
|
||||
"previousBindingStatus": previous_binding,
|
||||
"previousExecutionStatus": previous_execution,
|
||||
"baselineRole": str(account.game_name or "").strip(),
|
||||
},
|
||||
)
|
||||
_apply_task_lease_policy(db, task, lease=lease)
|
||||
_emit_order_site_binding_state(db, task.id)
|
||||
db.commit()
|
||||
return get_task_detail(db, task.id)
|
||||
|
||||
|
||||
def _apply_binding_task(
|
||||
db: Session,
|
||||
task: PlatformFulfillmentTask,
|
||||
@@ -809,9 +875,9 @@ def _apply_binding_task(
|
||||
role_name = binding.pending_role_name
|
||||
if not role_name:
|
||||
return False
|
||||
if not _actionable_pending_role(source.result, role_name):
|
||||
# cjm/legacy 先出现的新角色:订单继续保持等待动作通道。
|
||||
return False
|
||||
# cjm/legacy 先出现的新角色也进入 role_ready:客户页需要能看到角色并
|
||||
# 发起确认;确认执行器会在 actBind 前重新查询 QYOOB,若动作通道尚未
|
||||
# 同步会返回可重试失败,而不是让客户卡在“没有待确认角色”。
|
||||
if phase == "confirming":
|
||||
# 确认任务执行中,后到的扫码结果不能把订单打回待确认、丢掉确认任务指针。
|
||||
return False
|
||||
@@ -1162,8 +1228,7 @@ def _latest_pending_binding_task(
|
||||
binding = resolve_douyu_binding(row, account=account)
|
||||
if binding.status != BINDING_VIEW_PENDING:
|
||||
continue
|
||||
if _actionable_pending_role(row.result, binding.pending_role_name):
|
||||
return row
|
||||
return row
|
||||
return None
|
||||
|
||||
|
||||
@@ -1185,10 +1250,6 @@ def _attach_pending_binding_task(
|
||||
or int(bind_task.account_id or 0) != int(task.account_id)
|
||||
or bind_task.task_type not in PENDING_BINDING_TASK_TYPES
|
||||
or binding.status != BINDING_VIEW_PENDING
|
||||
or not _actionable_pending_role(
|
||||
bind_task.result if isinstance(bind_task.result, dict) else {},
|
||||
binding.pending_role_name,
|
||||
)
|
||||
or not lease_is_active(lease)
|
||||
or not source_created_within_lease(lease, bind_task)
|
||||
or (
|
||||
@@ -1426,14 +1487,6 @@ def confirm_binding_sync(db: Session, *, task_id: int, current: User) -> dict[st
|
||||
db.commit()
|
||||
return get_task_detail(db, task.id)
|
||||
expected_role_name = str(current_bind_result.get("role_name") or "").strip()
|
||||
if expected_role_name and not _actionable_pending_role(
|
||||
current_bind_result,
|
||||
expected_role_name,
|
||||
):
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail="当前动作通道没有待确认角色,请客户重新扫码后再确认",
|
||||
)
|
||||
baseline_role_name = str(current_bind_result.get("current_role_name") or "").strip()
|
||||
batch_id = f"pfconfirm-{task.id}-{uuid.uuid4().hex[:8]}"
|
||||
confirm_task = DouyuTask(
|
||||
|
||||
Reference in New Issue
Block a user