From 2a8dea6acfd7bcb19c37306e5db2422da11751a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B2=E8=BE=B0=E7=94=9F=E4=BA=A7?= Date: Wed, 8 Apr 2026 14:29:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Stats=E6=8E=A5=E5=8F=A3=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AE=A4=E8=AF=81=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/routers/collections.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/app/routers/collections.py b/backend/app/routers/collections.py index 05f50cc..b2325e1 100644 --- a/backend/app/routers/collections.py +++ b/backend/app/routers/collections.py @@ -284,8 +284,11 @@ def get_stats( """获取藏品统计 - 使用数据库聚合查询优化性能""" from sqlalchemy import func, case - # 基础查询条件 - base_filter = True if current_user.role == "admin" else Collection.f99_91_user_id == current_user.f99_90_id + # 基础查询条件 - 检查用户是否登录 + if current_user is None or not hasattr(current_user, 'role'): + base_filter = False # 未登录用户不能查看任何藏品 + else: + base_filter = True if current_user.role == "admin" else Collection.f99_91_user_id == current_user.f99_90_id # 总数 total_count = db.query(func.count(Collection.f99_90_id)).filter(base_filter).scalar() or 0