Update: 2026-07-02 16:52:25

This commit is contained in:
Hamza-Ayed
2026-07-02 16:52:25 +03:00
parent 75e6fc42d7
commit 5d14493ff4
9 changed files with 213 additions and 20 deletions
+39 -4
View File
@@ -160,6 +160,10 @@ $price = $tokenData['prices'][$tokenCarType]['price'];
$price_for_driver = $tokenData['prices'][$tokenCarType]['driver_price'];
$price_for_passenger = $price;
// 🆕 Destination Matching
$is_destination_match = isset($tokenData['is_destination_match']) ? (int)$tokenData['is_destination_match'] : 0;
$matched_driver_id = isset($tokenData['matched_driver_id']) ? $tokenData['matched_driver_id'] : 0;
// ── 2. تنسيق التواريخ ─────────────────────────────────────────
$date_formatted = date("Y-m-d");
$time_formatted = date("H:i:s");
@@ -191,16 +195,17 @@ $insertData = [
':price_for_driver' => $price_for_driver,
':price_for_passenger' => $price_for_passenger,
':distance' => $distance,
':is_destination_match' => $is_destination_match,
];
$sqlInsert = "INSERT INTO `ride`
(`start_location`,`end_location`,`date`,`time`,`endtime`,
`price`,`passenger_id`,`driver_id`,`status`,`carType`,
`price_for_driver`,`price_for_passenger`,`distance`)
`price_for_driver`,`price_for_passenger`,`distance`,`is_destination_match`)
VALUES
(:start_location,:end_location,:date,:time,:endtime,
:price,:passenger_id,:driver_id,:status,:carType,
:price_for_driver,:price_for_passenger,:distance)";
:price_for_driver,:price_for_passenger,:distance,:is_destination_match)";
try {
// ═══════════════════════════════════════════════════════════
@@ -224,11 +229,11 @@ try {
$sqlInsertWithId = "INSERT INTO `ride`
(`id`,`start_location`,`end_location`,`date`,`time`,`endtime`,
`price`,`passenger_id`,`driver_id`,`status`,`carType`,
`price_for_driver`,`price_for_passenger`,`distance`)
`price_for_driver`,`price_for_passenger`,`distance`,`is_destination_match`)
VALUES
(:id,:start_location,:end_location,:date,:time,:endtime,
:price,:passenger_id,:driver_id,:status,:carType,
:price_for_driver,:price_for_passenger,:distance)";
:price_for_driver,:price_for_passenger,:distance,:is_destination_match)";
try {
$primaryData = $insertData;
@@ -285,6 +290,36 @@ try {
// Direct dispatch للسائقين القريبين
$driversData = findBestDrivers($con, $startLat, $startLng, $carType, $endLat, $endLng);
// 🆕 Destination Matching Priority
if ($is_destination_match && $matched_driver_id) {
$found = false;
foreach ($driversData as $k => $d) {
if ($d['captain_id'] == $matched_driver_id) {
// Remove from current position and move to the very front
unset($driversData[$k]);
$d['is_destination_match'] = 1;
array_unshift($driversData, $d);
$found = true;
break;
}
}
// If driver wasn't nearby but we still want to give it to them because it's their route
if (!$found) {
$stmtD = $con->prepare("SELECT token FROM driverToken WHERE captain_id = :d");
$stmtD->execute([':d' => $matched_driver_id]);
$dT = $stmtD->fetchColumn();
if ($dT) {
array_unshift($driversData, [
'captain_id' => $matched_driver_id,
'token' => $dT,
'is_destination_match' => 1
]);
}
}
}
if (!empty($driversData)) {
dispatchRideToDrivers($driversData, $insertedId, $payload, $start_name_loc, $encryptionHelper);
error_log("[add_ride] Dispatched RideID=$insertedId to " . count($driversData) . " drivers.");