Update: 2026-07-06 00:53:15

This commit is contained in:
Hamza-Ayed
2026-07-06 00:53:15 +03:00
parent 0c19486a24
commit d00502769a
4 changed files with 92 additions and 30 deletions
+8 -24
View File
@@ -184,19 +184,12 @@ function calculateDynamicPrice($country, $minFare, $distance, $duration, $kazanR
break;
}
$longSpeedThresholdKm = 40.0;
$longSpeedPerKm = 26.0;
$mediumDistThresholdKm = 25.0;
$longDistThresholdKm = 35.0;
$longTripPerMin = 6.0;
$minuteCapMedium = 60;
$minuteCapLong = 80;
$freeMinutesLong = 10;
$extraReduction100 = 0.07;
$maxReductionCap = 0.35;
$totalMinutes = floor($duration / 60);
$airportCtx = (stripos($startNameAddress, 'airport') !== false || stripos($startNameAddress, 'مطار') !== false || stripos($endNameAddress, 'airport') !== false || stripos($endNameAddress, 'مطار') !== false);
@@ -210,23 +203,15 @@ function calculateDynamicPrice($country, $minFare, $distance, $duration, $kazanR
$isInDamascusAirportBoundCtx = ($passengerLat <= $northLat && $passengerLat >= $southLat && $passengerLng <= $eastLng && $passengerLng >= $westLng);
$billableDistance = ($distance < $minBillableKm) ? $minBillableKm : $distance;
$isLongSpeed = $billableDistance > $longSpeedThresholdKm;
$perKmSpeedBaseFromServer = getPerKmRate($carType, $kazanRow);
$perKmSpeed = $isLongSpeed ? $longSpeedPerKm : $perKmSpeedBaseFromServer;
$reductionPct40 = 0.0;
if ($perKmSpeedBaseFromServer > 0) {
$r = 1.0 - ($longSpeedPerKm / $perKmSpeedBaseFromServer);
$reductionPct40 = max(0.0, min($maxReductionCap, $r));
}
$reductionPct100 = max(0.0, min($maxReductionCap, $reductionPct40 + $extraReduction100));
$distanceReduction = 0.0;
if ($billableDistance > 100.0) {
$distanceReduction = $reductionPct100;
} else if ($billableDistance > 40.0) {
$distanceReduction = $reductionPct40;
// Apply dynamic percentage discount instead of hardcoded currencies for long trips
$perKmSpeed = $perKmSpeedBaseFromServer;
if ($billableDistance > $longDistThresholdKm) {
$perKmSpeed = $perKmSpeedBaseFromServer * 0.85; // 15% discount per km
} else if ($billableDistance > $mediumDistThresholdKm) {
$perKmSpeed = $perKmSpeedBaseFromServer * 0.90; // 10% discount per km
}
date_default_timezone_set('Asia/Damascus');
@@ -242,11 +227,10 @@ function calculateDynamicPrice($country, $minFare, $distance, $duration, $kazanR
$billableMinutes = $totalMinutes;
if ($billableDistance > $longDistThresholdKm) {
$effectivePerMin = $longTripPerMin;
// Prevent absurd time billing for very long trips
$capped = ($billableMinutes > $minuteCapLong) ? $minuteCapLong : $billableMinutes;
$billableMinutes = max(0, $capped - $freeMinutesLong);
} else if ($billableDistance > $mediumDistThresholdKm) {
$effectivePerMin = $longTripPerMin;
$billableMinutes = ($billableMinutes > $minuteCapMedium) ? $minuteCapMedium : $billableMinutes;
}