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
@@ -27,6 +27,9 @@ from ...models import Account, AccountEvent, AccountLease
#: 新的履约 issue code:用户角色 7 天内已绑定其他斗鱼账号。
ROLE_LOCK_ISSUE = "customer_role_bound_elsewhere"
#: 新的履约 issue code:当前分配的斗鱼账号 7 天内已绑定其他角色。
ACCOUNT_LOCK_ISSUE = "account_role_bound_elsewhere"
#: 官方规则窗口。
ROLE_LOCK_WINDOW = timedelta(days=7)
@@ -39,6 +42,23 @@ _LEASE_PURPOSE_LABELS = {
}
@dataclass(frozen=True)
class AccountLock:
role_name: str
account_id: int
account_name: str
bound_at: datetime
reusable_at: datetime
def message(self) -> str:
return (
f"该斗鱼账号 7 天内已绑定角色({self.role_name}),"
f"绑定时间 {_beijing_text(self.bound_at)},"
f"预计 {_beijing_text(self.reusable_at)} 后可再次换绑;"
"如需绑定新角色请换号或等待。"
)
@dataclass(frozen=True)
class RoleLock:
role_name: str
@@ -143,9 +163,68 @@ def find_role_lock(
)
def find_account_lock(
db: Session,
account_id: int | None,
scanned_role: str,
*,
now: datetime | None = None,
) -> AccountLock | None:
"""当前分配的斗鱼账号 7 天内是否已经绑定过别的角色。
同一角色(同一对)不算锁:复用已有绑定即可。
"""
role = str(scanned_role or "").strip()
if account_id is None or not role:
return None
moment = now or datetime.now(UTC)
since = moment - ROLE_LOCK_WINDOW
event = (
db.query(AccountEvent)
.filter(
AccountEvent.event_type == "bind_ok",
AccountEvent.subject_type == "elite_role",
AccountEvent.account_id == int(account_id),
AccountEvent.occurred_at >= since,
AccountEvent.occurred_at <= moment,
)
.order_by(AccountEvent.occurred_at.desc(), AccountEvent.id.desc())
.first()
)
if event is None:
return None
bound_role = str(event.subject_key or "").strip()
if not bound_role or bound_role == role:
return None
account = db.get(Account, int(account_id))
account_name = (
(
str(account.nickname or "").strip()
or str(account.username or "").strip()
or f"账号#{account.id}"
)
if account is not None
else f"账号#{account_id}"
)
bound_at = (
event.occurred_at
if event.occurred_at.tzinfo is not None
else event.occurred_at.replace(tzinfo=UTC)
)
return AccountLock(
role_name=bound_role,
account_id=int(account_id),
account_name=account_name,
bound_at=bound_at,
reusable_at=bound_at + ROLE_LOCK_WINDOW,
)
__all__ = [
"ROLE_LOCK_ISSUE",
"ROLE_LOCK_WINDOW",
"AccountLock",
"RoleLock",
"find_account_lock",
"find_role_lock",
]