+# 超级销售担当
50
+urlpatterns += [
51
+    url(r'^supersr$', supersr_views.supersr_oauthqr, name='supersr_oauthqr'),  # 授权二维码
52
+    url(r'^supersr/oauth$', supersr_views.supersr_oauth, name='supersr_oauth'),  # 授权成功
53
+]

+ 0 - 0
sales/__init__.py


+ 6 - 0
sales/admin.py

@@ -0,0 +1,6 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.contrib import admin
5
+
6
+# Register your models here.

+ 8 - 0
sales/apps.py

@@ -0,0 +1,8 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.apps import AppConfig
5
+
6
+
7
+class SalesConfig(AppConfig):
8
+    name = 'sales'

+ 0 - 0
sales/migrations/__init__.py


+ 145 - 0
sales/models.py

@@ -0,0 +1,145 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from django.db import models
4
+from django.utils.translation import ugettext_lazy as _
5
+from django_models_ext import BaseModelMixin, upload_file_url, upload_path
6
+from shortuuidfield import ShortUUIDField
7
+
8
+
9
+class SalesResponsibilityInfo(BaseModelMixin):
10
+    REFUSED = -1
11
+    UNVERIFIED = 0
12
+    ACTIVATED = 1
13
+    DISABLED = 2
14
+    DELETED = 3
15
+    ASSIGN = 10
16
+
17
+    USER_STATUS_TUPLE = (
18
+        (REFUSED, u'已拒绝'),
19
+        (UNVERIFIED, u'未验证'),
20
+        (ACTIVATED, u'已激活'),
21
+        (DISABLED, u'已禁用'),
22
+        (DELETED, u'已删除'),
23
+        (ASSIGN, u'已分配'),
24
+    )
25
+
26
+    brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
27
+    brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
28
+
29
+    sr_id = ShortUUIDField(_(u'sr_id'), max_length=32, blank=True, null=True, help_text=u'销售担当唯一标识', db_index=True, unique=True)
30
+
31
+    user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True)
32
+    unionid = models.CharField(_(u'unionid'), max_length=32, blank=True, null=True, help_text=u'微信 UnionID', db_index=True)
33
+    openid = models.CharField(_(u'openid'), max_length=32, blank=True, null=True, help_text=u'微信 OpenID', db_index=True)
34
+
35
+    name = models.CharField(_(u'name'), max_length=255, blank=True, null=True, help_text=u'销售担当姓名')
36
+    phone = models.CharField(_(u'phone'), max_length=11, blank=True, null=True, help_text=u'销售担当联系电话')
37
+
38
+    user_status = models.IntegerField(_(u'user_status'), choices=USER_STATUS_TUPLE, default=UNVERIFIED, help_text=u'用户状态', db_index=True)
39
+    refused_reason = models.TextField(_(u'refused_reason'), blank=True, null=True, help_text=u'审核拒绝原因')
40
+
41
+    is_auth = models.BooleanField(_(u'is_auth'), default=False, help_text=_(u'是否已授权'), db_index=True)
42
+
43
+    is_super = models.BooleanField(_(u'is_super'), default=True, help_text=_(u'是否超级销售担当'), db_index=True)
44
+
45
+    class Meta:
46
+        verbose_name = _(u'销售担当信息')
47
+        verbose_name_plural = _(u'销售担当信息')
48
+
49
+        unique_together = (
50
+            ('brand_id', 'sr_id'),
51
+        )
52
+
53
+    def __unicode__(self):
54
+        return u'{}-{}'.format(self.name, self.phone)
55
+
56
+    @property
57
+    def admindata(self):
58
+        return {
59
+            'brand_id': self.brand_id,
60
+            'brand_name': self.brand_name,
61
+            'sr_id': self.sr_id,
62
+            'name': self.name,
63
+            'phone': self.phone,
64
+            'status': self.user_status,
65
+            'refused_reason': self.refused_reason,
66
+            'is_auth': self.is_auth,
67
+        }
68
+
69
+    data = admindata
70
+
71
+
72
+class SalesResponsibilityInfoModelsSaleStatisticInfo(BaseModelMixin):
73
+    brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
74
+
75
+    # 经销商
76
+    distributor_id = models.CharField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True)
77
+    distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称')
78
+
79
+    # 型号
80
+    model_id = models.CharField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True)
81
+    model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称', db_index=True)
82
+    is_important = models.BooleanField(_(u'is_important'), default=True, help_text=_(u'是否重要型号'), db_index=True)
83
+
84
+    ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True)  # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
85
+
86
+    today_num = models.IntegerField(_(u'today_num'), default=0, help_text=u'支数(今日)')
87
+    yesterday_num = models.IntegerField(_(u'yesterday_num'), default=0, help_text=u'支数(昨日)')
88
+    current_month = models.IntegerField(_(u'current_month'), default=0, help_text=u'支数(本月)')
89
+    last_month = models.IntegerField(_(u'last_month'), default=0, help_text=u'支数(上月)')
90
+
91
+    position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
92
+
93
+    class Meta:
94
+        verbose_name = _(u'[销售担当]型号销量统计')
95
+        verbose_name_plural = _(u'[销售担当]型号销量统计')
96
+
97
+    def __unicode__(self):
98
+        return unicode(self.pk)
99
+
100
+    @property
101
+    def data(self):
102
+        return {
103
+            'model_id': self.model_id,
104
+            'model_name': self.model_name,
105
+            'is_important': self.is_important,
106
+            'today_num': self.today_num,
107
+            'yesterday_num': self.yesterday_num,
108
+            'current_month': self.current_month,
109
+            'last_month': self.last_month,
110
+        }
111
+
112
+
113
+class SuperSalesResponsibilityInfoModelsSaleStatisticInfo(BaseModelMixin):
114
+    brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
115
+
116
+    # 销售担当
117
+    sr_id = models.CharField(_(u'sr_id'), max_length=32, help_text=u'销售担当唯一标识', db_index=True)
118
+    sr_name = models.CharField(_(u'sr_name'), max_length=255, blank=True, null=True, help_text=u'销售担当名称')
119
+
120
+    ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True)  # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
121
+
122
+    today_num = models.IntegerField(_(u'today_num'), default=0, help_text=u'支数(今日)')
123
+    yesterday_num = models.IntegerField(_(u'yesterday_num'), default=0, help_text=u'支数(昨日)')
124
+    current_month = models.IntegerField(_(u'current_month'), default=0, help_text=u'支数(本月)')
125
+    last_month = models.IntegerField(_(u'last_month'), default=0, help_text=u'支数(上月)')
126
+
127
+    position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
128
+
129
+    class Meta:
130
+        verbose_name = _(u'[超级销售担当]销售担当销量统计')
131
+        verbose_name_plural = _(u'[超级销售担当]销售担当销量统计')
132
+
133
+    def __unicode__(self):
134
+        return unicode(self.pk)
135
+
136
+    @property
137
+    def data(self):
138
+        return {
139
+            'sr_id': self.sr_id,
140
+            'sr_name': self.sr_name,
141
+            'today_num': self.today_num,
142
+            'yesterday_num': self.yesterday_num,
143
+            'current_month': self.current_month,
144
+            'last_month': self.last_month,
145
+        }

