Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	uis/views/store/index.html
wushaodong 4 years ago
parent
commit
c72031ff8e

+ 2 - 0
apps/agent/serializers.py

@@ -29,6 +29,8 @@ class StoreComboboxSerializer(serializers.ModelSerializer):
 
 class StoreSerializer(serializers.ModelSerializer):
     create_user_text = serializers.CharField(source='create_user.name', read_only=True)
+    status_text = serializers.CharField(source='get_status_display', read_only=True)
+    check_user_text = serializers.CharField(source='check_user.name', read_only=True)
 
     class Meta:
         model = Store

+ 24 - 0
apps/agent/views.py

@@ -2,9 +2,12 @@
 from utils.custom_modelviewset import CustomModelViewSet
 from django.db.models import Q
 from django.utils import timezone
+from rest_framework.decorators import action
 from rest_framework.views import APIView
+from django.conf import settings
 
 from utils import response_ok, response_error
+from utils.exceptions import CustomError
 from .models import Agent,Store
 from .serializers import AgentSerializer,StoreSerializer
 from .filters import AgentFilter,StoreFilter
@@ -51,6 +54,27 @@ class StoreViewSet(CustomModelViewSet):
         super(StoreViewSet, self).perform_destroy(instance)
         return response_ok()
 
+    @action(methods=['post'], detail=True)
+    def check(self, request, pk):
+        # 审核
+        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 = self.request.user
+            instance.status = status
+            instance.check_time = timezone.now()
+            instance.save()
+        except CustomError as e:
+            return response_error(e.get_error_msg())
+        except Exception as e:
+            return response_error(str(e))
+        return response_ok('审核完成!')
+
 class AgentDictView(APIView):
     permission_classes = [isLogin, ]
 

+ 19 - 18
apps/customer/models.py

@@ -24,7 +24,8 @@ class ReportCustomer(models.Model):
     village = models.CharField(max_length=100, verbose_name=u'小区')
     address = models.CharField(max_length=100, verbose_name=u'地址')
     source = models.ForeignKey(Option, verbose_name=u'来源', related_name='customer_source', on_delete=models.PROTECT)
-    project = models.ManyToManyField(Option, verbose_name=u'项目', related_name='customer_category', editable=False, null=True,blank=True)
+    project = models.ManyToManyField(Option, verbose_name=u'项目', related_name='customer_category', editable=False,
+                                     null=True,blank=True)
     notes = models.CharField(max_length=500, verbose_name=u"备注", null=True)
     report_status = models.PositiveSmallIntegerField(choices=STATUS_CHOICES, verbose_name=u'报备状态', default=NOT_CHECKED)
     check_user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=u'审核人', related_name='customer_check_user',
@@ -41,22 +42,22 @@ class ReportCustomer(models.Model):
         ordering = ['-id']
         default_permissions = ()
         permissions = [
-            ('view_customer', u'查看'),
-            ('add_customer', u'添加'),
-            ('update_customer', u'更新'),
-            ('delete_customer', u'删除'),
-            ('check_customer', u'审核'),
+            ('view_report_customer', u'查看'),
+            ('add_report_customer', u'添加'),
+            ('update_report_customer', u'更新'),
+            ('delete_report_customer', u'删除'),
+            ('check_report_customer', u'审核'),
         ]
 
-    def check_customer(self, user):
-        # 审核
-        if self.report_status == ReportCustomer.REPEAT_REPORT:
-            raise CustomError('当前客户报备状态为重复报备!')
-
-        if self.report_status == ReportCustomer.NOT_CHECKED:
-            self.check_user = user
-            self.report_status = ReportCustomer.CHECKED
-            self.check_time = timezone.now()
-            self.save()
-        # if self.report_status == Customer.CHECKED:
-        #     # 撞单
+    # def check_customer(self, user):
+    #     # 审核
+    #     if self.report_status == ReportCustomer.REPEAT_REPORT:
+    #
+    #
+    #     if self.report_status == ReportCustomer.NOT_CHECKED:
+    #         self.check_user = user
+    #         self.report_status = ReportCustomer.CHECKED
+    #         self.check_time = timezone.now()
+    #         self.save()
+    #     # if self.report_status == Customer.CHECKED:
+    #     #     # 撞单

+ 2 - 2
apps/customer/serializers.py

@@ -36,7 +36,7 @@ class ReportCustomerSerializer(serializers.ModelSerializer):
         return instance
 
     def update(self, instance, validated_data):
-        instance = super(ReportCustomerSerializer, self).update(instance, validated_data)
+        instance.project.clear()
         projects = self.initial_data['project']
         if projects:
             projects = json.loads(projects)
@@ -45,5 +45,5 @@ class ReportCustomerSerializer(serializers.ModelSerializer):
 
         for project in projects:
             instance.project.add(project)
+        instance = super(ReportCustomerSerializer, self).update(instance, validated_data)
         return instance
-

