feat(fulfillment): 支持选号优先级、三皮肤联合资格捆绑与同角色共享租约
This commit is contained in:
@@ -65,6 +65,7 @@ class _TaskOutputContext:
|
||||
leases: dict[int, AccountLease]
|
||||
bind_tasks: dict[int, DouyuTask]
|
||||
collab_orders: dict[int, DouyuExternalOrder]
|
||||
shared_lease_tasks: dict[int, list[int]]
|
||||
|
||||
|
||||
def invalidate_task_list_count_cache() -> None:
|
||||
@@ -124,15 +125,9 @@ def _load_task_output_context(
|
||||
tasks: list[PlatformFulfillmentTask],
|
||||
) -> _TaskOutputContext:
|
||||
mapping_ids = {
|
||||
int(task.commodity_mapping_id)
|
||||
for task in tasks
|
||||
if task.commodity_mapping_id
|
||||
}
|
||||
commodity_ids = {
|
||||
str(task.commodity_id)
|
||||
for task in tasks
|
||||
if task.commodity_id
|
||||
int(task.commodity_mapping_id) for task in tasks if task.commodity_mapping_id
|
||||
}
|
||||
commodity_ids = {str(task.commodity_id) for task in tasks if task.commodity_id}
|
||||
account_ids = {int(task.account_id) for task in tasks if task.account_id}
|
||||
lease_ids = {int(task.lease_id) for task in tasks if task.lease_id}
|
||||
bind_task_ids = {int(task.bind_task_id) for task in tasks if task.bind_task_id}
|
||||
@@ -178,9 +173,7 @@ def _load_task_output_context(
|
||||
bind_tasks = (
|
||||
{
|
||||
int(row.id): row
|
||||
for row in db.query(DouyuTask)
|
||||
.filter(DouyuTask.id.in_(bind_task_ids))
|
||||
.all()
|
||||
for row in db.query(DouyuTask).filter(DouyuTask.id.in_(bind_task_ids)).all()
|
||||
}
|
||||
if bind_task_ids
|
||||
else {}
|
||||
@@ -195,6 +188,22 @@ def _load_task_output_context(
|
||||
):
|
||||
if row.source_task_id is not None:
|
||||
collab_orders.setdefault(int(row.source_task_id), row)
|
||||
shared_lease_tasks: dict[int, list[int]] = {}
|
||||
if lease_ids:
|
||||
for row_id, row_lease_id in (
|
||||
db.query(
|
||||
PlatformFulfillmentTask.id,
|
||||
PlatformFulfillmentTask.lease_id,
|
||||
)
|
||||
.filter(
|
||||
PlatformFulfillmentTask.lease_id.in_(lease_ids),
|
||||
PlatformFulfillmentTask.execution_status != "cancelled",
|
||||
)
|
||||
.order_by(PlatformFulfillmentTask.id.asc())
|
||||
.all()
|
||||
):
|
||||
if row_lease_id is not None:
|
||||
shared_lease_tasks.setdefault(int(row_lease_id), []).append(int(row_id))
|
||||
return _TaskOutputContext(
|
||||
mappings=mappings,
|
||||
goods=goods,
|
||||
@@ -202,6 +211,7 @@ def _load_task_output_context(
|
||||
leases=leases,
|
||||
bind_tasks=bind_tasks,
|
||||
collab_orders=collab_orders,
|
||||
shared_lease_tasks=shared_lease_tasks,
|
||||
)
|
||||
|
||||
|
||||
@@ -355,25 +365,17 @@ def _task_out(
|
||||
if task.commodity_mapping_id
|
||||
else None
|
||||
)
|
||||
goods = (
|
||||
resolved.goods.get(str(task.commodity_id))
|
||||
if task.commodity_id
|
||||
else None
|
||||
)
|
||||
goods = resolved.goods.get(str(task.commodity_id)) if task.commodity_id else None
|
||||
goods_name = (
|
||||
str(getattr(mapping, "goods_name", "") or "")
|
||||
or str(getattr(goods, "name", "") or "")
|
||||
or task.sku_name
|
||||
or task.internal_sku_key
|
||||
)
|
||||
account = (
|
||||
resolved.accounts.get(int(task.account_id)) if task.account_id else None
|
||||
)
|
||||
account = resolved.accounts.get(int(task.account_id)) if task.account_id else None
|
||||
lease = resolved.leases.get(int(task.lease_id)) if task.lease_id else None
|
||||
bind_task = (
|
||||
resolved.bind_tasks.get(int(task.bind_task_id))
|
||||
if task.bind_task_id
|
||||
else None
|
||||
resolved.bind_tasks.get(int(task.bind_task_id)) if task.bind_task_id else None
|
||||
)
|
||||
collab_order = resolved.collab_orders.get(int(task.id))
|
||||
bind_result = (bind_task.result or {}) if bind_task else {}
|
||||
@@ -489,6 +491,15 @@ def _task_out(
|
||||
if lease
|
||||
else None
|
||||
),
|
||||
"sharedLeaseTaskIds": (
|
||||
[
|
||||
tid
|
||||
for tid in resolved.shared_lease_tasks.get(int(task.lease_id), [])
|
||||
if tid != int(task.id)
|
||||
]
|
||||
if task.lease_id
|
||||
else []
|
||||
),
|
||||
"bindTask": (
|
||||
{
|
||||
"id": bind_task.id,
|
||||
@@ -501,12 +512,12 @@ def _task_out(
|
||||
"platName": binding.effective_plat_name,
|
||||
"bindPhase": binding.bind_phase,
|
||||
# 客户页的“可确认”必须与确认接口读的同一层事实一致:
|
||||
# 绑定任务 pending 且平台任务已经进入 role_ready,才显示确认按钮。
|
||||
# 否则会出现客户页让确认、确认接口报“没有待确认角色”的错位。
|
||||
"bindReadyForConfirm": (
|
||||
binding.status == BINDING_VIEW_PENDING
|
||||
and str(task.binding_status or "") == "role_ready"
|
||||
),
|
||||
# 绑定任务 pending 且平台任务已经进入 role_ready,才显示确认按钮。
|
||||
# 否则会出现客户页让确认、确认接口报“没有待确认角色”的错位。
|
||||
"bindReadyForConfirm": (
|
||||
binding.status == BINDING_VIEW_PENDING
|
||||
and str(task.binding_status or "") == "role_ready"
|
||||
),
|
||||
"bindConfirmed": binding.bind_confirmed,
|
||||
}
|
||||
if bind_task
|
||||
@@ -736,7 +747,9 @@ def _customer_profile_out(
|
||||
or ""
|
||||
)
|
||||
if customer_channel and account_channel:
|
||||
channel_matched = all(part in account_channel for part in customer_channel.split())
|
||||
channel_matched = all(
|
||||
part in account_channel for part in customer_channel.split()
|
||||
)
|
||||
if role and not platform_role:
|
||||
message = "客户已填角色,平台还未识别绑定角色"
|
||||
elif role_matched is True and channel_matched is not False:
|
||||
|
||||
Reference in New Issue
Block a user