diff --git a/backend/ride/location/get.php b/backend/ride/location/get.php index d04fabc2..d93179a0 100644 --- a/backend/ride/location/get.php +++ b/backend/ride/location/get.php @@ -104,7 +104,6 @@ try { SELECT driver_id, AVG(rating) AS ratingDriver FROM ratingDriver GROUP BY driver_id ) rdAvg ON rdAvg.driver_id = d.id WHERE d.id IN ($placeholders) - AND COALESCE(cr.year, 0) > 2000 "; $stmt = $con->prepare($sql_drivers_info); @@ -112,9 +111,11 @@ try { $drivers_db = $stmt->fetchAll(PDO::FETCH_ASSOC); $fieldsToDecrypt = ['phone','email','gender','birthdate','first_name','last_name','token','car_plate','vin']; + $foundIds = []; foreach ($drivers_db as $row) { $did = $row['driver_id']; + $foundIds[] = $did; if (isset($driversMap[$did])) { $redisInfo = $driversMap[$did]; @@ -172,6 +173,27 @@ try { ]), ]); } + + // 🚀 Fallback: إذا كان السائق نشط في Redis لكن بيانت السيارة في MySQL مفقودة/قديمة، أظهر موقعه للراكب + $missingIds = array_diff($mysqlIds, $foundIds); + foreach ($missingIds as $mid) { + if (isset($driversMap[$mid])) { + $d = $driversMap[$mid]; + $final_result[] = [ + 'driver_id' => $mid, + 'id' => $mid, + 'first_name'=> 'Driver', + 'last_name' => '', + 'latitude' => $d['latitude'] ?? $d['lat'] ?? '', + 'longitude' => $d['longitude'] ?? $d['lng'] ?? '', + 'heading' => $d['heading'] ?? '0', + 'speed' => $d['speed'] ?? '0', + 'make' => '', + 'model' => '', + 'serverNow' => $serverNow, + ]; + } + } } // إرجاع النتيجة diff --git a/loction_server/api_get_nearby.php b/loction_server/api_get_nearby.php index 7cc3e3d3..43a80b60 100755 --- a/loction_server/api_get_nearby.php +++ b/loction_server/api_get_nearby.php @@ -37,7 +37,7 @@ if (!empty($INTERNAL_KEY) && $receivedKey !== $INTERNAL_KEY) { $lat = $_REQUEST['lat'] ?? null; $lng = $_REQUEST['lng'] ?? null; -$radius = $_REQUEST['radius'] ?? 25; +$radius = $_REQUEST['radius'] ?? 5; $limit = $_REQUEST['limit'] ?? 100; if (!$lat || !$lng) { @@ -67,7 +67,7 @@ try { $validDrivers = []; $currentTime = time(); - $max_silence = 900; // 15 دقيقة سماحية للسائق المنتظر في مكانه + $max_silence = 180; foreach ($geoResults as $res) { // هيكل النتيجة مع WITHCOORD يختلف قليلاً @@ -76,9 +76,9 @@ try { $d_coord= $res[2]; // [0=>lng, 1=>lat] 🔥 الإحداثيات هنا $profile = $redis->hgetall("driver:profile:$d_id"); - $lastUpdate = isset($profile['updated_at']) ? (int)$profile['updated_at'] : $currentTime; + $lastUpdate = isset($profile['updated_at']) ? (int)$profile['updated_at'] : 0; - if (!empty($lastUpdate) && ($currentTime - $lastUpdate) > $max_silence) { + if (empty($profile) || ($currentTime - $lastUpdate) > $max_silence) { $redis->zrem('geo:drivers:available', $d_id); $redis->zrem('geo:drivers:busy', $d_id); continue;