+ 6 - 0
sales/tests.py

@@ -0,0 +1,6 @@
1
+# -*- coding: utf-8 -*-
2
+from __future__ import unicode_literals
3
+
4
+from django.test import TestCase
5
+
6
+# Create your tests here.

+ 82 - 0
sales/views.py

@@ -0,0 +1,82 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from __future__ import division
4
+
5
+from django.conf import settings
6
+from django_logit import logit
7
+from django_response import response
8
+from TimeConvert import TimeConvert as tc
9
+
10
+from mch.models import DistributorInfo
11
+from sales.models import SalesResponsibilityInfo, SalesResponsibilityInfoModelsSaleStatisticInfo, SuperSalesResponsibilityInfoModelsSaleStatisticInfo
12
+from utils.error.errno_utils import SalesResponsibilityStatusCode
13
+
14
+
15
+@logit
16
+def sr_submit_api(request):
17
+    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
18
+    user_id = request.POST.get('user_id', '')
19
+    unionid = request.POST.get('unionid', '')
20
+    openid = request.POST.get('openid', '')
21
+    phone = request.POST.get('phone', '')
22
+
23
+    if SalesResponsibilityInfo.objects.filter(brand_id=brand_id, phone=phone).exclude(user_id=user_id).exists():
24
+        return response(SalesResponsibilityStatusCode.SR_PHONE_ALREADY_EXISTS)
25
+
26
+    SalesResponsibilityInfo.objects.update_or_create(brand_id=brand_id, user_id=user_id, defaults={
27
+        'name': request.POST.get('name', ''),
28
+        'phone': request.POST.get('phone', ''),
29
+        'unionid': unionid,
30
+        'openid': openid,
31
+        'user_status': SalesResponsibilityInfo.UNVERIFIED,
32
+        'status': True,
33
+    })
34
+
35
+    return response(200, 'Submit Success', u'提交成功', {})
36
+
37
+
38
+@logit
39
+def sr_distributor_list(request):
40
+    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
41
+    user_id = request.POST.get('user_id', '')
42
+    sr_id = request.POST.get('sr_id', '')
43
+
44
+    # if not sr_id:
45
+    #     try:
46
+    #         sr = SalesResponsibilityInfo.objects.get(brand_id=brand_id, user_id=user_id)
47
+    #     except SalesResponsibilityInfo.DoesNotExist:
48
+    #         return response(SalesResponsibilityStatusCode.SR_NOT_FOUND)
49
+    #     sr_id = sr.sr_id
50
+
51
+    distributors = DistributorInfo.objects.filter(brand_id=brand_id, sr_id=sr_id, status=True)
52
+    distributors = [d.admindata for d in distributors]
53
+
54
+    return response(data={
55
+        'distributors': distributors,
56
+    })
57
+
58
+
59
+@logit
60
+def sr_distributor_tj(request):
61
+    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
62
+    distributor_id = request.POST.get('distributor_id', '')
63
+
64
+    sales = SalesResponsibilityInfoModelsSaleStatisticInfo.objects.filter(brand_id=brand_id, distributor_id=distributor_id, ymd=tc.local_string(format='%Y%m%d'), status=True).order_by('-is_important')
65
+    sales = [sale.data for sale in sales]
66
+
67
+    return response(data={
68
+        'sales': sales,
69
+    })
70
+
71
+
72
+@logit
73
+def supersr_sr_tj(request):
74
+    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
75
+    sr_id = request.POST.get('sr_id', '')
76
+
77
+    sales = SuperSalesResponsibilityInfoModelsSaleStatisticInfo.objects.filter(brand_id=brand_id, sr_id=sr_id, ymd=tc.local_string(format='%Y%m%d'), status=True).order_by('-is_important')
78
+    sales = [sale.data for sale in sales]
79
+
80
+    return response(data={
81
+        'sales': sales,
82
+    })

