fix: 订单分页缓存、统计与列表一致、admin-assignments 解析
This commit is contained in:
101
jituan/views.py
101
jituan/views.py
@@ -3,6 +3,7 @@ import logging
|
||||
|
||||
from django.utils import timezone
|
||||
from rest_framework import status
|
||||
from rest_framework.parsers import JSONParser
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
@@ -197,59 +198,65 @@ class ClubMeContextView(APIView):
|
||||
class ClubAdminAssignmentListView(APIView):
|
||||
"""POST /jituan/houtai/admin-assignments — 查看数据范围任职(非 gvsdsdk 功能权限)。"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
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
|
||||
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
|
||||
|
||||
user = request.user
|
||||
is_super = bool(user.IsSuperuser) or user.UserType == 'admin'
|
||||
if is_super:
|
||||
qs = AdminAssignment.query.filter(status=1).order_by('yonghuid', '-is_primary', 'club_id')
|
||||
else:
|
||||
qs = AdminAssignment.query.filter(yonghuid=user.UserUID, status=1).order_by('-is_primary')
|
||||
user = request.user
|
||||
is_super = bool(user.IsSuperuser) or user.UserType == 'admin'
|
||||
if is_super:
|
||||
qs = AdminAssignment.query.filter(status=1).order_by('yonghuid', '-is_primary', 'club_id')
|
||||
else:
|
||||
qs = AdminAssignment.query.filter(yonghuid=user.UserUID, status=1).order_by('-is_primary')
|
||||
|
||||
club_name_map = {
|
||||
c.club_id: c.name for c in Club.query.filter(status=1)
|
||||
}
|
||||
uids = list({a.yonghuid for a in qs})
|
||||
user_map = {}
|
||||
if uids:
|
||||
for u in User.query.filter(UserUID__in=uids).only('UserUID', 'Phone', 'UserName'):
|
||||
user_map[u.UserUID] = u.Phone or u.UserName or u.UserUID
|
||||
assignments = qs.to_list()
|
||||
club_name_map = {
|
||||
c.club_id: c.name for c in Club.query.filter(status=1)
|
||||
}
|
||||
uids = list({a.yonghuid for a in assignments})
|
||||
user_map = {}
|
||||
if uids:
|
||||
for u in User.query.filter(UserUID__in=uids).only('UserUID', 'Phone', 'UserName'):
|
||||
user_map[u.UserUID] = u.Phone or u.UserName or u.UserUID
|
||||
|
||||
rows = []
|
||||
for a in qs:
|
||||
club_label = '集团(全部子公司)'
|
||||
if a.club_id:
|
||||
club_label = club_name_map.get(a.club_id, a.club_id)
|
||||
rows.append({
|
||||
'yonghuid': a.yonghuid,
|
||||
'phone': user_map.get(a.yonghuid, ''),
|
||||
'club_id': a.club_id,
|
||||
'club_label': club_label,
|
||||
'role_code': a.role_code,
|
||||
'role_name': ADMIN_ROLE_LABELS.get(a.role_code, a.role_code),
|
||||
'data_scope': a.data_scope,
|
||||
'is_primary': a.is_primary,
|
||||
rows = []
|
||||
for a in assignments:
|
||||
club_label = '集团(全部子公司)'
|
||||
if a.club_id:
|
||||
club_label = club_name_map.get(a.club_id, a.club_id)
|
||||
rows.append({
|
||||
'yonghuid': a.yonghuid,
|
||||
'phone': user_map.get(a.yonghuid, ''),
|
||||
'club_id': a.club_id,
|
||||
'club_label': club_label,
|
||||
'role_code': a.role_code,
|
||||
'role_name': ADMIN_ROLE_LABELS.get(a.role_code, a.role_code),
|
||||
'data_scope': a.data_scope,
|
||||
'is_primary': a.is_primary,
|
||||
})
|
||||
|
||||
return Response({
|
||||
'code': 0,
|
||||
'msg': 'ok',
|
||||
'data': {
|
||||
'list': rows,
|
||||
'perm_note': (
|
||||
'功能菜单权限(能进哪些页面)在「角色管理」配置;'
|
||||
'本表 admin_assignment 仅控制集团/子公司数据范围。'
|
||||
),
|
||||
'current_context': build_admin_club_context(user),
|
||||
},
|
||||
})
|
||||
|
||||
return Response({
|
||||
'code': 0,
|
||||
'msg': 'ok',
|
||||
'data': {
|
||||
'list': rows,
|
||||
'perm_note': (
|
||||
'功能菜单权限(能进哪些页面)在「角色管理」配置;'
|
||||
'本表 admin_assignment 仅控制集团/子公司数据范围。'
|
||||
),
|
||||
'current_context': build_admin_club_context(user),
|
||||
},
|
||||
})
|
||||
except Exception:
|
||||
logger.exception('ClubAdminAssignmentListView 异常')
|
||||
return Response({'code': 99, 'msg': '加载任职数据失败,请确认已执行 migrate jituan'}, status=500)
|
||||
|
||||
|
||||
class ClubCaiwuView(APIView):
|
||||
|
||||
Reference in New Issue
Block a user