发布(0.4.5): 修复重选号台账同步并移除强制确认
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# 直播账号运营后台
|
# 直播账号运营后台
|
||||||
|
|
||||||
斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.3)。
|
斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.5)。
|
||||||
|
|
||||||
## 能做什么
|
## 能做什么
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "live-hub-py"
|
name = "live-hub-py"
|
||||||
version = "0.4.3"
|
version = "0.4.5"
|
||||||
description = "直播账号运营 Web 后台"
|
description = "直播账号运营 Web 后台"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12,<3.13"
|
requires-python = ">=3.12,<3.13"
|
||||||
|
|||||||
@@ -751,6 +751,93 @@ class TestFulfillmentCollabSync(_Base):
|
|||||||
lease = self.session.query(AccountLease).one()
|
lease = self.session.query(AccountLease).one()
|
||||||
assert lease.purpose == "douyu_collab"
|
assert lease.purpose == "douyu_collab"
|
||||||
|
|
||||||
|
def test_platform_sync_replaces_account_and_role_after_reallocation(self):
|
||||||
|
"""履约单释放后重选账号,台账必须清掉首单角色并投影新账号。"""
|
||||||
|
task = self._task_with_account()
|
||||||
|
old_account = self.session.get(Account, task.account_id)
|
||||||
|
old_bind = DouyuTask(
|
||||||
|
batch_id="collab-old-account-bind",
|
||||||
|
account_id=old_account.id,
|
||||||
|
task_type="get_bind_qr",
|
||||||
|
handbook_scope="elite",
|
||||||
|
status="success",
|
||||||
|
result={
|
||||||
|
"role_name": "旧角色",
|
||||||
|
"bind_confirmed": True,
|
||||||
|
"area_name": "微信",
|
||||||
|
"plat_name": "苹果(iOS)",
|
||||||
|
},
|
||||||
|
created_by=self.admin_id,
|
||||||
|
)
|
||||||
|
self.session.add(old_bind)
|
||||||
|
self.session.flush()
|
||||||
|
task.bind_task_id = old_bind.id
|
||||||
|
task.binding_status = "bound"
|
||||||
|
task.execution_status = "bound"
|
||||||
|
self.session.commit()
|
||||||
|
|
||||||
|
order, _ = collab.sync_platform_fulfillment_order(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
task,
|
||||||
|
)
|
||||||
|
assert order.account_id == old_account.id
|
||||||
|
assert order.bind_game_role == "旧角色"
|
||||||
|
|
||||||
|
replacement = self.account("collab-replacement-account")
|
||||||
|
replacement.role_bind_status = "bound"
|
||||||
|
replacement.game_name = "新角色"
|
||||||
|
replacement.game_channel = "手Q · 安卓(android)"
|
||||||
|
task.account_id = replacement.id
|
||||||
|
task.bind_task_id = None
|
||||||
|
task.binding_status = "not_started"
|
||||||
|
task.execution_status = "allocated"
|
||||||
|
self.session.commit()
|
||||||
|
|
||||||
|
reallocated, _ = collab.sync_platform_fulfillment_order(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
task,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert reallocated.account_id == replacement.id
|
||||||
|
assert reallocated.account_username == replacement.username
|
||||||
|
assert reallocated.bind_game_role == ""
|
||||||
|
assert reallocated.bind_game_channel == ""
|
||||||
|
assert reallocated.bind_snapshot_at is None
|
||||||
|
|
||||||
|
new_bind = DouyuTask(
|
||||||
|
batch_id="collab-new-account-bind",
|
||||||
|
account_id=replacement.id,
|
||||||
|
task_type="get_bind_qr",
|
||||||
|
handbook_scope="elite",
|
||||||
|
status="success",
|
||||||
|
result={
|
||||||
|
"role_name": "新角色",
|
||||||
|
"bind_confirmed": True,
|
||||||
|
"area_name": "手Q",
|
||||||
|
"plat_name": "安卓(android)",
|
||||||
|
},
|
||||||
|
created_by=self.admin_id,
|
||||||
|
)
|
||||||
|
self.session.add(new_bind)
|
||||||
|
self.session.flush()
|
||||||
|
task.bind_task_id = new_bind.id
|
||||||
|
task.binding_status = "bound"
|
||||||
|
task.execution_status = "bound"
|
||||||
|
self.session.commit()
|
||||||
|
|
||||||
|
rebound, _ = collab.sync_platform_fulfillment_order(
|
||||||
|
self.session,
|
||||||
|
self.admin,
|
||||||
|
task,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert rebound.account_id == replacement.id
|
||||||
|
assert rebound.bind_game_role == "新角色"
|
||||||
|
assert rebound.bind_game_channel == "手Q / 安卓(android)"
|
||||||
|
assert rebound.bind_snapshot_at is not None
|
||||||
|
|
||||||
def test_manual_sync_does_not_clear_account_added_in_collab(self):
|
def test_manual_sync_does_not_clear_account_added_in_collab(self):
|
||||||
task = self.task()
|
task = self.task()
|
||||||
order, _ = collab.sync_platform_fulfillment_order(
|
order, _ = collab.sync_platform_fulfillment_order(
|
||||||
@@ -3418,75 +3505,6 @@ class TestBindingAndCompletion(_Base):
|
|||||||
assert evidence["actionCurrent"]["roleName"] == "兔稚儿"
|
assert evidence["actionCurrent"]["roleName"] == "兔稚儿"
|
||||||
assert evidence["decisionReason"] == "no_role"
|
assert evidence["decisionReason"] == "no_role"
|
||||||
|
|
||||||
def test_manual_confirm_binding_marks_bound_without_scan(self):
|
|
||||||
task = self._allocated()
|
|
||||||
account = self.session.get(Account, task.account_id)
|
|
||||||
account.game_name = "兔稚儿"
|
|
||||||
account.role_bind_status = "bound"
|
|
||||||
qr_task = DouyuTask(
|
|
||||||
batch_id="manual-confirm-qr",
|
|
||||||
account_id=task.account_id,
|
|
||||||
account_assigned_to=self.admin_id,
|
|
||||||
task_type="get_bind_qr",
|
|
||||||
handbook_scope="elite",
|
|
||||||
status="running",
|
|
||||||
platform_task_id=task.id,
|
|
||||||
result={"bind_phase": "waiting_scan", "bind_polling": True},
|
|
||||||
created_by=self.admin_id,
|
|
||||||
)
|
|
||||||
self.session.add(qr_task)
|
|
||||||
self.session.flush()
|
|
||||||
task.bind_task_id = qr_task.id
|
|
||||||
task.binding_status = "qr_pending"
|
|
||||||
task.execution_status = "waiting_bind"
|
|
||||||
self.session.commit()
|
|
||||||
|
|
||||||
detail = service.manual_confirm_binding_sync(
|
|
||||||
self.session,
|
|
||||||
task_id=task.id,
|
|
||||||
current=self.admin,
|
|
||||||
role_name="兔稚儿",
|
|
||||||
note="客户已在精英宝典完成绑定",
|
|
||||||
)
|
|
||||||
|
|
||||||
self.session.refresh(task)
|
|
||||||
self.session.refresh(qr_task)
|
|
||||||
assert detail["task"]["bindingStatus"] == "bound"
|
|
||||||
assert detail["task"]["executionStatus"] == "bound"
|
|
||||||
assert task.binding_status == "bound"
|
|
||||||
assert task.execution_status == "bound"
|
|
||||||
assert qr_task.status == "success"
|
|
||||||
assert "人工确认绑定" in qr_task.message
|
|
||||||
assert detail["task"]["bindTask"]["roleName"] == "兔稚儿"
|
|
||||||
assert detail["task"]["bindTask"]["bindConfirmed"] is True
|
|
||||||
assert qr_task.result["manual_confirmed"] is True
|
|
||||||
assert qr_task.result["manual_confirmed_role"] == "兔稚儿"
|
|
||||||
assert qr_task.result["role_name"] == "兔稚儿"
|
|
||||||
assert qr_task.result["bind_ready_for_confirm"] is False
|
|
||||||
event = (
|
|
||||||
self.session.query(PlatformFulfillmentEvent)
|
|
||||||
.filter_by(task_id=task.id, event_type="binding_manually_confirmed")
|
|
||||||
.one()
|
|
||||||
)
|
|
||||||
assert event.detail_json["roleName"] == "兔稚儿"
|
|
||||||
assert event.detail_json["note"] == "客户已在精英宝典完成绑定"
|
|
||||||
assert event.detail_json["operatorId"] == self.admin_id
|
|
||||||
|
|
||||||
# 幂等:重复确认不再重复写事件。
|
|
||||||
service.manual_confirm_binding_sync(
|
|
||||||
self.session,
|
|
||||||
task_id=task.id,
|
|
||||||
current=self.admin,
|
|
||||||
role_name="兔稚儿",
|
|
||||||
note="重复确认",
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
self.session.query(PlatformFulfillmentEvent)
|
|
||||||
.filter_by(task_id=task.id, event_type="binding_manually_confirmed")
|
|
||||||
.count()
|
|
||||||
== 1
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_operator_confirm_uses_scanned_role_without_form(self):
|
def test_operator_confirm_uses_scanned_role_without_form(self):
|
||||||
task = self._allocated()
|
task = self._allocated()
|
||||||
account = self.session.get(Account, task.account_id)
|
account = self.session.get(Account, task.account_id)
|
||||||
@@ -3657,50 +3675,6 @@ class TestBindingAndCompletion(_Base):
|
|||||||
assert exc_info.value.status_code == 409
|
assert exc_info.value.status_code == 409
|
||||||
assert "主页截图" in str(exc_info.value.detail)
|
assert "主页截图" in str(exc_info.value.detail)
|
||||||
|
|
||||||
def test_manual_confirm_rejects_role_not_currently_bound(self):
|
|
||||||
task = self._allocated()
|
|
||||||
account = self.session.get(Account, task.account_id)
|
|
||||||
account.game_name = "小乖悄"
|
|
||||||
account.role_bind_status = "bound"
|
|
||||||
qr_task = DouyuTask(
|
|
||||||
batch_id="manual-mismatch-qr",
|
|
||||||
account_id=task.account_id,
|
|
||||||
account_assigned_to=self.admin_id,
|
|
||||||
task_type="get_bind_qr",
|
|
||||||
handbook_scope="elite",
|
|
||||||
status="success",
|
|
||||||
platform_task_id=task.id,
|
|
||||||
result={"bind_phase": "waiting_scan", "role_name": "等清晰"},
|
|
||||||
created_by=self.admin_id,
|
|
||||||
)
|
|
||||||
self.session.add(qr_task)
|
|
||||||
self.session.flush()
|
|
||||||
task.bind_task_id = qr_task.id
|
|
||||||
task.binding_status = "qr_pending"
|
|
||||||
task.execution_status = "waiting_bind"
|
|
||||||
self.session.commit()
|
|
||||||
|
|
||||||
with pytest.raises(HTTPException) as exc_info:
|
|
||||||
service.manual_confirm_binding_sync(
|
|
||||||
self.session,
|
|
||||||
task_id=task.id,
|
|
||||||
current=self.admin,
|
|
||||||
role_name="等清晰",
|
|
||||||
note="客户说角色是等清晰",
|
|
||||||
)
|
|
||||||
|
|
||||||
self.session.refresh(task)
|
|
||||||
assert exc_info.value.status_code == 409
|
|
||||||
assert "不一致" in str(exc_info.value.detail)
|
|
||||||
assert task.binding_status == "qr_pending"
|
|
||||||
assert task.execution_status == "waiting_bind"
|
|
||||||
assert (
|
|
||||||
self.session.query(PlatformFulfillmentEvent)
|
|
||||||
.filter_by(task_id=task.id, event_type="binding_manually_confirmed")
|
|
||||||
.count()
|
|
||||||
== 0
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_cjm_only_transient_role_waits_for_action_alias_sync(self):
|
def test_cjm_only_transient_role_waits_for_action_alias_sync(self):
|
||||||
task = self._allocated()
|
task = self._allocated()
|
||||||
qr_task = DouyuTask(
|
qr_task = DouyuTask(
|
||||||
|
|||||||
@@ -381,7 +381,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "live-hub-py"
|
name = "live-hub-py"
|
||||||
version = "0.4.3"
|
version = "0.4.5"
|
||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "alembic" },
|
{ name = "alembic" },
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from ..schemas import (
|
|||||||
PlatformFulfillmentCollabSyncRequest,
|
PlatformFulfillmentCollabSyncRequest,
|
||||||
PlatformFulfillmentCompleteRequest,
|
PlatformFulfillmentCompleteRequest,
|
||||||
PlatformFulfillmentCustomerProfileUpdate,
|
PlatformFulfillmentCustomerProfileUpdate,
|
||||||
PlatformFulfillmentManualBindingRequest,
|
|
||||||
PlatformFulfillmentMappingUpsert,
|
PlatformFulfillmentMappingUpsert,
|
||||||
PlatformFulfillmentMappingWrite,
|
PlatformFulfillmentMappingWrite,
|
||||||
PlatformFulfillmentReasonRequest,
|
PlatformFulfillmentReasonRequest,
|
||||||
@@ -494,37 +493,6 @@ def operator_confirm_binding(
|
|||||||
return result
|
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")
|
@router.patch("/tasks/{task_id}/customer-profile")
|
||||||
def update_customer_profile(
|
def update_customer_profile(
|
||||||
task_id: int,
|
task_id: int,
|
||||||
|
|||||||
@@ -1778,11 +1778,6 @@ class PlatformFulfillmentCompleteRequest(BaseModel):
|
|||||||
note: str = Field(default="", max_length=1000)
|
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):
|
class PlatformFulfillmentCustomerProfileUpdate(BaseModel):
|
||||||
customer_role_name: str = Field(..., min_length=1, max_length=128)
|
customer_role_name: str = Field(..., min_length=1, max_length=128)
|
||||||
customer_platform: str = Field(..., pattern="^(wechat|qq)$")
|
customer_platform: str = Field(..., pattern="^(wechat|qq)$")
|
||||||
|
|||||||
@@ -223,6 +223,10 @@ def sync_platform_fulfillment_order(
|
|||||||
)
|
)
|
||||||
order = order_by_no
|
order = order_by_no
|
||||||
created = False
|
created = False
|
||||||
|
was_platform_projection = (
|
||||||
|
order is not None
|
||||||
|
and order.source_type == SOURCE_TYPE_PLATFORM_FULFILLMENT
|
||||||
|
)
|
||||||
|
|
||||||
now = _now()
|
now = _now()
|
||||||
account = (
|
account = (
|
||||||
@@ -232,6 +236,11 @@ def sync_platform_fulfillment_order(
|
|||||||
)
|
)
|
||||||
gift_name, commodity_id, required_points = _platform_fulfillment_gift(db, task)
|
gift_name, commodity_id, required_points = _platform_fulfillment_gift(db, task)
|
||||||
home_images = _platform_fulfillment_home_images(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:
|
if order is None:
|
||||||
order = DouyuExternalOrder(
|
order = DouyuExternalOrder(
|
||||||
@@ -266,17 +275,30 @@ def sync_platform_fulfillment_order(
|
|||||||
if home_images:
|
if home_images:
|
||||||
order.home_images = home_images
|
order.home_images = home_images
|
||||||
if account is not None and (
|
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_id = int(account.id)
|
||||||
order.account_username = _text(account.username, max_length=128)
|
order.account_username = _text(account.username, max_length=128)
|
||||||
order.account_uid = _text(account.uid, max_length=32)
|
order.account_uid = _text(account.uid, max_length=32)
|
||||||
order.account_nickname = _text(account.nickname, max_length=128)
|
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(
|
_apply_platform_fulfillment_binding(
|
||||||
db,
|
db,
|
||||||
order,
|
order,
|
||||||
task,
|
task,
|
||||||
overwrite=created,
|
overwrite=created or was_platform_projection,
|
||||||
)
|
)
|
||||||
_apply_platform_fulfillment_status(order, task, created=created)
|
_apply_platform_fulfillment_status(order, task, created=created)
|
||||||
order.version = int(order.version or 0) + 1
|
order.version = int(order.version or 0) + 1
|
||||||
|
|||||||
@@ -914,7 +914,7 @@ def operator_confirm_binding_sync(
|
|||||||
"""普通人工代确认:客户已扫码但没点确认,运营代为提交正常 actBind。
|
"""普通人工代确认:客户已扫码但没点确认,运营代为提交正常 actBind。
|
||||||
|
|
||||||
不填写角色/备注,不直接标 bound;复用客户确认的同一套确认任务。
|
不填写角色/备注,不直接标 bound;复用客户确认的同一套确认任务。
|
||||||
当前没有可确认的扫码角色时,要求客户扫码或走“强制确认”。
|
当前没有可确认的扫码角色时,要求客户重新扫码。
|
||||||
"""
|
"""
|
||||||
task = _load_task_for_update(db, task_id)
|
task = _load_task_for_update(db, task_id)
|
||||||
if _frozen(task):
|
if _frozen(task):
|
||||||
@@ -926,137 +926,11 @@ def operator_confirm_binding_sync(
|
|||||||
if task.binding_status != "role_ready":
|
if task.binding_status != "role_ready":
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=409,
|
status_code=409,
|
||||||
detail=(
|
detail="当前没有可代确认的扫码角色,请让客户先扫码。",
|
||||||
"当前没有可代确认的扫码角色。请让客户先扫码;"
|
|
||||||
"只有账号已绑定到该角色、但缺少本次扫码证据时,才使用强制确认。"
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
return confirm_binding_sync(db, task_id=task.id, current=current)
|
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(
|
def _apply_binding_task(
|
||||||
db: Session,
|
db: Session,
|
||||||
task: PlatformFulfillmentTask,
|
task: PlatformFulfillmentTask,
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ from .binding import ( # noqa: F401
|
|||||||
confirm_binding,
|
confirm_binding,
|
||||||
confirm_binding_sync,
|
confirm_binding_sync,
|
||||||
ensure_customer_profile_for_binding,
|
ensure_customer_profile_for_binding,
|
||||||
manual_confirm_binding_sync,
|
|
||||||
operator_confirm_binding_sync,
|
operator_confirm_binding_sync,
|
||||||
reconcile_binding_observations,
|
reconcile_binding_observations,
|
||||||
reconcile_binding_state_outbox,
|
reconcile_binding_state_outbox,
|
||||||
@@ -160,7 +159,6 @@ __all__ = [
|
|||||||
"get_task_detail",
|
"get_task_detail",
|
||||||
"list_mappings",
|
"list_mappings",
|
||||||
"list_tasks",
|
"list_tasks",
|
||||||
"manual_confirm_binding_sync",
|
|
||||||
"mapping_impact",
|
"mapping_impact",
|
||||||
"mark_manual_required",
|
"mark_manual_required",
|
||||||
"operator_confirm_binding_sync",
|
"operator_confirm_binding_sync",
|
||||||
|
|||||||
@@ -142,11 +142,6 @@ export const platformFulfillmentApi = {
|
|||||||
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
||||||
`/platform-fulfillment/tasks/${taskId}/bind/operator-confirm`,
|
`/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) =>
|
verifyBinding: (taskId: number) =>
|
||||||
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
api.post<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
||||||
`/platform-fulfillment/tasks/${taskId}/bind/verify`,
|
`/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;
|
if (!task.account) return false;
|
||||||
return !['bound', 'completed', 'cancelled'].includes(task.executionStatus);
|
return !['bound', 'completed', 'cancelled'].includes(task.executionStatus);
|
||||||
}
|
}
|
||||||
@@ -535,10 +535,6 @@ export default function PlatformFulfillmentPage() {
|
|||||||
const [manualReleaseTarget, setManualReleaseTarget] = useState<PlatformFulfillmentTask | null>(null);
|
const [manualReleaseTarget, setManualReleaseTarget] = useState<PlatformFulfillmentTask | null>(null);
|
||||||
const [manualReleaseReason, setManualReleaseReason] = useState('');
|
const [manualReleaseReason, setManualReleaseReason] = useState('');
|
||||||
const [manualReleasing, setManualReleasing] = useState(false);
|
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 [profileEditTarget, setProfileEditTarget] = useState<PlatformFulfillmentTask | null>(null);
|
||||||
const [profileEditRole, setProfileEditRole] = useState('');
|
const [profileEditRole, setProfileEditRole] = useState('');
|
||||||
const [profileEditPlatform, setProfileEditPlatform] = useState<'wechat' | 'qq'>('wechat');
|
const [profileEditPlatform, setProfileEditPlatform] = useState<'wechat' | 'qq'>('wechat');
|
||||||
@@ -546,13 +542,6 @@ export default function PlatformFulfillmentPage() {
|
|||||||
const [profileEditReopen, setProfileEditReopen] = useState(true);
|
const [profileEditReopen, setProfileEditReopen] = useState(true);
|
||||||
const [profileEditSaving, setProfileEditSaving] = useState(false);
|
const [profileEditSaving, setProfileEditSaving] = useState(false);
|
||||||
const [verifyingBinding, setVerifyingBinding] = 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 [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||||
const [selectedId, setSelectedId] = useState<number | null>(null);
|
const [selectedId, setSelectedId] = useState<number | null>(null);
|
||||||
const [detail, setDetail] = useState<PlatformFulfillmentDetail | 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) => {
|
const submitOperatorConfirm = async (task: PlatformFulfillmentTask) => {
|
||||||
try {
|
try {
|
||||||
const result = await platformFulfillmentApi.operatorConfirmBinding(task.id);
|
const result = await platformFulfillmentApi.operatorConfirmBinding(task.id);
|
||||||
@@ -1681,16 +1627,11 @@ export default function PlatformFulfillmentPage() {
|
|||||||
代客户确认
|
代客户确认
|
||||||
</Button>
|
</Button>
|
||||||
) : null}
|
) : 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 size="small" type="primary" icon={<CheckCircleOutlined />} onClick={() => void submitOperatorConfirm(task)}>
|
||||||
代客户确认
|
代客户确认
|
||||||
</Button>
|
</Button>
|
||||||
) : null}
|
) : null}
|
||||||
{can('platform_fulfillment:use') && canManualConfirmBinding(task) ? (
|
|
||||||
<Button size="small" danger icon={<CheckCircleOutlined />} onClick={() => openManualBinding(task)}>
|
|
||||||
强制确认
|
|
||||||
</Button>
|
|
||||||
) : null}
|
|
||||||
{canResetBinding(task) ? (
|
{canResetBinding(task) ? (
|
||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
@@ -1770,11 +1711,6 @@ export default function PlatformFulfillmentPage() {
|
|||||||
代客户确认
|
代客户确认
|
||||||
</Button>
|
</Button>
|
||||||
) : null}
|
) : null}
|
||||||
{selected && can('platform_fulfillment:use') && canManualConfirmBinding(selected) ? (
|
|
||||||
<Button danger icon={<CheckCircleOutlined />} onClick={() => openManualBinding(selected)}>
|
|
||||||
强制确认
|
|
||||||
</Button>
|
|
||||||
) : null}
|
|
||||||
{selected &&
|
{selected &&
|
||||||
selected.account &&
|
selected.account &&
|
||||||
selected.bindingStatus === 'bound' &&
|
selected.bindingStatus === 'bound' &&
|
||||||
@@ -2690,68 +2626,6 @@ export default function PlatformFulfillmentPage() {
|
|||||||
</Space>
|
</Space>
|
||||||
</Modal>
|
</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
|
<Modal
|
||||||
title={`修改用户资料 ${profileEditTarget ? `#${profileEditTarget.id}` : ''}`}
|
title={`修改用户资料 ${profileEditTarget ? `#${profileEditTarget.id}` : ''}`}
|
||||||
open={Boolean(profileEditTarget)}
|
open={Boolean(profileEditTarget)}
|
||||||
|
|||||||
Reference in New Issue
Block a user