feat: integrate seasonal surge multipliers and grid-specific commission discounts into pricing logic
This commit is contained in:
@@ -51,7 +51,7 @@ try {
|
||||
// 1. Economy tier (الأكثر تنافسية)
|
||||
// 2. Standard tier (إذا ما في Economy)
|
||||
// 3. أي tier ثاني بأعلى R²
|
||||
$tierPriority = ['standard', 'economy', 'premium'];
|
||||
$tierPriority = ['economy', 'standard', 'premium'];
|
||||
$bestFormula = null;
|
||||
$bestTierIdx = 999;
|
||||
|
||||
@@ -192,17 +192,19 @@ try {
|
||||
$avgMult = round($data['avg_multiplier'] / $data['count'], 3);
|
||||
$peakHoursStr = implode(', ', array_unique($data['peak_hours']));
|
||||
|
||||
// تخزين معلومات الـ Surge في Redis — مفتاحين:
|
||||
// 1. surge:opportunities (متوافق مع get.php الحالي)
|
||||
// 2. surge:opportunities:{country} (متوافق مع cron_kazan_adjuster.php)
|
||||
// تخزين ملخص إحصائي (object) على مفتاح خاص ومستقل — لا نكتب على
|
||||
// surge:opportunities / surge:opportunities:{country} لأنها خرائط
|
||||
// grid_id → multiplier يملأها ويقرأها نظام آخر بالكامل
|
||||
// (cron_surge_opportunity.php / get.php / get_surge_heatmap.php /
|
||||
// winback_hotspot_targets.php / cron_kazan_adjuster.php). كتابة
|
||||
// object مسطّح على نفس المفتاح كانت تبهدل تلك الخريطة كل 3 ساعات.
|
||||
$surgeData = [
|
||||
'avg_competitor_surge' => $avgMult,
|
||||
'suggested_multiplier' => round(1.0 + ($avgMult - 1.0) * 0.6, 3),
|
||||
'peak_hours' => $data['peak_hours'],
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
$redis->setex("surge:opportunities", 7200, json_encode($surgeData));
|
||||
$redis->setex("surge:opportunities:{$country}", 7200, json_encode($surgeData));
|
||||
$redis->setex("pricing_engine:competitor_surge_summary:{$country}", 7200, json_encode($surgeData));
|
||||
|
||||
echo " ⚡ $country: Avg competitor surge = {$avgMult}x, peak hours: {$peakHoursStr}\n";
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ try {
|
||||
// 3. تحديد فرص الذروة
|
||||
$opportunities = [];
|
||||
$gridSurgeZones = [];
|
||||
$gridSurgeZonesByCountry = [];
|
||||
|
||||
foreach ($zones as $key => &$zone) {
|
||||
$zone['opportunity'] = (
|
||||
@@ -118,6 +119,15 @@ try {
|
||||
|
||||
// حفظ المنطقة مع المضاعف المقترح في Redis (للقراءة من get.php بعدين)
|
||||
$gridSurgeZones[$key] = $suggestedMultiplier;
|
||||
|
||||
// نفس البيانات مجمّعة حسب الدولة — يقرأها get_surge_heatmap.php،
|
||||
// winback_hotspot_targets.php، و cron_kazan_adjuster.php كخريطة
|
||||
// grid_id → multiplier لكل دولة على حدة
|
||||
$countryCode = $zone['country_code'];
|
||||
if (!isset($gridSurgeZonesByCountry[$countryCode])) {
|
||||
$gridSurgeZonesByCountry[$countryCode] = [];
|
||||
}
|
||||
$gridSurgeZonesByCountry[$countryCode][$key] = $suggestedMultiplier;
|
||||
}
|
||||
}
|
||||
unset($zone);
|
||||
@@ -137,6 +147,21 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
// 5. تخزين/مسح النسخة المقسّمة حسب الدولة — نفس مفتاح surge:opportunities:{CC}
|
||||
// اللي يقرأه get_surge_heatmap.php و winback_hotspot_targets.php و cron_kazan_adjuster.php
|
||||
if (isset($redis) && $redis !== null) {
|
||||
$knownCountries = ['SY', 'JO', 'EG', 'IQ'];
|
||||
foreach ($knownCountries as $cc) {
|
||||
$countryKey = "surge:opportunities:{$cc}";
|
||||
if (!empty($gridSurgeZonesByCountry[$cc])) {
|
||||
$redis->setex($countryKey, 600, json_encode($gridSurgeZonesByCountry[$cc]));
|
||||
echo "[".date('Y-m-d H:i:s')."] [$cc] Stored ".count($gridSurgeZonesByCountry[$cc])." surge zones.\n";
|
||||
} else {
|
||||
$redis->del($countryKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "[".date('Y-m-d H:i:s')."] cron_surge_opportunity completed successfully.\n";
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user