fix: Stats返回值修复

This commit is contained in:
甲辰生产 2026-04-08 14:33:45 +08:00
parent 2a8dea6acf
commit 190df56118
1 changed files with 13 additions and 5 deletions

View File

@ -398,13 +398,21 @@ def get_stats(
"byGradingScore": [{"score": s, "count": n} for s, n in by_grading_score], "byGradingScore": [{"score": s, "count": n} for s, n in by_grading_score],
"bySpecialMark": [{"mark": m, "count": n} for m, n in by_special_mark], "bySpecialMark": [{"mark": m, "count": n} for m, n in by_special_mark],
"byNumberCategory": [{"numberCategory": n, "count": c} for n, c in by_number_category], "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": [ "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": "profit", "label": "盈利", "count": profit_count},
{"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": "loss", "label": "亏损", "count": loss_count}
], ],
"totalCost": total_cost, "totalCost": cost_result,
"totalTarget": sum(c.f05_41_target_price or 0 for c in all_collections), "totalTarget": target_result,
"expectedProfit": expected_profit, "expectedProfit": expected_profit,
"totalRevenue": total_revenue, "totalRevenue": total_revenue,
"totalProfit": total_profit "totalProfit": total_profit