财务每日收入改从真实支付实时汇总,与统计表解耦
This commit is contained in:
@@ -6939,13 +6939,14 @@ class CaiwuView(APIView):
|
||||
today_start = datetime.combine(today, datetime.min.time())
|
||||
today_end = today_start + timedelta(days=1)
|
||||
|
||||
# 今日收入 / 支出(全平台各俱乐部合计)
|
||||
today_inc = DailyIncomeStat.query.filter(date=today).aggregate(
|
||||
total_amount=Sum('total_amount'),
|
||||
total_count=Sum('total_count'),
|
||||
from jituan.services.live_income_stats import (
|
||||
income_daily_stats_last_days,
|
||||
income_for_date,
|
||||
income_total_all_time,
|
||||
)
|
||||
today_income_amount = float(today_inc['total_amount'] or 0.00)
|
||||
today_income_count = int(today_inc['total_count'] or 0)
|
||||
|
||||
# 今日收入:从真实微信支付汇总,不读 daily_income_stat
|
||||
today_income_amount, today_income_count = income_for_date(today)
|
||||
|
||||
today_pay = DailyPayoutStat.query.filter(date=today).aggregate(
|
||||
total_amount=Sum('total_amount'),
|
||||
@@ -7016,23 +7017,20 @@ class CaiwuView(APIView):
|
||||
all_zuzhang_yue = float(UserZuzhang.query.aggregate(total=Sum('ketixian_jine'))['total'] or 0.00)
|
||||
all_shangjia_yue = float(UserShangjia.query.aggregate(total=Sum('yue'))['total'] or 0.00)
|
||||
|
||||
# 平台总收支及利润
|
||||
total_income = float(DailyIncomeStat.query.aggregate(total=Sum('total_amount'))['total'] or 0.00)
|
||||
# 平台总收支及利润(收入侧实时汇总)
|
||||
total_income, _ = income_total_all_time()
|
||||
total_payout = float(DailyPayoutStat.query.aggregate(total=Sum('total_amount'))['total'] or 0.00)
|
||||
platform_profit = round(total_income - total_payout, 2)
|
||||
|
||||
# 近30天每日收支明细(按日期合并各俱乐部)
|
||||
# 近30天每日收支明细
|
||||
daily_stats = []
|
||||
since = today - timedelta(days=30)
|
||||
income_by_date = {
|
||||
str(row['date']): {
|
||||
'income': float(row['total_amount'] or 0),
|
||||
'income_count': int(row['total_count'] or 0),
|
||||
row['date']: {
|
||||
'income': row['income'],
|
||||
'income_count': row['income_count'],
|
||||
}
|
||||
for row in DailyIncomeStat.query.filter(date__gte=since).values('date').annotate(
|
||||
total_amount=Sum('total_amount'),
|
||||
total_count=Sum('total_count'),
|
||||
)
|
||||
for row in income_daily_stats_last_days(30)
|
||||
}
|
||||
payout_by_date = {
|
||||
str(row['date']): float(row['total_amount'] or 0)
|
||||
@@ -7408,12 +7406,13 @@ class SzxxView(APIView):
|
||||
else:
|
||||
return Response({'code': 1, 'msg': '无效的颗粒度'}, status=400)
|
||||
|
||||
# ---------- 收入分组查询 ----------
|
||||
income_qs = filter_queryset_by_club(
|
||||
DailyIncomeStat.query.filter(**income_filter), request,
|
||||
).values(group_field) \
|
||||
.annotate(total_income=Sum('total_amount'), total_count=Sum('total_count')) \
|
||||
.order_by(group_field)
|
||||
# ---------- 收入:从真实支付汇总;支出仍读 daily_payout_stat ----------
|
||||
from jituan.services.live_income_stats import (
|
||||
income_summary_filter,
|
||||
income_time_series,
|
||||
)
|
||||
|
||||
income_map = income_time_series(granularity, year, month, request)
|
||||
|
||||
# ---------- 支出分组查询 ----------
|
||||
payout_qs = filter_queryset_by_club(
|
||||
@@ -7424,13 +7423,12 @@ class SzxxView(APIView):
|
||||
|
||||
# ---------- 合并数据 ----------
|
||||
data_map = {}
|
||||
for item in income_qs:
|
||||
key = item[group_field]
|
||||
for key, vals in income_map.items():
|
||||
data_map[key] = {
|
||||
'income': float(item['total_income'] or 0),
|
||||
'income_count': item['total_count'] or 0,
|
||||
'income': vals['income'],
|
||||
'income_count': vals.get('income_count', 0),
|
||||
'payout': 0.0,
|
||||
'payout_count': 0
|
||||
'payout_count': 0,
|
||||
}
|
||||
|
||||
for item in payout_qs:
|
||||
@@ -7459,17 +7457,25 @@ class SzxxView(APIView):
|
||||
time_series.sort(key=lambda x: x['date'])
|
||||
|
||||
# ---------- 汇总数据 ----------
|
||||
income_summary = filter_queryset_by_club(
|
||||
DailyIncomeStat.query.filter(**summary_filter), request,
|
||||
).aggregate(
|
||||
total_income=Sum('total_amount'), total_count=Sum('total_count')
|
||||
)
|
||||
if granularity == 'day':
|
||||
summary_day = int(summary_parts[2])
|
||||
total_income, total_income_count = income_summary_filter(
|
||||
'day', int(summary_parts[0]), int(summary_parts[1]), summary_day, request,
|
||||
)
|
||||
elif granularity == 'month':
|
||||
total_income, total_income_count = income_summary_filter(
|
||||
'month', int(summary_parts[0]), int(summary_parts[1]), None, request,
|
||||
)
|
||||
else:
|
||||
total_income, total_income_count = income_summary_filter(
|
||||
'year', int(summary_parts[0]), None, None, request,
|
||||
)
|
||||
|
||||
payout_summary = filter_queryset_by_club(
|
||||
DailyPayoutStat.query.filter(**summary_filter), request,
|
||||
).aggregate(
|
||||
total_payout=Sum('total_amount'), total_count=Sum('total_count')
|
||||
)
|
||||
total_income = float(income_summary['total_income'] or 0)
|
||||
total_payout = float(payout_summary['total_payout'] or 0)
|
||||
total_profit = round(total_income - total_payout, 2)
|
||||
|
||||
@@ -7480,7 +7486,7 @@ class SzxxView(APIView):
|
||||
'time_series': time_series,
|
||||
'summary': {
|
||||
'total_income': total_income,
|
||||
'total_income_count': income_summary['total_count'] or 0,
|
||||
'total_income_count': total_income_count,
|
||||
'total_payout': total_payout,
|
||||
'total_payout_count': payout_summary['total_count'] or 0,
|
||||
'total_profit': total_profit
|
||||
|
||||
Reference in New Issue
Block a user