Update: 2026-07-12 05:40:28

This commit is contained in:
Hamza-Ayed
2026-07-12 05:40:28 +03:00
parent 1fa517acc9
commit 24fb56f08f
75 changed files with 5051 additions and 9 deletions
+38
View File
@@ -0,0 +1,38 @@
<?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]);