Update: 2026-07-06 17:00:43

This commit is contained in:
Hamza-Ayed
2026-07-06 17:00:43 +03:00
parent 61cb615ae7
commit e42d700245
21 changed files with 3212 additions and 119 deletions
+20 -13
View File
@@ -1,9 +1,9 @@
<?php
/**
* cron_gemini_advisor.php
* يعمل هذا الملف كـ Cron Job (يفضل أسبوعياً أو كل 3 أيام)
* وظيفته: أخذ معادلات المنافسين المكتشفة، وإرسالها إلى جيميناي لاستخراج تقرير تسويقي متقدم
* ثم حفظ التقرير في قاعدة البيانات ليراه مدير النظام في لوحة الإدارة.
* cron_gemini_advisor.php - Gemini Market Advisor
*
* يأخذ المعادلات المُكتشَفة من Pricing Engine (مع الفئات والمؤشرات الإحصائية)
* ويُرسلها إلى Gemini لتحليل استراتيجي - لم يعُد التحليل الإحصائي من مسؤوليته.
*/
require_once __DIR__ . '/../core/bootstrap.php';
@@ -16,7 +16,7 @@ try {
die("Database connection failed: " . $e->getMessage() . "\n");
}
echo "Starting Gemini Market Advisor Engine...\n";
echo "Starting Gemini Market Advisor Engine v2...\n";
// 1. إنشاء جدول الإحصائيات الذكية إذا لم يكن موجوداً
$sqlInit = "
@@ -28,30 +28,37 @@ CREATE TABLE IF NOT EXISTS `gemini_market_insights` (
";
$con->exec($sqlInit);
// 2. سحب آخر المعادلات المكتشفة
$stmt = $con->query("SELECT * FROM competitor_secret_formulas");
// 2. سحب المعادلات المُطوّرة (مع الفئات والمؤشرات)
$stmt = $con->query("
SELECT csf.*,
(SELECT surge_multiplier FROM competitor_surge_insights
WHERE competitor_name = csf.competitor_name
AND country_code = csf.country_code
ORDER BY detected_at DESC LIMIT 1) as recent_surge
FROM competitor_secret_formulas csf
WHERE csf.tier IS NOT NULL
ORDER BY csf.country_code, csf.competitor_name, csf.tier
");
$formulas = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($formulas)) {
echo "No formulas found to analyze. Run ai_formula_solver.php first.\n";
echo "No enriched formulas found. Run pricing-engine first.\n";
exit;
}
// 3. تمرير البيانات إلى Gemini
// 3. تمرير البيانات المُثراة إلى Gemini
$geminiService = new SiroGeminiService();
echo "Sending data to Gemini AI for strategic analysis...\n";
echo "Sending enriched data to Gemini AI for strategic analysis...\n";
$result = $geminiService->analyzeCompetitorFormulas($formulas);
if ($result && $result['status'] === 'success') {
$htmlReport = $result['html_report'];
// 4. حفظ التقرير في قاعدة البيانات
$stmtInsert = $con->prepare("INSERT INTO gemini_market_insights (insight_html) VALUES (:html)");
$stmtInsert->execute([':html' => $htmlReport]);
echo "Gemini analysis saved successfully! Admin can now view the strategic report.\n";
echo "Gemini analysis saved successfully! Admin can view the strategic report.\n";
} else {
echo "Failed to get analysis from Gemini. Check API keys and logs.\n";
}
?>