发布(0.4.5): 修复重选号台账同步并移除强制确认

This commit is contained in:
yml
2026-11-26 23:11:12 +08:00
parent e6c89d9f59
commit 9100991cb1
11 changed files with 118 additions and 418 deletions
@@ -14,7 +14,6 @@ from ..schemas import (
PlatformFulfillmentCollabSyncRequest,
PlatformFulfillmentCompleteRequest,
PlatformFulfillmentCustomerProfileUpdate,
PlatformFulfillmentManualBindingRequest,
PlatformFulfillmentMappingUpsert,
PlatformFulfillmentMappingWrite,
PlatformFulfillmentReasonRequest,
@@ -494,37 +493,6 @@ def operator_confirm_binding(
return result
@router.post("/tasks/{task_id}/bind/manual-confirm")
def manual_confirm_binding(
task_id: int,
req: PlatformFulfillmentManualBindingRequest,
db: Session = Depends(get_db),
current: User = Depends(require_permission("platform_fulfillment:use")),
) -> dict[str, Any]:
"""运营人工确认绑定:用于客户已在别处绑定、或账号当前角色已确认的场景。"""
service.ensure_customer_profile_for_binding(db, task_id=task_id)
result = service.manual_confirm_binding_sync(
db,
task_id=task_id,
current=current,
role_name=req.role_name,
note=req.note,
)
record_audit(
db,
current,
action="platform_fulfillment:binding:manual_confirm",
target=f"platform_fulfillment_task:{task_id}",
detail={
"roleName": req.role_name,
"note": req.note,
"bindingStatus": result.get("task", {}).get("bindingStatus"),
},
)
db.commit()
return result
@router.patch("/tasks/{task_id}/customer-profile")
def update_customer_profile(
task_id: int,
-5
View File
@@ -1778,11 +1778,6 @@ class PlatformFulfillmentCompleteRequest(BaseModel):
note: str = Field(default="", max_length=1000)
class PlatformFulfillmentManualBindingRequest(BaseModel):
role_name: str = Field(default="", max_length=128)
note: str = Field(default="", max_length=500)
class PlatformFulfillmentCustomerProfileUpdate(BaseModel):
customer_role_name: str = Field(..., min_length=1, max_length=128)
customer_platform: str = Field(..., pattern="^(wechat|qq)$")
+24 -2
View File
@@ -223,6 +223,10 @@ def sync_platform_fulfillment_order(
)
order = order_by_no
created = False
was_platform_projection = (
order is not None
and order.source_type == SOURCE_TYPE_PLATFORM_FULFILLMENT
)
now = _now()
account = (
@@ -232,6 +236,11 @@ def sync_platform_fulfillment_order(
)
gift_name, commodity_id, required_points = _platform_fulfillment_gift(db, task)
home_images = _platform_fulfillment_home_images(task)
account_changed = bool(
account is not None
and order is not None
and int(order.account_id or 0) != int(account.id)
)
if order is None:
order = DouyuExternalOrder(
@@ -266,17 +275,30 @@ def sync_platform_fulfillment_order(
if home_images:
order.home_images = home_images
if account is not None and (
created or (order.account_id is None and not order.account_username)
created
or was_platform_projection
or (order.account_id is None and not order.account_username)
):
order.account_id = int(account.id)
order.account_username = _text(account.username, max_length=128)
order.account_uid = _text(account.uid, max_length=32)
order.account_nickname = _text(account.nickname, max_length=128)
if was_platform_projection and (
account_changed
or not task.bind_task_id
or task.binding_status != "bound"
):
# 履约单重选号或重新进入绑定流程后,预售台账是平台账号的投影,
# 不能继续展示首单/上一轮角色。
order.bind_game_account = ""
order.bind_game_role = ""
order.bind_game_channel = ""
order.bind_snapshot_at = None
_apply_platform_fulfillment_binding(
db,
order,
task,
overwrite=created,
overwrite=created or was_platform_projection,
)
_apply_platform_fulfillment_status(order, task, created=created)
order.version = int(order.version or 0) + 1
@@ -914,7 +914,7 @@ def operator_confirm_binding_sync(
"""普通人工代确认:客户已扫码但没点确认,运营代为提交正常 actBind。
不填写角色/备注,不直接标 bound;复用客户确认的同一套确认任务。
当前没有可确认的扫码角色时,要求客户扫码或走“强制确认”。
当前没有可确认的扫码角色时,要求客户重新扫码。
"""
task = _load_task_for_update(db, task_id)
if _frozen(task):
@@ -926,137 +926,11 @@ def operator_confirm_binding_sync(
if task.binding_status != "role_ready":
raise HTTPException(
status_code=409,
detail=(
"当前没有可代确认的扫码角色。请让客户先扫码;"
"只有账号已绑定到该角色、但缺少本次扫码证据时,才使用强制确认。"
),
detail="当前没有可代确认的扫码角色,请让客户先扫码。",
)
return confirm_binding_sync(db, task_id=task.id, current=current)
def manual_confirm_binding_sync(
db: Session,
*,
task_id: int,
current: User,
role_name: str = "",
note: str = "",
) -> dict[str, Any]:
"""运营人工确认绑定:不依赖本次扫码/actBind,直接落订单绑定事实。
用于客户已在别处完成绑定、或账号当前角色就是客户角色,但履约工作台没有
本次扫码证据的场景。必须由运营确认角色并记录操作人/备注;不做自动复用。
"""
task = _load_task_for_update(db, task_id)
if _frozen(task):
# 已 bound / completed / cancelled:幂等返回,不重复写事件。
return get_task_detail(db, task.id)
if not task.account_id or not task.lease_id:
raise HTTPException(status_code=409, detail="请先分配账号")
lease = db.query(AccountLease).filter(AccountLease.id == task.lease_id).first()
if lease is None or lease.status != "active":
raise HTTPException(status_code=409, detail="账号租约已失效,请重新分配")
account = db.get(Account, int(task.account_id))
if account is None:
raise HTTPException(status_code=409, detail="账号不存在")
confirmed_role = str(role_name or account.game_name or "").strip()
if not confirmed_role:
raise HTTPException(
status_code=409,
detail="账号没有可确认的角色,请先查询角色或填写确认角色",
)
account_role = str(account.game_name or "").strip()
if str(account.role_bind_status or "") != "bound" or not account_role:
raise HTTPException(
status_code=409,
detail="账号当前没有已生效角色,不能人工确认;请先刷新/查询角色",
)
if account_role != confirmed_role:
raise HTTPException(
status_code=409,
detail=(
f"账号当前角色是「{account_role}」,确认角色是「{confirmed_role}」,"
"不一致,不能人工确认。人工确认只能用于账号已经绑定到该角色的场景;"
"换绑请先完成 actBind 或使用正确账号。"
),
)
note = str(note or "").strip()[:500]
if len(note) < 2:
raise HTTPException(status_code=409, detail="请填写人工确认依据/备注")
previous_binding = str(task.binding_status or "")
previous_execution = str(task.execution_status or "")
bind_task = (
db.query(DouyuTask).filter(DouyuTask.id == int(task.bind_task_id)).first()
if task.bind_task_id
else None
)
if bind_task is not None:
result = dict(bind_task.result or {})
previous_pending_role = str(
result.get("pending_role_name") or result.get("role_name") or ""
).strip()
account_channel = str(account.game_channel or "").strip()
area_name, _, plat_name = account_channel.partition(" · ")
result.update(
{
"manual_confirmed": True,
"manual_confirmed_role": confirmed_role,
"manual_confirmed_by": int(current.id),
"manual_confirm_note": note,
"previous_pending_role_name": previous_pending_role[:128],
"bind_phase": "manual_confirmed",
"bind_polling": False,
"bind_ready_for_confirm": False,
"bind_confirmed": True,
"pending_role_name": "",
"role_name": confirmed_role,
"current_role_name": confirmed_role,
"area_name": area_name,
"plat_name": plat_name,
"is_bound_act": True,
"is_bound_role": True,
}
)
bind_task.status = "success"
bind_task.queue_lane = ""
bind_task.next_run_at = None
bind_task.run_deadline_at = None
bind_task.message = f"人工确认绑定: {confirmed_role}"[:512]
bind_task.finished_at = _now()
bind_task.result = result
task.binding_status = "bound"
task.execution_status = "bound"
task.issue_code = ""
task.last_error = ""
task.operator_id = int(current.id)
task.updated_at = _now()
_append_event(
db,
task.id,
"binding_manually_confirmed",
actor_type="user",
actor_id=str(current.id),
detail={
"roleName": confirmed_role[:128],
"accountId": int(task.account_id),
"accountName": (account.nickname or account.username),
"operatorId": int(current.id),
"note": note,
"sourceTaskId": int(bind_task.id) if bind_task is not None else None,
"sourceTaskStatus": str(bind_task.status or "") if bind_task else "",
"previousBindingStatus": previous_binding,
"previousExecutionStatus": previous_execution,
"baselineRole": str(account.game_name or "").strip(),
},
)
_apply_task_lease_policy(db, task, lease=lease)
_emit_order_site_binding_state(db, task.id)
db.commit()
return get_task_detail(db, task.id)
def _apply_binding_task(
db: Session,
task: PlatformFulfillmentTask,
@@ -30,7 +30,6 @@ from .binding import ( # noqa: F401
confirm_binding,
confirm_binding_sync,
ensure_customer_profile_for_binding,
manual_confirm_binding_sync,
operator_confirm_binding_sync,
reconcile_binding_observations,
reconcile_binding_state_outbox,
@@ -160,7 +159,6 @@ __all__ = [
"get_task_detail",
"list_mappings",
"list_tasks",
"manual_confirm_binding_sync",
"mapping_impact",
"mark_manual_required",
"operator_confirm_binding_sync",