35 lines
1.7 KiB
PHP
35 lines
1.7 KiB
PHP
<?php
|
|
// food/courier/history.php — سجل طلبات التوصيل المنتهية لهذا السائق
|
|
require_once __DIR__ . '/../connect_courier.php';
|
|
|
|
$limit = (int)(filterRequest('limit', 'int') ?: 20);
|
|
$offset = (int)(filterRequest('offset', 'int') ?: 0);
|
|
$limit = max(1, min($limit, 50));
|
|
$offset = max(0, $offset);
|
|
|
|
// العنوان النصّي للزبون لا يُعاد في السجل — انتهت الحاجة التشغيلية إليه بالتسليم،
|
|
// ونفس قاعدة الحجب المطبَّقة في active.php.
|
|
$st = $food_con->prepare(
|
|
"SELECT o.id, o.status, o.merchant_id, m.name_ar AS merchant_name_ar, m.address AS merchant_address,
|
|
o.delivery_fee, o.grand_total, o.payment_method, o.rating,
|
|
o.courier_assigned_at, o.picked_up_at, o.delivered_at, o.created_at,
|
|
(SELECT COALESCE(SUM(quantity),0) FROM food_order_items WHERE order_id=o.id) AS items_count,
|
|
TIMESTAMPDIFF(MINUTE, o.courier_assigned_at, o.delivered_at) AS duration_minutes
|
|
FROM food_orders o
|
|
JOIN food_merchants m ON m.id = o.merchant_id
|
|
WHERE o.courier_id = ? AND o.status = 'delivered'
|
|
ORDER BY o.delivered_at DESC
|
|
LIMIT $limit OFFSET $offset"
|
|
);
|
|
$st->execute([$food_courier_id]);
|
|
|
|
$orders = array_map(static function (array $o): array {
|
|
$o['items_count'] = (int)$o['items_count'];
|
|
$o['delivery_fee'] = (int)$o['delivery_fee'];
|
|
$o['grand_total'] = (int)$o['grand_total'];
|
|
$o['duration_minutes'] = $o['duration_minutes'] === null ? null : (int)$o['duration_minutes'];
|
|
return $o;
|
|
}, $st->fetchAll());
|
|
|
|
jsonSuccess(['orders' => $orders, 'limit' => $limit, 'offset' => $offset]);
|