This commit is contained in:
2026-07-21 10:34:23 +08:00
parent ea06edec3e
commit 5538ddaa43
4 changed files with 60 additions and 30 deletions
+6 -3
View File
@@ -1856,9 +1856,12 @@ async def get_stats(
)
)).scalar() or 0
# ── 每日各模块积分消耗(按日期+模块分组
# ── 每日各模块积分消耗(始终返回选中日期往前7天,便于图表展示
from sqlalchemy import Date, cast as sa_cast
_day_expr = sa_cast(CreditRecord.created_at, Date)
# 图表固定展示 [date_end - 6天, date_end] 共7天
_chart_end_dt = date_end
_chart_start_dt = _chart_end_dt - timedelta(days=6)
_inner = (
select(
_day_expr.label('date'),
@@ -1867,8 +1870,8 @@ async def get_stats(
)
.where(
CreditRecord.type == "consume",
CreditRecord.created_at >= date_start,
CreditRecord.created_at <= date_end,
CreditRecord.created_at >= _chart_start_dt,
CreditRecord.created_at <= _chart_end_dt,
)
.group_by(_day_expr, CreditRecord.source_module)
.subquery()