قرار المالك 2026-07-27: باك إند سيرو PHP هو المعتمد، وتطبيقاته المجرّبة ميدانياً تحل محل إعادة البناء المؤرشفة. سيرو نفسه لم يُمسّ. الخريطة: backend · payment_server · loction_server · ride_server · passenger_server · docker · dashboard · stress_test → الجذر siro_rider → apps/rider siro_driver → apps/driver siro_admin → dashboards/admin siro_service → dashboards/service android_bot → apps/android_bot socialBot → apps/socialBot نُسخ المتعقَّب في git سيرو فقط عبر `git archive` (3,198 ملفاً / ~169 م.ب) لا `cp -r` — فاستُثنيت مخلفات البناء تلقائياً. بلا أي تعديل محتوى عمداً: كل ما يلي يصير فرقاً مقروءاً مقابل المصدر. لم يُستورد وسببه: siromove.com (الموقع التسويقي يبقى marketing/ في تريبز، سيرو فيه 8 ملفات) · docs و planning (تريبز له docs/ الخاص) · deploy.sh (ليس نشراً على سيرفر بل `git add . && git push origin --all` — فخّ في مستودع آخر) · transit_dashboard (بانتظار قرار مصير backend-transit و dashboards/transit-web). ⚠️ لا يبني بعد — ثلاثة نواقص متوقعة ومقصودة: 1. `.env` و `lib/env/env.g.dart` غير متعقَّبين في سيرو (أسرار لكل مستأجر): كل تطبيق فلاتر يحتاج .env خاصاً ثم توليد env.g.dart بـ build_runner. 2. إعدادات Firebase (9 ملفات google-services.json و GoogleService-Info.plist) يستبعدها .gitignore تريبز — ولكل مستأجر مشروع Firebase خاص أصلاً. 3. apps/driver في سيرو يشير إلى `../../Intaleq/packages/get` خارج المستودع → يجب ضمّ الحزم داخله أسوة بـ apps/rider. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
111 lines
4.3 KiB
PHP
111 lines
4.3 KiB
PHP
<?php
|
|
/**
|
|
* what_if_simulator.php
|
|
* يحاكي تأثير تغيير الأسعار على مؤشر التنافسية (PCI) وحصة السوق المتوقعة
|
|
*/
|
|
|
|
require_once __DIR__ . '/../../connect.php';
|
|
|
|
if ($role !== 'admin' && $role !== 'super_admin') {
|
|
http_response_code(403);
|
|
echo json_encode(['status' => 'failure', 'message' => 'Unauthorized']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$countryCode = filterRequest('country_code');
|
|
$proposedSpeedPrice = (float)filterRequest('speed_price');
|
|
|
|
if (!$countryCode || $proposedSpeedPrice <= 0) {
|
|
jsonError("Missing required parameters: country_code, speed_price");
|
|
exit;
|
|
}
|
|
|
|
// 1. Fetch recent competitor trips (last 7 days, limit 500 for fast simulation)
|
|
$sql = "SELECT (price_amount / price_per_km) AS distance_km, price_amount AS total_price, competitor_name
|
|
FROM scraped_competitor_prices
|
|
WHERE country_code = :country
|
|
AND price_per_km > 0
|
|
AND created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)
|
|
ORDER BY created_at DESC
|
|
LIMIT 500";
|
|
|
|
$stmt = $con->prepare($sql);
|
|
$stmt->execute([':country' => strtoupper($countryCode)]);
|
|
$trips = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if (empty($trips)) {
|
|
jsonError("No competitor data available for simulation in this country.");
|
|
exit;
|
|
}
|
|
|
|
// 2. Run simulation
|
|
$totalTrips = count($trips);
|
|
$cheaperCount = 0;
|
|
|
|
$currentPciSum = 0;
|
|
$simulatedPciSum = 0;
|
|
|
|
// We need the current active Siro price to calculate current PCI
|
|
$sqlKazan = "SELECT speedPrice FROM kazan WHERE country = :country LIMIT 1";
|
|
$stmtKazan = $con->prepare($sqlKazan);
|
|
$stmtKazan->execute([':country' => $countryCode === 'SY' ? 'Syria' : ($countryCode === 'JO' ? 'Jordan' : 'Egypt')]);
|
|
$kazanRow = $stmtKazan->fetch(PDO::FETCH_ASSOC);
|
|
$currentSpeedPrice = $kazanRow ? (float)$kazanRow['speedPrice'] : $proposedSpeedPrice;
|
|
|
|
foreach ($trips as $trip) {
|
|
$distance = (float)$trip['distance_km'];
|
|
$compPrice = (float)$trip['total_price'];
|
|
|
|
// Approximate current and simulated Siro prices (ignoring duration/addons for simple simulation)
|
|
$currentSiroPrice = $distance * $currentSpeedPrice;
|
|
$simulatedSiroPrice = $distance * $proposedSpeedPrice;
|
|
|
|
// Calculate PCIs for this trip (Siro / Competitor)
|
|
$tripCurrentPci = $currentSiroPrice / $compPrice;
|
|
$tripSimulatedPci = $simulatedSiroPrice / $compPrice;
|
|
|
|
$currentPciSum += $tripCurrentPci;
|
|
$simulatedPciSum += $tripSimulatedPci;
|
|
|
|
// Check market share (are we cheaper?)
|
|
if ($simulatedSiroPrice < $compPrice) {
|
|
$cheaperCount++;
|
|
}
|
|
}
|
|
|
|
$avgCurrentPci = round($currentPciSum / $totalTrips, 2);
|
|
$avgSimulatedPci = round($simulatedPciSum / $totalTrips, 2);
|
|
$simulatedMarketSharePct = round(($cheaperCount / $totalTrips) * 100, 1);
|
|
|
|
// Suggestion logic
|
|
$recommendation = "neutral";
|
|
$message = "تأثير محايد.";
|
|
|
|
if ($avgSimulatedPci > 1.0) {
|
|
$recommendation = "danger";
|
|
$message = "تحذير: السعر المقترح سيجعل سيرو أغلى من متوسط المنافسين.";
|
|
} elseif ($avgSimulatedPci < 0.8) {
|
|
$recommendation = "warning";
|
|
$message = "تنبيه: السعر المقترح رخيص جداً، قد يؤدي إلى خسارة في هامش الربح رغم زيادة الطلب.";
|
|
} elseif ($avgSimulatedPci >= 0.9 && $avgSimulatedPci <= 0.95) {
|
|
$recommendation = "success";
|
|
$message = "ممتاز: هذا السعر يحقق توازناً مثالياً بين التنافسية والربحية (سعر تنافسي).";
|
|
}
|
|
|
|
jsonSuccess([
|
|
'total_trips_simulated' => $totalTrips,
|
|
'current_speed_price' => $currentSpeedPrice,
|
|
'proposed_speed_price' => $proposedSpeedPrice,
|
|
'current_pci' => $avgCurrentPci,
|
|
'simulated_pci' => $avgSimulatedPci,
|
|
'simulated_market_share_percent' => $simulatedMarketSharePct,
|
|
'recommendation_status' => $recommendation,
|
|
'recommendation_message' => $message
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
error_log("[what_if_simulator] Error: " . $e->getMessage());
|
|
jsonError("Simulation failed");
|
|
}
|