fix: bind kefu role by yonghuid when phone duplicated
This commit is contained in:
@@ -596,15 +596,13 @@ class ModifyAdminUserView(APIView):
|
||||
if '000001' not in permissions:
|
||||
return Response({'code': 403, 'msg': '您无权进行此操作'})
|
||||
|
||||
target_yonghuid = request.data.get('yonghuid', '').strip()
|
||||
target_phone = request.data.get('phone', '').strip()
|
||||
if not target_phone:
|
||||
return Response({'code': 400, 'msg': '缺少目标用户账号'})
|
||||
if not target_yonghuid and not target_phone:
|
||||
return Response({'code': 400, 'msg': '缺少目标用户(yonghuid 或 phone)'})
|
||||
|
||||
# Phone 非唯一,同一手机号可能对应多个微信用户;后台操作只定位客服账号
|
||||
target_user = User.query.filter(
|
||||
Phone=target_phone,
|
||||
KefuProfile__isnull=False,
|
||||
).first()
|
||||
from jituan.services.club_rbac import resolve_kefu_admin_user
|
||||
target_user = resolve_kefu_admin_user(yonghuid=target_yonghuid, phone=target_phone)
|
||||
if not target_user:
|
||||
return Response({'code': 404, 'msg': '用户不存在或非后台账号'})
|
||||
try:
|
||||
|
||||
@@ -85,3 +85,18 @@ def user_bound_role_names(user):
|
||||
return list(
|
||||
Role.objects.filter(RoleUUID__in=uuids, RoleStatus=1).values_list('RoleName', flat=True)
|
||||
)
|
||||
|
||||
|
||||
def resolve_kefu_admin_user(yonghuid=None, phone=None):
|
||||
"""定位后台客服 User;优先 yonghuid(同手机号多账号时必须用 ID)。"""
|
||||
from users.business_models import User
|
||||
|
||||
uid = (yonghuid or '').strip()
|
||||
if uid:
|
||||
user = User.objects.filter(UserUID=uid, KefuProfile__isnull=False).first()
|
||||
if user:
|
||||
return user
|
||||
ph = (phone or '').strip()
|
||||
if not ph:
|
||||
return None
|
||||
return User.objects.filter(Phone=ph, KefuProfile__isnull=False).order_by('-UserCreateTime').first()
|
||||
|
||||
@@ -134,6 +134,7 @@ def build_menu_access_payload(request, username=None):
|
||||
'visible_paths': visible_paths,
|
||||
'permission_codes': _permission_codes_list(permissions),
|
||||
'role_names': user_bound_role_names(request.user),
|
||||
'yonghuid': getattr(request.user, 'UserUID', '') or '',
|
||||
'can_switch_club': bool(club_ctx.get('can_switch_club')),
|
||||
'is_group_admin': bool(club_ctx.get('is_group_admin')),
|
||||
'menu_ready': True,
|
||||
|
||||
@@ -171,6 +171,7 @@ class ClubKefuLoginView(APIView):
|
||||
'visible_paths': [],
|
||||
'permission_codes': [],
|
||||
'role_names': [],
|
||||
'yonghuid': target_user.UserUID or '',
|
||||
'can_switch_club': False,
|
||||
'is_group_admin': False,
|
||||
'menu_ready': False,
|
||||
|
||||
Reference in New Issue
Block a user