Authored by htoooth

Merge branch 'master' into release/5.1

... ... @@ -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,
... ... @@ -741,7 +789,8 @@ const getShopListData = (channel, params, uid) => {
goods: productProcess.processProductList(goodsList, {
newCoverSort: true,
showDiscount: false,
gender: _getGender(channel)
gender: _getGender(channel),
query: params.query
}),
footPager: {tip: tip}
});
... ... @@ -812,7 +861,7 @@ const getBaseShopData = (params, extra, channel, shopId) => {
if (result[1].code === 200) {
let data = result[1].data || {},
decorator = shopHandler.getShopDecorator(data, {}, shopId);
decorator = shopHandler.getShopDecorator(data, {}, shopId, true);
Object.assign(decorator.shopTopBannerBase, {
shopId: shopId,
... ... @@ -822,6 +871,10 @@ const getBaseShopData = (params, extra, channel, shopId) => {
});
_.set(resData, 'brand.shopBanner', decorator.shopTopBannerBase);
_.unset(resData, 'brand.brandBanner');
if (decorator.signboard) {
_.set(resData, 'brand.signboard', decorator.signboard);
}
}
if (result[2].code === 200) {
... ... @@ -848,6 +901,7 @@ module.exports = {
getAdnav,
getShopInfo,
getShopData,
getShopGoodsData,
getShopListData,
getBaseShopData
};
... ...
... ... @@ -99,7 +99,7 @@ const handleBrandCheckedData = (params, origin) => {
if (!_.isEmpty(origin)) {
_.forEach(origin, (value) => {
if (typeof _.find(intBrands, o => {
return _.isEqual(o, value.id);
return _.isEqual(o, +value.id);
}) !== 'undefined') {
let checked = {
name: value.name
... ... @@ -204,9 +204,7 @@ const formatterFilterBrands = (source, paramBrand, params) => {
index: '0-9',
name: '0~9'
}],
selectedBrands: [],
showMore: true,
showMulti: true
selectedBrands: []
};
... ... @@ -233,7 +231,7 @@ const formatterFilterBrands = (source, paramBrand, params) => {
_.forEach(source, function(value) {
let brand = {
checked: (typeof _.find(intBrands, o => {
return _.isEqual(o, value.id);
return _.isEqual(o, +value.id);
}) !== 'undefined'),
href: handleFilterUrl(params, {brand: value.id}),
name: value.brand_name,
... ... @@ -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: [],
... ... @@ -873,11 +868,12 @@ exports.handleSeniorFilterData = (data, params) => {
};
exports.handleFilterDataAll = (data, qs) => {
let destFilter = {};
let params = _.cloneDeep(qs);
_.unset(params, 'page'); // 去除筛选项page
let baseFilter = this.handleFilterData(data.filter, params, data.total);
let baseFilter = this.handleFilterData(_.get(data, 'filter', {}), params, data.total);
let seniorFilter = this.handleSeniorFilterData({
style: _.get(data, 'filter.style', []),
standard: _.get(data, 'standard', [])
... ... @@ -886,12 +882,9 @@ exports.handleFilterDataAll = (data, qs) => {
let conditions = _.union(_.get(baseFilter, 'checkedConditions.conditions'),
_.get(seniorFilter, 'checkedConditions.conditions'));
let destFilter = Object.assign({}, seniorFilter, baseFilter);
Object.assign(destFilter, seniorFilter, baseFilter);
if (!destFilter.checkedConditions) {
destFilter.checkedConditions = {};
}
destFilter.checkedConditions.conditions = conditions;
_.set(destFilter, 'checkedConditions.conditions', conditions);
return destFilter;
};
... ...
... ... @@ -5,6 +5,8 @@
'use strict';
const _ = require('lodash');
const Fn = require('lodash/fp');
const qs = require('queryString');
const helpers = global.yoho.helpers;
... ... @@ -68,32 +70,34 @@ 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) {
_.forEach(_.sortBy(data.hot, o => {
return -o.position;
}), (value) => {
if (value.url && value.position) {
dest.hot.push({
name: value.name,
href: value.url
url: value.url
});
}
});
_.forEach(data.new, (value) => {
if (value.url) {
_.forEach(_.sortBy(data.new, o => {
return -o.position;
}), (value) => {
if (value.url && value.position) {
dest.new.push({
name: value.name,
href: value.url
url: value.url
});
}
});
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,17 +148,24 @@ 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}`
}
];
return {navigationBar: _.union(shopNav, _.filter(data, (value) => {
return value.url;
}))};
_.forEach(data, (value) => {
if (value.url) {
shopNav.push({
name: value.name,
url: `${value.url}&navBar=${shopNav.length}`
});
}
});
return {navigationBar: shopNav};
};
/**
... ... @@ -166,9 +177,10 @@ const largeSlideImg = (data) => {
let dest = [];
_.forEach(data, (value) => {
value = _.get(value, 'data[0]', {});
dest.push({
img: value.data[0].src,
url: helpers.urlFormat(value.data[0].url)
img: value.src,
url: value.url
});
});
... ... @@ -184,9 +196,10 @@ const oneRowTwoColImages = (data) => {
let dest = [];
_.forEach(data, (value) => {
value = _.get(value, 'data[0]', {});
dest.push({
img: value.data[0].src,
url: helpers.urlFormat(value.data[0].url)
img: value.src,
url: value.url
});
});
return {oneRowTwoColImages: dest};
... ... @@ -197,7 +210,7 @@ const oneRowTwoColImages = (data) => {
* @param type $data
* @return type []
*/
const recommend = (data, shopId) => {
const recommend = (data) => {
let dest = [];
_.forEach(data, (value) => {
... ... @@ -206,7 +219,7 @@ const recommend = (data, shopId) => {
name: value.name,
img: value.src,
title: value.title,
url: `${shopListUrl}?shopId=${shopId}&filter_poolId=${value.categoryId}`
url: value.url
});
});
... ... @@ -277,62 +290,130 @@ const hotRecommend = (data) => {
};
/**
* 店铺装修楼层数据
* @param data 装修数据
* @returns {{}}
* 水牌
*/
exports.getShopDecorator = (data, params, shopId) => {
let dest = {
newArrivel: {},
hotSingle: {}
const signboard = (data) => {
let list = [];
_.forEach(data, value => {
if (value.data) {
_.forEach(value.data, val => {
list.push({
img: helpers.image(val.src, 160, 240),
url: val.url
});
});
}
});
return {
title: _.get(list, '[0].title', ''),
list: list
};
};
_.forEach(data.list, (value) => {
let info = JSON.parse(value.resource_data);
let tabBar;
switch (value.resource_name) {
case 'signboard':
break;
case 'newProducts':
Object.assign(dest.newArrivel, newProducts(info));
break;
case 'hotProducts':
Object.assign(dest.hotSingle, hotProducts(info));
break;
case 'goodsTabBar':
tabBar = goodsTabBar(info);
Object.assign(dest.newArrivel, {navs: tabBar.new});
Object.assign(dest.hotSingle, {navs: tabBar.hot});
break;
case 'shopTopBanner':
Object.assign(dest, shopTopBanner(info));
break;
case 'shopTopBanner_base':
Object.assign(dest, shopTopBannerBase(info));
break;
case 'navigationBar':
Object.assign(dest, navigationBar(info, shopId));
break;
case 'largeSlideImg':
Object.assign(dest, largeSlideImg(info));
break;
case 'oneRowTwoColImages':
Object.assign(dest, oneRowTwoColImages(info, shopId));
break;
case 'recommend':
Object.assign(dest, recommend(info, shopId));
break;
case 'brandBrowse':
Object.assign(dest, brandBrowse(info, params));
break;
case 'hotRecommend':
Object.assign(dest, hotRecommend(info));
break;
default:
break;
// 销售类目
const _handleSaleCategory = (shopId, resourceObj) => {
const thisShop = (categoryId) => shopListUrl + '?' + qs.stringify({
productPool: categoryId,
shopId: shopId,
navBar: -1
});
let hasSaleCategory = Fn.pipe(Fn.prop('linkType'), Fn.eq('1'));
if (hasSaleCategory(resourceObj)) {
return Object.assign(resourceObj, {url: thisShop(resourceObj.categoryId)});
}
_(resourceObj).forEach((value) => {
if (_.has(value, 'data')) {
_.forEach(value.data, (it) => {
if (hasSaleCategory(it)) {
Object.assign(it, {url: thisShop(it.categoryId)});
}
});
}
if (hasSaleCategory(value)) {
Object.assign(value, {url: thisShop(value.categoryId)});
}
});
return resourceObj;
};
/**
* 店铺装修楼层数据
* @param data 装修数据
* @returns {{}}
*/
exports.getShopDecorator = (data, params, shopId, base) => {
let dest = {};
if (base) {
_.forEach(data.list, (value) => {
let info = Fn.pipe(JSON.parse, _.partial(_handleSaleCategory, shopId))(value.resource_data);
switch (value.resource_name) {
case 'signboard':
dest.signboard = signboard(info);
break;
case 'shopTopBanner_base':
Object.assign(dest, shopTopBannerBase(info));
break;
default:
break;
}
});
} else {
Object.assign(dest, {
newArrivel: {},
hotSingle: {}
});
_.forEach(data.list, (value) => {
let info = Fn.pipe(JSON.parse, _.partial(_handleSaleCategory, shopId))(value.resource_data);
let tabBar;
switch (value.resource_name) {
case 'newProducts':
Object.assign(dest.newArrivel, newProducts(info));
break;
case 'hotProducts':
Object.assign(dest.hotSingle, hotProducts(info));
break;
case 'goodsTabBar':
tabBar = goodsTabBar(info, shopId);
Object.assign(dest.newArrivel, {navs: tabBar.new});
Object.assign(dest.hotSingle, {navs: tabBar.hot});
break;
case 'shopTopBanner':
Object.assign(dest, shopTopBanner(info));
break;
case 'navigationBar':
Object.assign(dest, navigationBar(info, shopId));
break;
case 'largeSlideImg':
Object.assign(dest, largeSlideImg(info, shopId));
break;
case 'oneRowTwoColImages':
Object.assign(dest, oneRowTwoColImages(info, shopId));
break;
case 'recommend':
Object.assign(dest, recommend(info, shopId));
break;
case 'brandBrowse':
Object.assign(dest, brandBrowse(info, params));
break;
case 'hotRecommend':
Object.assign(dest, hotRecommend(info));
break;
default:
break;
}
});
}
return dest;
};
... ...
{{> list/shop-list}}
\ No newline at end of file
... ...