1、修改后台首页团队消耗没有算回退的数据

2、修改前台团队积分不可以下载回退积分的数据
This commit is contained in:
2026-08-04 18:05:02 +08:00
parent 97edb17062
commit ebd22d62a1
3 changed files with 64 additions and 10 deletions
+24 -4
View File
@@ -1948,23 +1948,43 @@ async def get_stats(
]
# ── 各团队积分消耗(有团队 vs 无团队,使用流水中的团队快照)
# 消耗 = 扣除金额 - 退回金额(净消耗)
team_credit_rows = (await db.execute(
select(
func.coalesce(CreditRecord.team_name_snapshot, '未分配团队').label('team_name'),
CreditRecord.team_id_snapshot.label('team_id'),
func.coalesce(func.sum(func.abs(CreditRecord.amount)), 0).label('credits'),
func.coalesce(
func.sum(
func.case(
(CreditRecord.type == "consume", func.abs(CreditRecord.amount)),
else_=0,
)
), 0
).label("total_consume"),
func.coalesce(
func.sum(
func.case(
(CreditRecord.type == "refund", func.abs(CreditRecord.amount)),
else_=0,
)
), 0
).label("total_refund"),
)
.where(
CreditRecord.type == "consume",
CreditRecord.type.in_(["consume", "refund"]),
real_credit_charge_filter,
CreditRecord.created_at >= date_start,
CreditRecord.created_at <= date_end,
)
.group_by(CreditRecord.team_id_snapshot, CreditRecord.team_name_snapshot)
.order_by(func.coalesce(func.sum(func.abs(CreditRecord.amount)), 0).desc())
.order_by(func.coalesce(func.sum(func.case((CreditRecord.type == "consume", func.abs(CreditRecord.amount)), else_=0)), 0).desc())
)).all()
credits_by_team = [
TeamCreditOut(team_name=row.team_name, team_id=row.team_id, credits=float(row.credits or 0))
TeamCreditOut(
team_name=row.team_name,
team_id=row.team_id,
credits=round(float(row.total_consume or 0) - float(row.total_refund or 0), 2),
)
for row in team_credit_rows
]