diff --git a/backend/app/routers/information.py b/backend/app/routers/information.py index a249fbb..9a70e31 100644 --- a/backend/app/routers/information.py +++ b/backend/app/routers/information.py @@ -1070,3 +1070,26 @@ def get_yichen_posts(category: str = None, search: str = None, page: int = 1, pa offset = (page - 1) * page_size items = query.order_by(desc(Information.created_at)).offset(offset).limit(page_size).all() return {"data": items, "pagination": {"page": page, "limit": page_size, "total": total}} + + +@router.get("/seek/stats") +def get_seek_stats( + current_user: User = Depends(get_current_user), + db: Session = Depends(get_db) +): + """获取寻配号统计数据""" + # 寻号需求数(seek类型总数) + seek_count = db.query(Information).filter( + Information.info_type == 'seek' + ).count() + + # 匹配成功总条数(is_matched = 'confirmed') + matched_count = db.query(Information).filter( + Information.info_type == 'seek', + Information.is_matched == 'confirmed' + ).count() + + return { + "seekCount": seek_count, + "matchedCount": matched_count + } diff --git a/frontend/src/pages/Home.jsx b/frontend/src/pages/Home.jsx index 1a044ca..33f5eac 100644 --- a/frontend/src/pages/Home.jsx +++ b/frontend/src/pages/Home.jsx @@ -6,6 +6,7 @@ export default function Home() { const [stats, setStats] = useState({ totalCount: 0, totalCost: 0, totalRevenue: 0, expectedProfit: 0, totalProfit: 0, gradedCount: 0 }) const [recentCollections, setRecentCollections] = useState([]) const [yichensStats, setYichensStats] = useState({ total: 0, deals: 0, wants: 0, dragons: 0, horses: 0, tianma: 0 }) + const [seekStats, setSeekStats] = useState({ seekCount: 0, matchedCount: 0 }) const [recentPosts, setRecentPosts] = useState([]) const currentPath = window.location.hash.slice(1) || '/' @@ -66,6 +67,11 @@ export default function Home() { fetch('/api/yichens/posts?limit=10&offset=0').then(res => res.json()).then(data => { setRecentPosts(Array.isArray(data) ? data : []) }).catch(() => {}) + + // 获取寻配号统计数据 + fetch('/api/information/seek/stats').then(res => res.json()).then(data => { + setSeekStats(data || {}) + }).catch(() => {}) }, []) // 检查是否为管理员 @@ -152,6 +158,31 @@ export default function Home() { ))} + {/* 寻配号数据 */} +