Food: single-source tracking, mode exclusivity, in-app navigation
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// food/order/courier_location.php — آخر موقع معروف لسائق طلبي (للراكب)
|
||||
//
|
||||
// مسار سحب (polling): تطبيق الراكب لا يحمل عميل سوكيت للطعام حالياً، وهذا
|
||||
// المصدر يكفي لخريطة تتبّع سلسة مع تحديث كل بضع ثوانٍ.
|
||||
// الموقع نفسه ينتهي من Redis خلال 90 ثانية، فبعد التسليم — أو بعد توقف
|
||||
// السائق عن البثّ — تُرجع الواجهة null بلا أي أثر متبقٍ.
|
||||
require_once __DIR__ . '/../connect_app.php';
|
||||
|
||||
$orderId = filterRequest('order_id', 'int');
|
||||
if (!$orderId) jsonError('order_id is required');
|
||||
|
||||
$order = foodAssertOrderOwnership($orderId, 'customer', $food_passenger_id);
|
||||
|
||||
// لا نكشف موقع السائق إلا خلال نافذة التوصيل — لا قبل الإسناد ولا بعد التسليم
|
||||
if (!in_array($order['status'], ['courier_assigned', 'picked_up'], true)) {
|
||||
jsonSuccess(['status' => $order['status'], 'courier_position' => null]);
|
||||
}
|
||||
|
||||
$position = null;
|
||||
if ($redis) {
|
||||
$raw = $redis->get("food:order:{$orderId}:courier_pos");
|
||||
if ($raw) $position = json_decode($raw, true);
|
||||
}
|
||||
|
||||
// إحداثيات وجهتَي الخريطة — المطعم وعنوان التسليم (كلاهما معروف للزبون أصلاً)
|
||||
$st = $food_con->prepare(
|
||||
"SELECT o.delivery_lat, o.delivery_lng, o.delivery_address,
|
||||
m.name_ar AS merchant_name_ar, m.latitude AS merchant_lat, m.longitude AS merchant_lng
|
||||
FROM food_orders o JOIN food_merchants m ON m.id = o.merchant_id
|
||||
WHERE o.id = ? LIMIT 1"
|
||||
);
|
||||
$st->execute([$orderId]);
|
||||
$meta = $st->fetch() ?: [];
|
||||
|
||||
jsonSuccess([
|
||||
'status' => $order['status'],
|
||||
'courier_position' => $position,
|
||||
'merchant' => $meta ? [
|
||||
'name_ar' => $meta['merchant_name_ar'],
|
||||
'lat' => (float)$meta['merchant_lat'],
|
||||
'lng' => (float)$meta['merchant_lng'],
|
||||
] : null,
|
||||
'destination' => $meta ? [
|
||||
'address' => $meta['delivery_address'],
|
||||
'lat' => (float)$meta['delivery_lat'],
|
||||
'lng' => (float)$meta['delivery_lng'],
|
||||
] : null,
|
||||
]);
|
||||
Reference in New Issue
Block a user