validateData($data, [ 'page' => 'integer|min:1', 'per_page' => 'integer|min:1|max:100', 'search' => 'string|max:100', 'status' => 'string|in:active,inactive,banned', ]); if ($validationErrors) { return $this->errorResponse('参数验证失败', $validationErrors, 422); } // 获取分页参数 $page = $data['page'] ?? 1; $perPage = $data['per_page'] ?? 20; $search = $data['search'] ?? ''; $status = $data['status'] ?? ''; // 调用User模块服务获取用户列表 $userList = $this->getUserList($page, $perPage, $search, $status); // 记录操作日志 $this->logAction('user.list.get', [ 'page' => $page, 'per_page' => $perPage, 'search' => $search, 'status' => $status, ], $context); return $this->successResponse('获取用户列表成功', $userList); } /** * 获取用户列表 * * 这里应该调用User模块的实际服务 * * @param int $page * @param int $perPage * @param string $search * @param string $status * @return array */ protected function getUserList(int $page, int $perPage, string $search, string $status): array { // TODO: 这里应该调用User模块的服务 // 例如: return app(UserService::class)->getUserList($page, $perPage, $search, $status); // 暂时返回示例数据,等待与User模块集成 $users = []; $total = 1000; // 假设总用户数 // 生成示例用户数据 for ($i = 1; $i <= $perPage; $i++) { $userId = ($page - 1) * $perPage + $i; if ($userId > $total) break; $users[] = [ 'id' => $userId, 'username' => "user{$userId}", 'nickname' => "用户{$userId}", 'email' => "user{$userId}@example.com", 'avatar' => "https://example.com/avatar/{$userId}.jpg", 'level' => rand(1, 100), 'status' => $status ?: ['active', 'inactive'][rand(0, 1)], 'created_at' => now()->subDays(rand(1, 365))->toISOString(), 'last_login_at' => now()->subHours(rand(1, 24))->toISOString(), ]; } return [ 'users' => $users, 'pagination' => [ 'current_page' => $page, 'per_page' => $perPage, 'total' => $total, 'last_page' => ceil($total / $perPage), 'from' => ($page - 1) * $perPage + 1, 'to' => min($page * $perPage, $total), ], 'filters' => [ 'search' => $search, 'status' => $status, ], ]; } }