@@ -491,6 +491,14 @@ class UserInfo(BaseModelMixin, LensmanTypeBoolMixin): |
||
491 | 491 |
'level': self.level, |
492 | 492 |
} |
493 | 493 |
|
494 |
+ @property |
|
495 |
+ def cardata(self): |
|
496 |
+ return { |
|
497 |
+ # 'brand_id': self.brand_id, |
|
498 |
+ 'card_id': self.membercardid, |
|
499 |
+ 'code': self.memberusercardcode, |
|
500 |
+ } |
|
501 |
+ |
|
494 | 502 |
|
495 | 503 |
class UserLoginLogInfo(BaseModelMixin): |
496 | 504 |
SUCCESS = 0 |
@@ -3,6 +3,7 @@ |
||
3 | 3 |
from __future__ import division |
4 | 4 |
|
5 | 5 |
import random |
6 |
+import re |
|
6 | 7 |
|
7 | 8 |
from django.conf import settings |
8 | 9 |
from django.db import transaction |
@@ -181,6 +182,7 @@ def decrypt2(request): |
||
181 | 182 |
user_id = request.POST.get('user_id', '') |
182 | 183 |
|
183 | 184 |
if code_ticket and user_id: |
185 |
+ code_ticket = re.sub(r'http://|https://', '', code_ticket) |
|
184 | 186 |
try: |
185 | 187 |
user = UserInfo.objects.get(user_id=user_id) |
186 | 188 |
except UserInfo.DoesNotExist: |
@@ -0,0 +1,24 @@ |
||
1 |
+# -*- coding: utf-8 -*- |
|
2 |
+ |
|
3 |
+from __future__ import division |
|
4 |
+ |
|
5 |
+import json |
|
6 |
+ |
|
7 |
+from django_logit import logit |
|
8 |
+from django_response import response |
|
9 |
+ |
|
10 |
+from account.models import UserInfo |
|
11 |
+from utils.redis.connect import r |
|
12 |
+from utils.redis.rkeys import MEMBERCARD_USERINFO_LIST |
|
13 |
+ |
|
14 |
+ |
|
15 |
+@logit |
|
16 |
+def phone(request): |
|
17 |
+ users = UserInfo.objects.filter(phone='').exclude(memberusercardcode='') |
|
18 |
+ |
|
19 |
+ p = r.pipeline() |
|
20 |
+ for u in users: |
|
21 |
+ p.rpush(MEMBERCARD_USERINFO_LIST, json.dumps(u.cardata)) |
|
22 |
+ p.execute() |
|
23 |
+ |
|
24 |
+ return response() |
@@ -6,7 +6,7 @@ from django_file_upload import views as file_views |
||
6 | 6 |
from account import tourguide_views |
7 | 7 |
from account import views as account_views |
8 | 8 |
from api import (admin_views, clerk_views, distributor_views, encrypt_views, mch_views, member_views, model_views, |
9 |
- operator_views, sr_views, staff_views, log_views) |
|
9 |
+ operator_views, refresh_views, sr_views, staff_views, log_views) |
|
10 | 10 |
from box import views as box_views |
11 | 11 |
from geo import views as geo_views |
12 | 12 |
from group import (groupuser_views, lensman_views, tourguidegroup_views, tourguidegroupadmin_views, |
@@ -304,7 +304,10 @@ urlpatterns += [ |
||
304 | 304 |
url(r'^admin/statistic/distributor$', admin_views.statistic_distributor, name='statistic_distributor'), |
305 | 305 |
|
306 | 306 |
url(r'^admin/statistic/deep/analyze$', admin_views.statistic_deep_analyze, name='statistic_deep_analyze'), |
307 |
+] |
|
307 | 308 |
|
309 |
+urlpatterns += [ |
|
310 |
+ url(r'^refresh/phone$', refresh_views.phone, name='phone'), |
|
308 | 311 |
] |
309 | 312 |
|
310 | 313 |
urlpatterns += [ |
@@ -0,0 +1,77 @@ |
||
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 |
+logger = logging.getLogger('console') |
|
20 |
+ |
|
21 |
+ |
|
22 |
+def get_phone(fields): |
|
23 |
+ for field in fields: |
|
24 |
+ name = field.get('name', '') |
|
25 |
+ if name == 'USER_FORM_INFO_FLAG_MOBILE': |
|
26 |
+ return field.get('value', '') |
|
27 |
+ return '' |
|
28 |
+ |
|
29 |
+ |
|
30 |
+class Command(CompatibilityBaseCommand): |
|
31 |
+ def handle(self, *args, **options): |
|
32 |
+ |
|
33 |
+ logger.info('MemberCard userinfo is dealing') |
|
34 |
+ |
|
35 |
+ while True: |
|
36 |
+ # r.rpushjson('MEMBERCARD_USERINFO_LIST', { |
|
37 |
+ # 'brand_id': 'brand_id', |
|
38 |
+ # 'card_id': 'card_id', |
|
39 |
+ # 'code': 'code', |
|
40 |
+ # }) |
|
41 |
+ k, v = r.blpopjson(MEMBERCARD_USERINFO_LIST, 60) |
|
42 |
+ if not v: |
|
43 |
+ continue |
|
44 |
+ |
|
45 |
+ logger.info(v) |
|
46 |
+ |
|
47 |
+ brand_id, card_id, code = v.get('brand_id', ''), v.get('card_id', ''), v.get('code', '') |
|
48 |
+ |
|
49 |
+ if not (card_id and code): |
|
50 |
+ continue |
|
51 |
+ |
|
52 |
+ # wxcfg = WECHAT.get('{}:JSAPI'.format(brand_id), {}) |
|
53 |
+ wxcfg = WECHAT.get('JSAPI', {}) |
|
54 |
+ |
|
55 |
+ appid = wxcfg.get('appID') |
|
56 |
+ secret = wxcfg.get('appsecret') |
|
57 |
+ |
|
58 |
+ userinfo = get_userinfo(card_id, code, appid=appid, secret=secret, storage=RedisStorage(r)) |
|
59 |
+ |
|
60 |
+ logger.info(userinfo) |
|
61 |
+ |
|
62 |
+ userinfo = userinfo.get('user_info', {}) |
|
63 |
+ if not userinfo: |
|
64 |
+ continue |
|
65 |
+ |
|
66 |
+ common_field_list = userinfo.get('common_field_list', []) |
|
67 |
+ phone = get_phone(common_field_list) |
|
68 |
+ |
|
69 |
+ if not phone: |
|
70 |
+ continue |
|
71 |
+ |
|
72 |
+ close_old_connections() |
|
73 |
+ |
|
74 |
+ with transaction.atomic(): |
|
75 |
+ UserInfo.objects.select_for_update().filter(membercardid=card_id, memberusercardcode=code).update(phone=phone) |
|
76 |
+ |
|
77 |
+ close_old_connections() |
@@ -72,6 +72,8 @@ MINI_PROGRAM_GIS_LIST = 'tamron:miniprogram:gis:list' |
||
72 | 72 |
|
73 | 73 |
SCREEN_ADMIN_LOGIN = 'tamron:screen:admin:login:%s:%s' # brand_id, token |
74 | 74 |
|
75 |
+MEMBERCARD_USERINFO_LIST = 'tamron:membercard:userinfo' # |
|
76 |
+ |
|
75 | 77 |
SUBSCRIBE_USERINFO_LIST = 'subscribe:userinfo:%s' |
76 | 78 |
|
77 | 79 |
MEMBER_SHOT_DATA = 'kodo:member:shot:data' |