Showing
3 changed files
with
42 additions
and
34 deletions
@@ -228,7 +228,7 @@ class BuyNowController { | @@ -228,7 +228,7 @@ class BuyNowController { | ||
228 | let buy_number = req.query.buy_number; | 228 | let buy_number = req.query.buy_number; |
229 | 229 | ||
230 | co(function * () { | 230 | co(function * () { |
231 | - let address = yield addressModel.addressData(uid); | 231 | + let address = yield req.ctx(addressModel).addressData(uid); |
232 | let moreUrl = helpers.urlFormat('/cart/index/buynow/orderensure', { | 232 | let moreUrl = helpers.urlFormat('/cart/index/buynow/orderensure', { |
233 | product_sku: product_sku, | 233 | product_sku: product_sku, |
234 | buy_number: buy_number | 234 | buy_number: buy_number |
@@ -78,7 +78,7 @@ exports.orderEnsure = (req, res, next) => { | @@ -78,7 +78,7 @@ exports.orderEnsure = (req, res, next) => { | ||
78 | let allPromise = [ | 78 | let allPromise = [ |
79 | orderPromise, | 79 | orderPromise, |
80 | req.ctx(userModel).queryProfile(uid), | 80 | req.ctx(userModel).queryProfile(uid), |
81 | - addressModel.addressData(uid) | 81 | + req.ctx(addressModel).addressData(uid) |
82 | ]; | 82 | ]; |
83 | 83 | ||
84 | if (_.isUndefined(req.cookies._isNewUser)) { | 84 | if (_.isUndefined(req.cookies._isNewUser)) { |
@@ -372,7 +372,7 @@ exports.useCouponCode = (req, res, next) => { | @@ -372,7 +372,7 @@ exports.useCouponCode = (req, res, next) => { | ||
372 | exports.selectAddress = (req, res, next) => { | 372 | exports.selectAddress = (req, res, next) => { |
373 | let uid = req.user.uid; | 373 | let uid = req.user.uid; |
374 | 374 | ||
375 | - return addressModel.addressData(uid).then(address => { | 375 | + return req.ctx(addressModel).addressData(uid).then(address => { |
376 | 376 | ||
377 | let moreUrl = (req.get('Referer') && !/\/home\/addressAct/.test(req.get('Referer')) && | 377 | let moreUrl = (req.get('Referer') && !/\/home\/addressAct/.test(req.get('Referer')) && |
378 | !/selectAddress/.test(req.get('Referer'))) ? | 378 | !/selectAddress/.test(req.get('Referer'))) ? |
@@ -5,36 +5,44 @@ | @@ -5,36 +5,44 @@ | ||
5 | const api = global.yoho.API; | 5 | const api = global.yoho.API; |
6 | const crypto = global.yoho.crypto; | 6 | const crypto = global.yoho.crypto; |
7 | 7 | ||
8 | -/** | ||
9 | - * 地址数据 | ||
10 | - * @param uid | ||
11 | - * @return | ||
12 | - */ | ||
13 | -exports.addressData = (uid) => { | ||
14 | - let params = { | ||
15 | - method: 'app.address.gethidden', | ||
16 | - uid | ||
17 | - }; | ||
18 | - | ||
19 | - let options = { | ||
20 | - cache: false | ||
21 | - }; | ||
22 | - | ||
23 | - return api.get('', params, options) | ||
24 | - .then( | ||
25 | - result => { | ||
26 | - if (result.code === 200) { | ||
27 | - // 加密address_id | ||
28 | - result.data.forEach(address => { | ||
29 | - address.address_id = encodeURIComponent(crypto.encryption(null, address.address_id)); | ||
30 | - }); | 8 | +class AddressModel extends global.yoho.BaseModel { |
9 | + constructor(ctx) { | ||
10 | + super(ctx); | ||
11 | + } | ||
12 | + | ||
13 | + /** | ||
14 | + * 地址数据 | ||
15 | + * @param uid | ||
16 | + * @return | ||
17 | + */ | ||
18 | + addressData(uid) { | ||
19 | + let params = { | ||
20 | + method: 'app.address.gethidden', | ||
21 | + uid | ||
22 | + }; | ||
23 | + | ||
24 | + let options = { | ||
25 | + cache: false | ||
26 | + }; | ||
27 | + | ||
28 | + return api.get('', params, options) | ||
29 | + .then( | ||
30 | + result => { | ||
31 | + if (result.code === 200) { | ||
32 | + // 加密address_id | ||
33 | + result.data.forEach(address => { | ||
34 | + address.address_id = encodeURIComponent(crypto.encryption(null, address.address_id)); | ||
35 | + }); | ||
36 | + } | ||
37 | + | ||
38 | + return result; | ||
39 | + } | ||
40 | + , | ||
41 | + () => { | ||
42 | + return {code: 500, data: [], message: '地址获取失败'}; | ||
31 | } | 43 | } |
44 | + ); | ||
45 | + } | ||
46 | +} | ||
32 | 47 | ||
33 | - return result; | ||
34 | - } | ||
35 | - , | ||
36 | - () => { | ||
37 | - return {code: 500, data: [], message: '地址获取失败'}; | ||
38 | - } | ||
39 | - ); | ||
40 | -}; | 48 | +module.exports = AddressModel; |
-
Please register or login to post a comment