feat(fulfillment): 支持选号优先级、三皮肤联合资格捆绑与同角色共享租约

This commit is contained in:
yml
2026-11-28 11:26:24 +08:00
parent ef226c9041
commit 20314a2f1d
24 changed files with 2504 additions and 495 deletions
@@ -360,9 +360,7 @@ def test_schedule_retry_preserves_longer_capability_retry(db):
def test_auto_allocator_ignores_legacy_tasks(db):
actor = User(
username="auto-legacy-actor", password_hash="h", role="super_admin"
)
actor = User(username="auto-legacy-actor", password_hash="h", role="super_admin")
db.add_all(
[
actor,
@@ -398,3 +396,98 @@ def test_auto_allocator_ignores_legacy_tasks(db):
result = auto_allocator.run_auto_allocation_once(db, limit=10)
assert result == {"checked": 0, "allocated": 0, "failed": 0}
def test_start_allocated_bindings_skips_shared_lease_sibling_when_active_bind_exists(
db,
):
actor = User(username="auto-shared-actor", password_hash="h", role="super_admin")
moment = datetime.now(UTC).replace(microsecond=0)
db.add_all(
[
actor,
PlatformFulfillmentSetting(
id=1,
lease_duration_minutes=None,
order_match_started_at=moment - timedelta(days=1),
),
]
)
db.flush()
from web.backend.models import Account, AccountLease
acc = Account(
username="shared-bind-acc",
password="p",
email="shared-bind@example.com",
email_password="ep",
status="active",
ck_check_status="valid",
cookie="PHPSESSID=x",
elite_opened=True,
points=8000,
)
db.add(acc)
db.flush()
lease = AccountLease(
account_id=acc.id,
holder_user_id=actor.id,
scope="elite",
purpose="platform_fulfillment",
batch_id="pf:shared-1",
status="active",
)
db.add(lease)
db.flush()
first = PlatformFulfillmentTask(
source_system="order_site",
source_order_id="shared-1",
source_order_item_id="shared-1",
platform_order_id="SHARED-1",
internal_sku_key="skin-1",
commodity_id="cid-1",
account_id=acc.id,
lease_id=lease.id,
execution_status="waiting_bind",
binding_status="qr_pending",
exchange_status="not_started",
paid_at=moment,
updated_at=moment,
)
sibling = PlatformFulfillmentTask(
source_system="order_site",
source_order_id="shared-2",
source_order_item_id="shared-2",
platform_order_id="SHARED-2",
internal_sku_key="skin-2",
commodity_id="cid-2",
account_id=acc.id,
lease_id=lease.id,
execution_status="allocated",
binding_status="not_started",
exchange_status="not_started",
paid_at=moment,
updated_at=moment,
)
db.add_all([first, sibling])
db.commit()
called_ids: list[int] = []
async def _fake_start_binding(_db, *, task_id: int, current):
called_ids.append(task_id)
with (
patch.object(auto_allocator.service, "_integration_actor", return_value=actor),
patch.object(
auto_allocator.service,
"start_binding",
side_effect=_fake_start_binding,
),
):
result = auto_allocator.start_allocated_bindings_once(db, limit=10)
assert called_ids == []
assert result == 0