Authored by 周少峰

Merge branch 'release/5.0.0' of git.yoho.cn:fe/yohobuy-node into release/5.0.0

... ... @@ -17,6 +17,16 @@ const shop = (shopId, req, res, next, brandInfo) => {
list.getShopInfo(shopId, req.user.id).then(shopInfo => {
if (+shopInfo.shopTemplateType === 2) { // 经典模板
let pjax = req.query._pjax;
if (pjax) {
list.getShopGoodsData(shopId, req.yoho.channel, req.query, shopInfo).then(result => {
Object.assign(result, {layout: false});
res.render('list/goods-list', result);
}).catch(next);
return;
}
list.getShopData(shopId, req.yoho.channel, req.query, shopInfo).then(result => {
Object.assign(result, {
page: 'shop',
... ... @@ -27,9 +37,9 @@ const shop = (shopId, req, res, next, brandInfo) => {
} else { // 基础模板
list.getBaseShopData(req.query, Object.assign({uid: req.user.uid}, brandInfo),
req.yoho.channel, shopId).then(result => {
Object.assign(result, {page: 'list'});
res.render('list/brand', result);
}).catch(next);
Object.assign(result, {page: 'list'});
res.render('list/brand', result);
}).catch(next);
}
}).catch(next);
};
... ...
... ... @@ -672,6 +672,54 @@ const getShopData = (shopId, channel, params, shopInfo) => {
});
};
/**
* 获取店铺商品数据
*/
const getShopGoodsData = (shopId, channel, params) => {
let gender = _getGender(channel);
let resData = {};
_.unset(params, '_pjax');
return Promise.all([
searchApi.getProductList(Object.assign({
shop_id: shopId
}, params)), // 搜索店铺商品
searchApi.getShopBrands(shopId) // 店铺品牌数据
]).then(result => {
// 获取商品数据和顶部筛选条件
if (result[0].code === 200) {
Object.assign(resData, {
sort: searchHandler.handleOptsData(params, _.get(result[0], 'data.total', 0)),
list: productProcess.processProductList(_.get(result[0], 'data.product_list', []), {
newCoverSort: true,
showDiscount: false,
gender: gender
})
});
_.set(resData, 'sort.newPage', true); // 启用新的分页导航
}
let shopBrandIds = []; // 店铺的所有品牌id
if (result[1].code === 200 && result[1].data) {
_.forEach(result[1].data, value => {
shopBrandIds.push(value.brand_id);
});
}
// 根据品牌获取分类 (腾讯云测试没有该接口,暂时不调用分类)
return searchApi.getSortList({brand: shopBrandIds}).then(subRes => {
if (subRes.code === 200) {
let groupSort = _.get(subRes, 'data.sort', []);
Object.assign(resData, searchHandler.setShopSort(groupSort, params));
}
return resData;
});
});
};
const getShopListData = (channel, params, uid) => {
let gender = _getGender(channel),
shopId = params.shopId,
... ... @@ -848,6 +896,7 @@ module.exports = {
getAdnav,
getShopInfo,
getShopData,
getShopGoodsData,
getShopListData,
getBaseShopData
};
... ...
... ... @@ -204,9 +204,7 @@ const formatterFilterBrands = (source, paramBrand, params) => {
index: '0-9',
name: '0~9'
}],
selectedBrands: [],
showMore: true,
showMulti: true
selectedBrands: []
};
... ... @@ -257,6 +255,13 @@ const formatterFilterBrands = (source, paramBrand, params) => {
count++;
});
if (dbrand.default.length > 9) {
Object.assign(dbrand, {
showMore: true,
showMulti: true
});
}
if (paramBrand) {
_.forEach(paramBrand, value => {
let brand = {
... ... @@ -538,7 +543,10 @@ exports.setShopSort = (data, params) => {
});
if (list.length) {
_.set(resData, 'goodsMenu.menuList', list);
resData.goodsMenu = {
menuList: list,
url: `/product/shoplist?navBar=1&shopId=${params.shopId}`
};
}
}
... ... @@ -554,19 +562,6 @@ exports.setShopSort = (data, params) => {
exports.handleFilterData = (origin, params, total) => {
let dest = {
ageLevel: [],
brand: {
default: [],
brandsShow: [],
brandIndex: [{
index: 'all',
name: '全部'
}, {
index: '0-9',
name: '0~9'
}],
showMore: true,
showMulti: true
},
price: [],
gender: [],
color: [],
... ...
... ... @@ -68,11 +68,9 @@ const hotProducts = (data) => {
*/
const goodsTabBar = (data, shopId) => {
let dest = {
hot: [],
new: []
},
more = {name: 'MORE', href: shopListUrl + '?shopId=' + shopId};
hot: [],
new: []
};
_.forEach(data.hot, (value) => {
if (value.url) {
... ... @@ -92,8 +90,8 @@ const goodsTabBar = (data, shopId) => {
});
}
});
dest.hot.push(more);
dest.new.push(more);
dest.hot.push({name: 'MORE', url: `${shopListUrl}?navBar=2&order=s_n_desc&shopId=${shopId}`});
dest.new.push({name: 'MORE', url: `${shopListUrl}?navBar=3&order=s_t_desc&shopId=${shopId}`});
return dest;
};
... ... @@ -144,11 +142,11 @@ const navigationBar = (data, shopId) => {
},
{
name: '人气单品',
url: `${shopListUrl}/?navBar=2&shopId=${shopId}`
url: `${shopListUrl}/?navBar=2&order=s_n_desc&shopId=${shopId}`
},
{
name: '新品上架',
url: `${shopListUrl}/?navBar=3&shopId=${shopId}`
url: `${shopListUrl}/?navBar=3&order=s_t_desc&shopId=${shopId}`
}
];
... ... @@ -162,13 +160,24 @@ const navigationBar = (data, shopId) => {
* @param type $data
* @return type []
*/
const largeSlideImg = (data) => {
const largeSlideImg = (data, shopId) => {
let dest = [];
_.forEach(data, (value) => {
let url;
value = _.get(value, 'data[0]', {});
url = value.url;
if (+value.categoryId > 0) {
if (!url) {
url = `${shopListUrl}?shopId=${shopId}`;
}
url += `&productPool=${value.categoryId}`;
}
dest.push({
img: value.data[0].src,
url: helpers.urlFormat(value.data[0].url)
img: value.src,
url: url
});
});
... ... @@ -180,13 +189,24 @@ const largeSlideImg = (data) => {
* @param data 装修数据
* @returns {{}}
*/
const oneRowTwoColImages = (data) => {
const oneRowTwoColImages = (data, shopId) => {
let dest = [];
_.forEach(data, (value) => {
let url;
value = _.get(value, 'data[0]', {});
url = value.url;
if (+value.categoryId > 0) {
if (!url) {
url = `${shopListUrl}?shopId=${shopId}`;
}
url += `&productPool=${value.categoryId}`;
}
dest.push({
img: value.data[0].src,
url: helpers.urlFormat(value.data[0].url)
img: value.src,
url: url
});
});
return {oneRowTwoColImages: dest};
... ... @@ -201,12 +221,17 @@ const recommend = (data, shopId) => {
let dest = [];
_.forEach(data, (value) => {
let url = value.url || `${shopListUrl}?shopId=${shopId}`;
if (+value.categoryId > 0) {
url += `&productPool=${value.categoryId}`;
}
dest.push({
enName: value.enName,
name: value.name,
img: value.src,
title: value.title,
url: `${shopListUrl}?shopId=${shopId}&filter_poolId=${value.categoryId}`
url: url
});
});
... ... @@ -301,7 +326,7 @@ exports.getShopDecorator = (data, params, shopId) => {
Object.assign(dest.hotSingle, hotProducts(info));
break;
case 'goodsTabBar':
tabBar = goodsTabBar(info);
tabBar = goodsTabBar(info, shopId);
Object.assign(dest.newArrivel, {navs: tabBar.new});
Object.assign(dest.hotSingle, {navs: tabBar.hot});
break;
... ... @@ -315,7 +340,7 @@ exports.getShopDecorator = (data, params, shopId) => {
Object.assign(dest, navigationBar(info, shopId));
break;
case 'largeSlideImg':
Object.assign(dest, largeSlideImg(info));
Object.assign(dest, largeSlideImg(info, shopId));
break;
case 'oneRowTwoColImages':
Object.assign(dest, oneRowTwoColImages(info, shopId));
... ...
{{> list/shop-list}}
\ No newline at end of file
... ...