优化(直播履约): 即时选号并收敛订单快照同步
This commit is contained in:
@@ -22,7 +22,7 @@ from ..services.integration.security import (
|
||||
verify_webhook_signature,
|
||||
webhook_tolerance_seconds,
|
||||
)
|
||||
from ..services.platform_fulfillment import service
|
||||
from ..services.platform_fulfillment import auto_allocator, service
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/api/integration/platform-fulfillment",
|
||||
@@ -81,9 +81,27 @@ async def sync_order_event(
|
||||
received_at=datetime.now(UTC),
|
||||
)
|
||||
db.add(inbox)
|
||||
result = service.sync_pending_tasks(db, limit=500, commit=False)
|
||||
data = payload.get("data")
|
||||
snapshot = data if isinstance(data, dict) else payload
|
||||
has_snapshot = bool(
|
||||
str(snapshot.get("sourceOrderItemId") or "").strip()
|
||||
and str(snapshot.get("internalSkuKey") or "").strip()
|
||||
)
|
||||
if has_snapshot:
|
||||
result = service.sync_order_snapshot(db, payload, commit=False)
|
||||
else:
|
||||
item_ids = [
|
||||
str(value).strip()
|
||||
for value in (
|
||||
snapshot.get("sourceOrderItemId"),
|
||||
snapshot.get("orderItemId"),
|
||||
)
|
||||
if str(value or "").strip()
|
||||
]
|
||||
result = service.sync_order_item_ids(db, item_ids, commit=False)
|
||||
inbox.processed_at = datetime.now(UTC)
|
||||
db.commit()
|
||||
auto_allocator.wake_auto_allocator(result.get("taskIds", []))
|
||||
return {**result, "duplicate": False}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user