+ 29 - 21
apps/customer/views.py

@@ -1,9 +1,12 @@
 # coding=utf-8
 from rest_framework.views import APIView
 from django.db.models import Q
+from django.utils import timezone
+from rest_framework.decorators import action
 
 from utils.custom_modelviewset import CustomModelViewSet
 from utils import response_ok, response_error
+from utils.exceptions import CustomError
 from apps.option.models import Option
 from apps.option.serializers import OptionComboboxSerializer
 from .models import ReportCustomer
@@ -35,25 +38,32 @@ class ReportCustomerViewSet(CustomModelViewSet):
         super(ReportCustomerViewSet, self).perform_destroy(instance)
 
 
-    # @action(methods=['post'], detail=False)
-    # def check(self, request, pk):
-    #     # 审核
-    #     report_status = request.POST.get('report_status')
-    #     try:
-    #         instance = Customer.objects.filter(id=pk).first()
-    #         if not instance:
-    #             raise CustomError('当前客户报备信息有误!')
-    #
-    #         instance.check_user = self.request.user
-    #         instance.report_status = report_status
-    #         instance.check_time = timezone.now()
-    #         instance.save()
-    #
-    #     except CustomError as e:
-    #         return response_error(e.get_error_msg())
-    #     except Exception as e:
-    #         return response_error(str(e))
-    #     return response_ok('审核完成!')
+    @action(methods=['post'], detail=False)
+    def check(self, request, pk):
+        # 审核
+        report_status = request.POST.get('report_status')
+        try:
+            instance = ReportCustomer.objects.filter(id=pk).first()
+            if not instance:
+                raise CustomError('当前客户报备信息有误!')
+            if report_status == ReportCustomer.REPEAT_REPORT:
+                raise CustomError('当前客户报备状态为重复报备!')
+            if instance.report_status == ReportCustomer.CHECKED and report_status == ReportCustomer.CHECKED:
+                # 撞单
+                instance.check_user = self.request.user
+                instance.report_status = ReportCustomer.REPEAT_REPORT
+                instance.check_time = timezone.now()
+                instance.save()
+            if instance.report_status == ReportCustomer.NOT_CHECKED and report_status == ReportCustomer.CHECKED:
+                instance.check_user = self.request.user
+                instance.report_status = ReportCustomer.CHECKED
+                instance.check_time = timezone.now()
+                instance.save()
+        except CustomError as e:
+            return response_error(e.get_error_msg())
+        except Exception as e:
+            return response_error(str(e))
+        return response_ok('审核完成!')
 
 class ReportCustomerDictView(APIView):
     permission_classes = []
@@ -67,5 +77,3 @@ class ReportCustomerDictView(APIView):
             'source': serializer_scouce.data,
             'project': serializer_project.data,
         })
-
-

+ 1 - 1
uis/views/agent/edit.html

@@ -110,7 +110,7 @@
                 , data: data.field
                 , type: type
                 , done: function (res) {
-                    parent.layui.onSubmitChild(res.data);
+                    parent.layui.onSubmitChild(res);
                 }
             });
 

+ 11 - 2
uis/views/agent/index.html

@@ -132,6 +132,9 @@
                         url: '/agent/agent/' + data.id + '/'
                         , type: 'delete'
                         , done: function (res) {
+                             if(res.code === 0){
+                                layer.msg('删除成功!', {icon: 1})
+                             }
                             table.reload('agent_datagrid', {});
                         }
                     });
@@ -145,7 +148,10 @@
                     area: ['40%', '50%'],
                     btn: ['保存', '取消'],
                     yes: function (index, dom) {
-                        layui.onSubmitChild = function (data) {
+                        layui.onSubmitChild = function (res) {
+                            if(res.code === 0){
+                                layer.msg('修改成功!', {icon: 1})
+                            }
                             layer.close(index);
                             table.reload('agent_datagrid', {});
                         };
@@ -175,7 +181,10 @@
                 area: ['40%', '50%'],
                 btn: ['保存', '取消'],
                 yes: function (index, dom) {
-                    layui.onSubmitChild = function (data) {
+                    layui.onSubmitChild = function (res) {
+                        if(res.code === 0){
+                            layer.msg('添加成功!', {icon: 1})
+                        }
                         layer.close(index);
                         table.reload('agent_datagrid', {});
                     };

+ 1 - 1
uis/views/customer/edit.html

@@ -170,7 +170,7 @@
                 , data: submitData
                 , type: type
                 , done: function (res) {
-                    parent.layui.onSubmitChild(res.data);
+                    parent.layui.onSubmitChild(res);
                 }
             });
 

+ 11 - 2
uis/views/customer/index.html

@@ -185,6 +185,9 @@
                         url: '/customer/report_customer/' + data.id + '/'
                         , type: 'delete'
                         , done: function (res) {
+                            if(res.code === 0){
+                                layer.msg('删除成功!', {icon: 1})
+                             }
                             table.reload('customer_datagrid', {});
                         }
                     });
