Update: 2026-07-02 05:56:57
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* cron_gemini_advisor.php
|
||||
* يعمل هذا الملف كـ Cron Job (يفضل أسبوعياً أو كل 3 أيام)
|
||||
* وظيفته: أخذ معادلات المنافسين المكتشفة، وإرسالها إلى جيميناي لاستخراج تقرير تسويقي متقدم
|
||||
* ثم حفظ التقرير في قاعدة البيانات ليراه مدير النظام في لوحة الإدارة.
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../core/bootstrap.php';
|
||||
require_once __DIR__ . '/../core/Services/SiroGeminiService.php';
|
||||
require_once __DIR__ . '/../functions.php';
|
||||
|
||||
try {
|
||||
$con = Database::get('main');
|
||||
} catch (Exception $e) {
|
||||
die("Database connection failed: " . $e->getMessage() . "\n");
|
||||
}
|
||||
|
||||
echo "Starting Gemini Market Advisor Engine...\n";
|
||||
|
||||
// 1. إنشاء جدول الإحصائيات الذكية إذا لم يكن موجوداً
|
||||
$sqlInit = "
|
||||
CREATE TABLE IF NOT EXISTS `gemini_market_insights` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`insight_html` TEXT NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
";
|
||||
$con->exec($sqlInit);
|
||||
|
||||
// 2. سحب آخر المعادلات المكتشفة
|
||||
$stmt = $con->query("SELECT * FROM competitor_secret_formulas");
|
||||
$formulas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if (empty($formulas)) {
|
||||
echo "No formulas found to analyze. Run ai_formula_solver.php first.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
// 3. تمرير البيانات إلى Gemini
|
||||
$geminiService = new SiroGeminiService();
|
||||
echo "Sending 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";
|
||||
} else {
|
||||
echo "Failed to get analysis from Gemini. Check API keys and logs.\n";
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user