Update: 2026-07-06 03:11:39
This commit is contained in:
@@ -13,33 +13,67 @@ if (!$lat || !$lng || !$country) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$lat = (float)$lat;
|
||||||
|
$lng = (float)$lng;
|
||||||
$countryCode = strtoupper($country);
|
$countryCode = strtoupper($country);
|
||||||
if ($countryCode == 'JORDAN') $countryCode = 'JO';
|
if ($countryCode == 'JORDAN') $countryCode = 'JO';
|
||||||
if ($countryCode == 'SYRIA') $countryCode = 'SY';
|
if ($countryCode == 'SYRIA') $countryCode = 'SY';
|
||||||
if ($countryCode == 'EGYPT') $countryCode = 'EG';
|
if ($countryCode == 'EGYPT') $countryCode = 'EG';
|
||||||
|
|
||||||
// Default Competitor info based on Country
|
$avgPricePerKm = 0;
|
||||||
$topComp = 'TaxiF';
|
$topComp = 'TaxiF'; // Default
|
||||||
$multiplier = 1.15; // 15% more expensive by default
|
|
||||||
|
|
||||||
if ($countryCode === 'JO') {
|
try {
|
||||||
$topComp = 'TaxiF';
|
$redis = getRedisConnection();
|
||||||
$multiplier = 1.15; // TaxiF is typically 15% more expensive
|
$cacheJson = $redis->get('siro:cache:pricing:grids');
|
||||||
} else if ($countryCode === 'SY') {
|
if ($cacheJson) {
|
||||||
$topComp = 'Yango';
|
$cacheData = json_decode($cacheJson, true);
|
||||||
$multiplier = 1.12;
|
if ($cacheData && isset($cacheData['grids'])) {
|
||||||
} else if ($countryCode === 'EG') {
|
$gridSize = 0.025;
|
||||||
$topComp = 'inDrive';
|
$gLat = round($lat / $gridSize) * $gridSize;
|
||||||
$multiplier = 1.10;
|
$gLng = round($lng / $gridSize) * $gridSize;
|
||||||
|
$gridKey = "{$countryCode}_" . number_format($gLat, 3) . "_" . number_format($gLng, 3);
|
||||||
|
|
||||||
|
$grids = $cacheData['grids'];
|
||||||
|
if (isset($grids[$gridKey])) {
|
||||||
|
$avgPricePerKm = (float)$grids[$gridKey]['avg_price'];
|
||||||
|
$topComp = $grids[$gridKey]['top_competitor'] ?? 'TaxiF';
|
||||||
|
} else {
|
||||||
|
$fallbackKey = "{$countryCode}_FALLBACK";
|
||||||
|
if (isset($grids[$fallbackKey])) {
|
||||||
|
$avgPricePerKm = (float)$grids[$fallbackKey]['avg_price'];
|
||||||
|
$topComp = $grids[$fallbackKey]['top_competitor'] ?? 'TaxiF';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Continue with defaults if Redis fails
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the competitor's total price based on our price
|
// If we couldn't get a price from Redis, use a smart default based on country
|
||||||
if ($siroPrice > 0) {
|
if ($avgPricePerKm <= 0) {
|
||||||
|
if ($countryCode === 'JO') {
|
||||||
|
$avgPricePerKm = 0.35;
|
||||||
|
$topComp = 'TaxiF';
|
||||||
|
} else if ($countryCode === 'SY') {
|
||||||
|
$avgPricePerKm = 4000;
|
||||||
|
$topComp = 'Yango';
|
||||||
|
} else if ($countryCode === 'EG') {
|
||||||
|
$avgPricePerKm = 15;
|
||||||
|
$topComp = 'inDrive';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate the competitor's total price based on distance and average market per-km rate
|
||||||
|
$competitorTotalPrice = round($distance * $avgPricePerKm, 2);
|
||||||
|
|
||||||
|
// Make sure competitor is slightly higher than us for psychological effect
|
||||||
|
// if their raw math somehow ended up lower due to straight per-km multiplication
|
||||||
|
if ($siroPrice > 0 && $competitorTotalPrice <= $siroPrice) {
|
||||||
|
// Force a dynamic difference based on country
|
||||||
|
$multiplier = ($countryCode === 'JO') ? 1.15 : 1.10;
|
||||||
$competitorTotalPrice = round($siroPrice * $multiplier, 2);
|
$competitorTotalPrice = round($siroPrice * $multiplier, 2);
|
||||||
} else {
|
|
||||||
// Fallback if siro_price is 0
|
|
||||||
$avgPricePerKm = ($countryCode === 'JO') ? 0.35 : (($countryCode === 'SY') ? 4000 : 15);
|
|
||||||
$competitorTotalPrice = round($distance * $avgPricePerKm, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate savings
|
// Calculate savings
|
||||||
@@ -55,8 +89,15 @@ $compNameAr = match(strtolower($topComp)) {
|
|||||||
'yallago' => 'يلا غو',
|
'yallago' => 'يلا غو',
|
||||||
'jenny' => 'جيني',
|
'jenny' => 'جيني',
|
||||||
'taxif' => 'تكسي إف',
|
'taxif' => 'تكسي إف',
|
||||||
|
'com.taxif.passenger' => 'تكسي إف',
|
||||||
'indrive' => 'إن درايف',
|
'indrive' => 'إن درايف',
|
||||||
'yango' => 'يانغو',
|
'yango' => 'يانغو',
|
||||||
|
'petra' => 'بترا رايد',
|
||||||
|
'petra ride' => 'بترا رايد',
|
||||||
|
'gojo' => 'جو جو',
|
||||||
|
'didi' => 'ديدي',
|
||||||
|
'zakin' => 'زاكن',
|
||||||
|
'tofaddal'=> 'تفضل',
|
||||||
default => $topComp
|
default => $topComp
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user