Update: 2026-08-02 17:52:28
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// food/merchant/browse.php — تصفح المطاعم النشطة في مدينة الزبون
|
||||
require_once __DIR__ . '/../connect_app.php';
|
||||
|
||||
$city = filterRequest('city');
|
||||
if (!$city) jsonError('city is required');
|
||||
|
||||
$category = filterRequest('category');
|
||||
|
||||
$sql = "SELECT id, name_ar, name_en, logo_url, cover_url, city, category,
|
||||
min_order_amount, avg_prep_minutes, rating_avg, rating_count,
|
||||
is_open_override, working_hours
|
||||
FROM food_merchants WHERE city=? AND status='active'";
|
||||
$params = [$city];
|
||||
|
||||
if ($category) {
|
||||
$sql .= " AND category=?";
|
||||
$params[] = $category;
|
||||
}
|
||||
$sql .= " ORDER BY rating_avg DESC, rating_count DESC";
|
||||
|
||||
$st = $food_con->prepare($sql);
|
||||
$st->execute($params);
|
||||
$merchants = $st->fetchAll();
|
||||
|
||||
foreach ($merchants as &$m) {
|
||||
$m['is_open'] = foodIsMerchantOpen($m);
|
||||
unset($m['working_hours'], $m['is_open_override']);
|
||||
}
|
||||
unset($m);
|
||||
|
||||
jsonSuccess(['merchants' => $merchants]);
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// food/merchant/details.php — تفاصيل مطعم واحد + قائمته الكاملة
|
||||
require_once __DIR__ . '/../connect_app.php';
|
||||
|
||||
$merchantId = filterRequest('merchant_id', 'int');
|
||||
if (!$merchantId) jsonError('merchant_id is required');
|
||||
|
||||
$st = $food_con->prepare(
|
||||
"SELECT id, name_ar, name_en, logo_url, cover_url, description_ar, city, address,
|
||||
latitude, longitude, category, min_order_amount, avg_prep_minutes,
|
||||
rating_avg, rating_count, is_open_override, working_hours
|
||||
FROM food_merchants WHERE id=? AND status='active' LIMIT 1"
|
||||
);
|
||||
$st->execute([$merchantId]);
|
||||
$merchant = $st->fetch();
|
||||
if (!$merchant) jsonError('Merchant not found', 404);
|
||||
|
||||
$merchant['is_open'] = foodIsMerchantOpen($merchant);
|
||||
unset($merchant['working_hours'], $merchant['is_open_override']);
|
||||
|
||||
$catSt = $food_con->prepare(
|
||||
"SELECT id, name_ar, name_en, sort_order FROM food_menu_categories
|
||||
WHERE merchant_id=? AND is_active=1 ORDER BY sort_order ASC"
|
||||
);
|
||||
$catSt->execute([$merchantId]);
|
||||
$categories = $catSt->fetchAll();
|
||||
|
||||
$itemSt = $food_con->prepare(
|
||||
"SELECT id, category_id, name_ar, name_en, description_ar, image_url, price,
|
||||
is_available, prep_minutes, sort_order
|
||||
FROM food_menu_items WHERE merchant_id=? ORDER BY sort_order ASC"
|
||||
);
|
||||
$itemSt->execute([$merchantId]);
|
||||
$items = $itemSt->fetchAll();
|
||||
|
||||
if ($items) {
|
||||
$itemIds = implode(',', array_map('intval', array_column($items, 'id')));
|
||||
$optSt = $food_con->query(
|
||||
"SELECT id, item_id, group_name_ar, is_required, max_select, choices, sort_order
|
||||
FROM food_item_options WHERE item_id IN ($itemIds) ORDER BY sort_order ASC"
|
||||
);
|
||||
$options = $optSt ? $optSt->fetchAll() : [];
|
||||
$byItem = [];
|
||||
foreach ($options as $o) {
|
||||
$o['choices'] = json_decode($o['choices'], true);
|
||||
$byItem[$o['item_id']][] = $o;
|
||||
}
|
||||
foreach ($items as &$it) {
|
||||
$it['options'] = $byItem[$it['id']] ?? [];
|
||||
}
|
||||
unset($it);
|
||||
}
|
||||
|
||||
foreach ($categories as &$c) {
|
||||
$c['items'] = array_values(array_filter($items, fn($i) => (int)$i['category_id'] === (int)$c['id']));
|
||||
}
|
||||
unset($c);
|
||||
|
||||
jsonSuccess(['merchant' => $merchant, 'categories' => $categories]);
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// food/merchant/search.php — بحث نصي في اسم المطعم أو أصنافه ضمن مدينة الزبون
|
||||
require_once __DIR__ . '/../connect_app.php';
|
||||
|
||||
$city = filterRequest('city');
|
||||
$q = filterRequest('q');
|
||||
if (!$city) jsonError('city is required');
|
||||
if (!$q || mb_strlen($q) < 2) jsonError('q must be at least 2 characters');
|
||||
|
||||
$like = '%' . $q . '%';
|
||||
|
||||
$st = $food_con->prepare(
|
||||
"SELECT DISTINCT m.id, m.name_ar, m.name_en, m.logo_url, m.city, m.category,
|
||||
m.rating_avg, m.rating_count
|
||||
FROM food_merchants m
|
||||
LEFT JOIN food_menu_items i ON i.merchant_id = m.id
|
||||
WHERE m.city = ? AND m.status='active'
|
||||
AND (m.name_ar LIKE ? OR m.name_en LIKE ? OR i.name_ar LIKE ? OR i.name_en LIKE ?)
|
||||
ORDER BY m.rating_avg DESC
|
||||
LIMIT 50"
|
||||
);
|
||||
$st->execute([$city, $like, $like, $like, $like]);
|
||||
|
||||
jsonSuccess(['merchants' => $st->fetchAll()]);
|
||||
Reference in New Issue
Block a user