@@ -202,7 +205,10 @@
                     area: ['45%', '80%'],
                     btn: ['保存', '取消'],
                     yes: function (index, dom) {
-                        layui.onSubmitChild = function (data) {
+                        layui.onSubmitChild = function (res) {
+                            if(res.code === 0){
+                                layer.msg('修改成功!', {icon: 1})
+                             }
                             layer.close(index);
                             table.reload('customer_datagrid', {});
                         };
@@ -232,7 +238,10 @@
                 area: ['45%', '80%'],
                 btn: ['保存', '取消'],
                 yes: function (index, dom) {
-                    layui.onSubmitChild = function (data) {
+                    layui.onSubmitChild = function (res) {
+                        if(res.code === 0){
+                            layer.msg('添加成功!', {icon: 1})
+                         }
                         layer.close(index);
                         table.reload('customer_datagrid', {});
                     };

+ 1 - 1
uis/views/store/edit.html

@@ -103,7 +103,7 @@
                 , data: data.field
                 , type: type
                 , done: function (res) {
-                    parent.layui.onSubmitChild(res.data);
+                    parent.layui.onSubmitChild(res);
                 }
             });
 

+ 40 - 5
uis/views/store/index.html

@@ -78,6 +78,10 @@
                     <table class="layui-hide" id="store_datagrid" lay-filter="store-operate"></table>
 
                     <script type="text/html" id="store-operate-bar">
+                        <div class="layui-btn-group">
+                            <a class="layui-btn layui-btn-xs" lay-event="store_check"
+                            >审核</a>
+                        </div>
                         <div class="layui-btn-group">
                             <a class="layui-btn layui-btn-xs" lay-event="store_edit" data-permission="agent.add_store"
                             >修改</a>
@@ -110,11 +114,14 @@
             , cols: [[
                 {field: 'name', title: '名称', width: 150}
                 , {field: 'address', title: '地址', width: 200}
-                , {field: 'create_user_text', title: '添加人', width: 100}
+                , {field: 'create_user_text', title: '添加人', width: 160}
                 , {field: 'create_time', title: '添加时间', width: 180}
                 , {field: 'end_date', title: '到期日期', width: 150}
                 , {field: 'notes', title: '备注', width: 200}
-                , {width: 150, align: 'center', fixed: 'right', toolbar: '#store-operate-bar'}
+                , {field: 'status_text', title: '状态', width: 150}
+                , {field: 'check_user_text', title: '审核人', width: 150}
+                , {field: 'check_time', title: '审核时间', width: 180}
+                , {width: 180, align: 'center', fixed: 'right', toolbar: '#store-operate-bar'}
             ]]
             , page: true
             , height: 'full-108'
@@ -127,9 +134,12 @@
                 layer.confirm('确定要删除吗?', function (index) {
                     layer.close(index);
                     admin.req({
-                        url: '/agent/agent/' + data.id + '/'
+                        url: '/agent/store/' + data.id + '/'
                         , type: 'delete'
                         , done: function (res) {
+                            if(res.code === 0){
+                                layer.msg('删除成功!', {icon: 1})
+                            }
                             table.reload('store_datagrid', {});
                         }
                     });
@@ -143,7 +153,10 @@
                     area: ['40%', '50%'],
                     btn: ['保存', '取消'],
                     yes: function (index, dom) {
-                        layui.onSubmitChild = function (data) {
+                        layui.onSubmitChild = function (res) {
+                            if(res.code === 0){
+                                layer.msg('修改成功!', {icon: 1})
+                            }
                             layer.close(index);
                             table.reload('store_datagrid', {});
                         };
@@ -154,6 +167,25 @@
                     },
                     content: 'edit.html?id=' + data.id
                 });
+            }else if(obj.event === 'store_check'){
+                if(data.status !== 0){
+                    layer.msg("只有待审核状态才允许审核");
+                    return
+                }
+                layer.confirm('确定要审核当前门店吗?', {icon: 3, title:'提示'}, function(index){
+                    admin.req({
+                        url: '/agent/store/' + data.id + '/check/'
+                        , type: 'post'
+                        , data: {status: 1}
+                        , done: function (res) {
+                            if(res.code === 0){
+                               layer.msg(res.data, {icon: 1});
+                               table.reload('store_datagrid', {});
+                            }
+                        }
+                    });
+                    layer.close(index);
+                });
             }
         });
 
@@ -173,7 +205,10 @@
                 area: ['40%', '50%'],
                 btn: ['保存', '取消'],
                 yes: function (index, dom) {
-                    layui.onSubmitChild = function (data) {
+                    layui.onSubmitChild = function (res) {
+                        if(res.code === 0){
+                            layer.msg('添加成功!', {icon: 1})
+                         }
                         layer.close(index);
                         table.reload('store_datagrid', {});
                     };