feat: add gamification endpoints for driver behavior
This commit is contained in:
32
ride/gamification/getWeeklyAggregate.php
Normal file
32
ride/gamification/getWeeklyAggregate.php
Normal 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([]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user