feat(履约绑定): 支持工作台修改客户资料、扫码不匹配时间线及确认后斗鱼复核
This commit is contained in:
@@ -5896,3 +5896,267 @@ class TestBindingAndCompletion(_Base):
|
||||
.count()
|
||||
== 1
|
||||
)
|
||||
|
||||
def test_operator_update_customer_profile_reopens_failed_and_syncs_pending(self):
|
||||
"""工作台修改客户资料:可修正名字/区服/系统并重置失败态,也会同步当前绑定任务与 Outbox。"""
|
||||
task = self._allocated()
|
||||
self.complete_customer_profile(task)
|
||||
task.customer_role_name = "妎䏓"
|
||||
task.customer_platform = "qq"
|
||||
task.customer_system = "ios"
|
||||
qr_task = DouyuTask(
|
||||
batch_id="edit-profile-failed",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="failed",
|
||||
platform_task_id=task.id,
|
||||
message="绑定二维码已过期:期间扫到「妎朊」,与填写角色「妎䏓」不一致",
|
||||
result={"expected_role_name": "妎䏓", "expected_role_required": True},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(qr_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = qr_task.id
|
||||
task.binding_status = "failed"
|
||||
task.execution_status = "manual_required"
|
||||
task.issue_code = "binding_failed"
|
||||
task.last_error = "已扫到角色「妎朊」,与下单填写的「妎䏓」不一致"
|
||||
self.session.commit()
|
||||
|
||||
detail = service.update_customer_profile_by_operator(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
customer_role_name="妎朊",
|
||||
platform="qq",
|
||||
system="ios",
|
||||
reopen_binding=True,
|
||||
)
|
||||
|
||||
self.session.refresh(task)
|
||||
assert task.customer_role_name == "妎朊"
|
||||
assert task.binding_status == "not_started"
|
||||
assert task.execution_status == "allocated"
|
||||
assert task.bind_task_id is None
|
||||
assert task.issue_code == ""
|
||||
assert task.last_error == ""
|
||||
assert detail["task"]["customerProfile"]["roleName"] == "妎朊"
|
||||
updated_events = (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="customer_profile_updated")
|
||||
.all()
|
||||
)
|
||||
assert len(updated_events) == 1
|
||||
assert updated_events[0].detail_json["previousRoleName"] == "妎䏓"
|
||||
assert updated_events[0].detail_json["customerRoleName"] == "妎朊"
|
||||
assert updated_events[0].detail_json["reopenedBinding"] is True
|
||||
|
||||
# 已绑定订单不允许直接修改资料
|
||||
task.binding_status = "bound"
|
||||
task.execution_status = "bound"
|
||||
self.session.commit()
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
service.update_customer_profile_by_operator(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
customer_role_name="新角色",
|
||||
platform="wechat",
|
||||
system="android",
|
||||
)
|
||||
assert exc.value.status_code == 409
|
||||
|
||||
def test_mismatched_scanned_role_is_recorded_in_timeline_and_evidence(self):
|
||||
"""扫码扫到与下单填写不一致的角色时,应写入时间线并在失败提示/证据中透出。"""
|
||||
task = self._allocated()
|
||||
self.complete_customer_profile(task)
|
||||
task.customer_role_name = "妎䏓"
|
||||
qr_task = DouyuTask(
|
||||
batch_id="mismatch-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={
|
||||
"url": "https://livelink.example/qr",
|
||||
"expected_role_name": "妎䏓",
|
||||
"expected_role_required": True,
|
||||
"last_mismatched_role": {
|
||||
"act_alias": "cjm",
|
||||
"role_name": "妎朊",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "苹果(iOS)",
|
||||
"expected_role_name": "妎䏓",
|
||||
"observed_at": NOW.isoformat(),
|
||||
},
|
||||
"mismatched_roles": [
|
||||
{
|
||||
"act_alias": "cjm",
|
||||
"role_name": "妎朊",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "苹果(iOS)",
|
||||
"expected_role_name": "妎䏓",
|
||||
"observed_at": NOW.isoformat(),
|
||||
}
|
||||
],
|
||||
},
|
||||
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()
|
||||
|
||||
# 轮询期间记录一次不匹配事件(重复同步应去重)
|
||||
service.sync_task_from_binding_runner(self.session, douyu_task_id=qr_task.id)
|
||||
service.sync_task_from_binding_runner(self.session, douyu_task_id=qr_task.id)
|
||||
mismatch_events = (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="binding_scanned_role_mismatch")
|
||||
.all()
|
||||
)
|
||||
assert len(mismatch_events) == 1
|
||||
assert mismatch_events[0].detail_json["scannedRoleName"] == "妎朊"
|
||||
assert mismatch_events[0].detail_json["expectedRoleName"] == "妎䏓"
|
||||
|
||||
detail = service.get_task_detail(self.session, task.id)
|
||||
assert detail["task"]["bindingEvidence"]["scannedRole"] == ""
|
||||
assert detail["task"]["bindingEvidence"]["mismatchedRole"]["roleName"] == "妎朊"
|
||||
|
||||
# 超时失败时明确提示曾扫到的不匹配角色
|
||||
qr_task.status = "failed"
|
||||
qr_task.message = "绑定二维码已过期:期间扫到「妎朊」,与填写角色「妎䏓」不一致"
|
||||
self.session.commit()
|
||||
service.sync_task_from_binding_runner(self.session, douyu_task_id=qr_task.id)
|
||||
self.session.refresh(task)
|
||||
assert task.binding_status == "failed"
|
||||
assert "妎朊" in task.last_error
|
||||
assert "妎䏓" in task.last_error
|
||||
|
||||
def test_verify_task_binding_records_success_and_reverts_mismatch(self, monkeypatch):
|
||||
"""确认绑定后复核斗鱼:一致时记复核通过;斗鱼未绑定或角色不一致时回退转人工。"""
|
||||
from web.backend.services.platform_fulfillment import binding as pf_binding
|
||||
|
||||
task = self._allocated()
|
||||
self.complete_customer_profile(task)
|
||||
task.customer_role_name = "越伤痛"
|
||||
confirm_task = DouyuTask(
|
||||
batch_id="verify-confirm",
|
||||
account_id=task.account_id,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="confirm_bind",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
platform_task_id=task.id,
|
||||
result={"role_name": "越伤痛", "bind_confirmed": True},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(confirm_task)
|
||||
self.session.flush()
|
||||
task.bind_task_id = confirm_task.id
|
||||
task.binding_status = "bound"
|
||||
task.execution_status = "bound"
|
||||
self.session.commit()
|
||||
|
||||
monkeypatch.setattr(pf_binding, "activity_client", lambda *_a, **_kw: object())
|
||||
monkeypatch.setattr(
|
||||
pf_binding,
|
||||
"resolve_elite_role",
|
||||
lambda _client, _cfg: {
|
||||
"status": "bound",
|
||||
"role_name": "越伤痛",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "安卓(android)",
|
||||
"game_channel": "手Q / 安卓(android)",
|
||||
"source_alias": "20260120QYOOB",
|
||||
"bind_info": {
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "越伤痛",
|
||||
"is_bound_act": True,
|
||||
"is_bound_role": True,
|
||||
},
|
||||
"bind_infos": [
|
||||
{
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "越伤痛",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "安卓(android)",
|
||||
"is_bound_act": True,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": True,
|
||||
"need_bind_role": True,
|
||||
}
|
||||
],
|
||||
"errors": [],
|
||||
},
|
||||
)
|
||||
|
||||
detail = service.verify_task_binding_sync(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
automatic=True,
|
||||
)
|
||||
self.session.refresh(task)
|
||||
assert task.binding_status == "bound"
|
||||
assert detail["events"][0]["eventType"] == "binding_verified"
|
||||
assert (
|
||||
self.session.query(DouyuRoleApiLog)
|
||||
.filter_by(account_id=task.account_id, stage="fulfillment.verify_binding")
|
||||
.count()
|
||||
== 1
|
||||
)
|
||||
|
||||
# 若复核发现斗鱼当前其实绑在别的旧角色上,应回退为人工处理
|
||||
monkeypatch.setattr(
|
||||
pf_binding,
|
||||
"resolve_elite_role",
|
||||
lambda _client, _cfg: {
|
||||
"status": "bound",
|
||||
"role_name": "清耆白清万入识",
|
||||
"area_name": "手Q",
|
||||
"plat_name": "安卓(android)",
|
||||
"game_channel": "手Q / 安卓(android)",
|
||||
"source_alias": "20260120QYOOB",
|
||||
"bind_info": {
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "清耆白清万入识",
|
||||
"is_bound_act": True,
|
||||
"is_bound_role": True,
|
||||
},
|
||||
"bind_infos": [
|
||||
{
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "清耆白清万入识",
|
||||
"is_bound_act": True,
|
||||
"is_bound_role": True,
|
||||
"need_bind_act": True,
|
||||
"need_bind_role": True,
|
||||
}
|
||||
],
|
||||
"errors": [],
|
||||
},
|
||||
)
|
||||
service.verify_task_binding_sync(
|
||||
self.session,
|
||||
task_id=task.id,
|
||||
current=self.admin,
|
||||
automatic=False,
|
||||
)
|
||||
self.session.refresh(task)
|
||||
assert task.binding_status == "failed"
|
||||
assert task.execution_status == "manual_required"
|
||||
assert task.issue_code == "role_changed"
|
||||
assert "清耆白清万入识" in task.last_error
|
||||
assert (
|
||||
self.session.query(PlatformFulfillmentEvent)
|
||||
.filter_by(task_id=task.id, event_type="binding_verify_failed")
|
||||
.count()
|
||||
== 1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user