From 190df561187820cfd2946238e23c1b4671790976 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:33:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Stats=E8=BF=94=E5=9B=9E=E5=80=BC?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/routers/collections.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/app/routers/collections.py b/backend/app/routers/collections.py index b2325e1..2307e4e 100644 --- a/backend/app/routers/collections.py +++ b/backend/app/routers/collections.py @@ -398,13 +398,21 @@ def get_stats( "byGradingScore": [{"score": s, "count": n} for s, n in by_grading_score], "bySpecialMark": [{"mark": m, "count": n} for m, n in by_special_mark], "byNumberCategory": [{"numberCategory": n, "count": c} for n, c in by_number_category], - # 盈亏统计(只统计已售且有价格的藏品) + # 盈亏统计 + profit_count = db.query(func.count(Collection.f99_90_id)).filter( + sold_filter, Collection.f05_42_goal_price > Collection.f05_40_cost_price + ).scalar() or 0 + + loss_count = db.query(func.count(Collection.f99_90_id)).filter( + sold_filter, Collection.f05_42_goal_price <= Collection.f05_40_cost_price + ).scalar() or 0 + "byProfitLoss": [ - {"type": "profit", "label": "盈利", "count": sum(1 for c in sold_collections if c.f05_42_goal_price and c.f05_40_cost_price and c.f05_42_goal_price > c.f05_40_cost_price)}, - {"type": "loss", "label": "亏损", "count": sum(1 for c in sold_collections if c.f05_42_goal_price and c.f05_40_cost_price and c.f05_42_goal_price <= c.f05_40_cost_price)} + {"type": "profit", "label": "盈利", "count": profit_count}, + {"type": "loss", "label": "亏损", "count": loss_count} ], - "totalCost": total_cost, - "totalTarget": sum(c.f05_41_target_price or 0 for c in all_collections), + "totalCost": cost_result, + "totalTarget": target_result, "expectedProfit": expected_profit, "totalRevenue": total_revenue, "totalProfit": total_profit