v1.2.55 - 修复stats接口类型错误
This commit is contained in:
parent
1d8246402c
commit
6b03f5e9c1
|
|
@ -365,17 +365,22 @@ def get_stats(
|
|||
|
||||
expected_profit = target_result - cost_result
|
||||
|
||||
# 已售商品统计
|
||||
sold_filter = base_filter & (Collection.f01_04_status == 'sold') & (Collection.f05_42_goal_price > 0)
|
||||
# 已售商品统计 - 处理管理员和普通用户两种情况
|
||||
if current_user.role == "admin":
|
||||
sold_filter = (Collection.f01_04_status == 'sold') & (Collection.f05_42_goal_price > 0)
|
||||
else:
|
||||
sold_filter = (Collection.f99_91_user_id == current_user.f99_90_id) & (Collection.f01_04_status == 'sold') & (Collection.f05_42_goal_price > 0)
|
||||
|
||||
total_revenue = db.query(func.sum(Collection.f05_42_goal_price)).filter(sold_filter).scalar() or 0
|
||||
|
||||
from sqlalchemy import case
|
||||
total_profit = db.query(
|
||||
func.sum(
|
||||
(Collection.f05_42_goal_price or 0) -
|
||||
(Collection.f05_40_cost_price or 0) -
|
||||
(Collection.f05_43_repair_fee or 0) -
|
||||
(Collection.f05_44_grading_fee or 0)
|
||||
case(
|
||||
(Collection.f05_42_goal_price.isnot(None),
|
||||
Collection.f05_42_goal_price - func.coalesce(Collection.f05_40_cost_price, 0) - func.coalesce(Collection.f05_43_repair_fee, 0) - func.coalesce(Collection.f05_44_grading_fee, 0)),
|
||||
else_=0
|
||||
)
|
||||
)
|
||||
).filter(sold_filter).scalar() or 0
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue