Update: 2026-08-02 17:52:28
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// food/admin/merchant_approve.php — اعتماد أو رفض مطعم بحالة pending_approval
|
||||
require_once __DIR__ . '/../connect_admin.php';
|
||||
|
||||
$merchantId = filterRequest('merchant_id', 'int');
|
||||
$action = filterRequest('action'); // 'approve' | 'reject'
|
||||
if (!$merchantId || !in_array($action, ['approve', 'reject'], true)) {
|
||||
jsonError('merchant_id and action (approve|reject) are required');
|
||||
}
|
||||
|
||||
$st = $food_con->prepare("SELECT id, status FROM food_merchants WHERE id=? LIMIT 1");
|
||||
$st->execute([$merchantId]);
|
||||
$merchant = $st->fetch();
|
||||
if (!$merchant) jsonError('Merchant not found', 404);
|
||||
if ($merchant['status'] !== 'pending_approval') jsonError('Merchant is not pending approval', 409);
|
||||
|
||||
$newStatus = $action === 'approve' ? 'active' : 'rejected';
|
||||
|
||||
$food_con->prepare(
|
||||
"UPDATE food_merchants SET status=?, approved_by=?, approved_at=NOW() WHERE id=?"
|
||||
)->execute([$newStatus, $food_admin_id, $merchantId]);
|
||||
|
||||
jsonSuccess(['merchant_id' => $merchantId, 'status' => $newStatus]);
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// food/admin/merchant_create.php — إنشاء مطعم جديد بحالة pending_approval + حساب مالكه
|
||||
require_once __DIR__ . '/../connect_admin.php';
|
||||
|
||||
requireFoodFields(['name_ar', 'city', 'address', 'latitude', 'longitude', 'owner_name', 'owner_phone', 'owner_password']);
|
||||
|
||||
$nameAr = filterRequest('name_ar');
|
||||
$nameEn = filterRequest('name_en');
|
||||
$city = filterRequest('city');
|
||||
$address = filterRequest('address');
|
||||
$lat = filterRequest('latitude', 'float');
|
||||
$lng = filterRequest('longitude', 'float');
|
||||
$category = filterRequest('category');
|
||||
$commission = filterRequest('commission_percent', 'float') ?? (float)(getenv('FOOD_COMMISSION_PERCENT') ?: 15);
|
||||
|
||||
$ownerName = filterRequest('owner_name');
|
||||
$ownerPhone = normalizePhone(filterRequest('owner_phone'));
|
||||
$ownerPassword = filterRequest('owner_password');
|
||||
|
||||
if (strlen($ownerPassword) < 8) jsonError('owner_password must be at least 8 characters');
|
||||
|
||||
$dupSt = $food_con->prepare("SELECT id FROM food_merchant_users WHERE phone=? LIMIT 1");
|
||||
$dupSt->execute([$ownerPhone]);
|
||||
if ($dupSt->fetch()) jsonError('A merchant account already uses this phone', 409);
|
||||
|
||||
$food_con->beginTransaction();
|
||||
try {
|
||||
$food_con->prepare(
|
||||
"INSERT INTO food_merchants
|
||||
(name_ar, name_en, city, address, latitude, longitude, category, commission_percent, status)
|
||||
VALUES (?,?,?,?,?,?,?,?,'pending_approval')"
|
||||
)->execute([$nameAr, $nameEn, $city, $address, $lat, $lng, $category, $commission]);
|
||||
|
||||
$merchantId = (int)$food_con->lastInsertId();
|
||||
|
||||
$food_con->prepare(
|
||||
"INSERT INTO food_merchant_users (merchant_id, name, phone, role, password_hash)
|
||||
VALUES (?,?,?,'owner',?)"
|
||||
)->execute([$merchantId, $ownerName, $ownerPhone, password_hash($ownerPassword, PASSWORD_DEFAULT)]);
|
||||
|
||||
$food_con->commit();
|
||||
} catch (Throwable $e) {
|
||||
$food_con->rollBack();
|
||||
appLog('[FOOD][ADMIN][merchant_create] ' . $e->getMessage(), 'ERROR');
|
||||
jsonError('Failed to create merchant', 500);
|
||||
}
|
||||
|
||||
jsonSuccess(['merchant_id' => $merchantId, 'status' => 'pending_approval'], 'Merchant created — awaiting approval');
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// food/admin/merchants.php — قائمة المطاعم لإدارة سيرو (فلترة حسب الحالة)
|
||||
require_once __DIR__ . '/../connect_admin.php';
|
||||
|
||||
$status = filterRequest('status') ?: 'all';
|
||||
$allowed = ['all', 'pending_approval', 'active', 'paused', 'suspended', 'rejected'];
|
||||
if (!in_array($status, $allowed, true)) $status = 'all';
|
||||
|
||||
$sql = "SELECT id, name_ar, name_en, city, category, status, commission_percent,
|
||||
rating_avg, rating_count, created_at, approved_at
|
||||
FROM food_merchants";
|
||||
$params = [];
|
||||
if ($status !== 'all') {
|
||||
$sql .= " WHERE status=?";
|
||||
$params[] = $status;
|
||||
}
|
||||
$sql .= " ORDER BY created_at DESC";
|
||||
|
||||
$st = $food_con->prepare($sql);
|
||||
$st->execute($params);
|
||||
|
||||
jsonSuccess(['merchants' => $st->fetchAll()]);
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// food/admin/payouts.php — تقرير تسويات المطاعم للفترة المطلوبة (توليد لا صرف آلي)
|
||||
//
|
||||
// ⚠️ هذا يُنتج تقريراً محاسبياً (food_merchant_payouts بحالة pending) — لا يحوّل
|
||||
// أموالاً فعلياً. الصرف الفعلي للمطاعم والسائقين خارج نطاق هذه الوحدة حتى يُؤكَّد
|
||||
// عقد S2S مخصص لذلك (انظر التنبيهات في food/functions.php حول foodWalletMove).
|
||||
require_once __DIR__ . '/../connect_admin.php';
|
||||
|
||||
$merchantId = filterRequest('merchant_id', 'int');
|
||||
$periodStart = filterRequest('period_start');
|
||||
$periodEnd = filterRequest('period_end');
|
||||
requireFoodFields(['merchant_id', 'period_start', 'period_end']);
|
||||
|
||||
$st = $food_con->prepare(
|
||||
"SELECT COUNT(*) orders_count, COALESCE(SUM(items_total),0) gross_amount, COALESCE(SUM(commission_amount),0) commission_amount
|
||||
FROM food_orders
|
||||
WHERE merchant_id=? AND status='delivered' AND delivered_at BETWEEN ? AND ?"
|
||||
);
|
||||
$st->execute([$merchantId, $periodStart, $periodEnd]);
|
||||
$summary = $st->fetch();
|
||||
|
||||
$netPayout = (int)$summary['gross_amount'] - (int)$summary['commission_amount'];
|
||||
|
||||
$food_con->prepare(
|
||||
"INSERT INTO food_merchant_payouts (merchant_id, period_start, period_end, orders_count, gross_amount, commission_amount, net_payout, status)
|
||||
VALUES (?,?,?,?,?,?,?,'pending')"
|
||||
)->execute([
|
||||
$merchantId, $periodStart, $periodEnd, $summary['orders_count'],
|
||||
$summary['gross_amount'], $summary['commission_amount'], $netPayout,
|
||||
]);
|
||||
|
||||
jsonSuccess([
|
||||
'merchant_id' => $merchantId,
|
||||
'orders_count' => (int)$summary['orders_count'],
|
||||
'gross_amount' => (int)$summary['gross_amount'],
|
||||
'commission_amount' => (int)$summary['commission_amount'],
|
||||
'net_payout' => $netPayout,
|
||||
'status' => 'pending',
|
||||
], 'Payout report generated');
|
||||
Reference in New Issue
Block a user