@@ -19,13 +19,14 @@ class Command(CompatibilityBaseCommand): |
||
| 19 | 19 |
while True: |
| 20 | 20 |
# r.rpushjson('TEMPLET_CMD_KEY', {})
|
| 21 | 21 |
k, v = r.blpopjson('TEMPLET_CMD_KEY', 60)
|
| 22 |
- if v: |
|
| 22 |
+ if not v: |
|
| 23 |
+ continue |
|
| 23 | 24 |
|
| 24 |
- close_old_connections() |
|
| 25 |
+ close_old_connections() |
|
| 25 | 26 |
|
| 26 |
- logger.info(v) |
|
| 27 |
+ logger.info(v) |
|
| 27 | 28 |
|
| 28 |
- with transaction.atomic(): |
|
| 29 |
- pass |
|
| 29 |
+ with transaction.atomic(): |
|
| 30 |
+ pass |
|
| 30 | 31 |
|
| 31 |
- close_old_connections() |
|
| 32 |
+ close_old_connections() |
@@ -31,79 +31,80 @@ class Command(CompatibilityBaseCommand): |
||
| 31 | 31 |
# 'ymd': '20121212', |
| 32 | 32 |
# }) |
| 33 | 33 |
k, v = r.blpopjson(MINI_PROGRAM_GIS_LIST, 60) |
| 34 |
- if v: |
|
| 34 |
+ if not v: |
|
| 35 |
+ continue |
|
| 35 | 36 |
|
| 36 |
- close_old_connections() |
|
| 37 |
+ logger.info(v) |
|
| 37 | 38 |
|
| 38 |
- logger.info(v) |
|
| 39 |
+ close_old_connections() |
|
| 39 | 40 |
|
| 40 |
- with transaction.atomic(): |
|
| 41 |
+ with transaction.atomic(): |
|
| 42 |
+ try: |
|
| 43 |
+ gisinfo = requests.get(settings.GIS_2_ADMINISTRATIVE_DIVISION.format(v.get('lat', 0), v.get('lon', 0))).json()
|
|
| 44 |
+ except Exception as e: |
|
| 45 |
+ logger.info(e.message) |
|
| 46 |
+ |
|
| 47 |
+ zh1 = gisinfo.get('data', {}).get('zh1', '')
|
|
| 48 |
+ |
|
| 49 |
+ province_code = ProvinceModelMixin.PROVINCE_NAME_CODE_DICT.get(zh1) if zh1 else '' |
|
| 50 |
+ |
|
| 51 |
+ # 手机归属地 |
|
| 52 |
+ if not province_code: |
|
| 41 | 53 |
try: |
| 42 |
- gisinfo = requests.get(settings.GIS_2_ADMINISTRATIVE_DIVISION.format(v.get('lat', 0), v.get('lon', 0))).json()
|
|
| 54 |
+ phoneinfo = requests.get(settings.PHONE_2_ADMINISTRATIVE_DIVISION.format(v.get('phone', 0)))
|
|
| 43 | 55 |
except Exception as e: |
| 44 | 56 |
logger.info(e.message) |
| 45 |
- |
|
| 46 |
- zh1 = gisinfo.get('data', {}).get('zh1', '')
|
|
| 47 |
- |
|
| 48 |
- province_code = ProvinceModelMixin.PROVINCE_NAME_CODE_DICT.get(zh1) if zh1 else '' |
|
| 49 |
- |
|
| 50 |
- # 手机归属地 |
|
| 51 |
- if not province_code: |
|
| 52 |
- try: |
|
| 53 |
- phoneinfo = requests.get(settings.PHONE_2_ADMINISTRATIVE_DIVISION.format(v.get('phone', 0)))
|
|
| 54 |
- except Exception as e: |
|
| 55 |
- logger.info(e.message) |
|
| 56 |
- continue |
|
| 57 |
- try: |
|
| 58 |
- province_name = json.loads(phoneinfo.content.split('(')[-1][:-1])['data']['area']
|
|
| 59 |
- except Exception as e: |
|
| 60 |
- logger.info(e.message) |
|
| 61 |
- continue |
|
| 62 |
- province_code = ProvinceShortModelMixin.PROVINCE_NAME_CODE_DICT.get(province_name) |
|
| 63 |
- |
|
| 64 |
- if not province_code: |
|
| 65 | 57 |
continue |
| 66 |
- |
|
| 67 |
- brand_id = v.get('brand_id', '')
|
|
| 68 |
- user_id = v.get('user_id', '')
|
|
| 69 |
- ymd = v.get('ymd', '')
|
|
| 70 |
- |
|
| 71 |
- # [消费者维度]省份销量统计 |
|
| 72 |
- # 日 |
|
| 73 |
- cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 74 |
- brand_id=brand_id, |
|
| 75 |
- province_code=province_code, |
|
| 76 |
- ymd=ymd, |
|
| 77 |
- ) |
|
| 78 |
- if not cpssi.province_name: |
|
| 79 |
- cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code) |
|
| 80 |
- cpssi.users = list(set(cpssi.users + [user_id])) |
|
| 81 |
- cpssi.num = len(cpssi.users) |
|
| 82 |
- cpssi.num2 += 1 |
|
| 83 |
- cpssi.save() |
|
| 84 |
- # 月 |
|
| 85 |
- cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 86 |
- brand_id=brand_id, |
|
| 87 |
- province_code=province_code, |
|
| 88 |
- ymd=ymd[:6], |
|
| 89 |
- ) |
|
| 90 |
- if not cpssi.province_name: |
|
| 91 |
- cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code) |
|
| 92 |
- cpssi.users = list(set(cpssi.users + [user_id])) |
|
| 93 |
- cpssi.num = len(cpssi.users) |
|
| 94 |
- cpssi.num2 += 1 |
|
| 95 |
- cpssi.save() |
|
| 96 |
- # 年 |
|
| 97 |
- cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 98 |
- brand_id=brand_id, |
|
| 99 |
- province_code=province_code, |
|
| 100 |
- ymd=ymd[:4], |
|
| 101 |
- ) |
|
| 102 |
- if not cpssi.province_name: |
|
| 103 |
- cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code) |
|
| 104 |
- cpssi.users = list(set(cpssi.users + [user_id])) |
|
| 105 |
- cpssi.num = len(cpssi.users) |
|
| 106 |
- cpssi.num2 += 1 |
|
| 107 |
- cpssi.save() |
|
| 108 |
- |
|
| 109 |
- close_old_connections() |
|
| 58 |
+ try: |
|
| 59 |
+ province_name = json.loads(phoneinfo.content.split('(')[-1][:-1])['data']['area']
|
|
| 60 |
+ except Exception as e: |
|
| 61 |
+ logger.info(e.message) |
|
| 62 |
+ continue |
|
| 63 |
+ province_code = ProvinceShortModelMixin.PROVINCE_NAME_CODE_DICT.get(province_name) |
|
| 64 |
+ |
|
| 65 |
+ if not province_code: |
|
| 66 |
+ continue |
|
| 67 |
+ |
|
| 68 |
+ brand_id = v.get('brand_id', '')
|
|
| 69 |
+ user_id = v.get('user_id', '')
|
|
| 70 |
+ ymd = v.get('ymd', '')
|
|
| 71 |
+ |
|
| 72 |
+ # [消费者维度]省份销量统计 |
|
| 73 |
+ # 日 |
|
| 74 |
+ cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 75 |
+ brand_id=brand_id, |
|
| 76 |
+ province_code=province_code, |
|
| 77 |
+ ymd=ymd, |
|
| 78 |
+ ) |
|
| 79 |
+ if not cpssi.province_name: |
|
| 80 |
+ cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code) |
|
| 81 |
+ cpssi.users = list(set(cpssi.users + [user_id])) |
|
| 82 |
+ cpssi.num = len(cpssi.users) |
|
| 83 |
+ cpssi.num2 += 1 |
|
| 84 |
+ cpssi.save() |
|
| 85 |
+ # 月 |
|
| 86 |
+ cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 87 |
+ brand_id=brand_id, |
|
| 88 |
+ province_code=province_code, |
|
| 89 |
+ ymd=ymd[:6], |
|
| 90 |
+ ) |
|
| 91 |
+ if not cpssi.province_name: |
|
| 92 |
+ cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code) |
|
| 93 |
+ cpssi.users = list(set(cpssi.users + [user_id])) |
|
| 94 |
+ cpssi.num = len(cpssi.users) |
|
| 95 |
+ cpssi.num2 += 1 |
|
| 96 |
+ cpssi.save() |
|
| 97 |
+ # 年 |
|
| 98 |
+ cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 99 |
+ brand_id=brand_id, |
|
| 100 |
+ province_code=province_code, |
|
| 101 |
+ ymd=ymd[:4], |
|
| 102 |
+ ) |
|
| 103 |
+ if not cpssi.province_name: |
|
| 104 |
+ cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code) |
|
| 105 |
+ cpssi.users = list(set(cpssi.users + [user_id])) |
|
| 106 |
+ cpssi.num = len(cpssi.users) |
|
| 107 |
+ cpssi.num2 += 1 |
|
| 108 |
+ cpssi.save() |
|
| 109 |
+ |
|
| 110 |
+ close_old_connections() |
@@ -30,10 +30,10 @@ class Command(CompatibilityBaseCommand): |
||
| 30 | 30 |
if not v: |
| 31 | 31 |
continue |
| 32 | 32 |
|
| 33 |
- close_old_connections() |
|
| 34 |
- |
|
| 35 | 33 |
logger.info(v) |
| 36 | 34 |
|
| 35 |
+ close_old_connections() |
|
| 36 |
+ |
|
| 37 | 37 |
with transaction.atomic(): |
| 38 | 38 |
try: |
| 39 | 39 |
elog = MchInfoEncryptLogInfo.objects.select_for_update().get(sn=v.get('sn', ''))
|
@@ -0,0 +1,70 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+import logging |
|
| 4 |
+ |
|
| 5 |
+from django.conf import settings |
|
| 6 |
+from django.db import transaction |
|
| 7 |
+from django_six import CompatibilityBaseCommand, close_old_connections |
|
| 8 |
+from pywe_membercard import get_userinfo |
|
| 9 |
+from pywe_storage import RedisStorage |
|
| 10 |
+ |
|
| 11 |
+from account.models import UserInfo |
|
| 12 |
+from utils.redis.connect import r |
|
| 13 |
+from utils.redis.rkeys import MEMBERCARD_USERINFO_LIST |
|
| 14 |
+ |
|
| 15 |
+ |
|
| 16 |
+WECHAT = settings.WECHAT |
|
| 17 |
+ |
|
| 18 |
+ |
|
| 19 |
+wxcfg = WECHAT.get('JSAPI', {})
|
|
| 20 |
+ |
|
| 21 |
+appid = wxcfg.get('appID')
|
|
| 22 |
+secret = wxcfg.get('appsecret')
|
|
| 23 |
+ |
|
| 24 |
+ |
|
| 25 |
+logger = logging.getLogger('console')
|
|
| 26 |
+ |
|
| 27 |
+ |
|
| 28 |
+def get_phone(fields): |
|
| 29 |
+ for field in fields: |
|
| 30 |
+ name = field.get('name', '')
|
|
| 31 |
+ if name == 'USER_FORM_INFO_FLAG_MOBILE': |
|
| 32 |
+ return field.get('value', '')
|
|
| 33 |
+ return '' |
|
| 34 |
+ |
|
| 35 |
+ |
|
| 36 |
+class Command(CompatibilityBaseCommand): |
|
| 37 |
+ def handle(self, *args, **options): |
|
| 38 |
+ |
|
| 39 |
+ logger.info('Redpack is dealing')
|
|
| 40 |
+ |
|
| 41 |
+ while True: |
|
| 42 |
+ # r.rpushjson('MEMBERCARD_USERINFO_LIST', {
|
|
| 43 |
+ # 'card_id': 'card_id', |
|
| 44 |
+ # 'code': 'code', |
|
| 45 |
+ # }) |
|
| 46 |
+ k, v = r.blpopjson(MEMBERCARD_USERINFO_LIST, 60) |
|
| 47 |
+ if not v: |
|
| 48 |
+ continue |
|
| 49 |
+ |
|
| 50 |
+ logger.info(v) |
|
| 51 |
+ |
|
| 52 |
+ card_id, code = v.get('card_id', ''), v.get('code', '')
|
|
| 53 |
+ |
|
| 54 |
+ if not (card_id and code): |
|
| 55 |
+ continue |
|
| 56 |
+ |
|
| 57 |
+ userinfo = get_userinfo(card_id, code, appid=appid, secret=secret, storage=RedisStorage(r)) |
|
| 58 |
+ |
|
| 59 |
+ common_field_list = userinfo.get('common_field_list', [])
|
|
| 60 |
+ phone = get_phone(common_field_list) |
|
| 61 |
+ |
|
| 62 |
+ if not phone: |
|
| 63 |
+ continue |
|
| 64 |
+ |
|
| 65 |
+ close_old_connections() |
|
| 66 |
+ |
|
| 67 |
+ with transaction.atomic(): |
|
| 68 |
+ UserInfo.objects.select_for_update().filter(membercardid=card_id, memberusercardcode=code).update(phone=phone) |
|
| 69 |
+ |
|
| 70 |
+ close_old_connections() |
@@ -1,4 +1,4 @@ |
||
| 1 |
-Django==1.11.22 |
|
| 1 |
+Django==1.11.23 |
|
| 2 | 2 |
django-admin==1.3.2 |
| 3 | 3 |
django-cors-headers==3.0.2 |
| 4 | 4 |
django-curtail-uuid==1.0.4 |
@@ -73,3 +73,5 @@ MINI_PROGRAM_GIS_LIST = 'tamron:miniprogram:gis:list' |
||
| 73 | 73 |
SCREEN_ADMIN_LOGIN = 'tamron:screen:admin:login:%s:%s' # brand_id, token |
| 74 | 74 |
|
| 75 | 75 |
REDPACK_WAITING_SEND_LIST = 'tamron:redpack:waiting:send' # |
| 76 |
+ |
|
| 77 |
+MEMBERCARD_USERINFO_LIST = 'tamron:membercard:userinfo' # |