Update: 2026-07-09 03:41:48
This commit is contained in:
@@ -440,6 +440,49 @@ $io->on('workerStart', function () use ($io, $INTERNAL_KEY) {
|
||||
logMsg("✅ Ride #$rideId taken by #$winnerDriverId.");
|
||||
$connection->send('OK');
|
||||
|
||||
// ── 4b. Ride Cancelled (بالراكب أو بالسائق) ─────────────
|
||||
} elseif ($action === 'cancel_ride') {
|
||||
$rideId = $post['ride_id'] ?? null;
|
||||
$driverId = $post['driver_id'] ?? null;
|
||||
$reason = $post['reason'] ?? '';
|
||||
|
||||
if (!$rideId) { $connection->send('Error: Missing ride_id'); return; }
|
||||
|
||||
// كل السائقين الذين وصلهم عرض هذه الرحلة (سواء قَبِلها أحد أم لا)
|
||||
$offeredDrivers = [];
|
||||
|
||||
if ($redis) {
|
||||
$redis->zrem('geo:rides:waiting', $rideId);
|
||||
|
||||
$offeredSetKey = "ride:offered_drivers:$rideId";
|
||||
$offeredDrivers = $redis->smembers($offeredSetKey);
|
||||
foreach ($offeredDrivers as $dId) {
|
||||
$redis->zrem("driver:pending_orders:$dId", $rideId);
|
||||
}
|
||||
$redis->del($offeredSetKey);
|
||||
$redis->del("ride:offer:$rideId");
|
||||
}
|
||||
|
||||
// نوحّد قائمة من يجب إشعارهم: السائق الحالي (إن وُجد) + كل من عُرضت عليهم الرحلة
|
||||
$notifyDrivers = $offeredDrivers;
|
||||
if ($driverId) $notifyDrivers[] = (string)$driverId;
|
||||
$notifyDrivers = array_unique(array_filter($notifyDrivers, fn($d) => $d && $d !== '0'));
|
||||
|
||||
$notified = 0;
|
||||
foreach ($notifyDrivers as $dId) {
|
||||
if (isset($connectedDrivers[$dId])) {
|
||||
$io->to('driver_' . $dId)->emit('ride_cancelled', [
|
||||
'ride_id' => $rideId,
|
||||
'reason' => $reason,
|
||||
]);
|
||||
$notified++;
|
||||
}
|
||||
}
|
||||
|
||||
unset($active_orders_drivers[$rideId]);
|
||||
logMsg("🚫 Ride #$rideId cancelled — notified $notified/" . count($notifyDrivers) . " driver(s).");
|
||||
$connection->send('OK');
|
||||
|
||||
// ── 7. Update Ride State (Redis Cache فقط — بدون Forward)
|
||||
} elseif ($action === 'update_ride_state') {
|
||||
$rideId = $post['ride_id'] ?? null;
|
||||
|
||||
Reference in New Issue
Block a user