Authored by yyq

shop list

... ... @@ -134,36 +134,6 @@ exports.brandAbout = (req, res, next) => {
};
/**
* 店铺商品列表页
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.shopList = (req, res, next) => {
let shopId = req.query.shopId;
if (!shopId) {
return next();
}
list.getShopListData(req.yoho.channel, req.query, req.user.uid).then(result => {
Object.assign(result, {
page: 'shop',
shopId: shopId
});
if (req.query.query) {
result.shopKey = req.query.query;
}
// 店铺装修为空则不cache
if (!result.shopTopBanner) {
res.set('Cache-Control', 'no-cache');
}
res.render('list/shop-list', result);
}).catch(next);
};
/**
* ajax调用品牌页左侧水牌
* @param {[type]} req [description]
* @param {[type]} res [description]
... ...
... ... @@ -5,6 +5,7 @@ const mRoot = '../models';
const shopModel = require(`${mRoot}/shop-service`);
const tdk = require('../../../utils/getTDK');
// 店铺首页(经典&基础)
exports.index = (req, res, next) => {
let domain = req.query.domain;
let shopId = req.query.shopId;
... ... @@ -23,7 +24,7 @@ exports.index = (req, res, next) => {
});
}
Promise.all([
return Promise.all([
tdk('shop', shopId, req),
shopModel.getShopInfoAsync(domain, req.yoho.channel, req.query)
]).then(result => {
... ... @@ -64,3 +65,26 @@ exports.index = (req, res, next) => {
}
}).catch(next);
};
// 经典店铺列表
exports.list = (req, res, next) => {
let shopId = req.query.shopId;
if (!shopId) {
return next();
}
return shopModel.getShopListInfoAsync(req.yoho.channel, req.query).then(result => {
Object.assign(result, {
page: 'shop',
shopId: shopId,
shopKey: req.query.query || ''
});
// 店铺装修为空则不cache
if (!result.shopTopBanner) {
res.set('Cache-Control', 'no-cache');
}
res.render('list/shop-list', result);
}).catch(next);
};
... ...
... ... @@ -23,34 +23,12 @@ const brandFolderSeries = '经典系列';
const folderTitle = '经典款型';
const seriesTitle = '经典系列';
// 经典店铺list url
const shopListUrl = '/product/shoplist';
// 搜索分类信息需要的参数
const positionId = 10;
// 获取分类左侧广告id
const sortAdsId = 79;
const _getGender = (channel) => {
let gender;
switch (channel) {
case 'boys':
gender = '1,3';
break;
case 'girls':
gender = '2,3';
break;
default:
gender = '1,2,3';
break;
}
return gender;
};
/**
* 获取商品分类列表数据
*/
... ... @@ -566,124 +544,6 @@ const getShopInfo = (shopId, uid) => {
});
};
const getShopListData = (channel, params, uid) => {
let gender = _getGender(channel),
shopId = params.shopId,
navBar = params.navBar || 1;
let apiArr = [
headerModel.requestHeaderData(channel), // 头部数据
searchApi.getShopDecorator(shopId), // 店铺装修数据
searchApi.getShopInfo(shopId, uid), // 店铺介绍
searchApi.getProductList(Object.assign({shop_id: shopId}, params,
{limit: (params.limit || 60) - 1}), 'shop'), // 搜索店铺商品
searchApi.getSortList({shop_id: shopId}) // 店铺分类
];
if (_.has(params, 'query')) {
// 如果有店内搜索,则并行查询店铺所有商品,搜索不到商品则显示所有商品
apiArr.push(searchApi.getProductList(Object.assign({shop_id: shopId},
params, {query: ''}), 'shop')); // 搜索店铺所有商品
}
return Promise.all(apiArr).then(result => {
let finalResult = {
headerData: Object.assign(result[0].headerData, {header: true})
};
// 面包屑导航
Object.assign(finalResult, searchHandler.handlePathNavData({}, params, 'shop', channel));
// 店铺装修
if (result[1].code === 200) {
Object.assign(finalResult, shopHandler.getShopDecorator(result[1].data, params, shopId));
// 设置shop nav选中状态
_.set(finalResult, `navigationBar[${navBar}].current`, true);
if (result[2].code === 200) {
let data = _.get(result[2], 'data', {});
_.set(finalResult, 'shopTopBanner.brandIntro', {
shopId: shopId,
brandName: data.shop_name || '',
isFavorite: data.is_favorite === 'Y',
brandCont: data.shop_intro || ''
});
// 店铺SEO
Object.assign(finalResult, searchHandler.getBrandShopSeo(channel, {
shopName: data.shop_name
}, params));
}
} else {
return Promise.reject('No ShopDecorator data');
}
// 获取商品数据和顶部筛选条件
if (result[3].code === 200) {
let info = result[3];
let goodsList = _.get(info, 'data.product_list', []);
if (goodsList.length) {
let totalPage = _.get(info, 'data.total', 1);
Object.assign(finalResult, {
filters: searchHandler.handleFilterDataAll(info.data, params),
opts: searchHandler.handleOptsData(params, totalPage),
goods: productProcess.processProductList(goodsList, {
newCoverSort: true,
showDiscount: false,
gender: _getGender(channel),
query: params.query
}),
hasNextPage: searchHandler.handleNextPage(params, totalPage),
footPager: searchHandler.handlePagerData(totalPage, params)
});
_.set(finalResult, 'filters.checkedConditions.clearUrl',
`?navBar=${params.navBar}&shopId=${params.shopId}`);
} else {
finalResult.searchEmpty = true;
if (result[5] && result[5].code === 200) {
let allGoods = {
name: '全部商品 ALL',
sort: searchHandler.handleOptsData(params, _.get(result[5], 'data.total', 0)),
list: productProcess.processProductList(_.get(result[5], 'data.product_list', []), {
newCoverSort: true,
showDiscount: false,
gender: gender
})
};
_.set(allGoods, 'sort.newPage', true); // 启用新的分页导航
finalResult.allGoods = allGoods;
}
}
}
if (result[4].code === 200) {
let groupSort = _.get(result[4], 'data', []),
noPageQs = Object.assign({}, params, {page: 1});
finalResult.leftContent = searchHandler.handleSortData(groupSort, noPageQs, params);
_.set(finalResult, 'brandShopAd', {baseUrl: shopListUrl});
if (finalResult.allGoods) {
Object.assign(finalResult.allGoods, searchHandler.setShopSort(groupSort, noPageQs));
}
}
finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult, 'goods'))};
return finalResult;
});
};
const getUserCoupunStatus = (id, uid, type) => {
if (type === 'shop') {
return shopApi.shopCouponListAsync(id, uid).then(result => {
... ... @@ -726,6 +586,5 @@ module.exports = {
getNodeContentData,
getAdnav,
getShopInfo,
getShopListData,
getUserCoupunStatus
};
... ...
... ... @@ -441,6 +441,120 @@ exports.getShopInfoAsync = (domain, channel, params) => {
})();
};
exports.getShopListInfoAsync = (channel, params) => {
let gender = _getGender(channel),
shopId = params.shopId,
navBar = params.navBar || 1;
let searchParams = searchHandler.getSearchParams(params);
return co(function * () {
let result = yield Promise.props({
header: headerModel.requestHeaderData(channel), // 头部数据
shopInfo: api.getShopInfo(shopId), // 店铺介绍
decorator: searchApi.getShopDecorator(shopId), // 店铺装修数据
sort: searchApi.getSortList({shop_id: shopId}),
product: searchApi.getProductList(Object.assign(searchParams,
{shop_id: shopId}), 'shop'), // 搜索店铺商品
// 如果有店内搜索,则并行查询店铺所有商品,搜索不到商品则显示所有商品
allProduct: params.query ? searchApi.getProductList(Object.assign(searchParams,
{shop_id: shopId, query: ''}), 'shop') : Promise.resolve({})
});
let resData = {headerData: Object.assign(result.header.headerData, {header: true})};
Object.assign(resData, searchHandler.handlePathNavData({}, params, 'shop', channel));
// 店铺装修
if (result.decorator.code === 200) {
Object.assign(resData, shopHandler.getShopDecorator(result.decorator.data, params, shopId));
// 设置shop nav选中状态
_.set(resData, `navigationBar[${navBar}].current`, true);
if (result.shopInfo.code === 200) {
let data = _.get(result, 'shopInfo.data', {});
_.set(resData, 'shopTopBanner.brandIntro', {
shopId: shopId,
brandName: data.shop_name || '',
brandCont: data.shop_intro || ''
});
// 店铺SEO
Object.assign(resData, searchHandler.getBrandShopSeo(channel, {
shopName: data.shop_name
}, params));
}
} else {
return Promise.reject('No ShopDecorator data');
}
// 获取商品数据和顶部筛选条件
if (result.product.code === 200) {
let info = result.product;
let goodsList = _.get(info, 'data.product_list', []);
if (goodsList.length) {
let totalPage = _.get(info, 'data.total', 1);
Object.assign(resData, {
filters: searchHandler.handleFilterDataAll(info.data, params),
opts: searchHandler.handleOptsData(params, totalPage),
goods: productProcess.processProductList(goodsList, {
newCoverSort: true,
showDiscount: false,
gender: _getGender(channel),
query: params.query
}),
hasNextPage: searchHandler.handleNextPage(params, totalPage),
footPager: searchHandler.handlePagerData(totalPage, params)
});
_.set(resData, 'filters.checkedConditions.clearUrl',
`?navBar=${params.navBar}&shopId=${params.shopId}`);
} else {
resData.searchEmpty = true;
let data = _.get(result, 'allProduct.data.total', 0);
let plist = _.get(data, 'product_list', []);
if (params.query && plist.length) {
resData.allGoods = {
name: '全部商品 ALL',
sort: searchHandler.handleOptsData(params, data.total || 0),
list: productProcess.processProductList(plist, {
newCoverSort: true,
showDiscount: false,
gender: gender
})
};
_.set(resData.allGoods, 'sort.newPage', true); // 启用新的分页导航
}
}
}
if (result.sort.code === 200) {
let groupSort = _.get(result.sort, 'data', []),
noPageQs = Object.assign({}, params, {page: 1});
resData.leftContent = searchHandler.handleSortData(groupSort, noPageQs, params);
_.set(resData, 'brandShopAd', {baseUrl: shopListUrl});
if (resData.allGoods) {
Object.assign(resData.allGoods, searchHandler.setShopSort(groupSort, noPageQs));
}
}
resData.criteo = {skn: searchHandler.getCriteo(_.get(resData, 'goods'))};
return resData;
})();
};
exports.getShopGoodsData = (shopId, channel, params) => {
let gender = _getGender(channel);
let resData = {};
... ...
... ... @@ -121,7 +121,7 @@ router.post('/index/isFavoriteBrand', list.isFavoriteBrand); // 判断用户是
router.post('/index/getNodeContent', list.getNodeContent); // 品牌页水牌
router.post('/index/getAdnav', list.getAdnav); // 品牌页系列
router.get('/shop', shop.index); // 店铺首页
router.get('/shoplist', list.shopList); // 店铺列表页
router.get('/shoplist', shop.list); // 店铺列表页
router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏
router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏品牌
router.get('/brand/couponsync', list.brandCouponSync);
... ...