fix: 支付 request.user、jituan import、财务日统计汇总
This commit is contained in:
@@ -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