Initial commit with updated Auth and media ignored
This commit is contained in:
38
ride/driver_order/add.php
Executable file
38
ride/driver_order/add.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
// استقبال المتغيرات
|
||||
$driver_id = filterRequest("driver_id");
|
||||
$order_id = filterRequest("order_id");
|
||||
$status = filterRequest("status");
|
||||
|
||||
// التحقق من وجود order_id مسبقًا
|
||||
$checkSql = "SELECT `order_id` FROM `driver_orders` WHERE `order_id` = ?";
|
||||
$checkStmt = $con->prepare($checkSql);
|
||||
$checkStmt->execute([$order_id]);
|
||||
|
||||
if ($checkStmt->rowCount() > 0) {
|
||||
// تحديث السجل إذا كان موجودًا
|
||||
$updateSql = "UPDATE `driver_orders` SET `driver_id` = ?, `status` = ?, `created_at` = NOW() WHERE `order_id` = ?";
|
||||
$updateStmt = $con->prepare($updateSql);
|
||||
$updateStmt->execute([$driver_id, $status, $order_id]);
|
||||
|
||||
if ($updateStmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Driver order data updated successfully");
|
||||
} else {
|
||||
jsonError("Failed to update driver order data");
|
||||
}
|
||||
} else {
|
||||
// إدخال سجل جديد إذا لم يكن موجودًا
|
||||
$insertSql = "INSERT INTO `driver_orders` (`driver_id`, `order_id`, `created_at`, `status`) VALUES (?, ?, NOW(), ?)";
|
||||
$insertStmt = $con->prepare($insertSql);
|
||||
$insertStmt->execute([$driver_id, $order_id, $status]);
|
||||
|
||||
if ($insertStmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Driver order data saved successfully");
|
||||
} else {
|
||||
jsonError("Failed to save driver order data");
|
||||
}
|
||||
}
|
||||
?>
|
||||
0
ride/driver_order/delete.php
Normal file
0
ride/driver_order/delete.php
Normal file
0
ride/driver_order/error_log
Normal file
0
ride/driver_order/error_log
Normal file
75
ride/driver_order/get.php
Executable file
75
ride/driver_order/get.php
Executable file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$driver_id = filterRequest("driver_id");
|
||||
$order_id = filterRequest("order_id");
|
||||
|
||||
if ($driver_id != null) {
|
||||
|
||||
// 1. First, get the statistics for the driver
|
||||
$stats_sql = "
|
||||
SELECT
|
||||
COUNT(*) AS total_rides,
|
||||
SUM(CASE WHEN status = 'Apply' THEN 1 ELSE 0 END) AS total_applied,
|
||||
SUM(CASE WHEN status = 'Refused' THEN 1 ELSE 0 END) AS total_refused
|
||||
FROM driver_orders
|
||||
WHERE
|
||||
driver_id = :driver_id
|
||||
AND MONTH(created_at) = MONTH(CURRENT_DATE())
|
||||
AND YEAR(created_at) = YEAR(CURRENT_DATE())
|
||||
";
|
||||
$stats_stmt = $con->prepare($stats_sql);
|
||||
$stats_stmt->execute([':driver_id' => $driver_id]);
|
||||
$stats = $stats_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
// Calculate the average
|
||||
if ($stats && $stats['total_rides'] > 0) {
|
||||
$stats['averageApplied'] = $stats['total_applied'] / $stats['total_rides'];
|
||||
} else {
|
||||
$stats['averageApplied'] = 0;
|
||||
}
|
||||
|
||||
|
||||
// 2. Second, get the actual order history
|
||||
$orders_sql = "
|
||||
SELECT * FROM driver_orders
|
||||
WHERE
|
||||
driver_id = :driver_id
|
||||
AND MONTH(created_at) = MONTH(CURRENT_DATE())
|
||||
AND YEAR(created_at) = YEAR(CURRENT_DATE())
|
||||
ORDER BY created_at DESC
|
||||
";
|
||||
$orders_stmt = $con->prepare($orders_sql);
|
||||
$orders_stmt->execute([':driver_id' => $driver_id]);
|
||||
$orders = $orders_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// 3. Combine the results into one response
|
||||
|
||||
|
||||
jsonSuccess($orders);
|
||||
|
||||
|
||||
} elseif ($order_id != null) {
|
||||
// This part remains the same, but let's ensure it's correct
|
||||
$sql = "
|
||||
SELECT * FROM driver_orders
|
||||
WHERE order_id = :order_id
|
||||
AND MONTH(created_at) = MONTH(CURRENT_DATE())
|
||||
AND YEAR(created_at) = YEAR(CURRENT_DATE())
|
||||
";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute([':order_id' => $order_id]);
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess($result);
|
||||
} else {
|
||||
jsonError("No driver order data found for this order_id");
|
||||
}
|
||||
|
||||
} else {
|
||||
jsonError("No driver_id or order_id provided");
|
||||
}
|
||||
|
||||
?>
|
||||
25
ride/driver_order/getOrderCancelStatus.php
Normal file
25
ride/driver_order/getOrderCancelStatus.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$order_id = filterRequest("order_id");
|
||||
|
||||
$sql = "SELECT `id`, `driver_id`, `order_id`, `created_at`, `status` FROM `driver_orders` WHERE `order_id` = :order_id";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(":order_id", $order_id, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($row) {
|
||||
echo json_encode([
|
||||
"status" => "success",
|
||||
"data" => $row
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
"status" => "failure",
|
||||
"message" => "No driver order data found for the specified order_id"
|
||||
]);
|
||||
}
|
||||
?>
|
||||
32
ride/driver_order/update.php
Normal file
32
ride/driver_order/update.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
// استقبال المتغيرات
|
||||
$order_id = filterRequest("order_id");
|
||||
$status = filterRequest("status");
|
||||
$notes = filterRequest("notes");
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// التحقق من الملاحظات: إذا كانت فارغة نضع قيمة افتراضية
|
||||
// ---------------------------------------------------------
|
||||
if (empty($notes)) {
|
||||
$notes = "Nothing"; // أو يمكنك كتابة "لا توجد ملاحظات"
|
||||
}
|
||||
|
||||
// تصحيح جملة SQL: يجب استخدام الفاصلة (,) للفصل بين الحقول وليس (and)
|
||||
$sql = "UPDATE `driver_orders` SET `status` = :status, `notes` = :notes WHERE `order_id` = :order_id";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindParam(":status", $status);
|
||||
$stmt->bindParam(":order_id", $order_id);
|
||||
$stmt->bindParam(":notes", $notes);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
// التحقق من النتيجة
|
||||
if ($stmt->rowCount() > 0) {
|
||||
jsonSuccess(null, "Driver order data updated successfully");
|
||||
} else {
|
||||
jsonError("Failed to update driver order data"); // أو لم يحدث تغيير في البيانات
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user