Update: 2026-07-12 05:40:28
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// transit/trip/end.php — السائق ينهي الرحلة
|
||||
|
||||
require_once __DIR__ . '/../../transit/connect_app.php';
|
||||
|
||||
requireTransitFields(['trip_id', 'driver_transit_id']);
|
||||
|
||||
$tripId = filterRequest('trip_id', 'int');
|
||||
$driverId = filterRequest('driver_transit_id', 'int');
|
||||
|
||||
$st = $transit_con->prepare(
|
||||
"SELECT id, route_id, status FROM transit_trips WHERE id=? AND driver_id=? LIMIT 1"
|
||||
);
|
||||
$st->execute([$tripId, $driverId]);
|
||||
$trip = $st->fetch();
|
||||
|
||||
if (!$trip) jsonError('Trip not found', 404);
|
||||
if ($trip['status'] !== 'started') jsonError('Trip is not in started state', 409);
|
||||
|
||||
$transit_con->prepare(
|
||||
"UPDATE transit_trips SET status='completed', completed_at=NOW(), updated_at=NOW() WHERE id=?"
|
||||
)->execute([$tripId]);
|
||||
|
||||
global $redis;
|
||||
if ($redis) $redis->del("transit:trip:{$tripId}:status");
|
||||
|
||||
// موقع الباص + ملكية الرحلة على Redis سيرفر الموقع
|
||||
transitClearTripOwner($tripId);
|
||||
global $redisLocation;
|
||||
if ($redisLocation) $redisLocation->del("transit:trip:{$tripId}:pos");
|
||||
|
||||
jsonSuccess(['trip_id' => $tripId, 'status' => 'completed'], 'Trip completed');
|
||||
Reference in New Issue
Block a user