发布(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",
@@ -142,11 +142,6 @@ export const platformFulfillmentApi = {
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
`/platform-fulfillment/tasks/${taskId}/bind/operator-confirm`,
),
manualConfirmBinding: (taskId: number, roleName: string, note: string) =>
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
`/platform-fulfillment/tasks/${taskId}/bind/manual-confirm`,
{ role_name: roleName, note },
),
verifyBinding: (taskId: number) =>
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
`/platform-fulfillment/tasks/${taskId}/bind/verify`,
@@ -500,7 +500,7 @@ function canReallocateAndBind(task: PlatformFulfillmentTask) {
);
}
function canManualConfirmBinding(task: PlatformFulfillmentTask) {
function canOperatorConfirmBinding(task: PlatformFulfillmentTask) {
if (!task.account) return false;
return !['bound', 'completed', 'cancelled'].includes(task.executionStatus);
}
@@ -535,10 +535,6 @@ export default function PlatformFulfillmentPage() {
const [manualReleaseTarget, setManualReleaseTarget] = useState<PlatformFulfillmentTask | null>(null);
const [manualReleaseReason, setManualReleaseReason] = useState('');
const [manualReleasing, setManualReleasing] = useState(false);
const [manualBindTarget, setManualBindTarget] = useState<PlatformFulfillmentTask | null>(null);
const [manualBindRole, setManualBindRole] = useState('');
const [manualBindNote, setManualBindNote] = useState('');
const [manualBinding, setManualBinding] = useState(false);
const [profileEditTarget, setProfileEditTarget] = useState<PlatformFulfillmentTask | null>(null);
const [profileEditRole, setProfileEditRole] = useState('');
const [profileEditPlatform, setProfileEditPlatform] = useState<'wechat' | 'qq'>('wechat');
@@ -546,13 +542,6 @@ export default function PlatformFulfillmentPage() {
const [profileEditReopen, setProfileEditReopen] = useState(true);
const [profileEditSaving, setProfileEditSaving] = useState(false);
const [verifyingBinding, setVerifyingBinding] = useState(false);
const manualBindCurrentRole =
manualBindTarget?.bindingEvidence?.accountCurrentRole || '';
const manualBindMismatch = Boolean(
manualBindCurrentRole &&
manualBindRole.trim() &&
manualBindRole.trim() !== manualBindCurrentRole,
);
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
const [selectedId, setSelectedId] = useState<number | null>(null);
const [detail, setDetail] = useState<PlatformFulfillmentDetail | null>(null);
@@ -955,49 +944,6 @@ export default function PlatformFulfillmentPage() {
}
};
const openManualBinding = (task: PlatformFulfillmentTask) => {
setManualBindTarget(task);
setManualBindRole(task.bindingEvidence?.accountCurrentRole || '');
setManualBindNote('');
};
const confirmManualBinding = async () => {
if (!manualBindTarget) return;
const role = manualBindRole.trim();
const note = manualBindNote.trim();
if (!role) {
message.warning('请填写客户确认的游戏角色');
return;
}
if (manualBindCurrentRole && role !== manualBindCurrentRole) {
message.error(`账号当前角色是「${manualBindCurrentRole}」,不能人工确认「${role}」`);
return;
}
if (note.length < 2) {
message.warning('请填写人工确认依据/备注');
return;
}
setManualBinding(true);
try {
const result = await platformFulfillmentApi.manualConfirmBinding(
manualBindTarget.id,
role,
note,
);
setDetail(result);
setSelectedId(result.task.id);
setManualBindTarget(null);
setManualBindRole('');
setManualBindNote('');
await loadTasks();
message.success('已人工确认绑定');
} catch (error) {
message.error(getErrorMessage(error));
} finally {
setManualBinding(false);
}
};
const submitOperatorConfirm = async (task: PlatformFulfillmentTask) => {
try {
const result = await platformFulfillmentApi.operatorConfirmBinding(task.id);
@@ -1681,16 +1627,11 @@ export default function PlatformFulfillmentPage() {
代客户确认
</Button>
) : null}
{canManualConfirmBinding(task) && task.executionStatus !== 'role_ready' && task.bindTask?.roleName ? (
{canOperatorConfirmBinding(task) && task.executionStatus !== 'role_ready' && task.bindTask?.roleName ? (
<Button size="small" type="primary" icon={<CheckCircleOutlined />} onClick={() => void submitOperatorConfirm(task)}>
代客户确认
</Button>
) : null}
{can('platform_fulfillment:use') && canManualConfirmBinding(task) ? (
<Button size="small" danger icon={<CheckCircleOutlined />} onClick={() => openManualBinding(task)}>
强制确认
</Button>
) : null}
{canResetBinding(task) ? (
<Button
size="small"
@@ -1770,11 +1711,6 @@ export default function PlatformFulfillmentPage() {
代客户确认
</Button>
) : null}
{selected && can('platform_fulfillment:use') && canManualConfirmBinding(selected) ? (
<Button danger icon={<CheckCircleOutlined />} onClick={() => openManualBinding(selected)}>
强制确认
</Button>
) : null}
{selected &&
selected.account &&
selected.bindingStatus === 'bound' &&
@@ -2690,68 +2626,6 @@ export default function PlatformFulfillmentPage() {
</Space>
</Modal>
<Modal
title={`人工强制确认 ${manualBindTarget ? `#${manualBindTarget.id}` : ''}`}
open={Boolean(manualBindTarget)}
okText="强制绑定"
cancelText="取消"
confirmLoading={manualBinding}
okButtonProps={{
disabled: manualBindMismatch || !manualBindRole.trim() || manualBindNote.trim().length < 2,
}}
onOk={() => void confirmManualBinding()}
onCancel={() => {
setManualBindTarget(null);
setManualBindRole('');
setManualBindNote('');
}}
>
<Space direction="vertical" size={12} style={{ width: '100%' }}>
<Alert
type="warning"
showIcon
message="强制确认会跳过 actBind 直接把订单标记为已绑定"
description="只在账号当前角色已经确认绑定到该角色、但缺少本次扫码证据时使用;必须填写依据。普通代确认请用“代客户确认”。"
/>
{manualBindMismatch ? (
<Alert
type="error"
showIcon
message="确认角色与账号当前角色不一致"
description="人工确认只能用于账号已经绑定到该角色的场景;换绑必须先完成 actBind 或使用正确账号。"
/>
) : null}
<Text type="secondary">
账号当前角色:{manualBindTarget?.bindingEvidence?.accountCurrentRole || '未知'}
{manualBindTarget?.bindingEvidence?.scannedRole
? `;本次扫码角色:${manualBindTarget.bindingEvidence.scannedRole}`
: ';本次未扫码'}
</Text>
<div>
<Text strong>确认角色</Text>
<Input
value={manualBindRole}
maxLength={128}
placeholder="客户确认的游戏角色"
onChange={(event) => setManualBindRole(event.target.value)}
style={{ marginTop: 8 }}
/>
</div>
<div>
<Text strong>确认依据 / 备注</Text>
<Input.TextArea
rows={3}
maxLength={500}
showCount
value={manualBindNote}
placeholder="例如:客户已在精英宝典完成绑定,客服核对角色一致"
onChange={(event) => setManualBindNote(event.target.value)}
style={{ marginTop: 8 }}
/>
</div>
</Space>
</Modal>
<Modal
title={`修改用户资料 ${profileEditTarget ? `#${profileEditTarget.id}` : ''}`}
open={Boolean(profileEditTarget)}