40 lines
1.6 KiB
PHP
40 lines
1.6 KiB
PHP
<?php
|
|
// food/order/call_courier.php — الزبون يتصل بسائق التوصيل عبر قناة مقنّعة
|
|
// لا رقم هاتف يُعرض لأي طرف — session_id فقط، والقناة تُقفل بانتهاء الطلب.
|
|
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 (!foodOrderAllowsCall($order)) {
|
|
jsonError('Calling is only allowed while a courier is delivering your order', 403);
|
|
}
|
|
|
|
if (foodCallQuotaExceeded($orderId, 'customer')) {
|
|
jsonError('Too many call attempts for this order', 429);
|
|
}
|
|
|
|
$courierId = (string)$order['courier_id'];
|
|
$session = foodCreateCallSession($orderId, $courierId, $food_passenger_id);
|
|
if (!$session) jsonError('Call service unavailable', 502);
|
|
|
|
// السائق يصله التنبيه عبر سوكيت الطعام (غرفة courier_food_{id}) — لا موضوع FCM
|
|
// خاصاً بكل سائق في النظام، والسوكيت حيّ أصلاً أثناء وضع التوصيل.
|
|
// الاسم المعروض عام عمداً: هوية الزبون لا تُكشف للسائق.
|
|
foodPushToSocket('courier_call', [
|
|
'order_id' => $orderId,
|
|
'courier_id' => $courierId,
|
|
'session_id' => $session['session_id'],
|
|
'caller_name' => 'زبون الطلب #' . $orderId,
|
|
'expires_in' => $session['expires_in'],
|
|
]);
|
|
|
|
appLog("[FOOD][CALL] passenger {$food_passenger_id} → courier (order {$orderId})", 'INFO');
|
|
|
|
jsonSuccess([
|
|
'session_id' => $session['session_id'],
|
|
'expires_in' => $session['expires_in'],
|
|
]);
|