@@ -2,8 +2,10 @@ |
||
2 | 2 |
|
3 | 3 |
from __future__ import division |
4 | 4 |
|
5 |
-from mch.models import DistributorInfo, ModelInfo |
|
6 |
-from statistic.models import DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo |
|
5 |
+from mch.models import BrandInfo, DistributorInfo, ModelInfo |
|
6 |
+from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo, |
|
7 |
+ ConsumeProvinceSaleStatisticInfo, DistributorSaleStatisticInfo, ModelSaleStatisticInfo, |
|
8 |
+ ProvinceSaleStatisticInfo) |
|
7 | 9 |
|
8 | 10 |
|
9 | 11 |
PROVINCE_LIST = { |
@@ -45,23 +47,47 @@ PROVINCE_LIST = { |
||
45 | 47 |
|
46 | 48 |
|
47 | 49 |
def pre_provinces(): |
48 |
- for pcode, pname in PROVINCE_LIST.items(): |
|
49 |
- pssi, created = ProvinceSaleStatisticInfo.objects.get_or_create(province_code=pcode, ymd=0) |
|
50 |
- pssi.province_name = pname |
|
51 |
- pssi.save() |
|
50 |
+ brands = BrandInfo.objects.filter(status=True) |
|
51 |
+ for brand in brands: |
|
52 |
+ for pcode, pname in PROVINCE_LIST.items(): |
|
53 |
+ pssi, created = ProvinceSaleStatisticInfo.objects.get_or_create(brand_id=brand.brand_id, province_code=pcode, ymd=0) |
|
54 |
+ pssi.province_name = pname |
|
55 |
+ pssi.save() |
|
56 |
+ |
|
57 |
+ cpssi, created = ConsumeProvinceSaleStatisticInfo.objects.get_or_create(brand_id=brand.brand_id, province_code=pcode, ymd=0) |
|
58 |
+ cpssi.province_name = pname |
|
59 |
+ cpssi.save() |
|
52 | 60 |
|
53 | 61 |
|
54 | 62 |
def pre_models(): |
55 |
- models = ModelInfo.objects.filter(status=True) |
|
56 |
- for mdl in models: |
|
57 |
- mssi, created = ModelSaleStatisticInfo.objects.get_or_create(model_id=mdl.model_id, ymd=0) |
|
58 |
- mssi.model_name = mdl.model_name |
|
59 |
- mssi.save() |
|
63 |
+ brands = BrandInfo.objects.filter(status=True) |
|
64 |
+ for brand in brands: |
|
65 |
+ models = ModelInfo.objects.filter(status=True) |
|
66 |
+ for mdl in models: |
|
67 |
+ mssi, created = ModelSaleStatisticInfo.objects.get_or_create(brand_id=brand.brand_id, model_id=mdl.model_id, ymd=0) |
|
68 |
+ mssi.model_name = mdl.model_name |
|
69 |
+ mssi.save() |
|
70 |
+ |
|
71 |
+ cmssi, created = ConsumeModelSaleStatisticInfo.objects.get_or_create(brand_id=brand.brand_id, model_id=mdl.model_id, ymd=0) |
|
72 |
+ cmssi.model_name = mdl.model_name |
|
73 |
+ cmssi.save() |
|
60 | 74 |
|
61 | 75 |
|
62 | 76 |
def pre_distributors(): |
63 |
- distributors = DistributorInfo.objects.filter(status=True) |
|
64 |
- for dtbt in distributors: |
|
65 |
- dssi, created = DistributorSaleStatisticInfo.objects.get_or_create(distributor_id=dtbt.distributor_id, ymd=0) |
|
66 |
- dssi.distributor_name = dtbt.distributor_name |
|
67 |
- dssi.save() |
|
77 |
+ brands = BrandInfo.objects.filter(status=True) |
|
78 |
+ for brand in brands: |
|
79 |
+ distributors = DistributorInfo.objects.filter(status=True) |
|
80 |
+ for dtbt in distributors: |
|
81 |
+ dssi, created = DistributorSaleStatisticInfo.objects.get_or_create(brand_id=brand.brand_id, distributor_id=dtbt.distributor_id, ymd=0) |
|
82 |
+ dssi.distributor_name = dtbt.distributor_name |
|
83 |
+ dssi.save() |
|
84 |
+ |
|
85 |
+ cdssi, created = ConsumeDistributorSaleStatisticInfo.objects.get_or_create(brand_id=brand.brand_id, distributor_id=dtbt.distributor_id, ymd=0) |
|
86 |
+ cdssi.distributor_name = dtbt.distributor_name |
|
87 |
+ cdssi.save() |
|
88 |
+ |
|
89 |
+ |
|
90 |
+def pre_all(): |
|
91 |
+ pre_provinces() |
|
92 |
+ pre_models() |
|
93 |
+ pre_distributors() |
@@ -6,6 +6,7 @@ from django_logit import logit |
||
6 | 6 |
from django_response import response |
7 | 7 |
from TimeConvert import TimeConvert as tc |
8 | 8 |
|
9 |
+from mch.models import BrandInfo |
|
9 | 10 |
from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo, |
10 | 11 |
ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, DistributorSaleStatisticInfo, |
11 | 12 |
ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, RegisterStatisticInfo, |
@@ -15,11 +16,13 @@ from utils.rdm_utils import randnum |
||
15 | 16 |
|
16 | 17 |
@logit |
17 | 18 |
def tj_distributor(request): |
19 |
+ brand_id = request.POST.get('brand_id', 'ywkRTh5vtswRvhh8uLvTTQ') |
|
20 |
+ |
|
18 | 21 |
ymd = int(tc.local_string(format='%Y%m%d')) |
19 | 22 |
|
20 | 23 |
# 注册用户统计 & 今日注册用户 |
21 | 24 |
try: |
22 |
- register_num = RegisterStatisticInfo.objects.get(ymd=ymd).num |
|
25 |
+ register_num = RegisterStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num |
|
23 | 26 |
except RegisterStatisticInfo.DoesNotExist: |
24 | 27 |
register_num = 0 |
25 | 28 |
|
@@ -29,7 +32,7 @@ def tj_distributor(request): |
||
29 | 32 |
|
30 | 33 |
# 销量统计 & 今日销量 |
31 | 34 |
try: |
32 |
- sale_num = SaleStatisticInfo.objects.get(ymd=ymd).num |
|
35 |
+ sale_num = SaleStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num |
|
33 | 36 |
except SaleStatisticInfo.DoesNotExist: |
34 | 37 |
sale_num = 0 |
35 | 38 |
|
@@ -38,19 +41,19 @@ def tj_distributor(request): |
||
38 | 41 |
# sale_trends = [s.data for s in sale_trends] |
39 | 42 |
|
40 | 43 |
# 型号销量统计 & 热销商品榜 |
41 |
- model_sales = ModelSaleStatisticInfo.objects.filter(ymd=0, status=True).order_by('-num') |
|
44 |
+ model_sales = ModelSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=0, status=True).order_by('-num') |
|
42 | 45 |
model_sales = [m.data for m in model_sales] |
43 | 46 |
|
44 | 47 |
# 经销商销量统计 & 经销商榜 |
45 |
- distributor_sales = DistributorSaleStatisticInfo.objects.filter(ymd=0, status=True).order_by('-num') |
|
48 |
+ distributor_sales = DistributorSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=0, status=True).order_by('-num') |
|
46 | 49 |
distributor_sales = [d.data for d in distributor_sales] |
47 | 50 |
|
48 | 51 |
# 各地区实时销量 |
49 |
- province_sales = ProvinceSaleStatisticInfo.objects.filter(ymd=0, status=True).order_by('position') |
|
52 |
+ province_sales = ProvinceSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=0, status=True).order_by('position') |
|
50 | 53 |
province_sales = [p.data for p in province_sales] |
51 | 54 |
|
52 | 55 |
# TOADD: ROI |
53 |
- rois = ModelSaleStatisticInfo.objects.filter(ymd=0, status=True) |
|
56 |
+ rois = ModelSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=0, status=True) |
|
54 | 57 |
rois = [m.roi for m in rois] |
55 | 58 |
|
56 | 59 |
return response(200, 'Get TJ Data Success', u'获取统计数据成功', { |
@@ -67,38 +70,40 @@ def tj_distributor(request): |
||
67 | 70 |
|
68 | 71 |
@logit |
69 | 72 |
def tj_consumer(request): |
73 |
+ brand_id = request.POST.get('brand_id', 'ywkRTh5vtswRvhh8uLvTTQ') |
|
74 |
+ |
|
70 | 75 |
ymd = int(tc.local_string(format='%Y%m%d')) |
71 | 76 |
|
72 | 77 |
# 注册用户统计 & 今日注册用户 |
73 | 78 |
try: |
74 |
- register_num = RegisterStatisticInfo.objects.get(ymd=ymd).num |
|
79 |
+ register_num = RegisterStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num |
|
75 | 80 |
except RegisterStatisticInfo.DoesNotExist: |
76 | 81 |
register_num = 0 |
77 | 82 |
|
78 | 83 |
# 注册用户数趋势 |
79 |
- register_trends = RegisterStatisticInfo.objects.filter(status=True).order_by('-ymd') |
|
84 |
+ register_trends = RegisterStatisticInfo.objects.filter(brand_id=brand_id, status=True).order_by('-ymd') |
|
80 | 85 |
register_trends = [r.data for r in register_trends] |
81 | 86 |
|
82 | 87 |
# 销量统计 & 今日销量 |
83 | 88 |
try: |
84 |
- sale_num = ConsumeSaleStatisticInfo.objects.get(ymd=ymd).num |
|
89 |
+ sale_num = ConsumeSaleStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num |
|
85 | 90 |
except ConsumeSaleStatisticInfo.DoesNotExist: |
86 | 91 |
sale_num = 0 |
87 | 92 |
|
88 | 93 |
# 商品销量趋势 |
89 |
- sale_trends = ConsumeSaleStatisticInfo.objects.filter(status=True).order_by('-ymd') |
|
94 |
+ sale_trends = ConsumeSaleStatisticInfo.objects.filter(brand_id=brand_id, status=True).order_by('-ymd') |
|
90 | 95 |
sale_trends = [s.data for s in sale_trends] |
91 | 96 |
|
92 | 97 |
# 型号销量统计 & 热销商品榜 |
93 |
- model_sales = ConsumeModelSaleStatisticInfo.objects.filter(ymd=0, status=True).order_by('-num') |
|
98 |
+ model_sales = ConsumeModelSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=0, status=True).order_by('-num') |
|
94 | 99 |
model_sales = [m.data for m in model_sales] |
95 | 100 |
|
96 | 101 |
# 经销商销量统计 & 经销商榜 |
97 |
- distributor_sales = ConsumeDistributorSaleStatisticInfo.objects.filter(ymd=0, status=True).order_by('-num') |
|
102 |
+ distributor_sales = ConsumeDistributorSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=0, status=True).order_by('-num') |
|
98 | 103 |
distributor_sales = [d.data for d in distributor_sales] |
99 | 104 |
|
100 | 105 |
# 各地区实时销量 |
101 |
- province_sales = ConsumeProvinceSaleStatisticInfo.objects.filter(ymd=0, status=True).order_by('position') |
|
106 |
+ province_sales = ConsumeProvinceSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=0, status=True).order_by('position') |
|
102 | 107 |
province_sales = [p.data for p in province_sales] |
103 | 108 |
|
104 | 109 |
return response(200, 'Get TJ Data Success', u'获取统计数据成功', { |
@@ -115,14 +120,25 @@ def tj_consumer(request): |
||
115 | 120 |
@logit |
116 | 121 |
@transaction.atomic |
117 | 122 |
def tj_generate(request): |
123 |
+ # 1 0 * * * curl http://kodo.xfoto.com.cn/api/tj/generate |
|
118 | 124 |
ymd = int(tc.local_string(format='%Y%m%d')) |
119 | 125 |
|
120 |
- RegisterStatisticInfo.objects.select_for_update().get_or_create( |
|
121 |
- ymd=ymd, |
|
122 |
- ) |
|
126 |
+ brands = BrandInfo.objects.filter(status=True) |
|
127 |
+ |
|
128 |
+ for brand in brands: |
|
129 |
+ RegisterStatisticInfo.objects.select_for_update().get_or_create( |
|
130 |
+ brand_id=brand.brand_id, |
|
131 |
+ ymd=ymd, |
|
132 |
+ ) |
|
133 |
+ |
|
134 |
+ SaleStatisticInfo.objects.select_for_update().get_or_create( |
|
135 |
+ brand_id=brand.brand_id, |
|
136 |
+ ymd=ymd, |
|
137 |
+ ) |
|
123 | 138 |
|
124 |
- SaleStatisticInfo.objects.select_for_update().get_or_create( |
|
125 |
- ymd=ymd, |
|
126 |
- ) |
|
139 |
+ ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
140 |
+ brand_id=brand.brand_id, |
|
141 |
+ ymd=ymd, |
|
142 |
+ ) |
|
127 | 143 |
|
128 | 144 |
return response() |