This commit is contained in:
2026-07-21 10:12:11 +08:00
parent 3c6deed786
commit fb3b95b687
+11 -4
View File
@@ -1859,10 +1859,10 @@ async def get_stats(
# ── 每日各模块积分消耗(按日期+模块分组)
from sqlalchemy import Date, cast as sa_cast
_day_expr = sa_cast(CreditRecord.created_at, Date)
daily_credits_rows = (await db.execute(
_inner = (
select(
_day_expr.label('date'),
func.coalesce(CreditRecord.source_module, 'other').label('module'),
CreditRecord.source_module.label('module'),
func.coalesce(func.sum(func.abs(CreditRecord.amount)), 0).label('credits'),
)
.where(
@@ -1870,8 +1870,15 @@ async def get_stats(
CreditRecord.created_at >= date_start,
CreditRecord.created_at <= date_end,
)
.group_by(_day_expr, func.coalesce(CreditRecord.source_module, 'other'))
.order_by(_day_expr)
.group_by(_day_expr, CreditRecord.source_module)
.subquery()
)
daily_credits_rows = (await db.execute(
select(
_inner.c.date,
func.coalesce(_inner.c.module, 'other').label('module'),
_inner.c.credits,
).order_by(_inner.c.date)
)).all()
daily_credits_by_module = [
DailyCreditOut(date=str(row.date), module=row.module, credits=float(row.credits or 0))