admin.site.register(ProvinceSaleStatisticInfo, ProvinceSaleStatisticInfoAdmin)
admin.site.register(SaleclerkSaleStatisticInfo, SaleclerkSaleStatisticInfoAdmin)
+admin.site.register(ConsumeUserStatisticInfo, ConsumeUserStatisticInfoAdmin)
admin.site.register(ConsumeSaleStatisticInfo, ConsumeSaleStatisticInfoAdmin)
admin.site.register(ConsumeModelSaleStatisticInfo, ConsumeModelSaleStatisticInfoAdmin)
admin.site.register(ConsumeDistributorSaleStatisticInfo, ConsumeDistributorSaleStatisticInfoAdmin)
@@ -4,6 +4,7 @@ from django.conf import settings |
||
| 4 | 4 |
from django.db import models |
| 5 | 5 |
from django.utils.translation import ugettext_lazy as _ |
| 6 | 6 |
from django_models_ext import BaseModelMixin |
| 7 |
+from jsonfield import JSONField |
|
| 7 | 8 |
|
| 8 | 9 |
from utils.rdm_utils import randnum |
| 9 | 10 |
|
@@ -165,6 +166,27 @@ class SaleclerkSaleStatisticInfo(BaseModelMixin): |
||
| 165 | 166 |
# 消费者维度 |
| 166 | 167 |
|
| 167 | 168 |
|
| 169 |
+class ConsumeUserStatisticInfo(BaseModelMixin): |
|
| 170 |
+ brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True) |
|
| 171 |
+ ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d') |
|
| 172 |
+ users = JSONField(_(u'users'), default=[], help_text=u'用户列表') |
|
| 173 |
+ num = models.IntegerField(_(u'num'), default=0, help_text=u'数量') |
|
| 174 |
+ |
|
| 175 |
+ class Meta: |
|
| 176 |
+ verbose_name = _(u'[消费者维度]销量统计') |
|
| 177 |
+ verbose_name_plural = _(u'[消费者维度]销量统计') |
|
| 178 |
+ |
|
| 179 |
+ def __unicode__(self): |
|
| 180 |
+ return unicode(self.pk) |
|
| 181 |
+ |
|
| 182 |
+ @property |
|
| 183 |
+ def data(self): |
|
| 184 |
+ return {
|
|
| 185 |
+ 'ymd': self.ymd, |
|
| 186 |
+ 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num, |
|
| 187 |
+ } |
|
| 188 |
+ |
|
| 189 |
+ |
|
| 168 | 190 |
class ConsumeSaleStatisticInfo(BaseModelMixin): |
| 169 | 191 |
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True) |
| 170 | 192 |
ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d') |
@@ -9,9 +9,9 @@ from TimeConvert import TimeConvert as tc |
||
| 9 | 9 |
|
| 10 | 10 |
from mch.models import BrandInfo, DistributorInfo, ModelInfo |
| 11 | 11 |
from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo, |
| 12 |
- ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, DistributorSaleStatisticInfo, |
|
| 13 |
- ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, RegisterStatisticInfo, |
|
| 14 |
- SaleclerkSaleStatisticInfo, SaleStatisticInfo) |
|
| 12 |
+ ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, ConsumeUserStatisticInfo, |
|
| 13 |
+ DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, |
|
| 14 |
+ RegisterStatisticInfo, SaleclerkSaleStatisticInfo, SaleStatisticInfo) |
|
| 15 | 15 |
from utils.rdm_utils import randnum |
| 16 | 16 |
|
| 17 | 17 |
|
@@ -206,15 +206,29 @@ def __tj_generate(ymd=None): |
||
| 206 | 206 |
def ymdtj(brand_id, ymd, lastymd): |
| 207 | 207 |
# [消费者维度] 周期内扫描用户人数 |
| 208 | 208 |
try: |
| 209 |
- scan_user_count = ConsumeSaleStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num |
|
| 210 |
- except ConsumeSaleStatisticInfo.DoesNotExist: |
|
| 209 |
+ scan_user_count = ConsumeUserStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num |
|
| 210 |
+ except ConsumeUserStatisticInfo.DoesNotExist: |
|
| 211 | 211 |
scan_user_count = 0 |
| 212 | 212 |
|
| 213 | 213 |
try: |
| 214 |
- last_scan_user_count = ConsumeSaleStatisticInfo.objects.get(brand_id=brand_id, ymd=lastymd).num |
|
| 215 |
- except ConsumeSaleStatisticInfo.DoesNotExist: |
|
| 214 |
+ last_scan_user_count = ConsumeUserStatisticInfo.objects.get(brand_id=brand_id, ymd=lastymd).num |
|
| 215 |
+ except ConsumeUserStatisticInfo.DoesNotExist: |
|
| 216 | 216 |
last_scan_user_count = 0 |
| 217 | 217 |
|
| 218 |
+ # [消费者维度] 周期内镜头销售支数 |
|
| 219 |
+ try: |
|
| 220 |
+ sell_volume_count = ConsumeSaleStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num |
|
| 221 |
+ except ConsumeSaleStatisticInfo.DoesNotExist: |
|
| 222 |
+ sell_volume_count = 0 |
|
| 223 |
+ |
|
| 224 |
+ try: |
|
| 225 |
+ last_sell_volume_count = ConsumeSaleStatisticInfo.objects.get(brand_id=brand_id, ymd=lastymd).num |
|
| 226 |
+ except ConsumeSaleStatisticInfo.DoesNotExist: |
|
| 227 |
+ last_sell_volume_count = 0 |
|
| 228 |
+ |
|
| 229 |
+ # 与上个统计周期数据的销售支数比例 |
|
| 230 |
+ volume_count_increase_pct = '%.2f' % (sell_volume_count * 100.0 / last_sell_volume_count) if last_sell_volume_count != 0 else -1 |
|
| 231 |
+ |
|
| 218 | 232 |
# 与上个统计周期数据的用户人数比例 |
| 219 | 233 |
user_count_increase_pct = '%.2f' % (scan_user_count * 100.0 / last_scan_user_count) if last_scan_user_count != 0 else -1 |
| 220 | 234 |
|
@@ -222,15 +236,6 @@ def ymdtj(brand_id, ymd, lastymd): |
||
| 222 | 236 |
current_models = ConsumeModelSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=ymd, status=True).order_by('-num')
|
| 223 | 237 |
models = [m.data for m in current_models[:20]] |
| 224 | 238 |
|
| 225 |
- # [消费者维度] 周期内镜头销售支数 |
|
| 226 |
- sell_volume_count = sum([m.num for m in current_models]) |
|
| 227 |
- |
|
| 228 |
- last_models = ConsumeModelSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=lastymd, status=True).order_by('-num')
|
|
| 229 |
- last_sell_volume_count = sum([m.num for m in last_models]) |
|
| 230 |
- |
|
| 231 |
- # 与上个统计周期数据的销售支数比例 |
|
| 232 |
- volume_count_increase_pct = '%.2f' % (sell_volume_count * 100.0 / last_sell_volume_count) if last_sell_volume_count != 0 else -1 |
|
| 233 |
- |
|
| 234 | 239 |
# [经销商维度] 统计周期内销售员排行数据,请按顺序返回 |
| 235 | 240 |
salesmen = SaleclerkSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=ymd, status=True).order_by('-num')[:20]
|
| 236 | 241 |
salesmen = [s.data for s in salesmen] |