Files
Siro/backend/serviceapp/getPassengersByPhone.php
2026-06-26 04:04:04 +03:00

110 lines
4.7 KiB
PHP

<?php
require_once __DIR__ . '/../connect.php';
$phone = filterRequest("phone");
$phoneEncrypted = $encryptionHelper->encryptData($phone);
$sql = "SELECT
p.*,
COALESCE(r.id, 0) AS ride_id,
COALESCE(r.start_location, '') AS start_location,
COALESCE(r.end_location, '') AS end_location,
COALESCE(r.date, '1970-01-01') AS ride_date,
COALESCE(r.time, '00:00:00') AS ride_time,
COALESCE(r.endtime, '00:00:00') AS ride_endtime,
COALESCE(r.price, 0) AS price,
COALESCE(r.passenger_id, 0) AS ride_passenger_id,
COALESCE(r.driver_id, 0) AS driver_id,
COALESCE(r.status, '') AS ride_status,
COALESCE(r.paymentMethod, '') AS ride_payment_method,
COALESCE(r.carType, '') AS car_type,
COALESCE(r.created_at, '1970-01-01 00:00:00') AS ride_created_at,
COALESCE(r.updated_at, '1970-01-01 00:00:00') AS ride_updated_at,
COALESCE(r.DriverIsGoingToPassenger, 0) AS driver_is_going_to_passenger,
COALESCE(r.rideTimeStart, '1970-01-01 00:00:00') AS ride_time_start,
COALESCE(r.rideTimeFinish, '1970-01-01 00:00:00') AS ride_time_finish,
COALESCE(r.price_for_driver, 0) AS price_for_driver,
COALESCE(r.price_for_passenger, 0) AS price_for_passenger,
COALESCE(r.distance, 0) AS distance
FROM
passengers p
LEFT JOIN
ride r ON p.id = r.passenger_id AND r.id = (
SELECT id
FROM ride
WHERE passenger_id = p.id
ORDER BY date DESC, time DESC
LIMIT 1
)
WHERE
p.phone = :phone";
$stmt = $con->prepare($sql);
$stmt->bindParam(':phone', $phoneEncrypted);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmtKazan = $con->prepare("SELECT country FROM kazan LIMIT 1");
$stmtKazan->execute();
$kazan = $stmtKazan->fetch(PDO::FETCH_ASSOC) ?: ["country" => "Jordan"];
$country = $kazan['country'] ?? 'Jordan';
$walletServer = "https://walletintaleq.intaleq.xyz";
if (strtolower($country) == 'jordan') {
$walletServer = getenv('WALLET_SERVER_JORDAN') ?: "https://walletintaleq.intaleq.xyz";
} elseif (strtolower($country) == 'egypt') {
$walletServer = getenv('WALLET_SERVER_EGYPT') ?: "https://walletintaleq.intaleq.xyz";
} else {
$walletServer = getenv('WALLET_SERVER_SYRIA') ?: "https://walletintaleq.intaleq.xyz";
}
foreach ($rows as &$row) {
if (isset($row['phone'])) $row['phone'] = $encryptionHelper->decryptData($row['phone']);
if (isset($row['email'])) $row['email'] = $encryptionHelper->decryptData($row['email']);
if (isset($row['gender'])) $row['gender'] = $encryptionHelper->decryptData($row['gender']);
if (isset($row['birthdate'])) $row['birthdate'] = $encryptionHelper->decryptData($row['birthdate']);
if (isset($row['site'])) $row['site'] = $encryptionHelper->decryptData($row['site']);
if (isset($row['first_name'])) $row['first_name'] = $encryptionHelper->decryptData($row['first_name']);
if (isset($row['last_name'])) $row['last_name'] = $encryptionHelper->decryptData($row['last_name']);
if (isset($row['employmentType']))$row['employmentType'] = $encryptionHelper->decryptData($row['employmentType']);
if (isset($row['maritalStatus'])) $row['maritalStatus'] = $encryptionHelper->decryptData($row['maritalStatus']);
unset($row['password']);
$passenger_id = $row['id'] ?? '';
if (!empty($passenger_id)) {
$walletUrl = "$walletServer/v2/main/ride/passengerWallet/get_s2s_wallet.php";
$ch = curl_init($walletUrl);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(["passenger_id" => $passenger_id]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_HTTPHEADER => [
'Content-Type: application/x-www-form-urlencoded',
'X-S2S-Api-Key: ' . getenv('S2S_SHARED_KEY')
]
]);
$s2sRes = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$totalWallet = 0.0;
if ($httpCode === 200 && $s2sRes) {
$resDecoded = json_decode($s2sRes, true);
if ($resDecoded && isset($resDecoded['status']) && $resDecoded['status'] === 'success') {
$totalWallet = (float)($resDecoded['message']['totalWallet'] ?? 0.0);
}
}
$row['passenger_wallet_balance'] = $totalWallet;
} else {
$row['passenger_wallet_balance'] = 0;
}
}
jsonSuccess($rows);
} else {
jsonError("No passenger found");
}
?>