|
@@ -1,6 +1,7 @@
|
|
|
# coding=utf-8
|
|
|
from rest_framework.views import APIView
|
|
|
from django.db.models import Q
|
|
|
+import datetime
|
|
|
from django.utils import timezone
|
|
|
from rest_framework.decorators import action
|
|
|
from utils.permission import isLogin, permission_required, check_permission
|
|
@@ -55,8 +56,8 @@ class ReportCustomerViewSet(CustomModelViewSet):
|
|
|
def dispatch_customer(self, request, pk):
|
|
|
check_permission(request, 'customer.check_report_customer')
|
|
|
# 审核
|
|
|
- # TODO 创建潜客跟踪表
|
|
|
user = request.POST.get('user')
|
|
|
+ user = User.objects.filter(id=user).first()
|
|
|
try:
|
|
|
instance = ReportCustomer.objects.filter(id=pk).first()
|
|
|
if not instance:
|
|
@@ -67,6 +68,16 @@ class ReportCustomerViewSet(CustomModelViewSet):
|
|
|
instance.save()
|
|
|
BizLog.objects.addnew(request.user, BizLog.INSERT,
|
|
|
u'分配客户报备[%s],id=%d' % (instance.name, instance.id))
|
|
|
+ # 创建潜客跟踪表
|
|
|
+ potential_level = Option.objects.filter(type=Option.POTENTIAL_LEVEL).order_by('sort').first()
|
|
|
+ stage_progress = Option.objects.filter(type=Option.STAGE_PROGRESS).order_by('sort').first()
|
|
|
+ if not potential_level.track_day:
|
|
|
+ raise CustomError('当前潜客级别,没有可用跟踪天数!')
|
|
|
+ next_time = (timezone.now() + datetime.timedelta(days=potential_level.track_day)).strftime('%Y-%m-%d')
|
|
|
+ NewCustomer.objects.create(report_customer=instance, potential_level=potential_level,
|
|
|
+ track_user=user, next_time=next_time, stage_progress=stage_progress,
|
|
|
+ create_user=instance.create_user,
|
|
|
+ )
|
|
|
except CustomError as e:
|
|
|
return response_error(e.get_error_msg())
|
|
|
except Exception as e:
|
|
@@ -107,4 +118,4 @@ class NewCustomerViewSet(CustomModelViewSet):
|
|
|
def filter_queryset(self, queryset):
|
|
|
queryset = queryset.filter()
|
|
|
f = NewCustomerFilter(self.request.GET, queryset=queryset)
|
|
|
- return f.qs
|
|
|
+ return f.qs
|