fix(fulfillment): 支持先分配后补角色或撞锁时的同角色自动合并改挂
This commit is contained in:
@@ -6929,3 +6929,215 @@ class TestAllocationPolicyAndSameRoleReuse(_Base):
|
||||
self.session.commit()
|
||||
detail = service.get_task_detail(self.session, task.id)
|
||||
assert detail["task"]["manualReason"] == issue
|
||||
|
||||
def test_late_customer_profile_merges_preallocated_sibling_and_releases_old_lease(
|
||||
self,
|
||||
):
|
||||
acc1 = self.account("late-merge-1", points=24000, capability=False)
|
||||
acc2 = self.account("late-merge-2", points=24000, capability=False)
|
||||
for acc in (acc1, acc2):
|
||||
for cid in (TRIO_BAG412, TRIO_BAG413, TRIO_BAG414):
|
||||
self._add_commodity_state(acc, cid, eligibility="eligible")
|
||||
self.session.commit()
|
||||
|
||||
# 先连下两单且当时均未填客户角色名,auto_allocator 分别预分配不同账号
|
||||
t1 = self._create_commodity_task(
|
||||
commodity_id=TRIO_BAG413,
|
||||
order_suffix="late-1",
|
||||
role_name="",
|
||||
)
|
||||
t2 = self._create_commodity_task(
|
||||
commodity_id=TRIO_BAG414,
|
||||
order_suffix="late-2",
|
||||
role_name="",
|
||||
)
|
||||
d1 = service.allocate_task(self.session, task_id=t1.id, current=self.admin)
|
||||
d2 = service.allocate_task(self.session, task_id=t2.id, current=self.admin)
|
||||
assert d1["task"]["account"]["id"] != d2["task"]["account"]["id"]
|
||||
old_t2_lease_id = d2["task"]["lease"]["id"]
|
||||
|
||||
# 买家随后补交同一角色名:第二单自动释放空号并合并共享第一单的账号与租约
|
||||
service.save_customer_profile(
|
||||
self.session,
|
||||
task_id=t1.id,
|
||||
customer_role_name="迟填多单老板",
|
||||
platform="wechat",
|
||||
system="android",
|
||||
home_images=[{"url": "https://example.com/late-1.png"}],
|
||||
)
|
||||
service.save_customer_profile(
|
||||
self.session,
|
||||
task_id=t2.id,
|
||||
customer_role_name="迟填多单老板",
|
||||
platform="wechat",
|
||||
system="android",
|
||||
home_images=[{"url": "https://example.com/late-2.png"}],
|
||||
)
|
||||
|
||||
self.session.refresh(t1)
|
||||
self.session.refresh(t2)
|
||||
old_lease = self.session.get(AccountLease, old_t2_lease_id)
|
||||
assert t2.account_id == t1.account_id
|
||||
assert t2.lease_id == t1.lease_id
|
||||
assert old_lease.status == "released"
|
||||
|
||||
def test_sibling_bound_and_role_lock_redirect_merges_preallocated_orders_to_bound(
|
||||
self,
|
||||
):
|
||||
acc1 = self.account("merge-bound-1", points=24000, capability=False)
|
||||
acc2 = self.account("merge-bound-2", points=24000, capability=False)
|
||||
acc3 = self.account("merge-bound-3", points=24000, capability=False)
|
||||
for acc in (acc1, acc2, acc3):
|
||||
for cid in (TRIO_BAG412, TRIO_BAG413, TRIO_BAG414):
|
||||
self._add_commodity_state(acc, cid, eligibility="eligible")
|
||||
self.session.commit()
|
||||
|
||||
t1 = self._create_commodity_task(
|
||||
commodity_id=TRIO_BAG413,
|
||||
order_suffix="merge-1",
|
||||
role_name="小李腰不准",
|
||||
)
|
||||
t2 = self._create_commodity_task(
|
||||
commodity_id=TRIO_BAG414,
|
||||
order_suffix="merge-2",
|
||||
role_name="",
|
||||
)
|
||||
t3 = self._create_commodity_task(
|
||||
commodity_id=TRIO_BAG412,
|
||||
order_suffix="merge-3",
|
||||
role_name="",
|
||||
)
|
||||
# 确保三单初始各拿不同账号,且 t2 已填好角色但尚未完成扫码(qr_pending)
|
||||
d1 = service.allocate_task(self.session, task_id=t1.id, current=self.admin)
|
||||
d2 = service.allocate_task(self.session, task_id=t2.id, current=self.admin)
|
||||
d3 = service.allocate_task(self.session, task_id=t3.id, current=self.admin)
|
||||
assert (
|
||||
len(
|
||||
{
|
||||
d1["task"]["account"]["id"],
|
||||
d2["task"]["account"]["id"],
|
||||
d3["task"]["account"]["id"],
|
||||
}
|
||||
)
|
||||
== 3
|
||||
)
|
||||
|
||||
t2_old_qr = DouyuTask(
|
||||
batch_id="t2-old-qr",
|
||||
account_id=d2["task"]["account"]["id"],
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="running",
|
||||
platform_task_id=t2.id,
|
||||
result={"url": "https://example.test/old-qr", "bind_phase": "qr_pending"},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(t2_old_qr)
|
||||
self.session.flush()
|
||||
t2.customer_role_name = "小李腰不准"
|
||||
t2.bind_task_id = t2_old_qr.id
|
||||
t2.binding_status = "qr_pending"
|
||||
t2.execution_status = "waiting_bind"
|
||||
self.session.commit()
|
||||
|
||||
# 场景 A:主单 t1 确认绑定 -> 跨账号的未绑定兄弟单 t2 自动停旧码、释放旧租约并合并为 bound
|
||||
confirm_t1 = DouyuTask(
|
||||
batch_id="t1-confirm",
|
||||
account_id=d1["task"]["account"]["id"],
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="confirm_bind",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
platform_task_id=t1.id,
|
||||
result={
|
||||
"role_name": "小李腰不准",
|
||||
"area_name": "微信",
|
||||
"plat_name": "安卓",
|
||||
"is_bound_act": True,
|
||||
"bind_confirmed": True,
|
||||
"bind_phase": "confirmed",
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(confirm_t1)
|
||||
self.session.flush()
|
||||
t1.bind_task_id = confirm_t1.id
|
||||
t1.binding_status = "role_ready"
|
||||
t1.execution_status = "role_ready"
|
||||
self.session.commit()
|
||||
|
||||
service.sync_task_from_binding_runner(self.session, douyu_task_id=confirm_t1.id)
|
||||
self.session.refresh(t1)
|
||||
self.session.refresh(t2)
|
||||
self.session.refresh(t2_old_qr)
|
||||
assert t2.account_id == t1.account_id
|
||||
assert t2.lease_id == t1.lease_id
|
||||
assert t2.binding_status == "bound"
|
||||
assert t2.execution_status == "bound"
|
||||
assert t2_old_qr.status == "stopped"
|
||||
|
||||
# 场景 B:t3 连客户资料角色都没预先匹配,直接扫码扫出「小李腰不准」撞 7 天锁 ->
|
||||
# 不应转 manual_required,而是直接改挂合并到 acc1 并标 bound
|
||||
acc1_row = self.session.get(Account, t1.account_id)
|
||||
acc1_row.role_bind_status = "bound"
|
||||
acc1_row.game_name = "小李腰不准"
|
||||
self.session.add(
|
||||
AccountEvent(
|
||||
account_id=acc1_row.id,
|
||||
event_type="bind_ok",
|
||||
category="account",
|
||||
title="绑定成功",
|
||||
subject_type="elite_role",
|
||||
subject_key="小李腰不准",
|
||||
source="test",
|
||||
actor_type="system",
|
||||
occurred_at=NOW,
|
||||
)
|
||||
)
|
||||
t3_old_acc = d3["task"]["account"]["id"]
|
||||
t3_old_lease_id = d3["task"]["lease"]["id"]
|
||||
t3_qr = DouyuTask(
|
||||
batch_id="t3-scan-locked-role",
|
||||
account_id=t3_old_acc,
|
||||
account_assigned_to=self.admin_id,
|
||||
task_type="get_bind_qr",
|
||||
handbook_scope="elite",
|
||||
status="success",
|
||||
platform_task_id=t3.id,
|
||||
result={
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "小李腰不准",
|
||||
"current_role_name": "小李腰不准",
|
||||
"baseline_role_name": "旧角色",
|
||||
"before_bind_info": {
|
||||
"act_alias": "20260120QYOOB",
|
||||
"role_name": "旧角色",
|
||||
"is_bound_act": True,
|
||||
"need_bind_act": True,
|
||||
},
|
||||
"area_name": "微信",
|
||||
"plat_name": "安卓",
|
||||
"is_bound_act": False,
|
||||
"bind_ready_for_confirm": True,
|
||||
"bind_confirmed": False,
|
||||
"bind_phase": "role_ready",
|
||||
},
|
||||
created_by=self.admin_id,
|
||||
)
|
||||
self.session.add(t3_qr)
|
||||
self.session.flush()
|
||||
t3.bind_task_id = t3_qr.id
|
||||
t3.binding_status = "qr_pending"
|
||||
t3.execution_status = "waiting_bind"
|
||||
self.session.commit()
|
||||
|
||||
service.sync_task_from_binding_runner(self.session, douyu_task_id=t3_qr.id)
|
||||
self.session.refresh(t3)
|
||||
t3_old_lease = self.session.get(AccountLease, t3_old_lease_id)
|
||||
assert t3.account_id == t1.account_id
|
||||
assert t3.lease_id == t1.lease_id
|
||||
assert t3.binding_status == "bound"
|
||||
assert t3.execution_status == "bound"
|
||||
assert t3.issue_code != "customer_role_bound_elsewhere"
|
||||
assert t3_old_lease.status == "released"
|
||||
|
||||
Reference in New Issue
Block a user