|
@@ -17,7 +17,7 @@ User = get_user_model()
|
|
|
from apps.account.serializers import JWTSerializer, EmployeeSerializer, GroupDictSerializer, GroupSerializer
|
|
|
from utils.custom_modelviewset import CustomModelViewSet
|
|
|
from apps.account.filters import UserFilter, GroupFilter
|
|
|
-from apps.account.models import ManageStoreUser
|
|
|
+from apps.account.models import ManageStoreUser,OfficeStoreUser
|
|
|
from apps.log.models import BizLog
|
|
|
from apps.account.consts import PermissionMenu
|
|
|
from collections import OrderedDict
|
|
@@ -159,6 +159,23 @@ class EmployeeViewSet(CustomModelViewSet):
|
|
|
traceback.print_exc()
|
|
|
return response_error(u'保存失败')
|
|
|
|
|
|
+ @action(methods=['post'], detail=True)
|
|
|
+ def office(self, request, pk):
|
|
|
+ check_permission(request, 'account.office_store')
|
|
|
+ data = json.loads(request.POST.get('stores'))
|
|
|
+ try:
|
|
|
+ with transaction.atomic():
|
|
|
+ instance = self.get_object()
|
|
|
+ OfficeStoreUser.objects.filter(office_user_id=pk).delete()
|
|
|
+ for row in data:
|
|
|
+ OfficeStoreUser.objects.create(store_id=row, office_user_id=pk)
|
|
|
+ BizLog.objects.addnew(self.request.user, BizLog.INSERT,
|
|
|
+ u'设置账号[%s]任职门店,id=%d' % (instance.username, instance.id), data)
|
|
|
+ return response_ok()
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ return response_error(u'保存失败')
|
|
|
+
|
|
|
|
|
|
class GroupsViewSet(CustomModelViewSet):
|
|
|
permission_classes = [isLogin, ]
|
|
@@ -412,3 +429,51 @@ class HomeStatisticsView(APIView):
|
|
|
return response_ok(statistics)
|
|
|
else:
|
|
|
return response_ok(statistics)
|
|
|
+
|
|
|
+
|
|
|
+class OfficeStoreView(APIView):
|
|
|
+ permission_classes = [isLogin, ]
|
|
|
+
|
|
|
+ @permission_required('account.office_store')
|
|
|
+ def get(self, request):
|
|
|
+ id = request.GET.get('id')
|
|
|
+ store_data = []
|
|
|
+ # 查询当前用户的代理商和管理的门店
|
|
|
+ general_agents = GeneralAgent.objects.filter()
|
|
|
+ if not request.user.is_superuser:
|
|
|
+ general_agents = GeneralAgent.objects.filter(id=request.user.general_agent_id)
|
|
|
+ general_agents = general_agents.values('id', 'name')
|
|
|
+ for general_agent in general_agents:
|
|
|
+ general_agent_item = {
|
|
|
+ 'title': general_agent['name'],
|
|
|
+ 'id': general_agent['id'],
|
|
|
+ 'field': 'general_agent',
|
|
|
+ 'children': [],
|
|
|
+ }
|
|
|
+ agents = Agent.objects.filter(general_agent_id=general_agent['id'])
|
|
|
+ if request.user.agent:
|
|
|
+ agents = agents.filter(id=request.user.agent_id)
|
|
|
+ agents = agents.values('id', 'name')
|
|
|
+ for agent in agents:
|
|
|
+ agent_item = {
|
|
|
+ 'title': agent['name'],
|
|
|
+ 'id': agent['id'],
|
|
|
+ 'field': 'agent',
|
|
|
+ 'children': [],
|
|
|
+ }
|
|
|
+ general_agent_item['children'].append(agent_item)
|
|
|
+ stores = Store.objects.filter(agent_id=agent['id'], id__in=request.user.get_manager_range(),
|
|
|
+ check_user__isnull=False, enable=True).values('id', 'name')
|
|
|
+ for store in stores:
|
|
|
+ office_store = OfficeStoreUser.objects.filter(office_user_id=id, store_id=store['id']).first()
|
|
|
+ checked = office_store and True or False
|
|
|
+ store_item = {
|
|
|
+ 'title': store['name'],
|
|
|
+ 'id': store['id'],
|
|
|
+ 'checked': checked,
|
|
|
+ 'field': 'store_{}'.format(store['id']),
|
|
|
+ }
|
|
|
+ agent_item['children'].append(store_item)
|
|
|
+ store_data.append(general_agent_item)
|
|
|
+
|
|
|
+ return response_ok(store_data)
|