refactor(binding): 收口斗鱼角色状态判定
This commit is contained in:
@@ -322,6 +322,53 @@ def is_pending_binding_role(
|
||||
)
|
||||
|
||||
|
||||
def pending_binding_role_from_result(result: dict[str, Any] | None) -> str:
|
||||
"""从执行器结果中提取“本次扫码产生的待确认角色”。
|
||||
|
||||
执行器结果已经是归一化快照,但仍必须复用 :func:`is_pending_binding_role`
|
||||
判断,避免履约 API、客户页和任务工作台各自实现一套同名角色规则。
|
||||
"""
|
||||
if not isinstance(result, dict) or bool(result.get("bind_confirmed")):
|
||||
return ""
|
||||
role_name = str(result.get("role_name") or "").strip()
|
||||
if not role_name or not bool(result.get("bind_ready_for_confirm")):
|
||||
return ""
|
||||
|
||||
baseline = str(
|
||||
result.get("baseline_role_name") or result.get("current_role_name") or ""
|
||||
).strip()
|
||||
baseline_info = result.get("before_bind_info")
|
||||
# 没有完整 before_bind_info 时无法证明同名角色发生过状态转换。
|
||||
# 此时宁可先不展示,也不能把账号历史角色误报成本次绑定结果。
|
||||
if is_pending_binding_role(
|
||||
result,
|
||||
baseline_role_name=baseline,
|
||||
baseline_is_bound_act=bool(result.get("baseline_is_bound_act")),
|
||||
baseline_info=baseline_info,
|
||||
):
|
||||
return role_name
|
||||
return ""
|
||||
|
||||
|
||||
def binding_role_from_result(result: dict[str, Any] | None) -> str:
|
||||
"""返回页面可展示的本次绑定角色。
|
||||
|
||||
- 待确认:只返回本次扫码产生的新角色。
|
||||
- 已确认:返回最终 ``bindAct=1`` 回查角色。
|
||||
- 其他状态:返回空,绝不把账号历史角色当成本次结果展示。
|
||||
"""
|
||||
if not isinstance(result, dict):
|
||||
return ""
|
||||
pending_role = pending_binding_role_from_result(result)
|
||||
if pending_role:
|
||||
return pending_role
|
||||
if bool(result.get("bind_confirmed")):
|
||||
return str(
|
||||
result.get("role_name") or result.get("current_role_name") or ""
|
||||
).strip()
|
||||
return ""
|
||||
|
||||
|
||||
def binding_channel(info: dict | None) -> str:
|
||||
"""统一游戏渠道展示:区服 / 平台。"""
|
||||
if not isinstance(info, dict):
|
||||
|
||||
Reference in New Issue
Block a user