lines-num lines-num-old"> 387
- # brand_id=brand.brand_id,
- # province_code=distributor.distributor_province_code,
- # ymd=ymd,
- # )
- # pssi.province_name = distributor.distributor_province_name
- # pssi.num += 1
- # pssi.save()
- #
- # pssi2, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(
- # brand_id=brand.brand_id,
- # province_code=distributor.distributor_province_code,
- # ymd=0,
- # )
- # pssi2.province_name = distributor.distributor_province_name
- # pssi2.num += 1
- # pssi2.save()
+ model_name=model.model_uni_name,
+ ymd=ymd[:4],
+ )
+ cmssi.num += 1
+ cmssi.save()
+
+ r.rpushjson(MINI_PROGRAM_GIS_LIST, {
+ 'brand_id': log.brand_id,
+ 'lat': log.lat,
+ 'lon': log.lon,
+ 'ymd': ymd,
+ })
return response(200, 'Submit Consumer Info Success', u'提交消费者信息成功')
@@ -416,9 +391,10 @@ def consumer_snlist_api(request):
return response(UserStatusCode.USER_NOT_FOUND)
# 用户信息提交列表
- # TODO: 按照序列号去重
- logs = ConsumeInfoSubmitLogInfo.objects.filter(user_id=user_id, status=True)
- logs = [log.data for log in logs]
+ logs = ConsumeInfoSubmitLogInfo.objects.filter(user_id=user_id, status=True).distinct()
+ seen = set()
+ seen_add = seen.add
+ logs = [log.data for log in logs if not (log.serialNo in seen or seen_add(log.serialNo))]
return response(200, 'Get Consumer Submit List Success', u'获取消费者提交列表成功', {
'logs': logs,
@@ -473,6 +473,8 @@ class ConsumeInfoSubmitLogInfo(BaseModelMixin): |
||
| 473 | 473 |
|
| 474 | 474 |
verifyResult = models.IntegerField(_(u'verifyResult'), default=0, help_text=u'验证结果', db_index=True) |
| 475 | 475 |
|
| 476 |
+ dupload = models.BooleanField(_(u'dupload'), default=False, help_text=_(u'是否为重复提交'), db_index=True) |
|
| 477 |
+ |
|
| 476 | 478 |
test_user = models.BooleanField(_(u'test_user'), default=False, help_text=_(u'是否为测试用户'), db_index=True) |
| 477 | 479 |
|
| 478 | 480 |
class Meta: |
@@ -9,8 +9,9 @@ from TimeConvert import TimeConvert as tc |
||
| 9 | 9 |
|
| 10 | 10 |
from mch.models import BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, ModelInfo |
| 11 | 11 |
from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo, |
| 12 |
- ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, DistributorSaleStatisticInfo, |
|
| 13 |
- ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, SaleStatisticInfo) |
|
| 12 |
+ ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, ConsumeUserStatisticInfo, |
|
| 13 |
+ DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, |
|
| 14 |
+ SaleStatisticInfo) |
|
| 14 | 15 |
from utils.redis.connect import r |
| 15 | 16 |
from utils.redis.rkeys import MINI_PROGRAM_GIS_LIST |
| 16 | 17 |
|
@@ -201,48 +202,91 @@ def fill_ym(): |
||
| 201 | 202 |
ssi.save() |
| 202 | 203 |
|
| 203 | 204 |
|
| 204 |
-def refreshp(): |
|
| 205 |
+def refreshs(): |
|
| 206 |
+ ConsumeUserStatisticInfo.objects.all().delete() |
|
| 207 |
+ ConsumeSaleStatisticInfo.objects.all().delete() |
|
| 205 | 208 |
ConsumeProvinceSaleStatisticInfo.objects.all().delete() |
| 206 |
- logs = ConsumeInfoSubmitLogInfo.objects.filter(test_user=False) |
|
| 207 |
- for log in logs: |
|
| 208 |
- r.rpushjson(MINI_PROGRAM_GIS_LIST, {
|
|
| 209 |
- 'brand_id': log.brand_id, |
|
| 210 |
- 'lat': log.lat, |
|
| 211 |
- 'lon': log.lon, |
|
| 212 |
- 'ymd': tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d'), |
|
| 213 |
- }) |
|
| 209 |
+ ConsumeModelSaleStatisticInfo.objects.all().delete() |
|
| 214 | 210 |
|
| 211 |
+ logs = ConsumeInfoSubmitLogInfo.objects.filter(verifyResult=1, dupload=False, test_user=False) |
|
| 215 | 212 |
|
| 216 |
-def refreshm(): |
|
| 217 |
- ConsumeModelSaleStatisticInfo.objects.all().delete() |
|
| 218 |
- logs = ConsumeInfoSubmitLogInfo.objects.filter(test_user=False) |
|
| 219 | 213 |
for log in logs: |
| 214 |
+ ymd = tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d') |
|
| 215 |
+ |
|
| 220 | 216 |
try: |
| 221 | 217 |
mdl = ModelInfo.objects.get(model_id=log.model_id) |
| 222 | 218 |
except ModelInfo.DoesNotExist: |
| 223 | 219 |
continue |
| 224 |
- ymd = tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d') |
|
| 220 |
+ |
|
| 221 |
+ cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create( |
|
| 222 |
+ brand_id=mdl.brand_id, |
|
| 223 |
+ ymd=ymd, |
|
| 224 |
+ ) |
|
| 225 |
+ cusi.users = list(set(cusi.users + [log.user_id])) |
|
| 226 |
+ cusi.num = len(cusi.users) |
|
| 227 |
+ cusi.save() |
|
| 228 |
+ cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create( |
|
| 229 |
+ brand_id=mdl.brand_id, |
|
| 230 |
+ ymd=ymd[:6], |
|
| 231 |
+ ) |
|
| 232 |
+ cusi.users = list(set(cusi.users + [log.user_id])) |
|
| 233 |
+ cusi.num = len(cusi.users) |
|
| 234 |
+ cusi.save() |
|
| 235 |
+ cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create( |
|
| 236 |
+ brand_id=mdl.brand_id, |
|
| 237 |
+ ymd=ymd[:4], |
|
| 238 |
+ ) |
|
| 239 |
+ cusi.users = list(set(cusi.users + [log.user_id])) |
|
| 240 |
+ cusi.num = len(cusi.users) |
|
| 241 |
+ cusi.save() |
|
| 242 |
+ |
|
| 243 |
+ cssi, _ = ConsumeSaleStatisticInfo.objects.get_or_create( |
|
| 244 |
+ brand_id=mdl.brand_id, |
|
| 245 |
+ ymd=ymd, |
|
| 246 |
+ ) |
|
| 247 |
+ cssi.num += 1 |
|
| 248 |
+ cssi.save() |
|
| 249 |
+ cssi, _ = ConsumeSaleStatisticInfo.objects.get_or_create( |
|
| 250 |
+ brand_id=mdl.brand_id, |
|
| 251 |
+ ymd=ymd[:6], |
|
| 252 |
+ ) |
|
| 253 |
+ cssi.num += 1 |
|
| 254 |
+ cssi.save() |
|
| 255 |
+ cssi, _ = ConsumeSaleStatisticInfo.objects.get_or_create( |
|
| 256 |
+ brand_id=mdl.brand_id, |
|
| 257 |
+ ymd=ymd[:4], |
|
| 258 |
+ ) |
|
| 259 |
+ cssi.num += 1 |
|
| 260 |
+ cssi.save() |
|
| 261 |
+ |
|
| 225 | 262 |
# 日型号销量统计 |
| 226 |
- mssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create( |
|
| 263 |
+ cmssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create( |
|
| 227 | 264 |
brand_id=mdl.brand_id, |
| 228 | 265 |
model_name=mdl.model_uni_name, |
| 229 | 266 |
ymd=ymd, |
| 230 | 267 |
) |
| 231 |
- mssi.num += 1 |
|
| 232 |
- mssi.save() |
|
| 268 |
+ cmssi.num += 1 |
|
| 269 |
+ cmssi.save() |
|
| 233 | 270 |
# 月型号销量统计 |
| 234 |
- mssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create( |
|
| 271 |
+ cmssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create( |
|
| 235 | 272 |
brand_id=mdl.brand_id, |
| 236 | 273 |
model_name=mdl.model_uni_name, |
| 237 | 274 |
ymd=ymd[:6], |
| 238 | 275 |
) |
| 239 |
- mssi.num += 1 |
|
| 240 |
- mssi.save() |
|
| 276 |
+ cmssi.num += 1 |
|
| 277 |
+ cmssi.save() |
|
| 241 | 278 |
# 年型号销量统计 |
| 242 |
- mssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create( |
|
| 279 |
+ cmssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create( |
|
| 243 | 280 |
brand_id=mdl.brand_id, |
| 244 | 281 |
model_name=mdl.model_uni_name, |
| 245 | 282 |
ymd=ymd[:4], |
| 246 | 283 |
) |
| 247 |
- mssi.num += 1 |
|
| 248 |
- mssi.save() |
|
| 284 |
+ cmssi.num += 1 |
|
| 285 |
+ cmssi.save() |
|
| 286 |
+ |
|
| 287 |
+ r.rpushjson(MINI_PROGRAM_GIS_LIST, {
|
|
| 288 |
+ 'brand_id': log.brand_id, |
|
| 289 |
+ 'lat': log.lat, |
|
| 290 |
+ 'lon': log.lon, |
|
| 291 |
+ 'ymd': tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d'), |
|
| 292 |
+ }) |
@@ -4,9 +4,9 @@ from django.contrib import admin |
||
| 4 | 4 |
from django_admin import ReadOnlyModelAdmin |
| 5 | 5 |
|
| 6 | 6 |
from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo, |
| 7 |
- ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, DistributorSaleStatisticInfo, |
|
| 8 |
- ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, RegisterStatisticInfo, |
|
| 9 |
- SaleclerkSaleStatisticInfo, SaleStatisticInfo) |
|
| 7 |
+ ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, ConsumeUserStatisticInfo, |
|
| 8 |
+ DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, |
|
| 9 |
+ RegisterStatisticInfo, SaleclerkSaleStatisticInfo, SaleStatisticInfo) |
|
| 10 | 10 |
|
| 11 | 11 |
|
| 12 | 12 |
class RegisterStatisticInfoAdmin(admin.ModelAdmin): |
@@ -45,6 +45,12 @@ class SaleclerkSaleStatisticInfoAdmin(admin.ModelAdmin): |
||
| 45 | 45 |
search_fields = ('brand_id', 'distributor_id', 'distributor_name', 'distributor_short_name', 'clerk_id', 'clerk_name', 'ymd')
|
| 46 | 46 |
|
| 47 | 47 |
|
| 48 |
+class ConsumeUserStatisticInfoAdmin(admin.ModelAdmin): |
|
| 49 |
+ list_display = ('brand_id', 'ymd', 'users', 'num', 'status', 'created_at', 'updated_at')
|
|
| 50 |
+ list_filter = ('brand_id', 'status')
|
|
| 51 |
+ search_fields = ('brand_id', 'ymd')
|
|
| 52 |
+ |
|
| 53 |
+ |
|
| 48 | 54 |
class ConsumeSaleStatisticInfoAdmin(admin.ModelAdmin): |
| 49 | 55 |
list_display = ('brand_id', 'ymd', 'num', 'status', 'created_at', 'updated_at')
|
| 50 | 56 |
list_filter = ('brand_id', 'status')
|
@@ -77,6 +83,7 @@ admin.site.register(DistributorSaleStatisticInfo, DistributorSaleStatisticInfoAd |
||
| 77 | 83 |
admin.site.register(ProvinceSaleStatisticInfo, ProvinceSaleStatisticInfoAdmin) |
| 78 | 84 |
admin.site.register(SaleclerkSaleStatisticInfo, SaleclerkSaleStatisticInfoAdmin) |
| 79 | 85 |
|
| 86 |
+admin.site.register(ConsumeUserStatisticInfo, ConsumeUserStatisticInfoAdmin) |
|
| 80 | 87 |
admin.site.register(ConsumeSaleStatisticInfo, ConsumeSaleStatisticInfoAdmin) |
| 81 | 88 |
admin.site.register(ConsumeModelSaleStatisticInfo, ConsumeModelSaleStatisticInfoAdmin) |
| 82 | 89 |
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] |