File manager - Edit - /home/webapp69.cm.in.th/u69319090028/Shop/app/Services/AdminSellerService.php
Back
<?php /** * AdminSellerService * Manages store listings, suspension, reactivation and official status via admin */ require_once __DIR__ . '/../Models/Store.php'; require_once __DIR__ . '/../Models/AdminAuditLog.php'; class AdminSellerService { private Store $storeModel; private AdminAuditLog $auditLog; public function __construct() { $this->storeModel = new Store(); $this->auditLog = new AdminAuditLog(); } public function getStores(array $filters, int $page = 1, int $perPage = 20): array { $offset = ($page - 1) * $perPage; $stores = $this->storeModel->getAdminStores($filters, $perPage, $offset); $total = $this->storeModel->countAdminStores($filters); return [ 'stores' => $stores, 'total' => $total, 'page' => $page, 'per_page' => $perPage, 'total_pages' => max(1, (int)ceil($total / $perPage)), ]; } public function getStoreDetail(int $storeId): ?array { $store = $this->storeModel->findAdminStore($storeId); if (!$store) return null; $store['stats'] = $this->storeModel->getStoreStats($storeId); return $store; } public function suspendStore(int $storeId, int $adminId): array { $store = $this->storeModel->findAdminStore($storeId); if (!$store) return ['success' => false, 'message' => 'ไม่พบร้านค้า']; $ok = $this->storeModel->suspendStore($storeId); if ($ok) { $this->auditLog->record($adminId, 'seller.suspend', 'sellers', 'store', $storeId, "Suspended store: {$store['store_name']}"); } return ['success' => $ok, 'message' => $ok ? 'ระงับร้านค้าเรียบร้อยแล้ว' : 'ไม่สามารถดำเนินการได้']; } public function reactivateStore(int $storeId, int $adminId): array { $store = $this->storeModel->findAdminStore($storeId); if (!$store) return ['success' => false, 'message' => 'ไม่พบร้านค้า']; $ok = $this->storeModel->reactivateStore($storeId); if ($ok) { $this->auditLog->record($adminId, 'seller.reactivate', 'sellers', 'store', $storeId, "Reactivated store: {$store['store_name']}"); } return ['success' => $ok, 'message' => $ok ? 'เปิดร้านค้าอีกครั้งเรียบร้อยแล้ว' : 'ไม่สามารถดำเนินการได้']; } public function setOfficialStatus(int $storeId, bool $official, int $adminId): array { $store = $this->storeModel->findAdminStore($storeId); if (!$store) return ['success' => false, 'message' => 'ไม่พบร้านค้า']; $ok = $this->storeModel->setOfficialStatus($storeId, $official); if ($ok) { $action = $official ? 'seller.set_official' : 'seller.remove_official'; $this->auditLog->record($adminId, $action, 'sellers', 'store', $storeId, ($official ? 'Set' : 'Removed') . " official status for store: {$store['store_name']}"); } $msg = $official ? 'กำหนด Official Status เรียบร้อยแล้ว' : 'ยกเลิก Official Status เรียบร้อยแล้ว'; return ['success' => $ok, 'message' => $ok ? $msg : 'ไม่สามารถดำเนินการได้']; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.24 |
proxy
|
phpinfo
|
Settings