feat(fulfillment): 增加订单匹配起算时间
This commit is contained in:
@@ -158,6 +158,7 @@ def _fetch_pending_manual_fulfillments(
|
||||
limit: int = 100,
|
||||
*,
|
||||
internal_sku_keys: list[str] | None = None,
|
||||
paid_at_from: datetime | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""读取最近的人工渠道待履约订单项。
|
||||
|
||||
@@ -172,8 +173,11 @@ def _fetch_pending_manual_fulfillments(
|
||||
if not sku_keys:
|
||||
return []
|
||||
engine = _get_engine()
|
||||
paid_at_filter = (
|
||||
"AND o.paid_at >= :paid_at_from" if paid_at_from is not None else ""
|
||||
)
|
||||
sql = text(
|
||||
"""
|
||||
f"""
|
||||
SELECT o.id AS source_order_id,
|
||||
o.platform_order_id,
|
||||
o.provider,
|
||||
@@ -204,6 +208,7 @@ def _fetch_pending_manual_fulfillments(
|
||||
AND f.status = 'assigned'
|
||||
AND o.pay_status = 'paid'
|
||||
AND o.order_status NOT IN ('refunded', 'cancelled', 'closed')
|
||||
{paid_at_filter}
|
||||
AND oi.quantity = 1
|
||||
AND COALESCE(f.issue_code, '') NOT IN ('user_refund', 'platform_cancelled')
|
||||
AND COALESCE(
|
||||
@@ -218,14 +223,17 @@ def _fetch_pending_manual_fulfillments(
|
||||
)
|
||||
try:
|
||||
with engine.connect() as conn:
|
||||
params: dict[str, Any] = {
|
||||
"limit": max(1, min(limit, 500)),
|
||||
"internal_sku_keys": sku_keys,
|
||||
}
|
||||
if paid_at_from is not None:
|
||||
params["paid_at_from"] = paid_at_from
|
||||
return [
|
||||
dict(row)
|
||||
for row in conn.execute(
|
||||
sql,
|
||||
{
|
||||
"limit": max(1, min(limit, 500)),
|
||||
"internal_sku_keys": sku_keys,
|
||||
},
|
||||
params,
|
||||
).mappings()
|
||||
]
|
||||
except Exception as exc:
|
||||
@@ -237,6 +245,7 @@ def list_pending_manual_fulfillments(
|
||||
limit: int = 100,
|
||||
*,
|
||||
internal_sku_keys: list[str] | None = None,
|
||||
paid_at_from: datetime | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""返回最近的人工渠道待履约订单项快照。"""
|
||||
if not _enabled():
|
||||
@@ -252,6 +261,7 @@ def list_pending_manual_fulfillments(
|
||||
for row in _fetch_pending_manual_fulfillments(
|
||||
limit=limit,
|
||||
internal_sku_keys=sku_keys,
|
||||
paid_at_from=paid_at_from,
|
||||
):
|
||||
internal_sku_key = str(
|
||||
row.get("manual_sku_key")
|
||||
|
||||
Reference in New Issue
Block a user