@@ -0,0 +1,110 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from __future__ import division |
|
| 4 |
+ |
|
| 5 |
+from django.conf import settings |
|
| 6 |
+from django.contrib.auth.hashers import make_password |
|
| 7 |
+from django_logit import logit |
|
| 8 |
+from django_response import response |
|
| 9 |
+from paginator import pagination |
|
| 10 |
+ |
|
| 11 |
+from mch.models import AdministratorInfo, DistributorInfo, OperatorInfo |
|
| 12 |
+from utils.error.errno_utils import AdministratorStatusCode, OperatorStatusCode, ProductDistributorStatusCode |
|
| 13 |
+ |
|
| 14 |
+ |
|
| 15 |
+@logit |
|
| 16 |
+def distributor_add(request): |
|
| 17 |
+ distributor_name = request.POST.get('distributor_name', '')
|
|
| 18 |
+ province_code = request.POST.get('province_code', '')
|
|
| 19 |
+ province_name = request.POST.get('province_name', '')
|
|
| 20 |
+ |
|
| 21 |
+ admin_id = request.session.get('admin_id')
|
|
| 22 |
+ |
|
| 23 |
+ try: |
|
| 24 |
+ administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True) |
|
| 25 |
+ except AdministratorInfo.DoesNotExist: |
|
| 26 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND) |
|
| 27 |
+ |
|
| 28 |
+ DistributorInfo.objects.create( |
|
| 29 |
+ brand_id=administrator.brand_id, |
|
| 30 |
+ distributor_name=distributor_name, |
|
| 31 |
+ distributor_province_code=province_code, |
|
| 32 |
+ distributor_province_name=province_name, |
|
| 33 |
+ ) |
|
| 34 |
+ |
|
| 35 |
+ return response(200, 'Distributor Add Success', u'经销商添加成功') |
|
| 36 |
+ |
|
| 37 |
+ |
|
| 38 |
+@logit |
|
| 39 |
+def distributor_delete(request): |
|
| 40 |
+ distributor_id = request.POST.get('distributor_id', '')
|
|
| 41 |
+ |
|
| 42 |
+ admin_id = request.session.get('admin_id')
|
|
| 43 |
+ |
|
| 44 |
+ try: |
|
| 45 |
+ administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True) |
|
| 46 |
+ except AdministratorInfo.DoesNotExist: |
|
| 47 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND) |
|
| 48 |
+ |
|
| 49 |
+ try: |
|
| 50 |
+ distributor = DistributorInfo.objects.get(brand_id=administrator.brand_id, distributor_id=distributor_id, status=True) |
|
| 51 |
+ except DistributorInfo.DoesNotExist: |
|
| 52 |
+ return response(ProductDistributorStatusCode.DISTRIBUTOR_NOT_FOUND) |
|
| 53 |
+ |
|
| 54 |
+ distributor.status = False |
|
| 55 |
+ distributor.save() |
|
| 56 |
+ |
|
| 57 |
+ return response(200, 'Distributor Delete Success', u'经销商删除成功') |
|
| 58 |
+ |
|
| 59 |
+ |
|
| 60 |
+@logit |
|
| 61 |
+def distributor_update(request): |
|
| 62 |
+ distributor_id = request.POST.get('distributor_id', '')
|
|
| 63 |
+ distributor_name = request.POST.get('distributor_name', '')
|
|
| 64 |
+ province_code = request.POST.get('province_code', '')
|
|
| 65 |
+ province_name = request.POST.get('province_name', '')
|
|
| 66 |
+ |
|
| 67 |
+ admin_id = request.session.get('admin_id')
|
|
| 68 |
+ |
|
| 69 |
+ try: |
|
| 70 |
+ administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True) |
|
| 71 |
+ except AdministratorInfo.DoesNotExist: |
|
| 72 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND) |
|
| 73 |
+ |
|
| 74 |
+ try: |
|
| 75 |
+ distributor = DistributorInfo.objects.get(brand_id=administrator.brand_id, distributor_id=distributor_id, status=True) |
|
| 76 |
+ except DistributorInfo.DoesNotExist: |
|
| 77 |
+ return response(ProductDistributorStatusCode.DISTRIBUTOR_NOT_FOUND) |
|
| 78 |
+ |
|
| 79 |
+ if distributor_name: |
|
| 80 |
+ distributor.distributor_name = distributor_name |
|
| 81 |
+ if province_code: |
|
| 82 |
+ distributor.distributor_province_code = province_code |
|
| 83 |
+ if province_name: |
|
| 84 |
+ distributor.distributor_province_name = province_name |
|
| 85 |
+ |
|
| 86 |
+ distributor.save() |
|
| 87 |
+ |
|
| 88 |
+ return response(200, 'Distributor Update Success', u'经销商更新成功') |
|
| 89 |
+ |
|
| 90 |
+ |
|
| 91 |
+@logit |
|
| 92 |
+def distributor_list(request): |
|
| 93 |
+ page = request.POST.get('page', 1)
|
|
| 94 |
+ num = request.POST.get('num', 20)
|
|
| 95 |
+ |
|
| 96 |
+ admin_id = request.session.get('admin_id')
|
|
| 97 |
+ |
|
| 98 |
+ try: |
|
| 99 |
+ administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True) |
|
| 100 |
+ except AdministratorInfo.DoesNotExist: |
|
| 101 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND) |
|
| 102 |
+ |
|
| 103 |
+ distributors = DistributorInfo.objects.filter(brand_id=administrator.brand_id, status=True) |
|
| 104 |
+ distributors, left = pagination(distributors, page, num) |
|
| 105 |
+ distributors = [distributor.admindata for distributor in distributors] |
|
| 106 |
+ |
|
| 107 |
+ return response(200, 'Get Distributor List Success', u'获取经销商列表成功', {
|
|
| 108 |
+ 'distributors': distributors, |
|
| 109 |
+ 'left': left, |
|
| 110 |
+ }) |
@@ -5,7 +5,7 @@ from django_file_upload import views as file_views |
||
| 5 | 5 |
|
| 6 | 6 |
from account import tourguide_views |
| 7 | 7 |
from account import views as account_views |
| 8 |
-from api import encrypt_views, mch_views, operator_views |
|
| 8 |
+from api import distributor_views, encrypt_views, mch_views, operator_views |
|
| 9 | 9 |
from box import views as box_views |
| 10 | 10 |
from geo import views as geo_views |
| 11 | 11 |
from group import (groupuser_views, lensman_views, tourguidegroup_views, tourguidegroupadmin_views, |
@@ -240,3 +240,10 @@ urlpatterns += [ |
||
| 240 | 240 |
url(r'^operator/update$', operator_views.operator_update, name='operator_update'), |
| 241 | 241 |
url(r'^operator/list$', operator_views.operator_list, name='operator_list'), |
| 242 | 242 |
] |
| 243 |
+ |
|
| 244 |
+urlpatterns += [ |
|
| 245 |
+ url(r'^distributor/add$', distributor_views.distributor_add, name='distributor_add'), |
|
| 246 |
+ url(r'^distributor/delete$', distributor_views.distributor_delete, name='distributor_delete'), |
|
| 247 |
+ url(r'^distributor/update$', distributor_views.distributor_update, name='distributor_update'), |
|
| 248 |
+ url(r'^distributor/list$', distributor_views.distributor_list, name='distributor_list'), |
|
| 249 |
+] |
@@ -215,6 +215,16 @@ class DistributorInfo(BaseModelMixin): |
||
| 215 | 215 |
'distributor_descr': self.distributor_descr, |
| 216 | 216 |
} |
| 217 | 217 |
|
| 218 |
+ @property |
|
| 219 |
+ def admindata(self): |
|
| 220 |
+ return {
|
|
| 221 |
+ 'distributor_id': self.distributor_id, |
|
| 222 |
+ 'distributor_name': self.distributor_name, |
|
| 223 |
+ 'distributor_descr': self.distributor_descr, |
|
| 224 |
+ 'province_code': self.distributor_province_code, |
|
| 225 |
+ 'province_name': self.distributor_province_name, |
|
| 226 |
+ } |
|
| 227 |
+ |
|
| 218 | 228 |
|
| 219 | 229 |
class BrandModelDistributorPriceInfo(BaseModelMixin): |
| 220 | 230 |
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True) |