发布(0.4.2): 修复履约绑定同步并支持特殊角色名核对
This commit is contained in:
@@ -28,6 +28,16 @@ from ..binding_ownership import (
|
||||
source_created_within_lease,
|
||||
)
|
||||
from ..business_events import record_douyu_task_started
|
||||
from ..douyu_account_probe import (
|
||||
ROLE_BOUND,
|
||||
ROLE_ERROR,
|
||||
ROLE_UNKNOWN,
|
||||
activity_client,
|
||||
config_mapping,
|
||||
elite_action_aliases,
|
||||
persist_probe_result,
|
||||
resolve_elite_role,
|
||||
)
|
||||
from ..douyu_binding import (
|
||||
BINDING_OBSERVATION_TASK_TYPES,
|
||||
BINDING_VIEW_CONFIRMED,
|
||||
@@ -35,6 +45,8 @@ from ..douyu_binding import (
|
||||
resolve_douyu_binding,
|
||||
resolve_fulfillment_binding,
|
||||
)
|
||||
from ..douyu_role_audit import record_role_api_candidates
|
||||
from ..douyu_service import ensure_douyu_config
|
||||
from ..execution_jobs import (
|
||||
JOB_DOUYU_BINDING,
|
||||
LANE_FULFILLMENT,
|
||||
@@ -65,18 +77,6 @@ from .runtime import (
|
||||
_apply_task_lease_policy,
|
||||
)
|
||||
from .views import get_task_detail
|
||||
from ..douyu_account_probe import (
|
||||
ROLE_BOUND,
|
||||
ROLE_ERROR,
|
||||
ROLE_UNKNOWN,
|
||||
activity_client,
|
||||
config_mapping,
|
||||
elite_action_aliases,
|
||||
persist_probe_result,
|
||||
resolve_elite_role,
|
||||
)
|
||||
from ..douyu_role_audit import record_role_api_candidates
|
||||
from ..douyu_service import ensure_douyu_config
|
||||
|
||||
BINDING_SYNC_TASK_TYPES = frozenset(
|
||||
{
|
||||
@@ -104,8 +104,6 @@ ACTIVE_BINDING_STATUSES = frozenset(
|
||||
"role_ready",
|
||||
}
|
||||
)
|
||||
#: 可以接受确认任务结算的阶段。
|
||||
CONFIRMABLE_BINDING_STATUSES = frozenset({"role_ready", "confirming"})
|
||||
#: 订单的权威绑定任务类型。查询任务只能展示,不能结算。
|
||||
BINDING_EVIDENCE_TASK_TYPES = frozenset({"get_bind_qr", "confirm_bind"})
|
||||
assert BINDING_EVIDENCE_TASK_TYPES <= BINDING_TASK_TYPES
|
||||
@@ -359,6 +357,22 @@ def _order_target_role(
|
||||
return ""
|
||||
|
||||
|
||||
def _binding_target_mismatch_message(
|
||||
confirmed_role: str,
|
||||
expected_role: str,
|
||||
) -> str:
|
||||
if expected_role:
|
||||
return (
|
||||
f"确认绑定已生效:账号当前角色「{confirmed_role}」"
|
||||
f"与客户填写「{expected_role}」不一致。"
|
||||
"请点击“修改资料”,复制或采用平台当前角色后保存。"
|
||||
)
|
||||
return (
|
||||
f"确认绑定已生效:账号当前角色「{confirmed_role}」,"
|
||||
"但订单缺少客户目标角色。请点击“修改资料”补齐后保存。"
|
||||
)
|
||||
|
||||
|
||||
def _sync_confirmed_observation(
|
||||
db: Session,
|
||||
observation: DouyuTask,
|
||||
@@ -1177,13 +1191,14 @@ def _apply_binding_task(
|
||||
|
||||
if binding.status == BINDING_VIEW_CONFIRMED:
|
||||
confirmed_role = binding.confirmed_role_name
|
||||
customer_role = str(task.customer_role_name or "").strip()
|
||||
explicit_expected = str(result.get("expected_role_name") or "").strip()
|
||||
target_role = _order_target_role(
|
||||
db,
|
||||
task,
|
||||
before_task_id=int(source.id) if source.task_type == "confirm_bind" else None,
|
||||
)
|
||||
customer_role = str(task.customer_role_name or "").strip()
|
||||
expected_role = target_role or customer_role
|
||||
expected_role = customer_role or explicit_expected or target_role
|
||||
if is_current:
|
||||
# 订单自己的当前任务(订单创建的或兼容路径挂上的)回查到 bindAct=1。
|
||||
# 查询类任务不会走到这里:resolve_fulfillment_binding 会把观测降级。
|
||||
@@ -1197,7 +1212,7 @@ def _apply_binding_task(
|
||||
accepted = False
|
||||
elif source.task_type == "confirm_bind":
|
||||
accepted = (
|
||||
phase in CONFIRMABLE_BINDING_STATUSES
|
||||
phase in ACTIVE_BINDING_STATUSES | {"confirming"}
|
||||
and bool(expected_role)
|
||||
and role_names_match(confirmed_role, expected_role)
|
||||
)
|
||||
@@ -1207,13 +1222,52 @@ def _apply_binding_task(
|
||||
not expected_role or role_names_match(confirmed_role, expected_role)
|
||||
)
|
||||
if not accepted:
|
||||
reason = (
|
||||
"target_mismatch"
|
||||
if expected_role and not role_names_match(confirmed_role, expected_role)
|
||||
else "missing_target"
|
||||
)
|
||||
if (
|
||||
source.task_type == "confirm_bind"
|
||||
and (owned or is_current)
|
||||
and phase in ACTIVE_BINDING_STATUSES | {"confirming"}
|
||||
):
|
||||
message = _binding_target_mismatch_message(
|
||||
confirmed_role,
|
||||
expected_role,
|
||||
)
|
||||
if (
|
||||
int(task.bind_task_id or 0) == int(source.id)
|
||||
and task.binding_status == "role_ready"
|
||||
and task.last_error == message
|
||||
):
|
||||
return False
|
||||
# 确认动作已经成功,旧 QR 指针必须让位。这里不宣告订单绑定完成,
|
||||
# 而是把实际角色交给运营核对;修改客户资料后会再次结算为 bound。
|
||||
task.bind_task_id = int(source.id)
|
||||
task.binding_status = "role_ready"
|
||||
task.execution_status = "role_ready"
|
||||
task.issue_code = ""
|
||||
task.last_error = message
|
||||
task.updated_at = _now()
|
||||
_record_binding_rejection(
|
||||
db,
|
||||
task,
|
||||
source,
|
||||
reason=reason,
|
||||
confirmed_role=confirmed_role,
|
||||
target_role=expected_role,
|
||||
)
|
||||
_apply_task_lease_policy(db, task, lease=lease)
|
||||
_emit_order_site_binding_state(db, task.id)
|
||||
return True
|
||||
_record_binding_rejection(
|
||||
db,
|
||||
task,
|
||||
source,
|
||||
reason=(
|
||||
"target_mismatch"
|
||||
if expected_role and not role_names_match(confirmed_role, expected_role)
|
||||
reason
|
||||
if reason != "missing_target"
|
||||
else "untrusted_confirmation"
|
||||
),
|
||||
confirmed_role=confirmed_role,
|
||||
@@ -1239,7 +1293,7 @@ def _apply_binding_task(
|
||||
or result.get("current_role_name")
|
||||
or ""
|
||||
)[:128],
|
||||
"targetRoleName": target_role[:128],
|
||||
"targetRoleName": expected_role[:128],
|
||||
"confirmedRoleName": confirmed_role[:128],
|
||||
"confirmedChannel": binding.confirmed_channel,
|
||||
},
|
||||
@@ -1355,6 +1409,18 @@ def refresh_binding(db: Session, *, task_id: int) -> dict[str, Any]:
|
||||
task = _load_task(db, task_id)
|
||||
if _frozen(task):
|
||||
return get_task_detail(db, task.id)
|
||||
# 精英宝典等外部入口可能先创建确认任务,履约订单仍指向更早的扫码任务。
|
||||
# 刷新时必须主动吸收更新、已归属本单的成功证据,不能只盯着旧指针。
|
||||
for evidence in _owned_binding_tasks(
|
||||
db,
|
||||
task,
|
||||
newer_than=int(task.bind_task_id or 0),
|
||||
):
|
||||
if evidence.status != "success":
|
||||
continue
|
||||
if _apply_binding_task(db, task, evidence, owned=True):
|
||||
db.commit()
|
||||
return get_task_detail(db, task.id)
|
||||
if task.binding_status in ACTIVE_BINDING_STATUSES:
|
||||
latest_pending = _latest_pending_binding_task(db, task)
|
||||
if latest_pending is not None and _attach_pending_binding_task(
|
||||
@@ -1609,7 +1675,10 @@ def reconcile_binding_observations(
|
||||
# role_ready 订单最可能已有新观测可自愈;先处理它们,避免
|
||||
# 大量历史 failed/manual_required 订单把固定 limit 的名额占满。
|
||||
case((PlatformFulfillmentTask.binding_status == "role_ready", 0), else_=1),
|
||||
PlatformFulfillmentTask.id.asc(),
|
||||
# 其余状态优先收敛最近更新的订单。生产有上千条失败/待扫码历史,
|
||||
# 按 id 正序会把刚确认的新订单挡在启动对账窗口之外。
|
||||
PlatformFulfillmentTask.updated_at.desc(),
|
||||
PlatformFulfillmentTask.id.desc(),
|
||||
)
|
||||
.limit(max(1, min(limit, 2000)))
|
||||
.all()
|
||||
|
||||
@@ -1508,7 +1508,11 @@ export default function PlatformFulfillmentPage() {
|
||||
{task.account && task.bindingStatus === 'failed' ? (
|
||||
<Tag color="orange">账号保留中</Tag>
|
||||
) : null}
|
||||
<Text ellipsis title={customerRole || '未填写'}>
|
||||
<Text
|
||||
ellipsis
|
||||
title={customerRole || '未填写'}
|
||||
copyable={customerRole ? { text: customerRole } : false}
|
||||
>
|
||||
客户提交角色:{customerRole || '未填写'}
|
||||
</Text>
|
||||
<Text
|
||||
@@ -1516,6 +1520,7 @@ export default function PlatformFulfillmentPage() {
|
||||
style={{ fontSize: 12 }}
|
||||
ellipsis
|
||||
title={scannedRole ? (scannedChannel ? `${scannedRole} (${scannedChannel})` : scannedRole) : '未识别'}
|
||||
copyable={scannedRole ? { text: scannedRole } : false}
|
||||
>
|
||||
扫码绑定角色:{scannedRole || '未识别'}
|
||||
{scannedRole && scannedChannel ? ` · ${scannedChannel}` : ''}
|
||||
@@ -2103,7 +2108,18 @@ export default function PlatformFulfillmentPage() {
|
||||
<Space direction="vertical" size={10} style={{ width: '100%' }}>
|
||||
<Descriptions bordered size="small" column={2}>
|
||||
<Descriptions.Item label="客户角色" span={2}>
|
||||
{selected.customerProfile.roleName || '未填写'}
|
||||
{selected.customerProfile.roleName ? (
|
||||
<Text
|
||||
copyable={{
|
||||
text: selected.customerProfile.roleName,
|
||||
tooltips: ['复制客户角色', '已复制'],
|
||||
}}
|
||||
>
|
||||
{selected.customerProfile.roleName}
|
||||
</Text>
|
||||
) : (
|
||||
'未填写'
|
||||
)}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="登录方式">
|
||||
{CUSTOMER_PLATFORM_LABELS[selected.customerProfile.platform] || selected.customerProfile.platform || '-'}
|
||||
@@ -2112,7 +2128,18 @@ export default function PlatformFulfillmentPage() {
|
||||
{CUSTOMER_SYSTEM_LABELS[selected.customerProfile.system] || selected.customerProfile.system || '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="平台当前角色">
|
||||
{selected.customerProfile.platformRoleName || '未识别'}
|
||||
{selected.customerProfile.platformRoleName ? (
|
||||
<Text
|
||||
copyable={{
|
||||
text: selected.customerProfile.platformRoleName,
|
||||
tooltips: ['复制平台当前角色', '已复制'],
|
||||
}}
|
||||
>
|
||||
{selected.customerProfile.platformRoleName}
|
||||
</Text>
|
||||
) : (
|
||||
'未识别'
|
||||
)}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="平台渠道">
|
||||
{selected.customerProfile.platformChannel || '-'}
|
||||
@@ -2742,6 +2769,36 @@ export default function PlatformFulfillmentPage() {
|
||||
message="请对照客户主页截图核对并修正"
|
||||
description="修改后会同步写入时间线和订单侧;若正在扫码中会立即按新角色名重算。"
|
||||
/>
|
||||
<div>
|
||||
<Text strong>平台当前角色</Text>
|
||||
<Space wrap size={8} style={{ marginTop: 8 }}>
|
||||
{profileEditTarget?.customerProfile?.platformRoleName ? (
|
||||
<>
|
||||
<Text
|
||||
copyable={{
|
||||
text: profileEditTarget.customerProfile.platformRoleName,
|
||||
tooltips: ['复制平台当前角色', '已复制'],
|
||||
}}
|
||||
>
|
||||
{profileEditTarget.customerProfile.platformRoleName}
|
||||
</Text>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() =>
|
||||
setProfileEditRole(
|
||||
profileEditTarget.customerProfile?.platformRoleName || '',
|
||||
)
|
||||
}
|
||||
>
|
||||
填入当前角色
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<Text type="secondary">暂未识别</Text>
|
||||
)}
|
||||
</Space>
|
||||
</div>
|
||||
<div>
|
||||
<Text strong>客户游戏角色名</Text>
|
||||
<Input
|
||||
|
||||
Reference in New Issue
Block a user