Showing
3 changed files
with
55 additions
and
18 deletions
@@ -7,7 +7,6 @@ const config = global.yoho.config; | @@ -7,7 +7,6 @@ const config = global.yoho.config; | ||
7 | 7 | ||
8 | module.exports = () => { | 8 | module.exports = () => { |
9 | return (req, res, next) => { | 9 | return (req, res, next) => { |
10 | - | ||
11 | if (!req.yoho.isApp) { | 10 | if (!req.yoho.isApp) { |
12 | // 从 SESSION 中获取到当前登录用户的 UID | 11 | // 从 SESSION 中获取到当前登录用户的 UID |
13 | if (req.session && _.isNumber(req.session.LOGIN_UID_)) { | 12 | if (req.session && _.isNumber(req.session.LOGIN_UID_)) { |
@@ -39,9 +38,11 @@ module.exports = () => { | @@ -39,9 +38,11 @@ module.exports = () => { | ||
39 | }; | 38 | }; |
40 | } | 39 | } |
41 | } else { | 40 | } else { |
41 | + let params = req.method === 'POST' ? req.body : req.query; | ||
42 | + | ||
42 | if (!req.user.uid && | 43 | if (!req.user.uid && |
43 | ( | 44 | ( |
44 | - (req.query.uid && req.query.uid !== '0') || | 45 | + (params.uid && params.uid !== '0') || |
45 | ( | 46 | ( |
46 | req.cookies.app_uid && | 47 | req.cookies.app_uid && |
47 | req.cookies.app_uid !== '0' && | 48 | req.cookies.app_uid !== '0' && |
@@ -50,12 +51,12 @@ module.exports = () => { | @@ -50,12 +51,12 @@ module.exports = () => { | ||
50 | ) | 51 | ) |
51 | ) | 52 | ) |
52 | ) { | 53 | ) { |
53 | - let appUid = req.query.uid || req.cookies.app_uid; | ||
54 | - let appVersion = req.query.app_version || req.cookies.app_version || config.appVersion; | ||
55 | - let appSessionType = req.query.client_type || req.cookies.app_client_type; | ||
56 | - let sessionKey = req.query.session_key || req.cookies.app_session_key; | 54 | + let appUid = params.uid || req.cookies.app_uid; |
55 | + let appVersion = params.app_version || req.cookies.app_version || config.appVersion; | ||
56 | + let appSessionType = params.client_type || req.cookies.app_client_type; | ||
57 | + let sessionKey = params.session_key || req.cookies.app_session_key; | ||
57 | 58 | ||
58 | - req.user.uid = req.query.uid = { | 59 | + req.user.uid = params.uid = { |
59 | toString: () => { | 60 | toString: () => { |
60 | return _.parseInt(appUid); | 61 | return _.parseInt(appUid); |
61 | }, | 62 | }, |
@@ -82,7 +83,7 @@ module.exports = () => { | @@ -82,7 +83,7 @@ module.exports = () => { | ||
82 | return _.parseInt(req.cookies.app_uid); | 83 | return _.parseInt(req.cookies.app_uid); |
83 | }, | 84 | }, |
84 | sessionKey: req.cookies.app_session_key, | 85 | sessionKey: req.cookies.app_session_key, |
85 | - appVersion: req.cookies.app_version || req.query.app_version || config.appVersion, | 86 | + appVersion: req.cookies.app_version || params.app_version || config.appVersion, |
86 | appSessionType: req.cookies.app_client_type | 87 | appSessionType: req.cookies.app_client_type |
87 | }; | 88 | }; |
88 | } | 89 | } |
@@ -390,7 +390,6 @@ seckillObj = { | @@ -390,7 +390,6 @@ seckillObj = { | ||
390 | onsuccess = $.noop; | 390 | onsuccess = $.noop; |
391 | 391 | ||
392 | 392 | ||
393 | - | ||
394 | if (actionName === 'cancel') { | 393 | if (actionName === 'cancel') { |
395 | on_off = false; | 394 | on_off = false; |
396 | action = 'go.delSecKill'; | 395 | action = 'go.delSecKill'; |
@@ -398,31 +397,43 @@ seckillObj = { | @@ -398,31 +397,43 @@ seckillObj = { | ||
398 | failTip = '取消提醒失败'; | 397 | failTip = '取消提醒失败'; |
399 | } | 398 | } |
400 | 399 | ||
401 | - onsuccess = function() { | ||
402 | - $.post('/product/seckill/remind', { | 400 | + onsuccess = function(info) { |
401 | + $.post('/product/seckill/remind', $.extend({ | ||
403 | on_off: on_off, | 402 | on_off: on_off, |
404 | activity_id: $product.data('activity'), | 403 | activity_id: $product.data('activity'), |
405 | product_skn: $product.data('skn'), | 404 | product_skn: $product.data('skn'), |
406 | - uid: yoho.isLogin(), | ||
407 | sec_kill_id: 1, | 405 | sec_kill_id: 1, |
408 | app_type: 0 | 406 | app_type: 0 |
409 | - }) | ||
410 | - .done(function(res) { | 407 | + }, info)).done(function(res) { |
411 | if (res.code === 200 && res.data === 'success') { | 408 | if (res.code === 200 && res.data === 'success') { |
412 | $remindBtn.hide().siblings().show(); | 409 | $remindBtn.hide().siblings().show(); |
413 | tip.show(okTip); | 410 | tip.show(okTip); |
414 | } else { | 411 | } else { |
415 | tip.show(failTip); | 412 | tip.show(failTip); |
416 | } | 413 | } |
417 | - }) | ||
418 | - .fail(function() { | 414 | + }).fail(function() { |
419 | tip.show(failTip); | 415 | tip.show(failTip); |
420 | }); | 416 | }); |
421 | }; | 417 | }; |
422 | 418 | ||
423 | - yoho.invokeMethod(action, params, onsuccess, function() { | 419 | + yoho.invokeMethod(action, params, function() { |
420 | + let uid = yoho.isLogin(); | ||
421 | + | ||
422 | + if (uid && uid !== '0') { | ||
423 | + onsuccess({uid}); | ||
424 | + } else { | ||
425 | + setTimeout(function() { | ||
426 | + yoho.getClientUserInfo().then(res => { | ||
427 | + onsuccess(res); | ||
428 | + }).catch(() => { | ||
424 | tip.show(failTip); | 429 | tip.show(failTip); |
425 | }); | 430 | }); |
431 | + }, 0); | ||
432 | + } | ||
433 | + }, function() { | ||
434 | + tip.show(failTip); | ||
435 | + }); | ||
436 | + | ||
426 | }, | 437 | }, |
427 | 438 | ||
428 | pageLoad: function(callback) { | 439 | pageLoad: function(callback) { |
@@ -125,6 +125,31 @@ yoho = { | @@ -125,6 +125,31 @@ yoho = { | ||
125 | }; | 125 | }; |
126 | }, | 126 | }, |
127 | 127 | ||
128 | + getClientUserInfo: function() { | ||
129 | + return new Promise((resolve, reject) => { | ||
130 | + let userInfo = {}; | ||
131 | + let successFn = function(info) { | ||
132 | + $.extend(userInfo, info); | ||
133 | + | ||
134 | + if (userInfo.hasOwnProperty('uid') && userInfo.hasOwnProperty('session_key')) { | ||
135 | + return resolve(userInfo); | ||
136 | + } | ||
137 | + }; | ||
138 | + | ||
139 | + this.invokeMethod('get.uid', {}, uid => { | ||
140 | + successFn({uid: uid}); | ||
141 | + }, () => { | ||
142 | + return reject(); | ||
143 | + }); | ||
144 | + | ||
145 | + this.invokeMethod('get.sessionId', {}, sessionId => { | ||
146 | + successFn({session_key: sessionId}); | ||
147 | + }, () => { | ||
148 | + return reject(); | ||
149 | + }); | ||
150 | + }); | ||
151 | + }, | ||
152 | + | ||
128 | getUid: function() { | 153 | getUid: function() { |
129 | if (yoho.isApp) { | 154 | if (yoho.isApp) { |
130 | return qs.uid || cookie.get('_YOHOUID') || cookie.get('app_uid'); | 155 | return qs.uid || cookie.get('_YOHOUID') || cookie.get('app_uid'); |
@@ -137,7 +162,7 @@ yoho = { | @@ -137,7 +162,7 @@ yoho = { | ||
137 | * 判断是否是 登录 | 162 | * 判断是否是 登录 |
138 | */ | 163 | */ |
139 | isLogin: function() { | 164 | isLogin: function() { |
140 | - return +this.getUid(); | 165 | + return this.getUid(); |
141 | }, | 166 | }, |
142 | 167 | ||
143 | goLogin: function(refer, data) { | 168 | goLogin: function(refer, data) { |
-
Please register or login to post a comment