39 lines
1.5 KiB
PHP
39 lines
1.5 KiB
PHP
<?php
|
|
// transit/trip/update_position.php
|
|
// ⚠️ مهجور (fallback فقط): المسار الأساسي لموقع الباص هو WebSocket:
|
|
// سائق الباص يبعث socket.emit('update_bus_location', {...}) إلى driver_socket:2020
|
|
// الذي يخزّن الموقع ويبثّه حياً لكل ركاب الخط عبر passenger_socket.
|
|
// هذا الـ endpoint يكتب الموقع في Redis فقط ولا يبثّه للركاب — لا تستخدمه
|
|
// إلا كخطة بديلة عند تعذّر السوكت. الموقع يُخزَّن على Redis سيرفر الموقع.
|
|
|
|
require_once __DIR__ . '/../../core/bootstrap.php';
|
|
require_once __DIR__ . '/../functions.php';
|
|
|
|
try { $transit_con = Database::get('transit'); }
|
|
catch (Exception $e) { http_response_code(503); exit; }
|
|
|
|
$tripId = filterRequest('trip_id', 'int');
|
|
$driverId = filterRequest('driver_transit_id', 'int');
|
|
$lat = (float)filterRequest('lat');
|
|
$lng = (float)filterRequest('lng');
|
|
$stopSeq = filterRequest('current_stop_seq', 'int');
|
|
|
|
if (!$tripId || !$driverId || !$lat || !$lng) {
|
|
jsonError('Missing required fields', 400);
|
|
}
|
|
|
|
transitUpdateBusPosition($tripId, $lat, $lng);
|
|
|
|
if ($stopSeq !== null) {
|
|
$transit_con->prepare(
|
|
"UPDATE transit_trips SET current_stop_seq=?, updated_at=NOW() WHERE id=? AND driver_id=?"
|
|
)->execute([$stopSeq, $tripId, $driverId]);
|
|
|
|
global $redis;
|
|
if ($redis) {
|
|
$redis->publish("transit:trip:{$tripId}:stop", json_encode(['seq' => $stopSeq, 'ts' => time()]));
|
|
}
|
|
}
|
|
|
|
jsonSuccess(['ok' => true]);
|