Merge branch 'tamron' into demo

Kimi.Huang 6 lat temu
rodzic
commit
acc85124f7

+ 1 - 0
api/mch_views.py

@@ -367,6 +367,7 @@ def consumer_info_api(request):
367 367
 
368 368
         r.rpushjson(MINI_PROGRAM_GIS_LIST, {
369 369
             'brand_id': log.brand_id,
370
+            'user_id': log.user_id,
370 371
             'lat': log.lat,
371 372
             'lon': log.lon,
372 373
             'phone': log.phone,

+ 10 - 3
commands/management/commands/gis.py

@@ -65,6 +65,7 @@ class Command(CompatibilityBaseCommand):
65 65
                         continue
66 66
 
67 67
                     brand_id = v.get('brand_id', '')
68
+                    user_id = v.get('user_id', '')
68 69
                     ymd = v.get('ymd', '')
69 70
 
70 71
                     # [消费者维度]省份销量统计
@@ -76,7 +77,9 @@ class Command(CompatibilityBaseCommand):
76 77
                     )
77 78
                     if not cpssi.province_name:
78 79
                         cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code)
79
-                    cpssi.num += 1
80
+                    cpssi.users = list(set(cpssi.users + [user_id]))
81
+                    cpssi.num = len(cpssi.users)
82
+                    cpssi.num2 += 1
80 83
                     cpssi.save()
81 84
                     # 月
82 85
                     cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(
@@ -86,7 +89,9 @@ class Command(CompatibilityBaseCommand):
86 89
                     )
87 90
                     if not cpssi.province_name:
88 91
                         cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code)
89
-                    cpssi.num += 1
92
+                    cpssi.users = list(set(cpssi.users + [user_id]))
93
+                    cpssi.num = len(cpssi.users)
94
+                    cpssi.num2 += 1
90 95
                     cpssi.save()
91 96
                     # 年
92 97
                     cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(
@@ -96,7 +101,9 @@ class Command(CompatibilityBaseCommand):
96 101
                     )
97 102
                     if not cpssi.province_name:
98 103
                         cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code)
99
-                    cpssi.num += 1
104
+                    cpssi.users = list(set(cpssi.users + [user_id]))
105
+                    cpssi.num = len(cpssi.users)
106
+                    cpssi.num2 += 1
100 107
                     cpssi.save()
101 108
 
102 109
                 close_old_connections()

+ 1 - 0
pre/views.py

@@ -286,6 +286,7 @@ def refreshs():
286 286
 
287 287
         r.rpushjson(MINI_PROGRAM_GIS_LIST, {
288 288
             'brand_id': log.brand_id,
289
+            'user_id': log.user_id,
289 290
             'lat': log.lat,
290 291
             'lon': log.lon,
291 292
             'phone': log.phone,

+ 1 - 1
statistic/admin.py

@@ -70,7 +70,7 @@ class ConsumeDistributorSaleStatisticInfoAdmin(admin.ModelAdmin):
70 70
 
71 71
 
72 72
 class ConsumeProvinceSaleStatisticInfoAdmin(admin.ModelAdmin):
73
-    list_display = ('brand_id', 'province_code', 'province_name', 'ymd', 'num', 'position', 'status', 'created_at', 'updated_at')
73
+    list_display = ('brand_id', 'province_code', 'province_name', 'ymd', 'users', 'num', 'num2', 'position', 'status', 'created_at', 'updated_at')
74 74
     list_filter = ('brand_id', 'status')
75 75
     search_fields = ('brand_id', 'province_code', 'province_name', 'ymd')
76 76
 

+ 31 - 0
statistic/migrations/0013_auto_20190403_1917.py

@@ -0,0 +1,31 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 1.11.20 on 2019-04-03 11:17
3
+from __future__ import unicode_literals
4
+
5
+from django.db import migrations, models
6
+import jsonfield.fields
7
+
8
+
9
+class Migration(migrations.Migration):
10
+
11
+    dependencies = [
12
+        ('statistic', '0012_auto_20181117_0052'),
13
+    ]
14
+
15
+    operations = [
16
+        migrations.AddField(
17
+            model_name='consumeprovincesalestatisticinfo',
18
+            name='num2',
19
+            field=models.IntegerField(default=0, help_text='\u652f\u6570', verbose_name='num2'),
20
+        ),
21
+        migrations.AddField(
22
+            model_name='consumeprovincesalestatisticinfo',
23
+            name='users',
24
+            field=jsonfield.fields.JSONField(default=[], help_text='\u7528\u6237\u5217\u8868', verbose_name='users'),
25
+        ),
26
+        migrations.AlterField(
27
+            model_name='consumeprovincesalestatisticinfo',
28
+            name='num',
29
+            field=models.IntegerField(default=0, help_text='\u4eba\u6570', verbose_name='num'),
30
+        ),
31
+    ]

+ 4 - 1
statistic/models.py

@@ -260,7 +260,9 @@ class ConsumeProvinceSaleStatisticInfo(BaseModelMixin):
260 260
     province_code = models.CharField(_(u'province_code'), max_length=6, help_text=u'省份编码', db_index=True)
261 261
     province_name = models.CharField(_(u'province_name'), max_length=8, blank=True, null=True, help_text=u'省份名称')
262 262
     ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True)  # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
263
-    num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
263
+    users = JSONField(_(u'users'), default=[], help_text=u'用户列表')
264
+    num = models.IntegerField(_(u'num'), default=0, help_text=u'人数')
265
+    num2 = models.IntegerField(_(u'num2'), default=0, help_text=u'支数')
264 266
 
265 267
     position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
266 268
 
@@ -278,4 +280,5 @@ class ConsumeProvinceSaleStatisticInfo(BaseModelMixin):
278 280
             'province_name': self.province_name,
279 281
             'ymd': self.ymd,
280 282
             'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
283
+            'num2': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num2,
281 284
         }

+ 17 - 10
statistic/views.py

@@ -210,7 +210,7 @@ def ytj(brand_id):
210 210
     users = []
211 211
     for cusi in cusis:
212 212
         users += cusi.users
213
-    scan_user_count = len(users)
213
+    scan_user_count = len(set(users))
214 214
 
215 215
     # [消费者维度] 周期内镜头销售支数
216 216
     sell_volume_count = ConsumeSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd__lt=9999).aggregate(Sum('num')).get('num__sum', 0) or 0
@@ -259,16 +259,23 @@ def ytj(brand_id):
259 259
         ymd__gt=startd,
260 260
         ymd__lte=endd,
261 261
         status=True
262
-    ).order_by(
263
-        'province_code'
264
-    ).values(
265
-        'province_code'
266
-    ).annotate(
267
-        num=Sum('num')
268
-    ).order_by(
269
-        '-num'
270 262
     )
271
-    provinces = [dict(p, **{'province_name': ''}) for p in provinces]
263
+    # ).order_by(
264
+    #     'province_code'
265
+    # ).values(
266
+    #     'province_code'
267
+    # ).annotate(
268
+    #     num=Sum('num')
269
+    # ).order_by(
270
+    #     '-num'
271
+    # )
272
+    provinces_users = {}
273
+    for province in provinces:
274
+        if provinces_users.get(province.province_code):
275
+            provinces_users[province.province_code] += province.users
276
+        else:
277
+            provinces_users[province.province_code] = province.users
278
+    provinces = [{'province_code': province_code, 'num': len(set(users))} for province_code, users in provinces_users.iteritems()]
272 279
 
273 280
     return {
274 281
         'scan_user_count': scan_user_count,