cfg

Kimi.Huang 5 ans auparavant
Parent
Commettre
cefc16fe75

+ 11 - 3
account/models.py

@@ -310,7 +310,7 @@ class UserInfo(BaseModelMixin, LensmanTypeBoolMixin):
310 310
     sex = models.IntegerField(_(u'sex'), choices=SexModelMixin.SEX_TUPLE, default=SexModelMixin.UNKNOWN, help_text=u'用户性别')
311 311
     nickname = models.CharField(_(u'nickname'), max_length=255, blank=True, null=True, help_text=u'用户昵称')
312 312
     avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'用户头像')
313
-    phone = models.CharField(_(u'phone'), max_length=11, blank=True, null=True, help_text=u'用户电话', db_index=True)
313
+    phone = models.CharField(_(u'phone'), max_length=11, default='', blank=True, help_text=u'用户电话', db_index=True)
314 314
     country = models.CharField(_(u'country'), max_length=255, blank=True, null=True, help_text=u'用户国家')
315 315
     province = models.CharField(_(u'province'), max_length=255, blank=True, null=True, help_text=u'用户省份')
316 316
     city = models.CharField(_(u'city'), max_length=255, blank=True, null=True, help_text=u'用户城市')
@@ -337,8 +337,8 @@ class UserInfo(BaseModelMixin, LensmanTypeBoolMixin):
337 337
     login_at = models.DateTimeField(_(u'login_at'), blank=True, null=True, help_text=_(u'登录时间'))
338 338
 
339 339
     has_membercard = models.BooleanField(_(u'has_membercard'), default=False, help_text=_(u'是否激活会员卡'), db_index=True)
340
-    membercardid = models.CharField(_(u'membercardid'), max_length=32, blank=True, null=True, help_text=_(u'会员卡编号'), db_index=True)
341
-    memberusercardcode = models.CharField(_(u'memberusercardcode'), max_length=32, blank=True, null=True, help_text=_(u'用户会员卡编号'), db_index=True)
340
+    membercardid = models.CharField(_(u'membercardid'), max_length=32, default='', blank=True, help_text=_(u'会员卡编号'), db_index=True)
341
+    memberusercardcode = models.CharField(_(u'memberusercardcode'), max_length=32, default='', blank=True, help_text=_(u'用户会员卡编号'), db_index=True)
342 342
 
343 343
     clerk_id = models.CharField(_(u'clerk_id'), max_length=32, blank=True, null=True, help_text=u'店员唯一标识', db_index=True)
344 344
 
@@ -416,6 +416,14 @@ class UserInfo(BaseModelMixin, LensmanTypeBoolMixin):
416 416
             'saleclerk_info': saleclerk_info,
417 417
         }
418 418
 
419
+    @property
420
+    def cardata(self):
421
+        return {
422
+            'brand_id': self.brand_id,
423
+            'membercardid': self.membercardid,
424
+            'memberusercardcode': self.memberusercardcode,
425
+        }
426
+
419 427
 
420 428
 class UserLoginLogInfo(BaseModelMixin):
421 429
     SUCCESS = 0

+ 4 - 6
api/mch_views.py

@@ -164,20 +164,18 @@ def upgrade_api(request):
164 164
 
165 165
 
166 166
 def getPhoneNumber(request):
167
+    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
168
+
167 169
     user_id = request.POST.get('user_id', '')
168 170
 
169
-    wxcfg = WECHAT.get('MINIAPP', {})
171
+    wxcfg = WECHAT.get('{}:MINIAPP'.format(brand_id), {})
170 172
 
171 173
     appid = wxcfg.get('appID')
174
+    secret = wxcfg.get('appsecret')
172 175
 
173 176
     # Just for compatible because of store session_key has changed
174 177
     session_key = None if user_id else RedisStorage(r).get('{0}:{1}:sessionKey'.format(appid, ''))
175 178
 
176
-    wxcfg = WECHAT.get('MINIAPP', {})
177
-
178
-    appid = wxcfg.get('appID')
179
-    secret = wxcfg.get('appsecret')
180
-
181 179
     iv = request.POST.get('iv', '')
182 180
     encryptedData = request.POST.get('encryptedData', '')
183 181
 

+ 24 - 0
api/refresh_views.py

