Authored by 郭成尧

addressModel-ctx

... ... @@ -228,7 +228,7 @@ class BuyNowController {
let buy_number = req.query.buy_number;
co(function * () {
let address = yield addressModel.addressData(uid);
let address = yield req.ctx(addressModel).addressData(uid);
let moreUrl = helpers.urlFormat('/cart/index/buynow/orderensure', {
product_sku: product_sku,
buy_number: buy_number
... ...
... ... @@ -78,7 +78,7 @@ exports.orderEnsure = (req, res, next) => {
let allPromise = [
orderPromise,
req.ctx(userModel).queryProfile(uid),
addressModel.addressData(uid)
req.ctx(addressModel).addressData(uid)
];
if (_.isUndefined(req.cookies._isNewUser)) {
... ... @@ -372,7 +372,7 @@ exports.useCouponCode = (req, res, next) => {
exports.selectAddress = (req, res, next) => {
let uid = req.user.uid;
return addressModel.addressData(uid).then(address => {
return req.ctx(addressModel).addressData(uid).then(address => {
let moreUrl = (req.get('Referer') && !/\/home\/addressAct/.test(req.get('Referer')) &&
!/selectAddress/.test(req.get('Referer'))) ?
... ...
... ... @@ -5,36 +5,44 @@
const api = global.yoho.API;
const crypto = global.yoho.crypto;
/**
* 地址数据
* @param uid
* @return
*/
exports.addressData = (uid) => {
let params = {
method: 'app.address.gethidden',
uid
};
let options = {
cache: false
};
return api.get('', params, options)
.then(
result => {
if (result.code === 200) {
// 加密address_id
result.data.forEach(address => {
address.address_id = encodeURIComponent(crypto.encryption(null, address.address_id));
});
class AddressModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 地址数据
* @param uid
* @return
*/
addressData(uid) {
let params = {
method: 'app.address.gethidden',
uid
};
let options = {
cache: false
};
return api.get('', params, options)
.then(
result => {
if (result.code === 200) {
// 加密address_id
result.data.forEach(address => {
address.address_id = encodeURIComponent(crypto.encryption(null, address.address_id));
});
}
return result;
}
,
() => {
return {code: 500, data: [], message: '地址获取失败'};
}
);
}
}
return result;
}
,
() => {
return {code: 500, data: [], message: '地址获取失败'};
}
);
};
module.exports = AddressModel;
... ...