|
@@ -99,6 +99,24 @@ class EmployeeViewSet(CustomModelViewSet):
|
|
|
BizLog.objects.addnew(self.request.user, BizLog.UPDATE,
|
|
|
u'修改用户[%s],id=%d' % (instance.name, instance.id), validated_data)
|
|
|
|
|
|
+ @action(methods=['post'], detail=True)
|
|
|
+ def manager(self, request, pk):
|
|
|
+ # 管理员工
|
|
|
+ if not request.user.is_superuser:
|
|
|
+ return response_error('无权操作')
|
|
|
+ data = json.loads(request.POST.get('users'))
|
|
|
+ try:
|
|
|
+ instance = self.get_object()
|
|
|
+ with transaction.atomic():
|
|
|
+ instance.manager_users = ','.join(data)
|
|
|
+ instance.save()
|
|
|
+ BizLog.objects.addnew(self.request.user, BizLog.INSERT,
|
|
|
+ u'设置[%s]管理员工,id=%d' % (instance.name, instance.id), data)
|
|
|
+ return response_ok()
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ return response_error(u'保存失败')
|
|
|
+
|
|
|
|
|
|
class SetUserInfoView(APIView):
|
|
|
permission_classes = [isLogin, ]
|
|
@@ -165,3 +183,26 @@ class UserDictView(APIView):
|
|
|
}
|
|
|
data.append(item)
|
|
|
return response_ok(data)
|
|
|
+
|
|
|
+class UserTreeView(APIView):
|
|
|
+ permission_classes = [isLogin, ]
|
|
|
+
|
|
|
+ def get(self, request):
|
|
|
+ if not request.user.is_superuser:
|
|
|
+ return response_error('无权操作')
|
|
|
+ id = request.GET.get('id')
|
|
|
+ agent_data = []
|
|
|
+ user = User.objects.filter(id=id).first()
|
|
|
+ manager_users = user.manager_users and user.manager_users.split(',') or [] # 选择用户
|
|
|
+ companys = User.objects.filter(is_active=True, is_superuser=False, type=User.SELLER)
|
|
|
+ for company in companys:
|
|
|
+ checked = False
|
|
|
+ if str(company.id) in manager_users:
|
|
|
+ checked = True
|
|
|
+ agent_item = {
|
|
|
+ 'title': company.name,
|
|
|
+ 'id': company.id,
|
|
|
+ 'checked': checked,
|
|
|
+ }
|
|
|
+ agent_data.append(agent_item)
|
|
|
+ return response_ok(agent_data)
|