feat(履约绑定): 支持工作台修改客户资料、扫码不匹配时间线及确认后斗鱼复核
This commit is contained in:
@@ -13,21 +13,23 @@ from ...models import (
|
||||
PlatformFulfillmentTask,
|
||||
)
|
||||
from .binding import (
|
||||
ACTIVE_BINDING_STATUSES,
|
||||
confirm_binding,
|
||||
refresh_binding,
|
||||
start_binding,
|
||||
sync_customer_role_to_bind_task,
|
||||
)
|
||||
from .common import FLOW_VERSION_CLEAN, _has_game_home_profile
|
||||
from .common import FLOW_VERSION_CLEAN, _has_game_home_profile, _now
|
||||
from .order_sync import sync_order_item_ids
|
||||
from .outbox import _emit_order_site_binding_state
|
||||
from .repository import (
|
||||
_find_customer_task,
|
||||
_integration_actor,
|
||||
_load_task,
|
||||
_load_task_for_update,
|
||||
)
|
||||
from .runtime import _append_event
|
||||
from .views import customer_binding_out
|
||||
from .runtime import _append_event, _apply_task_lease_policy
|
||||
from .views import customer_binding_out, get_task_detail
|
||||
|
||||
|
||||
def ensure_customer_session(
|
||||
@@ -199,3 +201,101 @@ async def customer_confirm_binding(db: Session, *, task_id: int) -> dict[str, An
|
||||
refresh_binding(db, task_id=task_id)
|
||||
await confirm_binding(db, task_id=task_id, current=_integration_actor(db))
|
||||
return customer_binding_out(db, task_id)
|
||||
|
||||
|
||||
def update_customer_profile_by_operator(
|
||||
db: Session,
|
||||
*,
|
||||
task_id: int,
|
||||
current: Any,
|
||||
customer_role_name: str,
|
||||
platform: str,
|
||||
system: str,
|
||||
reopen_binding: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
"""工作台运营人工修改客户填写的角色、登录方式和系统。"""
|
||||
task = _load_task_for_update(db, task_id)
|
||||
if task.execution_status in {"completed", "cancelled"}:
|
||||
raise HTTPException(status_code=409, detail="订单已结束,不能修改客户资料")
|
||||
if task.binding_status == "bound":
|
||||
raise HTTPException(status_code=409, detail="角色已绑定确认,不能直接修改客户资料")
|
||||
if task.binding_status == "confirming":
|
||||
raise HTTPException(status_code=409, detail="正在确认绑定中,请稍后再试")
|
||||
|
||||
new_role = str(customer_role_name or "").strip()[:128]
|
||||
new_platform = str(platform or "").strip()[:16]
|
||||
new_system = str(system or "").strip()[:16]
|
||||
if not new_role:
|
||||
raise HTTPException(status_code=422, detail="请填写客户游戏角色名")
|
||||
if new_platform not in {"wechat", "qq"}:
|
||||
raise HTTPException(status_code=422, detail="登录方式只能选择微信或 QQ")
|
||||
if new_system not in {"ios", "android"}:
|
||||
raise HTTPException(status_code=422, detail="系统只能选择苹果或安卓")
|
||||
|
||||
old_role = str(task.customer_role_name or "").strip()
|
||||
old_platform = str(task.customer_platform or "").strip()
|
||||
old_system = str(task.customer_system or "").strip()
|
||||
|
||||
now = _now()
|
||||
task.customer_role_name = new_role
|
||||
task.customer_platform = new_platform
|
||||
task.customer_system = new_system
|
||||
task.customer_profile_updated_at = now
|
||||
task.operator_id = int(current.id)
|
||||
task.updated_at = now
|
||||
|
||||
reopened = False
|
||||
if (
|
||||
reopen_binding
|
||||
and task.binding_status == "failed"
|
||||
and task.issue_code
|
||||
in {
|
||||
"binding_failed",
|
||||
"role_changed",
|
||||
"customer_role_cooldown",
|
||||
"customer_role_bound_elsewhere",
|
||||
}
|
||||
):
|
||||
lease = (
|
||||
db.query(AccountLease).filter(AccountLease.id == task.lease_id).first()
|
||||
if task.lease_id
|
||||
else None
|
||||
)
|
||||
task.bind_task_id = None
|
||||
task.binding_status = "not_started"
|
||||
task.issue_code = ""
|
||||
task.last_error = ""
|
||||
if task.account_id and lease is not None and lease.status == "active":
|
||||
task.execution_status = "allocated"
|
||||
_apply_task_lease_policy(db, task, lease=lease)
|
||||
else:
|
||||
task.account_id = None
|
||||
task.lease_id = None
|
||||
task.execution_status = "ready"
|
||||
reopened = True
|
||||
elif task.bind_task_id and task.binding_status in ACTIVE_BINDING_STATUSES:
|
||||
sync_customer_role_to_bind_task(db, task)
|
||||
|
||||
_append_event(
|
||||
db,
|
||||
task.id,
|
||||
"customer_profile_updated",
|
||||
actor_type="user",
|
||||
actor_id=current.id,
|
||||
detail={
|
||||
"previousRoleName": old_role,
|
||||
"customerRoleName": new_role,
|
||||
"previousPlatform": old_platform,
|
||||
"platform": new_platform,
|
||||
"previousSystem": old_system,
|
||||
"system": new_system,
|
||||
"reopenedBinding": reopened,
|
||||
},
|
||||
)
|
||||
_emit_order_site_binding_state(db, task.id)
|
||||
db.commit()
|
||||
if reopened and task.execution_status == "ready":
|
||||
from .auto_allocator import wake_auto_allocator
|
||||
|
||||
wake_auto_allocator([int(task.id)])
|
||||
return get_task_detail(db, task.id)
|
||||
|
||||
Reference in New Issue
Block a user