30 lines
1.3 KiB
PHP
30 lines
1.3 KiB
PHP
<?php
|
|
// food/courier/pending_offers.php — عروض التوصيل المعروضة على هذا السائق حالياً
|
|
// (polling fallback — food_socket يدفع 'food_delivery_offer' لحظياً، وهذا احتياطي
|
|
// لو انقطع اتصال السوكيت أو كان التطبيق لا يحمل اتصالاً حياً بالسوكيت)
|
|
require_once __DIR__ . '/../connect_courier.php';
|
|
|
|
$st = $food_con->prepare(
|
|
"SELECT a.order_id, a.offered_at
|
|
FROM food_courier_assignments a
|
|
JOIN food_orders o ON o.id = a.order_id
|
|
WHERE a.courier_id = ? AND a.status = 'offered' AND a.offered_at > (NOW() - INTERVAL 20 SECOND)
|
|
AND o.status = 'ready' AND o.courier_id IS NULL
|
|
ORDER BY a.offered_at ASC"
|
|
);
|
|
$st->execute([$food_courier_id]);
|
|
|
|
// نفس حمولة مسار السوكيت حرفياً (foodBuildCourierOfferPayload) — شاشة العرض
|
|
// عند السائق واحدة، فلا يجوز أن تختلف الحقول حسب المسار الذي وصل منه العرض.
|
|
$offers = [];
|
|
foreach ($st->fetchAll() as $row) {
|
|
$payload = foodBuildCourierOfferPayload((int)$row['order_id']);
|
|
if (!$payload) continue;
|
|
$offers[] = array_merge(
|
|
['order_id' => (int)$row['order_id'], 'offered_at' => $row['offered_at'], 'offer_ttl_seconds' => 20],
|
|
$payload
|
|
);
|
|
}
|
|
|
|
jsonSuccess(['offers' => $offers]);
|