Update: 2026-07-13 22:23:21
This commit is contained in:
@@ -1,9 +1,20 @@
|
||||
<?php
|
||||
// backend/transit/cron_approaching_alerts.php
|
||||
// يُنفذ كل دقيقة عبر Cron Job لإرسال تنبيهات اقتراب الباص من المحطات (أقل من 2 كم)
|
||||
//
|
||||
// ملاحظة أداء: الاستعلام الأول رخيص (فهرس idx على status)، ولكل رحلة نشطة
|
||||
// فقط استعلامان إضافيان — ويُتجاهل فوراً أي رحلة بلا موقع GPS حديث (< 3 دقائق)
|
||||
// لتفادي ضرب القاعدة لرحلات متوقفة أو باصات فقدت الاتصال.
|
||||
|
||||
require_once __DIR__ . '/../core/bootstrap.php';
|
||||
require_once __DIR__ . '/connect_transit.php';
|
||||
require_once __DIR__ . '/functions.php';
|
||||
|
||||
try {
|
||||
$transit_con = Database::get('transit');
|
||||
} catch (Exception $e) {
|
||||
echo "[ERROR] Cannot connect to siroTransitDb: " . $e->getMessage() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// 1. جلب الرحلات النشطة حالياً
|
||||
$stTrips = $transit_con->query(
|
||||
@@ -11,17 +22,23 @@ $stTrips = $transit_con->query(
|
||||
);
|
||||
$trips = $stTrips->fetchAll();
|
||||
|
||||
if (empty($trips)) {
|
||||
echo "No active trips. Nothing to check.\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
foreach ($trips as $trip) {
|
||||
$tripId = (int)$trip['id'];
|
||||
$routeId = (int)$trip['route_id'];
|
||||
$currentSeq = (int)$trip['current_stop_seq'];
|
||||
|
||||
// 2. جلب موقع الباص من Redis
|
||||
// 2. جلب موقع الباص من Redis — تجاهل إن كان قديماً (> 3 دقائق، أي الباص فقد الاتصال)
|
||||
$pos = transitGetBusPosition($tripId);
|
||||
if (!$pos || empty($pos['lat'])) continue;
|
||||
if (empty($pos['ts']) || (time() - (int)$pos['ts']) > 180) continue;
|
||||
|
||||
$busLat = (double)$pos['lat'];
|
||||
$busLng = (double)$pos['lng'];
|
||||
$busLat = (float)$pos['lat'];
|
||||
$busLng = (float)$pos['lng'];
|
||||
|
||||
// 3. جلب المحطة التالية
|
||||
$nextSeq = $currentSeq + 1;
|
||||
@@ -35,8 +52,8 @@ foreach ($trips as $trip) {
|
||||
|
||||
if ($nextStop) {
|
||||
$stopId = (int)$nextStop['id'];
|
||||
$stopLat = (double)$nextStop['latitude'];
|
||||
$stopLng = (double)$nextStop['longitude'];
|
||||
$stopLat = (float)$nextStop['latitude'];
|
||||
$stopLng = (float)$nextStop['longitude'];
|
||||
$stopName = $nextStop['name_ar'];
|
||||
|
||||
// حساب المسافة تقريبياً
|
||||
|
||||
Reference in New Issue
Block a user