hujingpei 4 vuotta sitten
vanhempi
sitoutus
9b0c759ab1

+ 11 - 4
apps/agent/serializers.py

@@ -2,11 +2,18 @@
 
 from rest_framework import serializers
 from django.conf import settings
-from .models import Upload
+from .models import Agent,Store
 
 
-class UploadSerializer(serializers.ModelSerializer):
+class AgentSerializer(serializers.ModelSerializer):
 
     class Meta:
-        model = Upload
-        fields = ('picture', 'width', 'height', 'type', 'voice_time')
+        model = Agent
+        fields = '__all__'
+
+
+class StoreSerializer(serializers.ModelSerializer):
+
+    class Meta:
+        model = Store
+        fields = '__all__'

+ 15 - 0
apps/agent/urls.py

@@ -0,0 +1,15 @@
+# coding=utf-8
+from django.conf.urls import url, include
+from rest_framework.routers import SimpleRouter
+
+from .views import AgentViewSet,StoreViewSet
+
+
+urlpatterns = [
+
+]
+
+router = SimpleRouter()
+router.register(r'agent', AgentViewSet)
+router.register(r'store', StoreViewSet)
+urlpatterns += router.urls

+ 19 - 0
apps/agent/views.py

@@ -0,0 +1,19 @@
+# coding=utf-8
+from utils.custom_modelviewset import CustomModelViewSet
+from utils.permission import IsAdministratorUser,IsTenantUser
+from utils.exceptions import CustomError
+from utils import response_ok, response_error
+from .models import Agent,Store
+from .serializers import AgentSerializer,StoreSerializer
+
+
+class AgentViewSet(CustomModelViewSet):
+    permission_classes = []
+    queryset = Agent.objects.filter()
+    serializer_class = AgentSerializer
+
+
+class StoreViewSet(CustomModelViewSet):
+    permission_classes = []
+    queryset = Store.objects.filter()
+    serializer_class = StoreSerializer

+ 19 - 12
apps/customer/models.py

@@ -1,7 +1,9 @@
 # coding=utf-8
 from django.db import models
 from django.conf import settings
+from django.utils import timezone
 
+from utils.exceptions import CustomError
 from apps.option.models import Option
 
 
@@ -19,15 +21,15 @@ class Customer(models.Model):
     tel = models.CharField(max_length=50, verbose_name=u'电话')
     gender = models.PositiveSmallIntegerField(choices=settings.GENDER_CHOICES, verbose_name=u'性别',
                                               default=settings.MALE)
-    village = models.CharField(max_length=100,verbose_name=u'小区')
-    address = models.CharField(max_length=100,verbose_name=u'地址')
-    source = models.ForeignKey(Option,max_length=100,verbose_name=u'来源',related_name='customer_source',
-                               on_delete=models.PROTECT,null=True)
-    project = models.ForeignKey(Option,max_length=100, verbose_name=u'项目',related_name='customer_category',
-                                on_delete=models.PROTECT,null=True)
+    village = models.CharField(max_length=100, verbose_name=u'小区')
+    address = models.CharField(max_length=100, verbose_name=u'地址')
+    source = models.ForeignKey(Option, max_length=100, verbose_name=u'来源', related_name='customer_source',
+                               on_delete=models.PROTECT, null=True)
+    project = models.ForeignKey(Option, max_length=100, verbose_name=u'项目', related_name='customer_category',
+                                on_delete=models.PROTECT, null=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',
+    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',
                                    on_delete=models.PROTECT,null=True)
     check_time = models.DateTimeField(verbose_name=u'审核时间', editable=False, null=True)
 
@@ -40,12 +42,17 @@ class Customer(models.Model):
         permissions = [
             ('view_customer', u'查看'),
             ('add_customer', u'添加'),
+            ('update_customer',u'更新'),
             ('delete_customer', u'删除'),
             ('check_customer', u'审核'),
         ]
 
+    def check_customer(self, user):
+        # 审核
+        if self.report_status == Customer.REPEAT_REPORT:
+            raise CustomError('当前客户报备状态为重复报备!')
 
