fix: 支付 request.user、jituan import、财务日统计汇总
This commit is contained in:
@@ -144,16 +144,11 @@ def build_caiwu_payload(request):
|
||||
|
||||
szjilu_payload = _build_szjilu_payload(request)
|
||||
|
||||
# 账户总收入/总支出:szjilu 全历史累计(非今日)
|
||||
total_income = float(szjilu_payload.get('zongliushui') or 0.00)
|
||||
total_payout = float(szjilu_payload.get('zongzhichu') or 0.00)
|
||||
# 俱乐部利润:累计总流水 − 累计总支出
|
||||
# 账户总收入/总支出:日收支统计表全历史 SUM(与「每日收支详细」按年汇总一致)
|
||||
total_income = float(income_qs.aggregate(total=Sum('total_amount'))['total'] or 0.00)
|
||||
total_payout = float(payout_qs.aggregate(total=Sum('total_amount'))['total'] or 0.00)
|
||||
platform_profit = round(total_income - total_payout, 2)
|
||||
|
||||
# 日统计表全历史合计(供核对)
|
||||
daily_sum_income = float(income_qs.aggregate(total=Sum('total_amount'))['total'] or 0.00)
|
||||
daily_sum_payout = float(payout_qs.aggregate(total=Sum('total_amount'))['total'] or 0.00)
|
||||
|
||||
daily_stats = []
|
||||
income_list = income_qs.order_by('-date')[:30]
|
||||
payout_dict = {
|
||||
@@ -195,7 +190,6 @@ def build_caiwu_payload(request):
|
||||
'total_income': round(total_income, 2),
|
||||
'total_payout': round(total_payout, 2),
|
||||
'platform_profit': platform_profit,
|
||||
'daily_stat_sum_income': round(daily_sum_income, 2),
|
||||
'daily_stat_sum_payout': round(daily_sum_payout, 2),
|
||||
'szjilu': szjilu_payload,
|
||||
'daily_stats': daily_stats,
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ from rest_framework.views import APIView
|
||||
from rest_framework.throttling import AnonRateThrottle
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
from jituan.constants import SUPER_ADMIN_PHONES
|
||||
from jituan.constants import SUPER_ADMIN_PHONES, ADMIN_ROLE_LABELS, CLUB_ID_DEFAULT
|
||||
from jituan.models import Club, AdminAssignment
|
||||
from jituan.services.admin_context import build_admin_club_context
|
||||
from jituan.services.wechat_login import login_or_register_by_club
|
||||
from jituan.services.caiwu_stats import build_caiwu_payload
|
||||
@@ -209,7 +210,6 @@ class ClubAdminAssignmentListView(APIView):
|
||||
return permissions
|
||||
|
||||
user = request.user
|
||||
from jituan.constants import SUPER_ADMIN_PHONES
|
||||
is_super = (
|
||||
bool(user.IsSuperuser)
|
||||
or user.UserType == 'admin'
|
||||
@@ -307,49 +307,53 @@ class ClubManageView(APIView):
|
||||
return base
|
||||
|
||||
def post(self, request):
|
||||
from jituan.constants import CLUB_ID_DEFAULT, SUPER_ADMIN_PHONES
|
||||
from jituan.constants import CLUB_ID_DEFAULT
|
||||
|
||||
username = (request.data.get('phone') or request.data.get('username') or '').strip()
|
||||
if not username:
|
||||
return Response({'code': 401, 'msg': '缺少账号'}, status=401)
|
||||
kefu_obj, permissions = verify_kefu_permission(request, username)
|
||||
if kefu_obj is None:
|
||||
return permissions
|
||||
if '000001' not in permissions:
|
||||
return Response({'code': 403, 'msg': '仅超级管理员可管理俱乐部配置'}, status=403)
|
||||
try:
|
||||
username = (request.data.get('phone') or request.data.get('username') or '').strip()
|
||||
if not username:
|
||||
return Response({'code': 401, 'msg': '缺少账号'}, status=401)
|
||||
kefu_obj, permissions = verify_kefu_permission(request, username)
|
||||
if kefu_obj is None:
|
||||
return permissions
|
||||
if '000001' not in permissions:
|
||||
return Response({'code': 403, 'msg': '仅超级管理员可管理俱乐部配置'}, status=403)
|
||||
|
||||
action = (request.data.get('action') or 'get').strip()
|
||||
club_id = (request.data.get('club_id') or '').strip() or CLUB_ID_DEFAULT
|
||||
action = (request.data.get('action') or 'get').strip()
|
||||
club_id = (request.data.get('club_id') or '').strip() or CLUB_ID_DEFAULT
|
||||
|
||||
if action == 'list':
|
||||
clubs = Club.query.order_by('sort_order', 'club_id')
|
||||
return Response({
|
||||
'code': 0,
|
||||
'data': [self._serialize(c, full=False) for c in clubs],
|
||||
})
|
||||
if action == 'list':
|
||||
clubs = Club.query.order_by('sort_order', 'club_id')
|
||||
return Response({
|
||||
'code': 0,
|
||||
'data': [self._serialize(c, full=False) for c in clubs],
|
||||
})
|
||||
|
||||
club = Club.query.filter(club_id=club_id).first()
|
||||
if not club and action != 'create':
|
||||
return Response({'code': 1, 'msg': f'俱乐部 {club_id} 不存在'})
|
||||
club = Club.query.filter(club_id=club_id).first()
|
||||
if not club and action != 'create':
|
||||
return Response({'code': 1, 'msg': f'俱乐部 {club_id} 不存在'})
|
||||
|
||||
if action == 'get':
|
||||
return Response({'code': 0, 'data': self._serialize(club, full=True)})
|
||||
if action == 'get':
|
||||
return Response({'code': 0, 'data': self._serialize(club, full=True)})
|
||||
|
||||
if action == 'update':
|
||||
update_fields = []
|
||||
for field in self._EDITABLE_FIELDS:
|
||||
if field in request.data:
|
||||
setattr(club, field, request.data[field])
|
||||
update_fields.append(field)
|
||||
if update_fields:
|
||||
club.save(update_fields=update_fields)
|
||||
return Response({
|
||||
'code': 0,
|
||||
'msg': '保存成功',
|
||||
'data': self._serialize(club, full=True),
|
||||
})
|
||||
if action == 'update':
|
||||
update_fields = []
|
||||
for field in self._EDITABLE_FIELDS:
|
||||
if field in request.data:
|
||||
setattr(club, field, request.data[field])
|
||||
update_fields.append(field)
|
||||
if update_fields:
|
||||
club.save(update_fields=update_fields)
|
||||
return Response({
|
||||
'code': 0,
|
||||
'msg': '保存成功',
|
||||
'data': self._serialize(club, full=True),
|
||||
})
|
||||
|
||||
return Response({'code': 400, 'msg': '无效 action,支持 list/get/update'})
|
||||
return Response({'code': 400, 'msg': '无效 action,支持 list/get/update'})
|
||||
except Exception:
|
||||
logger.exception('ClubManageView 异常')
|
||||
return Response({'code': 99, 'msg': '俱乐部配置操作失败'}, status=500)
|
||||
|
||||
|
||||
class ClubCaiwuView(APIView):
|
||||
|
||||
Reference in New Issue
Block a user