fix(douyu): 修正扫码前待确认角色误判
This commit is contained in:
@@ -296,8 +296,8 @@ def binding_pending_decision(
|
||||
"""解释一个绑定候选是否可进入确认阶段。
|
||||
|
||||
角色名不是唯一事实,也不能要求每次都必须换新角色。用户重新绑定同名角色
|
||||
时,判断还要对比扫码前后的活动绑定状态。活动 alias 只要仍要求
|
||||
``needBindAct=1``,即使当前 ``bindAct=1``,同名角色也可以进入确认流程。
|
||||
时,必须观察到二维码生成后的状态变化。``needBindAct=1`` 在本活动里是
|
||||
持续存在的“仍允许绑定”标志,不能单独证明存在新的扫码结果。
|
||||
"""
|
||||
result: dict[str, Any] = {
|
||||
"alias": str((info or {}).get("act_alias") or ""),
|
||||
@@ -309,6 +309,7 @@ def binding_pending_decision(
|
||||
"baseline_alias": str((baseline_info or {}).get("act_alias") or ""),
|
||||
"baseline_role_name": str(baseline_role_name or "").strip(),
|
||||
"baseline_is_bound_act": bool(baseline_is_bound_act),
|
||||
"baseline_need_bind_act": False,
|
||||
"baseline_is_pending": False,
|
||||
"same_alias": False,
|
||||
"role_changed": False,
|
||||
@@ -340,15 +341,13 @@ def binding_pending_decision(
|
||||
return result
|
||||
baseline = baseline_role_name.strip()
|
||||
if not baseline:
|
||||
if result["actionable_alias"] and snapshot["need_bind_act"]:
|
||||
result.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "existing_actionable_pending",
|
||||
}
|
||||
)
|
||||
return result
|
||||
result.update({"confirmable": True, "reason": "first_role_without_baseline"})
|
||||
# 2026-11-22:没有 baseline 无法证明这是本轮扫码产生的新角色。
|
||||
# 历史库中 bound + needBindAct 会长期并存,不能再次冒充 pending。
|
||||
result["reason"] = (
|
||||
"already_bound"
|
||||
if snapshot["is_bound_act"]
|
||||
else "pending_without_baseline"
|
||||
)
|
||||
return result
|
||||
if role_name.casefold() != baseline.casefold():
|
||||
result.update({"confirmable": True, "reason": "role_changed"})
|
||||
@@ -361,15 +360,16 @@ def binding_pending_decision(
|
||||
return result
|
||||
|
||||
baseline_snapshot = binding_snapshot(baseline_info)
|
||||
result["baseline_need_bind_act"] = bool(
|
||||
baseline_snapshot["need_bind_act"]
|
||||
)
|
||||
result["baseline_is_pending"] = bool(
|
||||
baseline_snapshot["role_name"]
|
||||
and not baseline_snapshot["is_bound_act"]
|
||||
and baseline_snapshot["need_bind_act"]
|
||||
)
|
||||
if (
|
||||
result["same_alias"]
|
||||
and baseline_snapshot["is_bound_act"]
|
||||
and snapshot["need_bind_act"]
|
||||
if result["same_alias"] and (
|
||||
baseline_snapshot["is_bound_act"] and not snapshot["is_bound_act"]
|
||||
):
|
||||
result.update(
|
||||
{
|
||||
@@ -378,18 +378,27 @@ def binding_pending_decision(
|
||||
}
|
||||
)
|
||||
return result
|
||||
if result["actionable_alias"] and snapshot["need_bind_act"]:
|
||||
if (
|
||||
result["same_alias"]
|
||||
and not snapshot["is_bound_act"]
|
||||
and snapshot["need_bind_act"]
|
||||
and not baseline_snapshot["need_bind_act"]
|
||||
):
|
||||
result.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "existing_actionable_pending",
|
||||
"reason": "same_alias_after_pending_transition",
|
||||
}
|
||||
)
|
||||
return result
|
||||
if snapshot["is_bound_act"]:
|
||||
result["reason"] = "already_bound"
|
||||
return result
|
||||
result["reason"] = "same_role_stale"
|
||||
result["reason"] = (
|
||||
"same_role_stale_pending"
|
||||
if result["baseline_is_pending"] and snapshot["need_bind_act"]
|
||||
else "same_role_stale"
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -344,6 +344,41 @@ def resolve_elite_role(
|
||||
),
|
||||
bind_infos=candidates_info,
|
||||
)
|
||||
if pending_info is None:
|
||||
# 2026-11-22:二维码流程没有扫码前基线时不能把同名活动态当 pending;
|
||||
# 但账号探针是只读观察,若活动 alias 明确未绑定、legacy alias 已返回
|
||||
# bindRole=1/bindAct=0,则仍可确认存在一个“已选角、未生效”的待确认角色。
|
||||
action_unbound = any(
|
||||
str(info.get("act_alias") or "") in action_aliases
|
||||
and derive_from_bind_info(info) == BIND_UNBOUND
|
||||
for info in candidates_info
|
||||
)
|
||||
if action_unbound:
|
||||
for alias in ordered_aliases:
|
||||
if alias in action_aliases:
|
||||
continue
|
||||
pending_info = next(
|
||||
(
|
||||
info
|
||||
for info in candidates_info
|
||||
if str(info.get("act_alias") or "") == alias
|
||||
and derive_from_bind_info(info) == BIND_PENDING
|
||||
and str(info.get("role_name") or "").strip()
|
||||
),
|
||||
None,
|
||||
)
|
||||
if pending_info is not None:
|
||||
pending_decision = binding_pending_decision(
|
||||
pending_info,
|
||||
actionable_aliases=action_aliases,
|
||||
)
|
||||
pending_decision.update(
|
||||
{
|
||||
"confirmable": True,
|
||||
"reason": "legacy_pending_after_action_unbound",
|
||||
}
|
||||
)
|
||||
break
|
||||
if pending_info is not None:
|
||||
result = _role_result(
|
||||
status=ROLE_PENDING,
|
||||
|
||||
@@ -178,9 +178,9 @@ class BindMixin:
|
||||
规则:
|
||||
1. 必须有角色名
|
||||
2. 角色名相对 baseline 变化,说明出现了新角色
|
||||
3. 角色名相同但活动状态从已绑定转为 needBindAct,说明用户本次
|
||||
扫码选择了同名角色,仍算 pending
|
||||
4. 无 baseline 且有角色,视为首次绑定的待确认角色
|
||||
3. 角色名相同但观察到绑定状态迁移,说明用户本次扫码选择了
|
||||
同名角色,仍算 pending
|
||||
4. 没有扫码前基线时不能把历史 pending 当成本次扫码结果
|
||||
"""
|
||||
return is_pending_binding_role(
|
||||
bind_info,
|
||||
@@ -1386,42 +1386,9 @@ class BindMixin:
|
||||
)
|
||||
),
|
||||
}
|
||||
if pending_decision["confirmable"]:
|
||||
pending_snapshot = self._bind_snapshot(pending_before)
|
||||
pending_role = str(pending_snapshot["role_name"] or "")
|
||||
pending_alias = str(pending_before.get("act_alias") or "")
|
||||
pending_summary = (
|
||||
f"act={pending_alias or '-'} "
|
||||
f"{self._format_bind_summary(pending_before, pending=True)}"
|
||||
)
|
||||
result.update(
|
||||
{
|
||||
**pending_snapshot,
|
||||
"act_alias": pending_alias,
|
||||
"query_act_alias": pending_alias,
|
||||
"pending_role_name": pending_role,
|
||||
"bind_ready_for_confirm": True,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "role_ready",
|
||||
"bind_polling": False,
|
||||
"bind_summary": pending_summary,
|
||||
}
|
||||
)
|
||||
account.updated_at = qr_generated_at
|
||||
self._push_log(
|
||||
"success",
|
||||
"生成二维码前已发现活动 alias 待确认角色 "
|
||||
f"act={pending_alias or '-'} role={pending_role or '-'} "
|
||||
f"reason={pending_decision['reason']}",
|
||||
)
|
||||
self._mark_task(
|
||||
db,
|
||||
task,
|
||||
"success",
|
||||
f"已识别现有待确认角色: {pending_role},待确认绑定",
|
||||
result,
|
||||
)
|
||||
return
|
||||
# 2026-11-22:二维码生成前的 pending 只能作为 baseline,不能直接
|
||||
# 推进 role_ready。官方活动 alias 会长期保留 needBindAct=1,必须在
|
||||
# 二维码生成后观察到绑定状态变化,才能证明这是本轮扫码结果。
|
||||
account.updated_at = datetime.now(UTC)
|
||||
task.queue_lane = "binding_poll"
|
||||
task.next_run_at = qr_generated_at + timedelta(
|
||||
|
||||
Reference in New Issue
Block a user