fix(douyu): coordinate collab and platform account leases
Avoid automatic allocation of accounts with active external collaboration, require explicit manual takeover of platform leases, and add Douyu account identity search.
This commit is contained in:
@@ -1001,13 +1001,19 @@ def list_tasks(
|
||||
text = keyword.strip()
|
||||
if text:
|
||||
pattern = f"%{text}%"
|
||||
query = query.filter(
|
||||
query = query.outerjoin(
|
||||
Account,
|
||||
Account.id == PlatformFulfillmentTask.account_id,
|
||||
).filter(
|
||||
or_(
|
||||
PlatformFulfillmentTask.platform_order_id.ilike(pattern),
|
||||
PlatformFulfillmentTask.sku_name.ilike(pattern),
|
||||
PlatformFulfillmentTask.sku_code.ilike(pattern),
|
||||
PlatformFulfillmentTask.internal_sku_key.ilike(pattern),
|
||||
PlatformFulfillmentTask.commodity_id.ilike(pattern),
|
||||
Account.username.ilike(pattern),
|
||||
Account.nickname.ilike(pattern),
|
||||
Account.uid.ilike(pattern),
|
||||
)
|
||||
)
|
||||
total = query.count()
|
||||
@@ -2581,6 +2587,48 @@ def restore_cancelled_task(
|
||||
return get_task_detail(db, task.id)
|
||||
|
||||
|
||||
def prepare_platform_task_for_collab_takeover(
|
||||
db: Session,
|
||||
*,
|
||||
task: PlatformFulfillmentTask,
|
||||
current: User,
|
||||
collab_order_no: str,
|
||||
) -> None:
|
||||
"""把平台履约任务转为人工,但不提交事务;由协作单接管流程原子提交。"""
|
||||
if task.execution_status in {"completed", "cancelled"}:
|
||||
raise HTTPException(status_code=409, detail="已结束的履约任务不能被协作单接管")
|
||||
account_id = task.account_id
|
||||
lease_id = task.lease_id
|
||||
reason = f"外部协作单 {collab_order_no} 人工接管账号"
|
||||
task.account_id = None
|
||||
task.lease_id = None
|
||||
task.bind_task_id = None
|
||||
task.exchange_task_id = None
|
||||
task.execution_status = "manual_required"
|
||||
task.binding_status = "not_started"
|
||||
task.exchange_status = "not_started"
|
||||
task.issue_code = "manual_required"
|
||||
task.next_allocate_at = None
|
||||
task.operator_id = current.id
|
||||
task.last_error = reason
|
||||
task.updated_at = _now()
|
||||
_append_event(
|
||||
db,
|
||||
task.id,
|
||||
"collab_takeover",
|
||||
actor_type="user",
|
||||
actor_id=current.id,
|
||||
detail={
|
||||
"reason": reason,
|
||||
"collabOrderNo": collab_order_no,
|
||||
"releasedAccountId": account_id,
|
||||
"releasedLeaseId": lease_id,
|
||||
},
|
||||
)
|
||||
_emit_order_site_binding_state(db, task.id)
|
||||
db.flush()
|
||||
|
||||
|
||||
def release_task_to_manual(
|
||||
db: Session,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user