feat: add gamification endpoints for driver behavior

This commit is contained in:
Hamza-Ayed
2026-05-08 06:06:33 +03:00
parent 975527f1d0
commit 5928695212
5 changed files with 181 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
<?php
require_once __DIR__ . '/../../connect.php';
$driver_id = filterRequest("driver_id");
$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
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();
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
jsonSuccess([]);
}
?>