File manager - Edit - /home/webapp69.cm.in.th/u69319090028/Shop/app/Services/AdminOrderService.php
Back
<?php /** * AdminOrderService * Admin cross-store order monitoring and investigation notes * Does NOT alter order status (read-only + notes only) */ require_once __DIR__ . '/../Models/Order.php'; require_once __DIR__ . '/../Models/AdminAuditLog.php'; class AdminOrderService { private Order $orderModel; private AdminAuditLog $auditLog; public function __construct() { $this->orderModel = new Order(); $this->auditLog = new AdminAuditLog(); } public function getOrders(array $filters, int $page = 1, int $perPage = 20): array { $offset = ($page - 1) * $perPage; $orders = $this->orderModel->getAdminOrders($filters, $perPage, $offset); $total = $this->orderModel->countAdminOrders($filters); return [ 'orders' => $orders, 'total' => $total, 'page' => $page, 'per_page' => $perPage, 'total_pages' => max(1, (int)ceil($total / $perPage)), ]; } public function getOrderDetail(string $orderNo): ?array { $order = $this->orderModel->findAdminOrderByNo($orderNo); if (!$order) return null; $order['items'] = $this->orderModel->getOrderItems((int)$order['id']); return $order; } /** * Admin adds investigation note to an order. * Stored in admin_audit_logs as investigation record. */ public function addInvestigationNote(string $orderNo, string $note, int $adminId): array { $order = $this->orderModel->findAdminOrderByNo($orderNo); if (!$order) return ['success' => false, 'message' => 'ไม่พบออเดอร์']; $note = trim($note); if (empty($note)) return ['success' => false, 'message' => 'กรุณาระบุโน้ต']; $this->auditLog->record($adminId, 'order.investigate', 'orders', 'order', (int)$order['id'], "Investigation note for {$orderNo}: " . mb_substr($note, 0, 500)); return ['success' => true, 'message' => 'บันทึกโน้ตการตรวจสอบเรียบร้อยแล้ว']; } public function getOrderStats(): array { return $this->orderModel->getPlatformOrderStats(); } /** * Get investigation history (audit log entries for this order) */ public function getOrderInvestigationHistory(int $orderId): array { $db = \Database::getInstance(); $sql = "SELECT aal.*, u.username as admin_username FROM `admin_audit_logs` aal LEFT JOIN `users` u ON aal.admin_id = u.id WHERE aal.target_type = 'order' AND aal.target_id = :order_id ORDER BY aal.created_at DESC"; $stmt = $db->prepare($sql); $stmt->execute([':order_id' => $orderId]); return $stmt->fetchAll(); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.24 |
proxy
|
phpinfo
|
Settings