+ 7 - 0
utils/error/errno_utils.py

@@ -16,6 +16,13 @@ class SaleclerkStatusCode(BaseStatusCode):
16 16
     DUPLICATE_SUBMIT = StatusCodeField(500199, 'Duplicate Submit', description=u'重复提交')
17 17
 
18 18
 
19
+class SalesResponsibilityStatusCode(BaseStatusCode):
20
+    """ 销售担当相关错误码 5002xx """
21
+    SR_NOT_FOUND = StatusCodeField(500201, 'SR Not Found', description=u'销售担当不存在')
22
+    # 手机号
23
+    SR_PHONE_ALREADY_EXISTS = StatusCodeField(500205, 'SR Phone Already Exists', description=u'手机号已经存在')
24
+
25
+
19 26
 class ProductBrandStatusCode(BaseStatusCode):
20 27
     """ 品牌相关错误码 5010xx """
21 28
     BRAND_NOT_FOUND = StatusCodeField(501001, 'Brand Not Found', description=u'品牌不存在')

kodo - Gogs: Go Git Service

Нет описания

Kimi.Huang: cefc16fe75 cfg лет %!s(int64=7): %!d(string=назад)
..
__init__.py 0ae1b7de95 tests лет %!s(int64=7): %!d(string=назад)
tests.py cefc16fe75 cfg лет %!s(int64=7): %!d(string=назад)
kodo - Gogs: Go Git Service

Brak opisu

views.py 129B

    # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.shortcuts import render # Create your views here.