...
|
...
|
@@ -9,6 +9,7 @@ |
|
|
const Promise = require('bluebird');
|
|
|
const co = Promise.coroutine;
|
|
|
const _ = require('lodash');
|
|
|
const Fn = require('lodash/fp');
|
|
|
const url = require('url');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
...
|
...
|
@@ -1404,6 +1405,57 @@ const showMainAsync = (data) => { |
|
|
})();
|
|
|
};
|
|
|
|
|
|
|
|
|
const recommendAsync = (skn, page, limit) => {
|
|
|
return co(function * () {
|
|
|
let recommendData = productAPI.getShopRecommendAsync(skn, page, limit);
|
|
|
|
|
|
if (_.get(recommendData, 'code', 400) !== 200) {
|
|
|
return {
|
|
|
code: 400,
|
|
|
message: '服务器错误!'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const formatPrice = p => `¥${p}`;
|
|
|
const productUrl = (pid, gid, cn) => helpers.urlFormat(`/product/pro_${pid}_${gid}/${cn}.html`, null, 'item');
|
|
|
const productImageUrl = Fn.pipe(Fn.prop('default_images'), _.partial(helpers.image, _, 150, 200, 2, 70));
|
|
|
|
|
|
let products = _.get(recommendData, 'product_list', []).map(rp => {
|
|
|
let marketPrice = rp.sales_price;
|
|
|
let salePrice = rp.market_price;
|
|
|
|
|
|
let defaultGoods = _.find(rp.goods_list, {is_default: 'Y'});
|
|
|
|
|
|
// 无默认商品取商品列表第一个
|
|
|
if (!defaultGoods) {
|
|
|
defaultGoods = rp.goods_list[0];
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
market_price: marketPrice === salePrice ? '' : formatPrice(helpers.round(marketPrice, 2)),
|
|
|
price: formatPrice(helpers.round(salePrice, 2)),
|
|
|
product_name: rp.product_name,
|
|
|
url: productUrl(rp.product_id, defaultGoods.goods_id, rp.cn_alphabet),
|
|
|
pic_url: productImageUrl(rp)
|
|
|
};
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
code: 200,
|
|
|
data: {
|
|
|
pager: {
|
|
|
total: _.get(recommendData, 'page_total', 0),
|
|
|
size: _.get(recommendData, 'page_size', 5),
|
|
|
num: _.get(recommendData, 'page', 1)
|
|
|
},
|
|
|
products: products,
|
|
|
total: _.get(recommendData, 'total', 0)
|
|
|
}
|
|
|
};
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
getShareOrderListAsync: commentService.getShareOrderListAsync, // 获取评论列表
|
|
|
indexConsultAsync: consultService.indexAsync, // 获取咨询列表
|
...
|
...
|
@@ -1412,5 +1464,6 @@ module.exports = { |
|
|
indexHotAreaAsync: hotAreaService.indexAsync, // 获取某一个商品的热区数据
|
|
|
saveRecentGoodInCookies, // 保存最近的商品
|
|
|
getDetailHeader,
|
|
|
saleReturn
|
|
|
saleReturn,
|
|
|
recommendAsync
|
|
|
}; |
...
|
...
|
|