feat(accounts): 统一可换绑时间并加本地 7 天锁
- 新增官方时间、本地 bind_ok、7 天锁到期、检查时间和来源字段 - role_change_available_at 改为官方时间与本地锁取较晚者 - 绑定成功和官方探测统一写有效时间 - 分配过滤增加最近 elite bind_ok 的数据库兜底 - 迁移 0129 从 account_events 回填历史账号 - 补充字段/回填过滤测试和生命周期文档
This commit is contained in:
@@ -30,13 +30,17 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
from loguru import logger
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..models import Account
|
||||
from .account_binding import (
|
||||
effective_role_change_available_at,
|
||||
role_bind_lock_until,
|
||||
)
|
||||
from .account_events_service import (
|
||||
CATEGORY_ACTIVITY,
|
||||
CATEGORY_BUSINESS,
|
||||
@@ -467,7 +471,7 @@ def record_bind(
|
||||
title += f":{role_name}"
|
||||
if weak:
|
||||
title += "(未回查确认)"
|
||||
return emit(
|
||||
emitted = emit(
|
||||
db,
|
||||
account_id=account.id,
|
||||
event_type=EVENT_BIND_OK,
|
||||
@@ -488,6 +492,19 @@ def record_bind(
|
||||
actor_id=actor_id,
|
||||
source_ref=task_ref(task_id),
|
||||
)
|
||||
if scope == "elite":
|
||||
# 本地 7 天锁:绑定事实发生即生效,不能等下一次官方查询。
|
||||
moment = occurred_at or datetime.now(UTC)
|
||||
if account.last_bind_ok_at is None or moment > account.last_bind_ok_at:
|
||||
account.last_bind_ok_at = moment
|
||||
account.role_bind_lock_until = role_bind_lock_until(moment)
|
||||
account.role_change_available_at = effective_role_change_available_at(
|
||||
official_at=account.role_change_official_at,
|
||||
last_bind_ok_at=account.last_bind_ok_at,
|
||||
)
|
||||
account.role_change_checked_at = datetime.now(UTC)
|
||||
account.role_change_source = "local_bind"
|
||||
return emitted
|
||||
|
||||
|
||||
def record_official_exchange(
|
||||
|
||||
Reference in New Issue
Block a user