fix(fulfillment): 拆分绑定事实并复用同账号角色

- 详情页增加 QYOOB / cjm / 7 天锁绑定判定面板
- 订单目标只认动作 alias pending,cjm-only 不再推进订单
- 同账号同角色直接复用已有绑定,不再等待二维码或调 actBind
- 补账号侧 7 天锁本地检查
- 补充绑定证据、同对复用和 7 天锁回归测试
This commit is contained in:
yml
2026-11-24 13:14:50 +08:00
parent ad6c31729d
commit 5b6d146f93
10 changed files with 1221 additions and 27 deletions
@@ -336,3 +336,54 @@ WHERE t.binding_status = 'bound'
仍未做:命中后**自动切回原账号 A**。A 往往被协作单占用,是否等待/复用需要
产品规则;当前先交给人工,避免继续产生 doomed `actBind`。
### 9.6 绑定事实拆分与自动复用(2026-11-24 第二轮)
**1. 详情页“绑定判定”面板**
- `binding_evidence.py` 把一个绑定任务拆成互不混淆的几层:
- `actionCurrent`:QYOOB 上 `bindAct=1` 的当前角色;
- `actionPending`:QYOOB 上 `bindAct=0`、本次可确认的角色;
- `legacyLatest`:cjm 最新角色(仅参考,不能确认);
- `accountCurrentRole`:账号表当前角色(覆盖式);
- `roleLock` / `accountLock`:角色侧 / 账号侧 7 天锁。
- 前端“绑定判定(QYOOB / cjm / 7 天锁)”卡片直接展示这些行;当 cjm 有角色
但 QYOOB 没有 pending 时,明确提示“不要直接确认”。
**2. 订单目标只认动作 alias**
- `_actionable_pending_role`:结果里 `action_act_aliases` 非空、且选中的
`act_alias` 不在其中时,不把该角色作为订单目标。
- `_apply_binding_task`、`_attach_pending_binding_task`、`_latest_pending_binding_task`、
`_order_target_role`、确认入口都执行这条约束;cjm-only pending 不再推进订单。
- 兼容部署前已 `role_ready` 的订单:确认入口返回
“当前动作通道没有待确认角色,请客户重新扫码后再确认”。
**3. 同账号同角色复用**
- `_same_pair_reuse_role`:只有 **cjm 上有本次扫码角色**、QYOOB 同一角色
`bindAct=1`、且账号当前角色也是该角色时,才复用。
- 命中后直接 `bound`,写 `binding_reused_existing_pair`,不再等新 pending、
不再调 `actBind`。覆盖二维码过期里 `same_role_stale` 的主体。
- 没有扫码角色(只有 `already_bound` 旧角色)不复用,避免把上一单角色套给新订单。
**4. 账号侧 7 天本地检查**
- `find_account_lock`:当前账号最近 7 天 `bind_ok` 的是**别的角色**时,命中
`account_role_bound_elsewhere`,订单转人工并记录账号上一角色/时间;
- 同一角色(同一对)不算锁;超过 7 天放行;
- pending、确认前、启动对账都会检查。
**5. 回归用例**
- `test_binding_evidence_separates_qyoob_cjm_and_locks`
- `test_binding_evidence_marks_same_account_same_role`
- `test_cjm_only_pending_keeps_order_waiting_action_alias`
- `test_same_account_same_role_is_reused_as_bound`
- `test_already_bound_without_scan_does_not_reuse`
- `test_pending_role_blocked_by_account_seven_day_lock`
- `test_account_seven_day_lock_older_than_seven_days_allows_binding`
仍未解决:本地没有任何 `bind_ok` 证据的**外部角色锁**(生产上新确认失败里
5/7 属于这类),只能让客服/客户使用原账号或等待;CK 失效、二维码过期、
17 单启动转人工和 2 单误结算仍需运营处理。