fix: 支付入账降级 + 财务全平台汇总
This commit is contained in:
@@ -6939,15 +6939,20 @@ class CaiwuView(APIView):
|
||||
today_start = datetime.combine(today, datetime.min.time())
|
||||
today_end = today_start + timedelta(days=1)
|
||||
|
||||
# 今日收入
|
||||
today_income = DailyIncomeStat.query.filter(date=today).first()
|
||||
today_income_amount = float(today_income.total_amount) if today_income else 0.00
|
||||
today_income_count = today_income.total_count if today_income else 0
|
||||
# 今日收入 / 支出(全平台各俱乐部合计)
|
||||
today_inc = DailyIncomeStat.query.filter(date=today).aggregate(
|
||||
total_amount=Sum('total_amount'),
|
||||
total_count=Sum('total_count'),
|
||||
)
|
||||
today_income_amount = float(today_inc['total_amount'] or 0.00)
|
||||
today_income_count = int(today_inc['total_count'] or 0)
|
||||
|
||||
# 今日支出
|
||||
today_payout = DailyPayoutStat.query.filter(date=today).first()
|
||||
today_payout_amount = float(today_payout.total_amount) if today_payout else 0.00
|
||||
today_payout_count = today_payout.total_count if today_payout else 0
|
||||
today_pay = DailyPayoutStat.query.filter(date=today).aggregate(
|
||||
total_amount=Sum('total_amount'),
|
||||
total_count=Sum('total_count'),
|
||||
)
|
||||
today_payout_amount = float(today_pay['total_amount'] or 0.00)
|
||||
today_payout_count = int(today_pay['total_count'] or 0)
|
||||
|
||||
# 今日订单(已付款及之后的状态)
|
||||
today_orders = Order.query.filter(
|
||||
@@ -7016,21 +7021,38 @@ class CaiwuView(APIView):
|
||||
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 = []
|
||||
income_qs = DailyIncomeStat.query.order_by('-date')[:30]
|
||||
payout_dict = {
|
||||
str(p.date): float(p.total_amount)
|
||||
for p in DailyPayoutStat.query.filter(date__gte=today - timedelta(days=30))
|
||||
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),
|
||||
}
|
||||
for row in DailyIncomeStat.query.filter(date__gte=since).values('date').annotate(
|
||||
total_amount=Sum('total_amount'),
|
||||
total_count=Sum('total_count'),
|
||||
)
|
||||
}
|
||||
for inc in income_qs:
|
||||
d = str(inc.date)
|
||||
payout_by_date = {
|
||||
str(row['date']): float(row['total_amount'] or 0)
|
||||
for row in DailyPayoutStat.query.filter(date__gte=since).values('date').annotate(
|
||||
total_amount=Sum('total_amount'),
|
||||
)
|
||||
}
|
||||
all_dates = sorted(
|
||||
set(income_by_date.keys()) | set(payout_by_date.keys()),
|
||||
reverse=True,
|
||||
)[:30]
|
||||
for d in all_dates:
|
||||
inc = income_by_date.get(d, {'income': 0.0, 'income_count': 0})
|
||||
payout_amt = payout_by_date.get(d, 0.00)
|
||||
daily_stats.append({
|
||||
'date': d,
|
||||
'income': float(inc.total_amount),
|
||||
'income_count': inc.total_count,
|
||||
'payout': payout_dict.get(d, 0.00),
|
||||
'profit': round(float(inc.total_amount) - payout_dict.get(d, 0.00), 2)
|
||||
'income': inc['income'],
|
||||
'income_count': inc['income_count'],
|
||||
'payout': payout_amt,
|
||||
'profit': round(inc['income'] - payout_amt, 2),
|
||||
})
|
||||
|
||||
return Response({
|
||||
|
||||
Reference in New Issue
Block a user