|
@@ -3,28 +3,29 @@ import traceback
|
|
from rest_framework.views import APIView
|
|
from rest_framework.views import APIView
|
|
from rest_framework.decorators import action
|
|
from rest_framework.decorators import action
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
-from django.conf import settings
|
|
|
|
-
|
|
|
|
|
|
+import datetime
|
|
|
|
+from django.utils import timezone
|
|
from utils.custom_modelviewset import CustomModelViewSet
|
|
from utils.custom_modelviewset import CustomModelViewSet
|
|
from utils.exceptions import CustomError
|
|
from utils.exceptions import CustomError
|
|
-from .serializers import OrderSerializer,ProgressDetailsSerializer
|
|
|
|
|
|
+from .serializers import OrderSerializer, ProgressDetailsSerializer
|
|
from .filters import OrderFilter
|
|
from .filters import OrderFilter
|
|
from apps.log.models import BizLog
|
|
from apps.log.models import BizLog
|
|
from django.db.models import Q
|
|
from django.db.models import Q
|
|
from utils import response_ok, response_error
|
|
from utils import response_ok, response_error
|
|
from utils.permission import isLogin, check_permission
|
|
from utils.permission import isLogin, check_permission
|
|
-from apps.customer.models import NewCustomer
|
|
|
|
-from apps.order.models import Order,ProgressDetails
|
|
|
|
|
|
+from apps.customer.models import NewCustomer, NewCustomerRemind
|
|
|
|
+from apps.order.models import Order, ProgressDetails
|
|
from apps.option.models import Option
|
|
from apps.option.models import Option
|
|
from apps.upload.models import Upload
|
|
from apps.upload.models import Upload
|
|
from apps.upload.serializers import UploadSerializer
|
|
from apps.upload.serializers import UploadSerializer
|
|
|
|
|
|
|
|
+
|
|
class GetProcessView(APIView):
|
|
class GetProcessView(APIView):
|
|
permission_classes = [isLogin]
|
|
permission_classes = [isLogin]
|
|
|
|
|
|
def get(self, request):
|
|
def get(self, request):
|
|
customer_id = request.query_params.get('customer_id')
|
|
customer_id = request.query_params.get('customer_id')
|
|
- dispatch = request.query_params.get('dispatch') # 分配服务人员,
|
|
|
|
|
|
+ dispatch = request.query_params.get('dispatch') # 分配服务人员,
|
|
|
|
|
|
instance = NewCustomer.objects.filter(id=customer_id).first()
|
|
instance = NewCustomer.objects.filter(id=customer_id).first()
|
|
if not instance:
|
|
if not instance:
|
|
@@ -44,9 +45,9 @@ class GetProcessView(APIView):
|
|
enable=True).order_by('sort').first()
|
|
enable=True).order_by('sort').first()
|
|
if option:
|
|
if option:
|
|
data = {
|
|
data = {
|
|
- 'now_process_text':instance.stage_progress.name,
|
|
|
|
- 'next_process_text':option.name,
|
|
|
|
- 'next_process_id':option.id,
|
|
|
|
|
|
+ 'now_process_text': instance.stage_progress.name,
|
|
|
|
+ 'next_process_text': option.name,
|
|
|
|
+ 'next_process_id': option.id,
|
|
}
|
|
}
|
|
return response_ok(data)
|
|
return response_ok(data)
|
|
else:
|
|
else:
|
|
@@ -76,6 +77,41 @@ class OrderViewSet(CustomModelViewSet):
|
|
return None
|
|
return None
|
|
return self.paginator.paginate_queryset(queryset, self.request, view=self)
|
|
return self.paginator.paginate_queryset(queryset, self.request, view=self)
|
|
|
|
|
|
|
|
+ @action(methods=['post'], detail=True)
|
|
|
|
+ def dispatch_service(self, request, pk):
|
|
|
|
+ # 订单分配服务人员
|
|
|
|
+ check_permission(request, 'order.order_process_dispatch')
|
|
|
|
+ stage_progress = request.POST.get('stage_progress')
|
|
|
|
+ service = request.POST.get('service')
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ with transaction.atomic():
|
|
|
|
+ stage_progress = Option.objects.filter(id=stage_progress, enable=True).order_by('sort').first()
|
|
|
|
+ if not stage_progress:
|
|
|
|
+ raise CustomError('阶段进度有误,请刷新重试!')
|
|
|
|
+ if not stage_progress.track_day:
|
|
|
|
+ raise CustomError('下一阶段进度,没有可用跟踪天数,请联系管理员设置!')
|
|
|
|
+ Order.objects.filter(id=pk).update(stage_progress=stage_progress, service_user_id=service,
|
|
|
|
+ status=Order.NORMAL)
|
|
|
|
+
|
|
|
|
+ next_time = (timezone.now() + datetime.timedelta(days=stage_progress.track_day)).strftime('%Y-%m-%d')
|
|
|
|
+ # 更新进度,删除上一个跟踪人提醒
|
|
|
|
+ order = self.get_object()
|
|
|
|
+ NewCustomerRemind.objects.filter(customer=order.customer, remind_user=order.customer.track_user).delete()
|
|
|
|
+ NewCustomer.objects.filter(id=order.customer_id).update(
|
|
|
|
+ stage_progress=stage_progress,
|
|
|
|
+ track_user_id=service,
|
|
|
|
+ next_time=next_time,
|
|
|
|
+ )
|
|
|
|
+ NewCustomerRemind.objects.create(customer=order.customer, remind_user_id=service, next_time=next_time)
|
|
|
|
+ operation = u'分配服务人员为:{}'.format(order.service_user.name)
|
|
|
|
+ ProgressDetails.objects.create(order=order, user=request.user, operation=operation,)
|
|
|
|
+ except CustomError as e:
|
|
|
|
+ return response_error(e.get_error_msg())
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response_error(str(e))
|
|
|
|
+ return response_ok()
|
|
|
|
+
|
|
|
|
|
|
class GetDetailsView(APIView):
|
|
class GetDetailsView(APIView):
|
|
permission_classes = [isLogin]
|
|
permission_classes = [isLogin]
|
|
@@ -96,4 +132,4 @@ class GetFilesView(APIView):
|
|
id = request.GET.get('id')
|
|
id = request.GET.get('id')
|
|
images = Upload.objects.filter(progress_details_id=id)
|
|
images = Upload.objects.filter(progress_details_id=id)
|
|
img_data = UploadSerializer(images, many=True).data
|
|
img_data = UploadSerializer(images, many=True).data
|
|
- return response_ok(img_data)
|
|
|
|
|
|
+ return response_ok(img_data)
|