@@ -0,0 +1,83 @@ |
||
1 |
+# -*- coding: utf-8 -*- |
|
2 |
+ |
|
3 |
+import logging |
|
4 |
+ |
|
5 |
+from django.db.models import Sum |
|
6 |
+from django_six import CompatibilityBaseCommand, close_old_connections |
|
7 |
+from TimeConvert import TimeConvert as tc |
|
8 |
+ |
|
9 |
+from integral.models import SaleclerkSubmitLogInfo |
|
10 |
+from mch.models import BrandInfo, DistributorInfo, ModelInfo |
|
11 |
+from sales.models import SalesResponsibilityInfo, SalesResponsibilityInfoModelsSaleStatisticInfo, SuperSalesResponsibilityInfoModelsSaleStatisticInfo |
|
12 |
+ |
|
13 |
+ |
|
14 |
+logger = logging.getLogger('console') |
|
15 |
+ |
|
16 |
+ |
|
17 |
+class Command(CompatibilityBaseCommand): |
|
18 |
+ def handle(self, *args, **options): |
|
19 |
+ |
|
20 |
+ logger.info('Sales is dealing') |
|
21 |
+ |
|
22 |
+ close_old_connections() |
|
23 |
+ |
|
24 |
+ # year = tc.local_string(format='%Y') |
|
25 |
+ month = tc.local_string(format='%Y%m') |
|
26 |
+ day = tc.local_string(format='%Y%m%d') |
|
27 |
+ |
|
28 |
+ # lastyear = tc.local_string(tc.several_time_ago(years=1), format='%Y') |
|
29 |
+ lastmonth = tc.local_string(tc.several_time_ago(months=1), format='%Y%m') |
|
30 |
+ lastday = tc.local_string(tc.several_time_ago(days=1), format='%Y%m%d') |
|
31 |
+ |
|
32 |
+ brands = BrandInfo.objects.filter(status=True) |
|
33 |
+ |
|
34 |
+ for b in brands: |
|
35 |
+ distributors = DistributorInfo.objects.filter(brand_id=b.brand_id, status=True) |
|
36 |
+ models = ModelInfo.objects.filter(brand_id=b.brand_id, status=True) |
|
37 |
+ for d in distributors: |
|
38 |
+ for m in models: |
|
39 |
+ logs = SaleclerkSubmitLogInfo.objects.filter(distributor_pk=d.pk, model_pk=m.pk, dupload=False, test_sn=False, status=True) |
|
40 |
+ # today_num = logs.filter(ymd=day).count() |
|
41 |
+ yesterday_num = logs.filter(ymd=lastday).count() |
|
42 |
+ current_month = logs.filter(ym=month).count() |
|
43 |
+ last_month = logs.filter(ym=lastmonth).count() |
|
44 |
+ if m.is_important or (yesterday_num or current_month or last_month): |
|
45 |
+ SalesResponsibilityInfoModelsSaleStatisticInfo.objects.create( |
|
46 |
+ brand_id=b.brand_id, |
|
47 |
+ sr_id=d.sr_id, |
|
48 |
+ distributor_id=d.distributor_id, |
|
49 |
+ distributor_name=d.distributor_name, |
|
50 |
+ model_id=m.model_id, |
|
51 |
+ model_name=m.model_name, |
|
52 |
+ is_important=m.is_important, |
|
53 |
+ ymd=day, |
|
54 |
+ yesterday_num=yesterday_num, |
|
55 |
+ current_month=current_month, |
|
56 |
+ last_month=last_month, |
|
57 |
+ ) |
|
58 |
+ |
|
59 |
+ srs = SalesResponsibilityInfo.objects.filter(brand_id=b.brand_id, status=True) |
|
60 |
+ for s in srs: |
|
61 |
+ sums = SalesResponsibilityInfoModelsSaleStatisticInfo.objects.filter( |
|
62 |
+ sr_id=s.sr_id, |
|
63 |
+ ymd=day, |
|
64 |
+ status=True |
|
65 |
+ ).aggregate( |
|
66 |
+ Sum('yesterday_num'), |
|
67 |
+ Sum('current_month'), |
|
68 |
+ Sum('last_month'), |
|
69 |
+ ) |
|
70 |
+ yesterday_num = sums.get('yesterday_num__sum', 0) or 0 |
|
71 |
+ current_month = sums.get('current_month__sum', 0) or 0 |
|
72 |
+ last_month = sums.get('last_month__sum', 0) or 0 |
|
73 |
+ SuperSalesResponsibilityInfoModelsSaleStatisticInfo.objects.create( |
|
74 |
+ brand_id=b.brand_id, |
|
75 |
+ sr_id=s.sr_id, |
|
76 |
+ sr_name=s.name, |
|
77 |
+ ymd=day, |
|
78 |
+ yesterday_num=yesterday_num, |
|
79 |
+ current_month=current_month, |
|
80 |
+ last_month=last_month, |
|
81 |
+ ) |
|
82 |
+ |
|
83 |
+ close_old_connections() |
@@ -108,6 +108,9 @@ class SaleclerkSubmitLogInfo(BaseModelMixin): |
||
108 | 108 |
test_user = models.BooleanField(_(u'test_user'), default=False, help_text=_(u'是否为测试用户'), db_index=True) |
109 | 109 |
test_sn = models.BooleanField(_(u'test_sn'), default=False, help_text=_(u'是否为测试序列号'), db_index=True) |
110 | 110 |
|
111 |
+ ym = models.IntegerField(_(u'ym'), default=0, help_text=u'年月', db_index=True) # 例:201712, tc.local_string(format='%Y%m') |
|
112 |
+ ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d') |
|
113 |
+ |
|
111 | 114 |
class Meta: |
112 | 115 |
verbose_name = _(u'saleclerksubmitloginfo') |
113 | 116 |
verbose_name_plural = _(u'saleclerksubmitloginfo') |
@@ -182,6 +182,8 @@ def clerk_sale_decrypt_api(request): |
||
182 | 182 |
image=file_path, |
183 | 183 |
test_user=clerk.test_user, |
184 | 184 |
test_sn=test_sn, |
185 |
+ ym=tc.local_string(format='%Y%m'), |
|
186 |
+ ymd=tc.local_string(format='%Y%m%d'), |
|
185 | 187 |
) |
186 | 188 |
|
187 | 189 |
if settings.CHECK_TESTSN_ENABLED and test_sn: |
@@ -483,6 +485,8 @@ def clerk_sale_submit_api(request): |
||
483 | 485 |
image=file_path, |
484 | 486 |
test_user=clerk.test_user, |
485 | 487 |
test_sn=test_sn, |
488 |
+ ym=tc.local_string(format='%Y%m'), |
|
489 |
+ ymd=tc.local_string(format='%Y%m%d'), |
|
486 | 490 |
) |
487 | 491 |
|
488 | 492 |
if settings.CHECK_TESTSN_ENABLED and test_sn: |
@@ -2,7 +2,7 @@ CodeConvert==2.0.5 |
||
2 | 2 |
MySQL-python==1.2.5 |
3 | 3 |
Pillow==6.1.0 |
4 | 4 |
StatusCode==1.0.0 |
5 |
-TimeConvert==1.4.4 |
|
5 |
+TimeConvert==1.5.0 |
|
6 | 6 |
furl==2.0.0 |
7 | 7 |
isoweek==1.3.3 |
8 | 8 |
jsonfield==2.0.2 |
@@ -80,6 +80,9 @@ class SalesResponsibilityInfo(BaseModelMixin): |
||
80 | 80 |
class SalesResponsibilityInfoModelsSaleStatisticInfo(BaseModelMixin): |
81 | 81 |
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True) |
82 | 82 |
|
83 |
+ # 销售担当,供 SuperSalesResponsibilityInfoModelsSaleStatisticInfo 统计使用 |
|
84 |
+ sr_id = models.CharField(_(u'sr_id'), max_length=32, help_text=u'销售担当唯一标识', db_index=True) |
|
85 |
+ |
|
83 | 86 |
# 经销商 |
84 | 87 |
distributor_id = models.CharField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True) |
85 | 88 |
distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称') |