@@ -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().exclude(phone='', 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()

+ 5 - 1
api/urls.py

@@ -5,7 +5,7 @@ from django_file_upload import views as file_views
5 5
 
6 6
 from account import tourguide_views
7 7
 from account import views as account_views
8
-from api import admin_views, clerk_views, distributor_views, encrypt_views, mch_views, model_views, operator_views, slide_views
8
+from api import admin_views, clerk_views, distributor_views, encrypt_views, mch_views, model_views, operator_views, refresh_views, slide_views
9 9
 from box import views as box_views
10 10
 from geo import views as geo_views
11 11
 from group import (groupuser_views, lensman_views, tourguidegroup_views, tourguidegroupadmin_views,
@@ -294,3 +294,7 @@ urlpatterns += [
294 294
 urlpatterns += [
295 295
     url(r'^slides$', slide_views.slides, name='slides'),
296 296
 ]
297
+
298
+urlpatterns += [
299
+    url(r'^refresh/phone$', refresh_views.phone, name='phone'),
300
+]

+ 6 - 7
commands/management/commands/membercard.py

@@ -16,12 +16,6 @@ from utils.redis.rkeys import MEMBERCARD_USERINFO_LIST
16 16
 WECHAT = settings.WECHAT
17 17
 
18 18
 
19
-wxcfg = WECHAT.get('JSAPI', {})
20
-
21
-appid = wxcfg.get('appID')
22
-secret = wxcfg.get('appsecret')
23
-
24
-
25 19
 logger = logging.getLogger('console')
26 20
 
27 21
 
@@ -49,11 +43,16 @@ class Command(CompatibilityBaseCommand):
49 43
 
50 44
             logger.info(v)
51 45
 
52
-            card_id, code = v.get('card_id', ''), v.get('code', '')
46
+            brand_id, card_id, code = v.get('brand_id', ''), v.get('card_id', ''), v.get('code', '')
53 47
 
54 48
             if not (card_id and code):
55 49
                 continue
56 50
 
51
+            wxcfg = WECHAT.get('{}:JSAPI'.format(brand_id), {})
52
+
53
+            appid = wxcfg.get('appID')
54
+            secret = wxcfg.get('appsecret')
55
+
57 56
             userinfo = get_userinfo(card_id, code, appid=appid, secret=secret, storage=RedisStorage(r))
58 57
 
59 58
             common_field_list = userinfo.get('common_field_list', [])

+ 6 - 4
miniapp/views.py

@@ -26,7 +26,7 @@ WECHAT = settings.WECHAT
26 26
 def get_userinfo_api(request):
27 27
     brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
28 28
 
29
-    wxcfg = WECHAT.get('MINIAPP', {})
29
+    wxcfg = WECHAT.get('{}:MINIAPP'.format(brand_id), {})
30 30
 
31 31
     appid = wxcfg.get('appID')
32 32
     secret = wxcfg.get('appsecret')
@@ -94,7 +94,7 @@ def get_userinfo_api(request):
94 94
 def mini_login_api(request):
95 95
     brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
96 96
 
97
-    wxcfg = WECHAT.get('MINIAPP', {})
97
+    wxcfg = WECHAT.get('{}:MINIAPP'.format(brand_id), {})
98 98
 
99 99
     appid = wxcfg.get('appID')
100 100
     secret = wxcfg.get('appsecret')
@@ -163,7 +163,7 @@ def get_userinfo_api2(request):
163 163
     brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
164 164
     user_id = request.POST.get('user_id', '')
165 165
 
166
-    wxcfg = WECHAT.get('MINIAPP', {})
166
+    wxcfg = WECHAT.get('{}:MINIAPP'.format(brand_id), {})
167 167
 
168 168
     appid = wxcfg.get('appID')
169 169
     secret = wxcfg.get('appsecret')
@@ -210,7 +210,9 @@ def get_userinfo_api2(request):
210 210
 @logit(res=True)
211 211
 @transaction.atomic
212 212
 def membercard_extradata(request):
213
-    wxcfg = WECHAT.get('JSAPI', {})
213
+    brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
214
+
215
+    wxcfg = WECHAT.get('{}:JSAPI'.format(brand_id), {})
214 216
 
215 217
     appid = wxcfg.get('appID')
216 218
     secret = wxcfg.get('appsecret')

+ 1 - 1
requirements_pywe.txt

@@ -2,7 +2,7 @@ pywe-card==1.0.0
2 2
 pywe-component==1.0.1
3 3
 pywe-component-preauthcode==1.0.3
4 4
 pywe-jssdk==1.1.0
5
-pywe-membercard==1.0.2
5
+pywe-membercard==1.0.3
6 6
 pywe-miniapp==1.1.5
7 7
 pywe-oauth==1.0.7
8 8
 pywe-pay==1.0.13

+ 2 - 2
utils/shells/tests.py

@@ -7,9 +7,9 @@ from pywe_pay import WeChatPay
7 7
 WECHAT = settings.WECHAT
8 8
 
9 9
 
10
-def test_pay(openid, amount=100, trade_type='JSAPI', pay_type='PACKET'):
10
+def test_pay(brand_id, openid, amount=100, trade_type='JSAPI', pay_type='PACKET'):
11 11
     # 根据 trade_type 获取 wechat 配置
12
-    wxcfg = WECHAT.get(trade_type, {})
12
+    wxcfg = WECHAT.get('{}:{}'.format(brand_id, trade_type), {})
13 13
     # WeChatPay 初始化
14 14
     wxpay = WeChatPay(wxcfg.get('appID'), wxcfg.get('apiKey'), wxcfg.get('mchID'), mch_cert=wxcfg.get('mch_cert'), mch_key=wxcfg.get('mch_key'))
15 15