ConsumeInfoSubmitLogInfo add province

FFIB 5 years ago
parent
commit
6a6695dd7d
5 changed files with 42 additions and 3 deletions
  1. 8 1
      api/mch_views.py
  2. 6 0
      commands/management/commands/gis.py
  3. 25 1
      commands/management/commands/membercard.py
  4. 1 1
      mch/models.py
  5. 2 0
      pre/views.py

+ 8 - 1
api/mch_views.py

@@ -298,6 +298,8 @@ def consumer_info_api(request):
298 298
         act = ActivityInfo.objects.filter(status=True).order_by('-pk').first()
299 299
         during_activity = True if act and act.has_unexpired_activity(model.model_uni_name) else False
300 300
 
301
+    ymd = tc.local_string(format='%Y%m%d')
302
+
301 303
     # 记录用户信息提交记录
302 304
     log = ConsumeInfoSubmitLogInfo.objects.create(
303 305
         user_id=user_id,
@@ -310,6 +312,7 @@ def consumer_info_api(request):
310 312
         brand_name=brand.brand_name,
311 313
         model_id=model.model_id,
312 314
         model_name=model.model_name,
315
+        model_uni_name=model.model_uni_name,
313 316
         # distributor_id=distributor.distributor_id,
314 317
         # distributor_name=distributor.distributor_name,
315 318
         distributor_id='',
@@ -323,11 +326,13 @@ def consumer_info_api(request):
323 326
         coupon_value=act.coupon_value if during_activity else 0,
324 327
         test_user=user.test_user,
325 328
         code_version=code_version,
329
+        ym=ymd[:6],
330
+        ymd=ymd,
331
+        province=user.province_name if user.province_name else user.province,
326 332
     )
327 333
 
328 334
     if not user.test_user and not dupload:
329 335
         # TODO: Make statistic async
330
-        ymd = tc.local_string(format='%Y%m%d')
331 336
 
332 337
         cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create(
333 338
             brand_id=brand.brand_id,
@@ -408,6 +413,8 @@ def consumer_info_api(request):
408 413
             'lon': log.lon,
409 414
             'phone': log.phone,
410 415
             'ymd': ymd,
416
+            'serialNo': serialNo,
417
+            'model_id': model.model_id,
411 418
         })
412 419
 
413 420
     # 更新销售员提交的表

+ 6 - 0
commands/management/commands/gis.py

@@ -11,6 +11,7 @@ from django_six import CompatibilityBaseCommand, close_old_connections
11 11
 
12 12
 from statistic.models import ConsumeProvinceSaleStatisticInfo
13 13
 from account.models import UserInfo
14
+from mch.models import ConsumeInfoSubmitLogInfo
14 15
 from utils.redis.connect import r
15 16
 from utils.redis.rkeys import MINI_PROGRAM_GIS_LIST
16 17
 
@@ -74,6 +75,11 @@ class Command(CompatibilityBaseCommand):
74 75
                     user.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code)
75 76
                     user.save()
76 77
 
78
+                    if v.get('model_id'):
79
+                        log = ConsumeInfoSubmitLogInfo.objects.get(model_id=v.get('model_id', ''), serialNo=v.get('serialNo', ''), status=True)
80
+                        log.province = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code)
81
+                        log.save()
82
+
77 83
                     # [消费者维度]省份销量统计
78 84
                     # 日
79 85
                     cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(

+ 25 - 1
commands/management/commands/membercard.py

@@ -1,7 +1,9 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
+import json
3 4
 import logging
4 5
 
6
+import requests
5 7
 from django.conf import settings
6 8
 from django.db import transaction
7 9
 from django_six import CompatibilityBaseCommand, close_old_connections
@@ -9,6 +11,7 @@ from pywe_membercard import get_userinfo
9 11
 from pywe_storage import RedisStorage
10 12
 
11 13
 from account.models import UserInfo
14
+from mch.models import ConsumeInfoSubmitLogInfo
12 15
 from utils.redis.connect import r
13 16
 from utils.redis.rkeys import MEMBERCARD_USERINFO_LIST
14 17
 
@@ -72,6 +75,27 @@ class Command(CompatibilityBaseCommand):
72 75
             close_old_connections()
73 76
 
74 77
             with transaction.atomic():
75
-                UserInfo.objects.select_for_update().filter(membercardid=card_id, memberusercardcode=code).update(phone=phone)
78
+                try:
79
+                    userinfo = UserInfo.objects.get(membercardid=card_id, memberusercardcode=code)
80
+                    userinfo.phone = phone
81
+                    userinfo.save()
82
+                except Exception as e:
83
+                    logger.info(e.message)
84
+                    continue
85
+
86
+                try:
87
+                    phoneinfo = requests.get(settings.PHONE_2_ADMINISTRATIVE_DIVISION.format(phone))
88
+                except Exception as e:
89
+                    logger.info(e.message)
90
+                    continue
91
+                try:
92
+                    province_name = json.loads(phoneinfo.content.split('(')[-1][:-1])['data']['area']
93
+                except Exception as e:
94
+                    logger.info(e.message)
95
+                    continue
96
+                
97
+                logs = ConsumeInfoSubmitLogInfo.objects.filter(user_id=userinfo.user_id)
98
+                for log in logs:
99
+                    log.province = log.province if log.lat and log.lon else province_name
76 100
 
77 101
             close_old_connections()

+ 1 - 1
mch/models.py

@@ -622,7 +622,7 @@ class ConsumeInfoSubmitLogInfo(BaseModelMixin):
622 622
     ym = models.IntegerField(_(u'ym'), default=0, help_text=u'年月', db_index=True)  # 例:201712, tc.local_string(format='%Y%m')
623 623
     ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True)  # 例:20171208, tc.local_string(format='%Y%m%d')
624 624
 
625
-    province = models.CharField(_(u'省份'), max_length=32, blank=True, null=True, help_text=u'省份', db_index=True)
625
+    province = models.CharField(_(u'province'), max_length=32, blank=True, null=True, help_text=u'省份', db_index=True)
626 626
 
627 627
     test_user = models.BooleanField(_(u'test_user'), default=False, help_text=_(u'是否为测试用户'), db_index=True)
628 628
 

+ 2 - 0
pre/views.py

@@ -330,6 +330,8 @@ def refreshs():
330 330
                 'lon': log.lon,
331 331
                 'phone': log.phone,
332 332
                 'ymd': tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d'),
333
+                'model_id': log.model_id,
334
+                'serialNo': log.serialNo
333 335
             })
334 336
 
335 337