fix: 支付 request.user、jituan import、财务日统计汇总

This commit is contained in:
XingQue
2026-06-24 06:34:35 +08:00
parent 5ae01a9ff2
commit bfc38c2d43
4 changed files with 52 additions and 54 deletions

View File

@@ -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,
}

View File

@@ -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):

View File

@@ -410,7 +410,7 @@ class YajinGoumai(APIView):
# 获取配置
from jituan.services.club_write import resolve_club_id_for_write
from jituan.services.wechat_pay import get_wechat_v2_config
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, request.user))
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, self.request.user))
APPID = pay_cfg['appid']
MCHID = pay_cfg['mch_id']
KEY = pay_cfg['key']
@@ -1002,7 +1002,7 @@ class JifenBuchong(APIView):
# 微信支付配置 - 从settings中获取
from jituan.services.club_write import resolve_club_id_for_write
from jituan.services.wechat_pay import get_wechat_v2_config
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, request.user))
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, self.request.user))
APPID = pay_cfg['appid']
MCHID = pay_cfg['mch_id']
KEY = pay_cfg['key']
@@ -1567,7 +1567,7 @@ class HuiyuanGoumai(APIView):
# 微信支付配置 - 从settings中获取
from jituan.services.club_write import resolve_club_id_for_write
from jituan.services.wechat_pay import get_wechat_v2_config
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, request.user))
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, self.request.user))
APPID = pay_cfg['appid']
MCHID = pay_cfg['mch_id']
KEY = pay_cfg['key']
@@ -2418,7 +2418,7 @@ class ShangjiaChongzhi(APIView):
# 获取配置
from jituan.services.club_write import resolve_club_id_for_write
from jituan.services.wechat_pay import get_wechat_v2_config
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, request.user))
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, self.request.user))
APPID = pay_cfg['appid']
MCHID = pay_cfg['mch_id']
KEY = pay_cfg['key']

View File

@@ -11784,7 +11784,7 @@ class FaKuanPayView(APIView):
def generate_wechat_pay_params(self, dingdanid, jine, openid, pay_type):
from jituan.services.club_write import resolve_club_id_for_write
from jituan.services.wechat_pay import get_wechat_v2_config
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, request.user))
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, self.request.user))
APPID = pay_cfg['appid']
MCHID = pay_cfg['mch_id']
KEY = pay_cfg['key']
@@ -12277,7 +12277,7 @@ class KaohePayView(APIView):
"""生成微信JSAPI支付参数"""
from jituan.services.club_write import resolve_club_id_for_write
from jituan.services.wechat_pay import get_wechat_v2_config
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, request.user))
pay_cfg = get_wechat_v2_config(resolve_club_id_for_write(self.request, self.request.user))
APPID = pay_cfg['appid']
MCHID = pay_cfg['mch_id']
KEY = pay_cfg['key']