33 lines
1.1 KiB
PHP
33 lines
1.1 KiB
PHP
<?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');
|