قرار المالك 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>
97 lines
3.1 KiB
PHP
97 lines
3.1 KiB
PHP
<?php
|
|
/**
|
|
* Nabeh Integration — Get User Recent Rides
|
|
*
|
|
* Returns the most recent rides for a user (driver or passenger)
|
|
* identified by phone number. Used by the complaint workflow to
|
|
* let the user pick which trip they're complaining about.
|
|
*
|
|
* Auth: X-API-Key header → NABEH_API_KEY
|
|
*
|
|
* Input:
|
|
* phone (required) — User's phone number
|
|
* limit (opt) — Max rides to return (default 5, max 20)
|
|
*
|
|
* Output:
|
|
* List of rides with id, date, time, price, locations, status, etc.
|
|
*/
|
|
|
|
require_once __DIR__ . '/../core/bootstrap.php';
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
|
header('Access-Control-Allow-Headers: Content-Type, X-API-Key');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
http_response_code(200);
|
|
exit;
|
|
}
|
|
|
|
$apiKey = $_SERVER['HTTP_X_API_KEY'] ?? '';
|
|
$expectedKey = getenv('NABEH_API_KEY') ?: '';
|
|
if (empty($apiKey) || $apiKey !== $expectedKey) {
|
|
http_response_code(401);
|
|
echo json_encode(['status' => 'failure', 'message' => 'Unauthorized']);
|
|
exit;
|
|
}
|
|
|
|
$raw = file_get_contents('php://input');
|
|
$input = json_decode($raw, true) ?: ($_SERVER['REQUEST_METHOD'] === 'GET' ? $_GET : []);
|
|
$phone = preg_replace('/\D+/', '', $input['phone'] ?? '');
|
|
$limit = min(max((int)($input['limit'] ?? 5), 1), 20);
|
|
|
|
if (empty($phone)) {
|
|
http_response_code(400);
|
|
echo json_encode(['status' => 'failure', 'message' => 'phone is required']);
|
|
exit;
|
|
}
|
|
|
|
$mainDb = Database::get('main');
|
|
$rideDb = Database::get('ride');
|
|
global $encryptionHelper;
|
|
|
|
// Resolve user
|
|
$encryptedPhone = $encryptionHelper->encryptData($phone);
|
|
global $blindIndex;
|
|
$dBidx = $blindIndex ? $blindIndex->index('driver.phone', $phone) : null;
|
|
$pBidx = $blindIndex ? $blindIndex->index('passengers.phone', $phone) : null;
|
|
$driver = $mainDb->prepare("SELECT id, 'driver' AS type FROM driver WHERE phone = :p OR (:bidx IS NOT NULL AND phone_bidx = :bidx) LIMIT 1");
|
|
$driver->execute([':p' => $encryptedPhone, ':bidx' => $dBidx]);
|
|
$user = $driver->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$user) {
|
|
$passenger = $mainDb->prepare("SELECT id, 'passenger' AS type FROM passengers WHERE phone = :p OR (:bidx IS NOT NULL AND phone_bidx = :bidx) LIMIT 1");
|
|
$passenger->execute([':p' => $encryptedPhone, ':bidx' => $pBidx]);
|
|
$user = $passenger->fetch(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
if (!$user) {
|
|
http_response_code(404);
|
|
echo json_encode(['status' => 'failure', 'message' => 'User not found']);
|
|
exit;
|
|
}
|
|
|
|
$col = $user['type'] === 'driver' ? 'driver_id' : 'passenger_id';
|
|
$stmt = $rideDb->prepare("
|
|
SELECT id, start_location, end_location, date, time, endtime,
|
|
price, price_for_driver, price_for_passenger,
|
|
status, paymentMethod, carType, distance, created_at
|
|
FROM ride
|
|
WHERE $col = :uid
|
|
ORDER BY created_at DESC
|
|
LIMIT :lim
|
|
");
|
|
$stmt->bindValue(':uid', $user['id'], PDO::PARAM_STR);
|
|
$stmt->bindValue(':lim', $limit, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$rides = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
echo json_encode([
|
|
'status' => 'success',
|
|
'user' => [
|
|
'id' => $user['id'],
|
|
'type' => $user['type'],
|
|
],
|
|
'rides' => $rides,
|
|
], JSON_UNESCAPED_UNICODE);
|