1
This commit is contained in:
@@ -1888,6 +1888,31 @@ async def get_stats(
|
||||
for row in daily_credits_rows
|
||||
]
|
||||
|
||||
# ── 选中周期内各模块积分占比(按 source_module 分组,不拆日期)
|
||||
_period_inner = (
|
||||
select(
|
||||
CreditRecord.source_module.label('module'),
|
||||
func.coalesce(func.sum(func.abs(CreditRecord.amount)), 0).label('credits'),
|
||||
)
|
||||
.where(
|
||||
CreditRecord.type == "consume",
|
||||
CreditRecord.created_at >= date_start,
|
||||
CreditRecord.created_at <= date_end,
|
||||
)
|
||||
.group_by(CreditRecord.source_module)
|
||||
.subquery()
|
||||
)
|
||||
period_credits_rows = (await db.execute(
|
||||
select(
|
||||
func.coalesce(_period_inner.c.module, 'other').label('module'),
|
||||
_period_inner.c.credits,
|
||||
).order_by(_period_inner.c.credits.desc())
|
||||
)).all()
|
||||
period_credits_by_module = [
|
||||
DailyCreditOut(date='', module=row.module, credits=float(row.credits or 0))
|
||||
for row in period_credits_rows
|
||||
]
|
||||
|
||||
# ── 各团队积分消耗(有团队 vs 无团队,使用流水中的团队快照)
|
||||
team_credit_rows = (await db.execute(
|
||||
select(
|
||||
@@ -1944,6 +1969,7 @@ async def get_stats(
|
||||
last_period_revenue=float(last_period_revenue),
|
||||
last_period_credits_consumed=float(last_period_credits_consumed),
|
||||
daily_credits_by_module=daily_credits_by_module,
|
||||
period_credits_by_module=period_credits_by_module,
|
||||
credits_by_team=credits_by_team,
|
||||
model_usage=model_usage,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user