v0.0.4 - 修复寻配号和管理页面API

This commit is contained in:
甲辰生产 2026-04-21 01:17:44 +08:00
parent c70a4f1221
commit 6667671f46
4 changed files with 50 additions and 25 deletions

View File

@ -1159,12 +1159,10 @@ def get_seek_stats(
db: Session = Depends(get_db)
):
"""获取寻配号统计数据 - 使用seek_info表"""
from app.services.yichens import match_collections_count_from_coolbot
# 寻号需求数seek_info表中status=active的总数
seek_count = db.query(SeekInfo).filter(SeekInfo.status == "active").count()
# 我的匹配:我发布且已匹配成功的寻号数量 (is_matched为true或false都算匹配)
# 我的匹配:我发布且已匹配成功的寻号数量
user_matched_count = 0
if current_user:
user_matched_count = db.query(SeekInfo).filter(
@ -1172,23 +1170,15 @@ def get_seek_stats(
SeekInfo.is_matched.in_(["true", "false"])
).count()
# 总共匹配:计算网络数据匹配成功数
total_network_matched = 0
all_seeks = db.query(SeekInfo).filter(
SeekInfo.status == "active",
SeekInfo.expect_number.isnot(None),
SeekInfo.expect_number != ''
).all()
for seek in all_seeks:
if seek.expect_number:
count = match_collections_count_from_coolbot(seek.expect_number)
total_network_matched += count
# 总共匹配:所有已匹配成功的寻号数量
total_matched_count = db.query(SeekInfo).filter(
SeekInfo.is_matched.in_(["true", "false"])
).count()
return {
"seekCount": seek_count,
"userMatchedCount": user_matched_count,
"totalMatchedCount": total_network_matched
"totalMatchedCount": total_matched_count
}
# 批量解析行情数据API

View File

@ -11,6 +11,7 @@ from app.core.database import get_db
from app.core.auth import get_current_user
from app.models.seek_info import SeekInfo
from app.models.models import User
from app.routers.information import match_collections_count_from_coolbot
router = APIRouter(prefix="/api/seek", tags=["寻配号"])
@ -40,6 +41,7 @@ class SeekInfoResponse(BaseModel):
id: str
user_id: str
user_name: Optional[str] = None
network_matched_count: Optional[int] = 0
title: str
content: Optional[str]
expect_category: Optional[str]
@ -84,7 +86,40 @@ def get_seek_list(
offset = (page - 1) * page_size
items = query.offset(offset).limit(page_size).all()
return items
# 关联查询用户名
result = []
for item in items:
user = db.query(User).filter(User.f99_90_id == item.user_id).first()
user_name = user.f01_01_name if user else None
# 计算网络数据匹配数
network_matched_count = 0
if item.expect_number:
network_matched_count = match_collections_count_from_coolbot(item.expect_number)
result.append({
"id": item.id,
"user_id": item.user_id,
"user_name": user_name,
"title": item.title,
"content": item.content,
"expect_category": item.expect_category,
"expect_version": item.expect_version,
"expect_packaging": item.expect_packaging,
"expect_number": item.expect_number,
"expect_price_min": item.expect_price_min,
"expect_price_max": item.expect_price_max,
"status": item.status,
"is_matched": item.is_matched,
"matched_user_id": item.matched_user_id,
"matched_contact": item.matched_contact,
"view_count": item.view_count,
"contact_count": item.contact_count,
"network_matched_count": network_matched_count,
"created_at": item.created_at.isoformat() if item.created_at else None,
"updated_at": item.updated_at.isoformat() if item.updated_at else None,
})
return result
@router.get("/stats")
def get_seek_stats(

View File

@ -7,7 +7,7 @@ from fastapi import APIRouter, Depends, HTTPException, status, Query, Body
from sqlalchemy.orm import Session
from app.core.database import get_db
from app.core.auth import get_current_user
from app.models.models import User, Collection
from app.models.models import User, Collection, Information
from app.schemas.schemas import UserResponse, UserUpdate
router = APIRouter(prefix="/api", tags=["用户"])
@ -100,7 +100,7 @@ def get_users(
db: Session = Depends(get_db)
):
"""获取用户列表(仅管理员)"""
if current_user.role not in ["admin", "editor"]:
if not current_user or current_user.role not in ["admin", "editor"]:
raise HTTPException(status_code=403, detail="无权访问")
total = db.query(User).count()
@ -152,7 +152,7 @@ def get_user(
db: Session = Depends(get_db)
):
"""获取单个用户信息"""
if current_user.role not in ["admin", "editor"]:
if not current_user or current_user.role not in ["admin", "editor"]:
raise HTTPException(status_code=403, detail="无权访问")
user = db.query(User).filter(User.id == user_id).first()
@ -177,7 +177,7 @@ def get_user_collections(
db: Session = Depends(get_db)
):
"""获取指定用户的藏品列表"""
if current_user.role not in ["admin", "editor"]:
if not current_user or current_user.role not in ["admin", "editor"]:
raise HTTPException(status_code=403, detail="无权访问")
collections = db.query(Collection).filter(
@ -194,7 +194,7 @@ def get_user_collection_count(
db: Session = Depends(get_db)
):
"""获取指定用户的藏品数量"""
if current_user.role not in ["admin", "editor"]:
if not current_user or current_user.role not in ["admin", "editor"]:
raise HTTPException(status_code=403, detail="E00050: 仅管理员可访问")
count = db.query(Collection).filter(Collection.user_id == user_id).count()
@ -219,7 +219,7 @@ def update_user(
db: Session = Depends(get_db)
):
"""更新用户信息(仅管理员)"""
if current_user.role not in ["admin", "editor"]:
if not current_user or current_user.role not in ["admin", "editor"]:
raise HTTPException(status_code=403, detail="E00050: 仅管理员可访问")
user = db.query(User).filter(User.f99_90_id == user_id).first()
@ -297,7 +297,7 @@ def delete_user(
db: Session = Depends(get_db)
):
"""删除用户(仅管理员)"""
if current_user.role not in ["admin", "editor"]:
if not current_user or current_user.role not in ["admin", "editor"]:
raise HTTPException(status_code=403, detail="E00050: 仅管理员可访问")
# 不能删除自己

View File

@ -84,7 +84,7 @@ export default function Home() {
}).catch(() => {})
//
fetch('/api/information/seek/stats').then(res => res.json()).then(data => {
fetch('/api/information/seek/stats?_=1776700744').then(res => res.json()).then(data => {
setSeekStats(data || {})
}).catch(() => {})
}, [])