refactor: update OTP system to support user-specific verification tables with legacy encryption and multi-role authentication.
This commit is contained in:
@@ -97,22 +97,102 @@ class TrackingController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/** GET /v2/tracking/heatmap */
|
||||
/**
|
||||
* GET /v2/tracking/heatmap
|
||||
* المطورة لتطابق V1 مع تحسين الأداء
|
||||
*/
|
||||
public function heatmap(Request $request): JsonResponse
|
||||
{
|
||||
// Use spatial query for active drivers
|
||||
$drivers = DB::connection('tracking')->table('car_locations')
|
||||
->select('latitude', 'longitude', 'carType')
|
||||
->where('status', 'on')
|
||||
->where('updated_at', '>', now()->subMinutes(10))
|
||||
$precision = 2; // دقة الشبكة (~1 كم)
|
||||
$grid = [];
|
||||
|
||||
// 1. جلب طلبات الانتظار (Waiting) من قاعدة البيانات الأساسية
|
||||
$waitingRides = DB::connection('primary')->table('waitingRides')
|
||||
->select('start_lat', 'start_lng')
|
||||
->whereIn('status', ['wait', 'waiting'])
|
||||
->get();
|
||||
|
||||
foreach ($waitingRides as $ride) {
|
||||
$this->addToGrid($grid, $ride->start_lat, $ride->start_lng, $precision, 5);
|
||||
}
|
||||
|
||||
// 2. جلب الطلبات الضائعة (Timeout/Cancelled) من خادم الرحلات - آخر 20 دقيقة
|
||||
$missedRides = DB::connection('ride')->table('ride')
|
||||
->select('start_location')
|
||||
->whereIn('status', ['timeout', 'cancelled_no_driver_found'])
|
||||
->where('created_at', '>=', now()->subMinutes(20))
|
||||
->get();
|
||||
|
||||
foreach ($missedRides as $ride) {
|
||||
$parts = explode(',', $ride->start_location);
|
||||
if (count($parts) == 2) {
|
||||
$this->addToGrid($grid, $parts[0], $parts[1], $precision, 8);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. جلب الطلبات النشطة (Active) - آخر 15 دقيقة
|
||||
$activeRides = DB::connection('ride')->table('ride')
|
||||
->select('start_location')
|
||||
->where('created_at', '>=', now()->subMinutes(15))
|
||||
->whereNotIn('status', ['timeout', 'cancelled_no_driver_found'])
|
||||
->get();
|
||||
|
||||
foreach ($activeRides as $ride) {
|
||||
$parts = explode(',', $ride->start_location);
|
||||
if (count($parts) == 2) {
|
||||
$this->addToGrid($grid, $parts[0], $parts[1], $precision, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. معالجة البيانات النهائية (التصنيف والـ Surge)
|
||||
$finalData = [];
|
||||
foreach ($grid as $cell) {
|
||||
$score = $cell['score'];
|
||||
$count = $cell['count'];
|
||||
|
||||
$intensity = 'normal';
|
||||
$surge = 1.0;
|
||||
|
||||
if ($score >= 15 || $count >= 5) {
|
||||
$intensity = 'high';
|
||||
$surge = 1.5;
|
||||
} elseif ($score >= 8 || $count >= 3) {
|
||||
$intensity = 'medium';
|
||||
$surge = 1.2;
|
||||
}
|
||||
|
||||
$finalData[] = [
|
||||
'lat' => $cell['lat'],
|
||||
'lng' => $cell['lng'],
|
||||
'count' => $count,
|
||||
'intensity' => $intensity,
|
||||
'surge' => $surge
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $drivers,
|
||||
'data' => $finalData
|
||||
]);
|
||||
}
|
||||
|
||||
/** دالة مساعدة لتجميع النقاط في الشبكة */
|
||||
private function addToGrid(&$grid, $lat, $lng, $precision, $weight): void
|
||||
{
|
||||
if (empty($lat) || empty($lng)) return;
|
||||
|
||||
$rLat = round((float)$lat, $precision);
|
||||
$rLng = round((float)$lng, $precision);
|
||||
$key = "{$rLat},{$rLng}";
|
||||
|
||||
if (!isset($grid[$key])) {
|
||||
$grid[$key] = ['lat' => $rLat, 'lng' => $rLng, 'count' => 0, 'score' => 0];
|
||||
}
|
||||
|
||||
$grid[$key]['count']++;
|
||||
$grid[$key]['score'] += $weight;
|
||||
}
|
||||
|
||||
/** GET /v2/tracking/captain-stats */
|
||||
public function captainStats(Request $request): JsonResponse
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user