Files
Siro/backend/food/admin/merchant_approve.php
T

24 lines
1003 B
PHP

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