true]); [$page, $limit] = pageParams(); $keyword = trim($_REQUEST['keyword'] ?? ''); $action = trim($_REQUEST['action'] ?? ''); $module = trim($_REQUEST['module'] ?? ''); $username = trim($_REQUEST['username'] ?? ''); $startDate = trim($_REQUEST['start_date'] ?? ''); $endDate = trim($_REQUEST['end_date'] ?? ''); $where = ['created_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH)']; $params = []; if ($keyword !== '') { $where[] = '(username LIKE ? OR content LIKE ? OR module LIKE ?)'; $like = "%$keyword%"; array_push($params, $like, $like, $like); } if ($action !== '') { $where[] = 'action = ?'; $params[] = $action; } if ($module !== '') { $where[] = 'module = ?'; $params[] = $module; } if ($username !== '') { $where[] = 'username = ?'; $params[] = $username; } if ($startDate !== '') { $where[] = 'DATE(created_at) >= ?'; $params[] = $startDate; } if ($endDate !== '') { $where[] = 'DATE(created_at) <= ?'; $params[] = $endDate; } $whereSql = implode(' AND ', $where); $pdo = DB::getInstance()->getPdo(); $stmt = $pdo->prepare("SELECT COUNT(*) FROM system_logs WHERE $whereSql"); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); $offset = ($page - 1) * $limit; $stmt = $pdo->prepare( "SELECT id, user_id, username, action, module, target_table, target_id, content, ip, created_at FROM system_logs WHERE $whereSql ORDER BY id DESC LIMIT $limit OFFSET $offset" ); $stmt->execute($params); $list = $stmt->fetchAll(); // 筛选下拉字典 $dict = [ 'actions' => $pdo->query("SELECT DISTINCT action FROM system_logs ORDER BY action")->fetchAll(PDO::FETCH_COLUMN), 'modules' => $pdo->query("SELECT DISTINCT module FROM system_logs ORDER BY module")->fetchAll(PDO::FETCH_COLUMN), ]; Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit, 'dict' => $dict]);