|
@@ -5,17 +5,16 @@ from django.utils import timezone
|
|
|
from rest_framework.decorators import action
|
|
|
from rest_framework.views import APIView
|
|
|
from django.conf import settings
|
|
|
-
|
|
|
+from django.db import transaction
|
|
|
from utils import response_ok, response_error
|
|
|
from utils.exceptions import CustomError
|
|
|
from apps.log.models import BizLog
|
|
|
from .models import GeneralAgent, Agent, Store
|
|
|
from .serializers import GeneralAgentSerializer, AgentSerializer, StoreSerializer
|
|
|
from .filters import GeneralAgentFilter, AgentFilter, StoreFilter
|
|
|
-from utils.permission import isLogin, permission_required
|
|
|
+from utils.permission import isLogin, check_permission, permission_required
|
|
|
from apps.agent.serializers import AgentComboboxSerializer, StoreComboboxSerializer, GeneralAgentComboboxSerializer
|
|
|
|
|
|
-
|
|
|
class GeneralAgentViewSet(CustomModelViewSet):
|
|
|
permission_classes = [isLogin, ]
|
|
|
queryset = GeneralAgent.objects.filter()
|
|
@@ -23,7 +22,9 @@ class GeneralAgentViewSet(CustomModelViewSet):
|
|
|
|
|
|
@permission_required('agent.view_agent')
|
|
|
def filter_queryset(self, queryset):
|
|
|
- queryset = queryset.filter(Q(id=self.request.user.general_agent_id) | Q(create_user=self.request.user))
|
|
|
+ queryset = queryset.filter(create_user=self.request.user)
|
|
|
+ if self.request.user.general_agent:
|
|
|
+ queryset = queryset.filter(id=self.request.user.general_agent.id)
|
|
|
f = GeneralAgentFilter(self.request.GET, queryset=queryset)
|
|
|
return f.qs
|
|
|
|
|
@@ -100,24 +101,25 @@ class StoreViewSet(CustomModelViewSet):
|
|
|
super(StoreViewSet, self).perform_destroy(instance)
|
|
|
return response_ok()
|
|
|
|
|
|
- @permission_required('agent.check_store')
|
|
|
@action(methods=['post'], detail=True)
|
|
|
def check(self, request, pk):
|
|
|
# 审核
|
|
|
+ check_permission(request, 'agent.check_store')
|
|
|
status = request.POST.get('status')
|
|
|
try:
|
|
|
- instance = Store.objects.filter(id=pk).first()
|
|
|
- if not instance:
|
|
|
- raise CustomError('当前门店信息有误!')
|
|
|
- if instance.status > settings.DEFAULT:
|
|
|
- raise CustomError('当前企业已审核!')
|
|
|
-
|
|
|
- instance.check_user = request.user
|
|
|
- instance.status = status
|
|
|
- instance.check_time = timezone.now()
|
|
|
- instance.save()
|
|
|
- BizLog.objects.addnew(request.user, BizLog.INSERT,
|
|
|
- u'审核门店[%s]状态为[%s],id=%d' % (instance.name, status, instance.id))
|
|
|
+ with transaction.atomic():
|
|
|
+ instance = Store.objects.filter(id=pk).first()
|
|
|
+ if not instance:
|
|
|
+ raise CustomError('当前门店信息有误!')
|
|
|
+ if instance.status > settings.DEFAULT:
|
|
|
+ raise CustomError('当前企业已审核!')
|
|
|
+
|
|
|
+ instance.check_user = request.user
|
|
|
+ instance.status = status
|
|
|
+ instance.check_time = timezone.now()
|
|
|
+ instance.save()
|
|
|
+ BizLog.objects.addnew(request.user, BizLog.INSERT,
|
|
|
+ u'审核门店[%s]状态为[%s],id=%d' % (instance.name, status, instance.id))
|
|
|
except CustomError as e:
|
|
|
return response_error(e.get_error_msg())
|
|
|
except Exception as e:
|