add new featurs like gamination

This commit is contained in:
Hamza-Ayed
2026-05-08 22:46:34 +03:00
parent 5928695212
commit fc74c20730
4 changed files with 72 additions and 62 deletions

View File

@@ -3,21 +3,23 @@ require_once __DIR__ . '/../../connect.php';
$type = isset($_POST['type']) ? filterRequest("type") : 'trips';
if ($type === 'earnings') {
try {
if ($type === 'earnings') {
$sql = "
SELECT
d.id as driver_id,
COALESCE(d.name, d.nameArabic, d.firstName, 'Driver') as name,
d.personal_photo as photoUrl,
COALESCE(SUM(p.amount), 0) as value
COALESCE(SUM(r.price_for_driver), 0) as value
FROM `driver` d
JOIN `payments` p ON d.id = p.driverID
WHERE p.created_at >= DATE(NOW() - INTERVAL WEEKDAY(NOW()) DAY)
JOIN `ride` r ON d.id = r.driver_id
WHERE r.status = 'Finished'
AND r.created_at >= DATE(NOW() - INTERVAL WEEKDAY(NOW()) DAY)
GROUP BY d.id
ORDER BY value DESC
LIMIT 10
";
} else {
} else {
// Default to trips
$sql = "
SELECT
@@ -33,10 +35,14 @@ if ($type === 'earnings') {
ORDER BY value DESC
LIMIT 10
";
}
}
$stmt = $con->prepare($sql);
$stmt->execute();
$stmt = $con->prepare($sql);
$stmt->execute();
} catch (PDOException $e) {
error_log("getLeaderboard Error: " . $e->getMessage());
jsonError("Database error occurred");
}
if ($stmt->rowCount() > 0) {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

View File

@@ -3,30 +3,34 @@ require_once __DIR__ . '/../../connect.php';
$driver_id = filterRequest("driver_id");
$sql = "
try {
$sql = "
SELECT
DATE(r.created_at) as day,
COUNT(r.id) as trips,
COALESCE(SUM(p.amount), 0) as earnings,
COALESCE(SUM(r.duration)/60, 0) as hours
COALESCE(SUM(r.price_for_driver), 0) as earnings,
COALESCE(SUM(TIMESTAMPDIFF(MINUTE, r.time, r.endtime))/60, 0) as hours
FROM `ride` r
LEFT JOIN `payments` p ON r.id = p.rideId
WHERE r.driver_id = :driver_id
AND r.status = 'Finished'
AND r.created_at >= DATE(NOW()) - INTERVAL 6 DAY
GROUP BY DATE(r.created_at)
ORDER BY DATE(r.created_at) ASC
";
";
$stmt = $con->prepare($sql);
$stmt->bindParam(':driver_id', $driver_id, PDO::PARAM_INT);
$stmt->execute();
$stmt = $con->prepare($sql);
$stmt->bindParam(':driver_id', $driver_id, PDO::PARAM_INT);
$stmt->execute();
if ($stmt->rowCount() > 0) {
if ($stmt->rowCount() > 0) {
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
jsonSuccess($rows);
} else {
// Return empty array instead of error so the app doesn't crash
} else {
jsonSuccess([]);
}
} catch (PDOException $e) {
// Return empty but log error
error_log("getWeeklyAggregate Error: " . $e->getMessage());
jsonError("Database error occurred");
}
?>

View File

@@ -2,10 +2,10 @@
require_once __DIR__ . '/../../connect.php';
function generateUniqueCode($con, $length = 7) {
function generateUniqueCode($con) {
while (true) {
$letters = substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 4);
$numbers = substr(str_shuffle("0123456789"), 0, 3);
$letters = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ"), 0, 2); // Excluded I, O for clarity
$numbers = substr(str_shuffle("23456789"), 0, 3); // Excluded 0, 1 for clarity
$code = $letters . $numbers;
$stmt = $con->prepare("SELECT COUNT(*) FROM invites WHERE inviteCode = ?");
@@ -38,7 +38,7 @@ if ($checkStmt->rowCount() > 0) {
// تحديث الدعوة الحالية
$updateSql = "UPDATE `invites` SET `driverId` = :driverId, `expirationTime` = :expirationTime, `createdAt` = NOW() WHERE `id` = :id";
$updateStmt = $con->prepare($updateSql);
$expirationTime = date('Y-m-d H:i:s', strtotime('+1 hour'));
$expirationTime = date('Y-m-d H:i:s', strtotime('+24 hours'));
$updateStmt->bindParam(':driverId', $driverId, PDO::PARAM_INT);
$updateStmt->bindParam(':expirationTime', $expirationTime);
$updateStmt->bindParam(':id', $existingInvite['id'], PDO::PARAM_INT);
@@ -59,7 +59,7 @@ if ($checkStmt->rowCount() > 0) {
} else {
// إنشاء دعوة جديدة
$inviteCode = generateUniqueCode($con);
$expirationTime = date('Y-m-d H:i:s', strtotime('+1 hour'));
$expirationTime = date('Y-m-d H:i:s', strtotime('+24 hours'));
$sql = "INSERT INTO `invites` (`driverId`, `inviterDriverPhone`, `inviteCode`, `expirationTime`, `createdAt`, `isInstall`)
VALUES (:driverId, :inviterDriverPhone, :inviteCode, :expirationTime, NOW(), 0)";

View File

@@ -11,7 +11,7 @@ $sql = "SELECT
i.`isInstall`,
d.`id` AS driverInviterId,
d.`phone` AS invitorPhone,
d.`name_arabic` AS invitorName,
d.`nameArabic` AS invitorName,
COALESCE(r.finishedTrips, 0) AS countOfInvitDriver
FROM
`invites` i