'system']); [$page, $limit] = pageParams(); $keyword = trim($_REQUEST['keyword'] ?? ''); $active = isset($_REQUEST['is_active']) && $_REQUEST['is_active'] !== '' ? (int)$_REQUEST['is_active'] : null; $where = ['1=1']; $params = []; if ($keyword !== '') { $where[] = 'role_name LIKE ?'; $params[] = "%$keyword%"; } if ($active !== null) { $where[] = 'is_active = ?'; $params[] = $active; } $whereSql = implode(' AND ', $where); $pdo = DB::getInstance()->getPdo(); $stmt = $pdo->prepare("SELECT COUNT(*) FROM system_roles WHERE $whereSql"); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); $offset = ($page - 1) * $limit; $stmt = $pdo->prepare( "SELECT id, role_name, permissions, is_active, created_at, (SELECT COUNT(*) FROM system_users u WHERE u.role_id = system_roles.id) AS user_count FROM system_roles WHERE $whereSql ORDER BY id ASC LIMIT $limit OFFSET $offset" ); $stmt->execute($params); $list = $stmt->fetchAll(); foreach ($list as &$r) { $r['permissions'] = json_decode($r['permissions'], true) ?: []; } unset($r); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);