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]);