Update: 2026-07-12 18:53:59
This commit is contained in:
@@ -3,12 +3,21 @@
|
||||
|
||||
require_once __DIR__ . '/../../transit/connect_app.php';
|
||||
|
||||
requireTransitFields(['trip_id', 'driver_transit_id', 'delay_minutes']);
|
||||
if ($transit_user_role !== 'driver') jsonError('Only drivers can access this endpoint', 403);
|
||||
|
||||
$tripId = filterRequest('trip_id', 'int');
|
||||
$driverId = filterRequest('driver_transit_id', 'int');
|
||||
$delay = min((int)filterRequest('delay_minutes'), 120);
|
||||
$reason = filterRequest('reason');
|
||||
$tripId = filterRequest('trip_id', 'int');
|
||||
$delay = min((int)filterRequest('delay_minutes'), 120);
|
||||
$reason = filterRequest('reason');
|
||||
if (!$tripId || $delay <= 0) jsonError('trip_id and delay_minutes are required', 400);
|
||||
|
||||
// استخرج سجل السائق من JWT
|
||||
$driverRow = $transit_con->prepare(
|
||||
"SELECT id FROM transit_drivers WHERE main_driver_id=? AND status='active' LIMIT 1"
|
||||
);
|
||||
$driverRow->execute([(string)$transit_user_id]);
|
||||
$driverRec = $driverRow->fetch();
|
||||
if (!$driverRec) jsonError('Driver not found or not active', 403);
|
||||
$driverId = (int)$driverRec['id'];
|
||||
|
||||
$st = $transit_con->prepare(
|
||||
"SELECT t.id, t.route_id, r.name_ar AS route_name
|
||||
|
||||
@@ -3,10 +3,19 @@
|
||||
|
||||
require_once __DIR__ . '/../../transit/connect_app.php';
|
||||
|
||||
requireTransitFields(['trip_id', 'driver_transit_id']);
|
||||
if ($transit_user_role !== 'driver') jsonError('Only drivers can access this endpoint', 403);
|
||||
|
||||
$tripId = filterRequest('trip_id', 'int');
|
||||
$driverId = filterRequest('driver_transit_id', 'int');
|
||||
$tripId = filterRequest('trip_id', 'int');
|
||||
if (!$tripId) jsonError('trip_id is required', 400);
|
||||
|
||||
// استخرج سجل السائق من JWT
|
||||
$driverRow = $transit_con->prepare(
|
||||
"SELECT id FROM transit_drivers WHERE main_driver_id=? AND status='active' LIMIT 1"
|
||||
);
|
||||
$driverRow->execute([(string)$transit_user_id]);
|
||||
$driverRec = $driverRow->fetch();
|
||||
if (!$driverRec) jsonError('Driver not found or not active', 403);
|
||||
$driverId = (int)$driverRec['id'];
|
||||
|
||||
$st = $transit_con->prepare(
|
||||
"SELECT id, route_id, status FROM transit_trips WHERE id=? AND driver_id=? LIMIT 1"
|
||||
|
||||
@@ -19,7 +19,7 @@ if (!$tripId) jsonError('No active trip found', 404);
|
||||
|
||||
$st = $transit_con->prepare(
|
||||
"SELECT t.id, t.org_id, t.status, t.delay_minutes, t.current_stop_seq, t.started_at,
|
||||
r.name_ar AS route_name, sc.departure_time, d.name AS driver_name
|
||||
r.name_ar AS route_name, r.polyline AS route_polyline, sc.departure_time, d.name AS driver_name
|
||||
FROM transit_trips t
|
||||
JOIN transit_routes r ON r.id = t.route_id
|
||||
JOIN transit_schedules sc ON sc.id = t.schedule_id
|
||||
|
||||
@@ -3,18 +3,26 @@
|
||||
|
||||
require_once __DIR__ . '/../../transit/connect_app.php';
|
||||
|
||||
requireTransitFields(['trip_id', 'driver_transit_id', 'lat', 'lng']);
|
||||
if ($transit_user_role !== 'driver') jsonError('Only drivers can access this endpoint', 403);
|
||||
|
||||
$tripId = filterRequest('trip_id', 'int');
|
||||
$driverId = filterRequest('driver_transit_id', 'int');
|
||||
$lat = (float)filterRequest('lat');
|
||||
$lng = (float)filterRequest('lng');
|
||||
requireTransitFields(['trip_id', 'lat', 'lng']);
|
||||
$tripId = filterRequest('trip_id', 'int');
|
||||
$lat = (float)filterRequest('lat');
|
||||
$lng = (float)filterRequest('lng');
|
||||
|
||||
// استخرج سجل السائق من JWT — تحقق أن الرحلة تخصه
|
||||
$driverRow = $transit_con->prepare(
|
||||
"SELECT id FROM transit_drivers WHERE main_driver_id=? AND status='active' LIMIT 1"
|
||||
);
|
||||
$driverRow->execute([(string)$transit_user_id]);
|
||||
$driverRec = $driverRow->fetch();
|
||||
if (!$driverRec) jsonError('Driver not found or not active', 403);
|
||||
$driverId = (int)$driverRec['id'];
|
||||
|
||||
$st = $transit_con->prepare(
|
||||
"SELECT t.id, t.route_id, t.status, r.name_ar AS route_name, d.main_driver_id
|
||||
"SELECT t.id, t.route_id, t.status, r.name_ar AS route_name
|
||||
FROM transit_trips t
|
||||
JOIN transit_routes r ON r.id = t.route_id
|
||||
JOIN transit_drivers d ON d.id = t.driver_id
|
||||
JOIN transit_routes r ON r.id = t.route_id
|
||||
WHERE t.id=? AND t.driver_id=? LIMIT 1"
|
||||
);
|
||||
$st->execute([$tripId, $driverId]);
|
||||
@@ -24,7 +32,6 @@ if (!$trip) jsonError('Trip not found', 404);
|
||||
if ($trip['status'] === 'started') jsonError('Trip already started', 409);
|
||||
if ($trip['status'] === 'completed') jsonError('Trip already completed', 409);
|
||||
if ($trip['status'] === 'cancelled') jsonError('Trip was cancelled', 409);
|
||||
if (!$trip['main_driver_id']) jsonError('Driver has no linked main account — cannot start live tracking', 422);
|
||||
|
||||
$transit_con->prepare(
|
||||
"UPDATE transit_trips SET status='started', started_at=NOW(), current_stop_seq=1 WHERE id=?"
|
||||
@@ -33,7 +40,8 @@ $transit_con->prepare(
|
||||
transitUpdateBusPosition($tripId, $lat, $lng);
|
||||
|
||||
// تخزين ملكية الرحلة — يتحقق منها driver_socket قبل أي بثّ حي للراكبين
|
||||
transitSetTripOwner($tripId, (string)$trip['main_driver_id'], (int)$trip['route_id']);
|
||||
// transit_user_id هو main_driver_id بالفعل (يُستخرج من JWT السائق)
|
||||
transitSetTripOwner($tripId, (string)$transit_user_id, (int)$trip['route_id']);
|
||||
|
||||
global $redis;
|
||||
if ($redis) {
|
||||
|
||||
@@ -3,15 +3,16 @@
|
||||
|
||||
require_once __DIR__ . '/../../transit/connect_app.php';
|
||||
|
||||
$driverTransitId = filterRequest('driver_transit_id', 'int');
|
||||
if (!$driverTransitId) jsonError('driver_transit_id is required', 400);
|
||||
if ($transit_user_role !== 'driver') jsonError('Only drivers can access this endpoint', 403);
|
||||
|
||||
// استخرج سجل السائق من JWT — لا نثق بـ driver_transit_id من العميل
|
||||
$chk = $transit_con->prepare(
|
||||
"SELECT id, org_id FROM transit_drivers WHERE id=? AND status='active' LIMIT 1"
|
||||
"SELECT id, org_id FROM transit_drivers WHERE main_driver_id=? AND status='active' LIMIT 1"
|
||||
);
|
||||
$chk->execute([$driverTransitId]);
|
||||
$chk->execute([(string)$transit_user_id]);
|
||||
$driver = $chk->fetch();
|
||||
if (!$driver) jsonError('Driver not found or not active', 403);
|
||||
if (!$driver) jsonError('Driver not found or not active — activate your account first', 403);
|
||||
$driverTransitId = (int)$driver['id'];
|
||||
|
||||
$today = date('Y-m-d');
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
<?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]);
|
||||
Reference in New Issue
Block a user