...
|
...
|
@@ -26,6 +26,107 @@ const channelMap = { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 处理列表数据、及页码
|
|
|
* @param data
|
|
|
* @returns {{footPager: type[], newProList: Array}}
|
|
|
* @private
|
|
|
*/
|
|
|
const _proListHandler = (data, params) => {
|
|
|
let total = data.total || '',
|
|
|
proList = data.product_list || [],
|
|
|
newProList = [];
|
|
|
|
|
|
// 页码
|
|
|
let footPager = searchHandler.handlePagerData(total,
|
|
|
Object.assign(params, {limit: _.get(data, 'page_size', '50')}), true);
|
|
|
|
|
|
// 商品列表
|
|
|
_.forEach(proList, pro => {
|
|
|
let proObj = {};
|
|
|
|
|
|
// 应季热门
|
|
|
if (pro.recommend_type === 'seasonSort') {
|
|
|
let tags = [];
|
|
|
|
|
|
_.forEach(pro.data, subData => {
|
|
|
tags.push({
|
|
|
url: helpers.urlFormat('', {sort: subData.relationParameter}, 'list'),
|
|
|
name: subData.categoryName
|
|
|
});
|
|
|
});
|
|
|
|
|
|
proObj.tags = tags;
|
|
|
proObj.tagType = true;
|
|
|
}
|
|
|
|
|
|
// 热门搜索
|
|
|
if (pro.recommend_type === 'hotSearchTerm') {
|
|
|
let tags = [];
|
|
|
|
|
|
_.forEach(pro.data, subData => {
|
|
|
tags.push({
|
|
|
url: helpers.urlFormat('', {query: subData}, 'search'),
|
|
|
name: subData
|
|
|
});
|
|
|
});
|
|
|
|
|
|
proObj.tags = tags;
|
|
|
proObj.tagType = true;
|
|
|
proObj.hotSearch = true;
|
|
|
}
|
|
|
|
|
|
// 店铺
|
|
|
if (pro.recommend_type === 'hotShop') {
|
|
|
|
|
|
proObj = {
|
|
|
url: helpers.urlFormat('', {shopId: pro.data.shops_id}, pro.data.shop_domain),
|
|
|
src: pro.data.shop_logo,
|
|
|
newNum: pro.data.new_product_num,
|
|
|
collNum: pro.data.favorite_num
|
|
|
};
|
|
|
proObj.shopType = true;
|
|
|
}
|
|
|
|
|
|
// 文章
|
|
|
if (pro.recommend_type === 'fashionArticle') {
|
|
|
|
|
|
proObj = {
|
|
|
url: helpers.urlFormat('/' + pro.data.id + '.html', {channel: params.channel}, 'guang'),
|
|
|
src: pro.data.src,
|
|
|
title: pro.data.title,
|
|
|
publishTime: moment(parseInt(pro.data.publish_time_long, 10)).format('YYYY年MM月DD HH:mm'),
|
|
|
num: pro.data.browse || 0
|
|
|
};
|
|
|
proObj.articalType = true;
|
|
|
}
|
|
|
|
|
|
// 普通商品
|
|
|
if (!pro.recommend_type) {
|
|
|
let defaultGoods = _.find(pro.goods_list, {is_default: 'Y'});
|
|
|
|
|
|
// 无默认商品取商品列表第一个
|
|
|
if (!defaultGoods) {
|
|
|
defaultGoods = pro.goods_list[0];
|
|
|
}
|
|
|
proObj = {
|
|
|
url: helpers.getUrlBySkc(pro.product_id, defaultGoods.goods_id, pro.cn_alphabet),
|
|
|
src: pro.default_images,
|
|
|
proName: pro.product_name,
|
|
|
salesPrice: pro.sales_price
|
|
|
};
|
|
|
proObj.goodsType = true;
|
|
|
}
|
|
|
|
|
|
newProList.push(proObj);
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
footPager: footPager,
|
|
|
newProList: newProList
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 加载新品到着首页
|
|
|
* @param req
|
|
|
* @returns {Promise.<TResult>}
|
...
|
...
|
@@ -83,8 +184,8 @@ const index = (req) => { |
|
|
// 面包屑头部
|
|
|
Object.assign(respData, searchHandler.handlePathNavData({}, {}, 'new', channel));
|
|
|
|
|
|
if (result[1].code === 200 && result[1].data && result[1].data.shop_list) {
|
|
|
let shopsData = result[1].data.shop_list,
|
|
|
if (result[1].code === 200 && result[1].data) {
|
|
|
let shopsData = _.get(result, '[1].data.shop_list', []),
|
|
|
dataList = [];
|
|
|
|
|
|
_.forEach(shopsData, shop => {
|
...
|
...
|
@@ -98,7 +199,7 @@ const index = (req) => { |
|
|
// 为您推荐
|
|
|
Object.assign(respData.recommond.dataList, dataList);
|
|
|
|
|
|
_.forEach(result[1].data.ads, ads => {
|
|
|
_.forEach(_.get(result, '[1].data.ads', []), ads => {
|
|
|
// banner
|
|
|
if (ads.template_name === 'focus') {
|
|
|
Object.assign(respData.slide.list, ads.data);
|
...
|
...
|
@@ -113,8 +214,8 @@ const index = (req) => { |
|
|
}
|
|
|
|
|
|
// 新品牌入驻
|
|
|
if (result[2].code === 200 && result[2].data && result[2].data.new_brand_list) {
|
|
|
let brandsData = result[2].data.new_brand_list,
|
|
|
if (result[2].code === 200 && result[2].data) {
|
|
|
let brandsData = _.get(result, '[2].data.new_brand_list', []),
|
|
|
brandList = [];
|
|
|
|
|
|
_.forEach(brandsData, brand => {
|
...
|
...
|
@@ -129,7 +230,7 @@ const index = (req) => { |
|
|
|
|
|
// 最新上架
|
|
|
if (result[3].code === 200 && result[3].data) {
|
|
|
let groupSort = result[3].data.filter.group_sort || [],
|
|
|
let groupSort = _.get(result, '[3].data.filter.group_sort', []),
|
|
|
ctyList = [];
|
|
|
|
|
|
// 推荐品类
|
...
|
...
|
@@ -148,7 +249,8 @@ const index = (req) => { |
|
|
Object.assign(respData.newProduct.ctyList, ctyList);
|
|
|
|
|
|
// 列表数据
|
|
|
Object.assign(respData.newProduct, _proListHandler(result[3].data, Object.assign({}, params, {channel: channel})));
|
|
|
Object.assign(respData.newProduct, _proListHandler(result[3].data,
|
|
|
Object.assign({}, recParams, {channel: channel})));
|
|
|
}
|
|
|
|
|
|
// 数据为空,不显示页面模块
|
...
|
...
|
@@ -172,116 +274,18 @@ const index = (req) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 处理列表数据、及页码
|
|
|
* @param data
|
|
|
* @returns {{footPager: type[], newProList: Array}}
|
|
|
* @private
|
|
|
*/
|
|
|
const _proListHandler = (data, params) => {
|
|
|
let total = data.total || '',
|
|
|
proList = data.product_list || [],
|
|
|
newProList = [];
|
|
|
|
|
|
// 页码
|
|
|
let footPager = searchHandler.handlePagerData(total, params);
|
|
|
|
|
|
// 商品列表
|
|
|
_.forEach(proList, pro => {
|
|
|
let proObj = {};
|
|
|
|
|
|
// 应季热门
|
|
|
if (pro.recommend_type === 'seasonSort') {
|
|
|
let tags = [];
|
|
|
|
|
|
_.forEach(pro.data, subData => {
|
|
|
tags.push({
|
|
|
url: helpers.urlFormat('', {sort: subData.relationParameter}, 'list'),
|
|
|
name: subData.categoryName
|
|
|
});
|
|
|
});
|
|
|
|
|
|
proObj.tags = tags;
|
|
|
proObj.tagType = true;
|
|
|
}
|
|
|
|
|
|
// 热门搜索
|
|
|
if (pro.recommend_type === 'hotSearchTerm') {
|
|
|
let tags = [];
|
|
|
|
|
|
_.forEach(pro.data, subData => {
|
|
|
tags.push({
|
|
|
url: helpers.urlFormat('', {query: subData}, 'search'),
|
|
|
name: subData
|
|
|
});
|
|
|
});
|
|
|
|
|
|
proObj.tags = tags;
|
|
|
proObj.tagType = true;
|
|
|
proObj.hotSearch = true;
|
|
|
}
|
|
|
|
|
|
// 店铺
|
|
|
if (pro.recommend_type === 'hotShop') {
|
|
|
|
|
|
proObj = {
|
|
|
url: helpers.urlFormat('', {shopId: pro.data.shops_id}, pro.data.shop_domain),
|
|
|
src: pro.data.shop_logo,
|
|
|
newNum: pro.data.new_product_num,
|
|
|
collNum: pro.data.favorite_num
|
|
|
};
|
|
|
proObj.shopType = true;
|
|
|
}
|
|
|
|
|
|
// 文章
|
|
|
if (pro.recommend_type === 'fashionArticle') {
|
|
|
|
|
|
proObj = {
|
|
|
url: helpers.urlFormat('/' + pro.data.id + '.html', {channel: params.channel}, 'guang'),
|
|
|
src: pro.data.src,
|
|
|
title: pro.data.title,
|
|
|
publishTime: moment(parseInt(pro.data.publish_time_long)).format('YYYY年MM月DD HH:mm'),
|
|
|
num: pro.data.browse || 0
|
|
|
};
|
|
|
proObj.articalType = true;
|
|
|
}
|
|
|
|
|
|
// 普通商品
|
|
|
if (!pro.recommend_type) {
|
|
|
let defaultGoods = _.find(pro.goods_list, {is_default: 'Y'});
|
|
|
|
|
|
// 无默认商品取商品列表第一个
|
|
|
if (!defaultGoods) {
|
|
|
defaultGoods = pro.goods_list[0];
|
|
|
}
|
|
|
proObj = {
|
|
|
url: helpers.getUrlBySkc(pro.product_id, defaultGoods.goods_id, pro.cn_alphabet),
|
|
|
src: pro.default_images,
|
|
|
proName: pro.product_name,
|
|
|
salesPrice: pro.sales_price
|
|
|
};
|
|
|
proObj.goodsType = true;
|
|
|
}
|
|
|
|
|
|
newProList.push(proObj);
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
footPager: footPager,
|
|
|
newProList: newProList
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 加载最新上架数据
|
|
|
* @param req
|
|
|
* @returns {Promise.<TResult>}
|
|
|
*/
|
|
|
const getRecList = (req) => {
|
|
|
let channel = req.query.channel || req.cookies._Channel || 'boys';
|
|
|
|
|
|
let params = {
|
|
|
yh_channel: channelMap[channel].yh_channel,
|
|
|
uid: req.user.uid || ''
|
|
|
};
|
|
|
|
|
|
Object.assign(params, {
|
|
|
sort: req.query.sort || '',
|
|
|
page: req.query.page || 1
|
...
|
...
|
@@ -293,6 +297,7 @@ const getRecList = (req) => { |
|
|
|
|
|
return Promise.all(apiMethod).then(result => {
|
|
|
let respData = {};
|
|
|
|
|
|
if (result[0].code === 200 && result[0].data) {
|
|
|
Object.assign(respData, _proListHandler(result[0].data, params));
|
|
|
}
|
...
|
...
|
|