Authored by yyq

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

... ... @@ -7,6 +7,7 @@
'use strict';
const mRoot = '../models';
const search = require(`${mRoot}/search`);
const _ = require('lodash');
/**
* search 首页
... ... @@ -25,6 +26,11 @@ exports.index = (req, res, next) => {
search.getSearchData(req.query, req.yoho.channel).then(result => {
Object.assign(resData, result);
if (!_.get(resData, 'search.goods') || !_.get(resData, 'search.goods').length) {
_.set(resData, 'search.keyWord', req.query.query);
return res.render('search/no-result', resData);
}
res.render('search/index', resData);
}).catch(next);
... ...
... ... @@ -53,7 +53,7 @@ exports.getListData = (params, channel) => {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
searchApi.getSortList(params),
searchApi.getSortList(Object.assign({}, params, {msort: '', misort: ''})),
searchApi.getProductList(searchParams)
];
... ... @@ -81,9 +81,10 @@ exports.getListData = (params, channel) => {
// 获取左侧类目数据
if (result[1].code === 200) {
finalResult.list = Object.assign(searchHandler.handlePathNavData(result[1].data.sort, params, 'sort'), {
leftContent: searchHandler.handleSortData(result[1].data.sort, params)
});
finalResult.list = Object.assign(
searchHandler.handlePathNavData(result[1].data.sort, params, 'sort', channel), {
leftContent: searchHandler.handleSortData(result[1].data.sort, params)
});
}
// 获取商品数据和顶部筛选条件
... ... @@ -133,7 +134,7 @@ exports.getListNewData = (params, channel) => {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
searchApi.getSortList(searchParams),
searchApi.getSortList(Object.assign({}, searchParams, {msort: '', misort: ''})),
searchApi.getProductList(Object.assign({new: 'Y'}, searchParams)),
searchApi.getWeekNew(params)
];
... ... @@ -150,9 +151,10 @@ exports.getListNewData = (params, channel) => {
// 获取左侧类目数据
if (result[1].code === 200) {
finalResult.list = Object.assign(searchHandler.handlePathNavData(result[1].data.sort, params, 'new'), {
leftContent: searchHandler.handleSortData(result[1].data.sort, params)
});
finalResult.list = Object.assign(
searchHandler.handlePathNavData(result[1].data.sort, params, 'new', channel), {
leftContent: searchHandler.handleSortData(result[1].data.sort, params)
});
}
// 获取商品数据和顶部筛选条件
... ... @@ -226,7 +228,7 @@ exports.getBrandData = (params, extra, channel) => {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
searchApi.getSortList(Object.assign({}, params, {brand: extra.brandId})),
searchApi.getSortList(Object.assign({}, params, {brand: extra.brandId, msort: '', misort: ''})),
searchApi.getProductList(Object.assign({order: order, brand: extra.brandId}, searchParams))
];
... ... @@ -247,7 +249,7 @@ exports.getBrandData = (params, extra, channel) => {
if (result[1].code === 200) {
Object.assign(finalResult.brand, {
leftContent: searchHandler.handleSortData(result[1].data.sort, params)
}, searchHandler.handlePathNavData(extra, params, 'brand'));
}, searchHandler.handlePathNavData(extra, params, 'brand', channel));
}
// 获取商品数据和顶部筛选条件
... ... @@ -443,7 +445,7 @@ exports.getShopData = (shopId, channel, params, shopInfo) => {
Object.assign(finalResult,
result[0], // 头部数据
searchHandler.handlePathNavData(shopInfo, params, 'shop') // 面包屑导航
searchHandler.handlePathNavData(shopInfo, params, 'shop', channel) // 面包屑导航
);
_.set(finalResult, 'headerData.header', true);
... ... @@ -578,7 +580,7 @@ exports.getShopListData = (channel, params, uid) => {
};
// 面包屑导航
Object.assign(finalResult, searchHandler.handlePathNavData({}, params, 'shop'));
Object.assign(finalResult, searchHandler.handlePathNavData({}, params, 'shop', channel));
// 店铺装修
if (result[1].code === 200) {
... ...
... ... @@ -509,7 +509,7 @@ exports.getSaleSpecialData = (id, params, channel) => {
},
apiList = [
headerModel.requestHeaderData(channel),
searchApi.getSortList()
searchApi.getSortList(params)
];
if (special && special.data) {
... ...
... ... @@ -16,6 +16,7 @@ const images = require('../../../utils/images.js');
const cache = global.yoho.cache;
const logger = global.yoho.logger;
const md5 = require('md5');
const config = require('../../../config/common');
const getSortByConditionAsync = (condition) => {
return api.get('sortgroup.json', condition);
... ... @@ -42,6 +43,13 @@ const getSearchCackeKey = params => {
return md5(ks.join('_'));
};
const getProductListOrig = (finalParams) => {
return yohoApi.get('', finalParams).then(result => {
return result;
});
};
/**
* 获取商品列表
* @return
... ... @@ -58,39 +66,49 @@ const getProductList = (params) => {
Object.assign(finalParams, params);
let cKey = getSearchCackeKey(finalParams);
if (!config.useCache) {
return getProductListOrig(finalParams);
} else {
let cKey = getSearchCackeKey(finalParams);
return cache.get(cKey).catch().then(cdata => {
let hasCache = false;
return cache.get(cKey).catch().then(cdata => {
let hasCache = false;
if (cdata) {
if (cdata) {
try {
cdata = JSON.parse(cdata);
} catch (e) {
logger.debug('getProductList cache data parse fail.');
}
try {
cdata = JSON.parse(cdata);
} catch (e) {
logger.debug('getProductList cache data parse fail.');
}
if (cdata.filter && cdata.standard) {
hasCache = true;
finalParams.need_filter = 'no';
if (cdata.filter && cdata.standard) {
hasCache = true;
finalParams.need_filter = 'no';
}
}
}
return yohoApi.get('', finalParams).then(result => {
if (hasCache && result && result.data) {
Object.assign(result.data, cdata);
} else {
if (result && result.data && result.data.filter) {
cache.set(cKey, Object.assign({}, {
filter: result.data.filter,
standard: result.data.standard
}), 3600);
return getProductListOrig(finalParams).then(result => {
if (hasCache && result && result.data) {
Object.assign(result.data, cdata);
} else {
if (result && result.data && result.data.filter) {
cache.set(cKey, Object.assign({}, {
filter: result.data.filter,
standard: result.data.standard
}), 3600);
}
}
}
return result;
return result;
});
});
}
};
const getSortListOrig = (finalParams) => {
return yohoApi.get('', finalParams).then(ret => {
return ret;
});
};
... ... @@ -108,31 +126,34 @@ const getSortList = (params) => {
Object.assign(finalParams, params);
let cKey = getSearchCackeKey(finalParams);
if (!config.useCache) {
return getSortListOrig(finalParams);
} else {
let cKey = getSearchCackeKey(finalParams);
return cache.get(cKey).catch().then(cdata => {
let cdataObj;
return cache.get(cKey).catch().then(cdata => {
let cdataObj;
if (cdata) {
try {
cdataObj = JSON.parse(cdata);
} catch (e) {
logger.debug('getSortList cache data parse fail.');
if (cdata) {
try {
cdataObj = JSON.parse(cdata);
} catch (e) {
logger.debug('getSortList cache data parse fail.');
}
}
}
if (cdataObj) {
return cdataObj;
} else {
return yohoApi.get('', finalParams).then(ret => {
if (ret && ret.code === 200) {
cache.set(cKey, ret, 3600);
}
return ret;
});
}
});
if (cdataObj) {
return cdataObj;
} else {
return getSortListOrig(finalParams).then(ret => {
if (ret && ret.code === 200) {
cache.set(cKey, ret, 3600);
}
return ret;
});
}
});
}
};
/**
... ...
... ... @@ -649,14 +649,14 @@ exports.handleFilterData = (origin, params, total) => {
_.forEach(origin.ageLevel, (value) => {
let ageLevel = {
checked: params.ageLevel === value.id || isChecked,
href: handleFilterUrl(params, {ageLevel: value.id}),
checked: params.age_level === value.id || isChecked,
href: handleFilterUrl(params, {age_level: value.id}),
name: value.name
};
// 处理颜色年龄段数据
if (ageLevel.checked || isChecked) {
ageLevel.href = handleFilterUrl(params, null, {ageLevel: value.id});
ageLevel.href = handleFilterUrl(params, null, {age_level: value.id});
dest.checkedConditions.conditions.push(ageLevel);
}
... ... @@ -829,11 +829,18 @@ exports.handleFilterDataAll = (data, params) => {
* 根据页面设置面包屑导航
* @type {[type]}
*/
exports.handlePathNavData = (data, params, page) => {
exports.handlePathNavData = (data, params, page, channel) => {
let rootName = '首页';
if (channel && _.isString(channel)) {
rootName = channel.toUpperCase() + rootName;
}
let pathNav = [{
href: '/',
name: '首页', // TODO 从根据cookie获取频道
pathTitle: '首页'
name: rootName, // '首页', // TODO 从根据cookie获取频道
pathTitle: rootName // '首页'
}];
switch (page) {
... ... @@ -921,6 +928,7 @@ exports.handlePathNavData = (data, params, page) => {
* 分页
* @param {[type]} total 总页数
* @param {[type]} params 筛选条件
* @param {[noNextBtn]} 列表是否有下一页的按钮,如果有则实际查询数比传递参数的少一个,入60 => 59
* @return {[type]} [description]
*/
exports.handlePagerData = (total, params, noNextBtn) => {
... ... @@ -936,7 +944,21 @@ exports.handlePagerData = (total, params, noNextBtn) => {
let currentPage = parseInt(_.get(params, 'page', 1), 10); // 当前页
let perPageCount = parseInt(_.get(params, 'limit', true === noNextBtn ? 60 : 59), 10); // 每页商品数
let totalPage = parseInt(total / perPageCount, 10) + 1; // 总页数
let totalPage = Math.ceil(total / perPageCount); // 总页数
if (true !== noNextBtn) {
switch (perPageCount) {
case 200:
perPageCount = 199;
break;
case 100:
perPageCount = 99;
break;
case 60:
perPageCount = 59;
break;
}
}
if (currentPage === 1) {
// 当前页为 1,一定没有上一页
... ...
<div class="product-search-page product-page yoho-page center-content">
{{# search}}
{{> common/path-nav}}
{{> product/no-result}}
{{> product/latest-walk}}
{{/ search}}
</div>
\ No newline at end of file
... ...
... ... @@ -395,7 +395,7 @@ exports.processProduct = (productData, options) => {
}
result.is_soon_sold_out = (productData.is_soon_sold_out === 'Y');
result.url = helpers.urlFormat(`/product/pro_${productData.product_id}_${productData.goods_list[0].goods_id}/${productData.cn_alphabet}.html`, null, 'list'); // eslint-disable-line
result.url = helpers.urlFormat(`/product/pro_${productData.product_id}_${productData.goods_list[0].goods_id}/${productData.cn_alphabet}.html`, null, 'item'); // eslint-disable-line
if (options.showTags) {
... ...