-
-
-
-
+        self.check_user = user
+        self.report_status = Customer.CHECKED
+        self.check_time = timezone.now()
+        self.save()

+ 1 - 1
apps/customer/serializers.py

@@ -10,4 +10,4 @@ class CustomerSerializer(serializers.ModelSerializer):
 
     class Meta:
         model = Customer
-        fields = '__all__'
+        fields = '__all__'

+ 3 - 6
apps/customer/urls.py

@@ -2,15 +2,12 @@
 from django.conf.urls import url, include
 from rest_framework.routers import SimpleRouter
 
-from .views import CustomerViewSet
-
-from django.conf.urls import url, include
-from rest_framework.routers import SimpleRouter
-
-from .views import CustomerViewSet
+from .views import CustomerViewSet,SourceDictView,ProjectDictView
 
 
 urlpatterns = [
+    url(r'^source/dict/$',SourceDictView.as_view()),
+    url(r'^projects/dict/$',ProjectDictView.as_view()),
 
 ]
 

+ 38 - 23
apps/customer/views.py

@@ -1,12 +1,15 @@
 # coding=utf-8
 from rest_framework.decorators import action
 from rest_framework import permissions
-from django.utils import timezone
+
+from rest_framework.views import APIView
 
 from utils.custom_modelviewset import CustomModelViewSet
 from utils.permission import IsAdministratorUser,IsTenantUser
 from utils.exceptions import CustomError
 from utils import response_ok, response_error
+from apps.option.models import Option
+from apps.option.serializers import OptionComboboxSerializer
 from .models import Customer
 from .serializers import CustomerSerializer
 from .filters import CustomerFilter
@@ -38,27 +41,39 @@ class CustomerViewSet(CustomModelViewSet):
         super(CustomerViewSet, self).destroy(self, request, *args, **kwargs)
         return response_ok()
 
-    @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('当前客户报备有误!')
-            if instance.report_status == Customer.CHECKED:
-                instance.report_status = Customer.REPEAT_REPORT
-                instance.save()
-                return response_ok('当前客户已审核!')
-            if instance.report_status == Customer.REPEAT_REPORT:
-                raise CustomError('当前用户已重复报备!')
+    # @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('审核完成!')
+
+class SourceDictView(APIView):
+    permission_classes = []
+
+    def get(self, request):
+        rows = Option.objects.filter(type=Option.CUSTOMER_SOURCE,enable=True)
+        serializer = OptionComboboxSerializer(rows, many=True)
+        return response_ok(serializer.data)
+
 
-            instance.report_status = report_status
-            instance.check_time = timezone.now()
-            instance.save()
+class ProjectDictView(APIView):
+    permission_classes = []
 
-        except CustomError as e:
-            return response_error(e.get_error_msg())
-        except Exception as e:
-            return response_error(str(e))
-        return response_ok('审核完成!')
+    def get(self, request):
+        rows = Option.objects.filter(type=Option.CATEGORY, enable=True)
+        serializer = OptionComboboxSerializer(rows, many=True)
+        return response_ok(serializer.data)

+ 7 - 0
apps/option/serializers.py

@@ -40,3 +40,10 @@ class OptionSerializer(serializers.ModelSerializer):
             raise CustomError(u'自定义项[%s]已存在!' % validated_data['name'])
         instance = super(OptionSerializer, self).update(instance, validated_data)
         return instance
+
+
+class OptionComboboxSerializer(serializers.ModelSerializer):
+
+    class Meta:
+        model = Option
+        fields = ('id','name')

+ 2 - 0
decorate/urls.py

@@ -25,8 +25,10 @@ urlpatterns = [
     url(r'^$', index),
     url(r'^account/', include('apps.account.urls')),
     url(r'^api/', include('apps.api.urls')),
+    url(r'^agent', include('apps.agent.urls')),
     url(r'^customer/', include('apps.customer.urls')),
     url(r'^option/', include('apps.option.urls')),
+
 ]
 
 urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)