fix: 支付入账降级 + 财务全平台汇总
This commit is contained in:
@@ -87,13 +87,29 @@ def build_caiwu_payload(request):
|
||||
income_qs = _daily_income_qs(request)
|
||||
payout_qs = _daily_payout_qs(request)
|
||||
|
||||
today_income = income_qs.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_payout = payout_qs.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
|
||||
scope = resolve_club_scope(request)
|
||||
today_income_qs = income_qs.filter(date=today)
|
||||
today_payout_qs = payout_qs.filter(date=today)
|
||||
if scope == DATA_SCOPE_ALL:
|
||||
inc_agg = today_income_qs.aggregate(
|
||||
total_amount=Sum('total_amount'),
|
||||
total_count=Sum('total_count'),
|
||||
)
|
||||
today_income_amount = float(inc_agg['total_amount'] or 0.00)
|
||||
today_income_count = int(inc_agg['total_count'] or 0)
|
||||
pay_agg = today_payout_qs.aggregate(
|
||||
total_amount=Sum('total_amount'),
|
||||
total_count=Sum('total_count'),
|
||||
)
|
||||
today_payout_amount = float(pay_agg['total_amount'] or 0.00)
|
||||
today_payout_count = int(pay_agg['total_count'] or 0)
|
||||
else:
|
||||
today_income = today_income_qs.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_payout = today_payout_qs.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_orders = order_qs.filter(
|
||||
CreateTime__gte=today_start,
|
||||
@@ -150,20 +166,54 @@ def build_caiwu_payload(request):
|
||||
platform_profit = round(total_income - total_payout, 2)
|
||||
|
||||
daily_stats = []
|
||||
income_list = income_qs.order_by('-date')[:30]
|
||||
payout_dict = {
|
||||
str(p.date): float(p.total_amount)
|
||||
for p in payout_qs.filter(date__gte=today - timedelta(days=30))
|
||||
}
|
||||
for inc in income_list:
|
||||
d = str(inc.date)
|
||||
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),
|
||||
})
|
||||
since = today - timedelta(days=30)
|
||||
if scope == DATA_SCOPE_ALL:
|
||||
income_by_date = {
|
||||
str(row['date']): {
|
||||
'income': float(row['total_amount'] or 0),
|
||||
'income_count': int(row['total_count'] or 0),
|
||||
}
|
||||
for row in income_qs.filter(date__gte=since).values('date').annotate(
|
||||
total_amount=Sum('total_amount'),
|
||||
total_count=Sum('total_count'),
|
||||
)
|
||||
}
|
||||
payout_by_date = {
|
||||
str(row['date']): float(row['total_amount'] or 0)
|
||||
for row in payout_qs.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': inc['income'],
|
||||
'income_count': inc['income_count'],
|
||||
'payout': payout_amt,
|
||||
'profit': round(inc['income'] - payout_amt, 2),
|
||||
})
|
||||
else:
|
||||
income_list = income_qs.filter(date__gte=since).order_by('-date')[:30]
|
||||
payout_dict = {
|
||||
str(p.date): float(p.total_amount)
|
||||
for p in payout_qs.filter(date__gte=since)
|
||||
}
|
||||
for inc in income_list:
|
||||
d = str(inc.date)
|
||||
payout_amt = payout_dict.get(d, 0.00)
|
||||
daily_stats.append({
|
||||
'date': d,
|
||||
'income': float(inc.total_amount),
|
||||
'income_count': inc.total_count,
|
||||
'payout': payout_amt,
|
||||
'profit': round(float(inc.total_amount) - payout_amt, 2),
|
||||
})
|
||||
|
||||
return {
|
||||
'club_id': club_id,
|
||||
|
||||
Reference in New Issue
Block a user