R109">109
+
+ 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' # |