Authored by 周少峰

Merge branch 'feature/suggestItem' into release/5.8

... ... @@ -9,6 +9,8 @@ const mRoot = '../models';
const search = require(`${mRoot}/search`);
const _ = require('lodash');
const helpers = global.yoho.helpers;
const utils = '../../../utils';
const stringCode = require(`${utils}/string-code`);
const config = global.yoho.config;
... ... @@ -163,12 +165,43 @@ const searchLessRecommend = (req, res, next) => {
};
/**
* 搜索推荐列表页
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
const keyword = (req, res, next) => {
let params = req.query;
let query = stringCode.hexToUtf8(req.params.id || '');
let resData = {};
return search.getSearchKeywordData(Object.assign(params, {query: query}),
req.yoho.channel).then(result => {
Object.assign(resData, result, {
title: `${query}价格_图片_品牌_怎么样-YOHO!BUY有货`,
keywords: `${query},${query}价格,${query}图片,${query}怎么样,${query}品牌,YOHO!BUY有货`,
description: `YOHO!BUY有货网yohobuy.com是国内专业的${query}网上潮流购物商城,为您找到${_.get(result,
'search.totalCount', 0)}${query}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${query},就上YOHO!BUY有货`
});
if (!_.get(resData, 'search.goods') || !_.get(resData, 'search.goods').length) {
_.set(resData, 'search.keyWord', query);
return res.render('search/no-result', resData);
}
res.render('search/index', resData);
}).catch(next);
};
module.exports = {
index,
suggest,
suggest4Old,
searchFilterBrands,
searchHistory, // 搜索历史记录
searchLessRecommend
searchLessRecommend,
keyword
};
... ...
... ... @@ -372,6 +372,7 @@ const getShopList = params => {
* @return
*/
const getSuggest = (params) => {
let finalParams = {
method: 'app.search.fuzzy',
keyword: params.keyword || ''
... ...
... ... @@ -10,12 +10,15 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
const crypto = global.yoho.crypto;
const queryString = require('querystring');
const logger = global.yoho.logger;
const indexUrl = {
boys: helpers.urlFormat('/'),
girls: helpers.urlFormat('/woman'),
kids: helpers.urlFormat('/kids'),
lifestyle: helpers.urlFormat('/lifestyle')
};
const utils = '../../../utils';
const stringCode = require(`${utils}/string-code`);
// 打折、新品、限量
const checksName = {
... ... @@ -1685,12 +1688,15 @@ exports.getSearchParams = params => {
});
}
/** 查询参数再处理 **/
// 对可能有中文的情况进行处理
if (params.query) {
params.query = decodeURIComponent(params.query);
try {
params.query = decodeURIComponent(params.query);
} catch (e) {
logger.info(e);
}
}
return Object.assign({}, params, nparams);
... ... @@ -1732,5 +1738,43 @@ exports.handleBrandShopCoupons = (data, params) => {
return false;
};
/**
* 处理页面左侧分类筛选数据
* @param origin 分类原始数据,一般是接口返回数据中的 group_sort 字段
* @param params 当前 URL 中已有的参数
* @param extra 可以任意传值用来处理特殊情况
* @param {string} [baseUrl] 需要跳转非当前页面传的相对路径(可不传,默认为空字符串)
* @returns {{}}
*/
exports.handleSuggestData = (origin, query) => {
let leftContent = {};
let list = [];
let all = [{
name: '全部推荐'
}];
_.forEach(origin, value => {
if (query === value.keyword) {
return;
}
list.push({
childList: [
{
name: `${value.keyword}`,
href: helpers.urlFormat(`/so/${stringCode.utf8ToHex(value.keyword)}.html`, null, 'www')
}
]
});
});
leftContent.allSuggest = {all: all, list: list};
return leftContent;
};
... ...
... ... @@ -321,3 +321,83 @@ exports.getSearchLessProduct = (channelNum, uid, udid, page) => {
})();
};
const setSearchKeywordData = (result, params, channel) => {
let changeQuery = Object.assign({}, params);
let finalResult = {
headerData: Object.assign(result[0].headerData, {
header: true
}),
search: {}
};
_.unset(changeQuery, 'query');
// 获取左侧类目数据
if (result[1].code === 200) {
finalResult.search = {
leftContent: searchHandler.handleSuggestData(_.get(result, '[1].data', []), params.query),
isSearch: true
};
}
// 获取商品数据和顶部筛选条件
if (result[2].code === 200) {
Object.assign(finalResult.search,
searchHandler.handlePathNavData({total: result[2].data.total }, params, 'search', channel),
{
opts: searchHandler.handleOptsData(changeQuery, result[2].data.total),
totalCount: result[2].data.total,
footPager: searchHandler.handlePagerData(result[2].data.total, changeQuery),
goods: productProcess.processProductList(result[2].data.product_list,
Object.assign({showDiscount: false, from: {type: 'search', params: params}}, params)),
latestWalk: 6,
hasNextPage: searchHandler.handleNextPage(changeQuery, result[2].data.total),
name: params.query
});
finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.search, 'goods'))};
}
return finalResult;
};
/**
* 获取搜索建议数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.getSearchKeywordData = (params, channel) => {
let searchParams = searchHandler.getSearchParams(params);
switch (channel) {
case 'boys':
searchParams.physical_channel = 1;
break;
case 'girls':
searchParams.physical_channel = 2;
break;
case 'kids':
searchParams.physical_channel = 3;
break;
case 'lifestyle':
searchParams.physical_channel = 4;
break;
default:
break;
}
searchParams.need_filter = 'no';
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
searchApi.getSuggest({keyword: searchParams.query}),
searchApi.getProductList(searchParams, 'fuzzySearch')
];
return api.all(apiMethod).then(result => {
return setSearchKeywordData(result, params, channel);
});
};
... ...
... ... @@ -101,6 +101,7 @@ router.get('/search/suggest', search.suggest); // 搜索提示
router.get('/api/suggest', search.suggest4Old);
router.get('/search/history', search.searchHistory); // 搜索历史提示
router.get('/search/less/recommend', search.searchLessRecommend);// 搜索少或无 有可能喜欢
router.get('/search/keyword/:id', search.keyword);
// 商品分类列表页
router.get('/list/index', gbk2utf, list.index);
... ...
... ... @@ -70,6 +70,13 @@ module.exports = [
}
},
// 推荐词列表页
{
type: TYPE.rewrite,
origin: /^\/so\/(.*)\.html(.*)/,
target: (req, match, p1) => `/product/search/keyword/${p1}`
},
// erp2good
{
type: TYPE.rewrite,
... ...
<div class="filter-box">
{{# checkedConditions}}
{{# checkedConditions}}
<div class="filter-box">
{{#if conditions}}
<div class="checked-conditions section">
<span class="title">已选条件:</span>
... ... @@ -268,5 +267,6 @@
</div>
</div>
</div>
{{/if}}
</div>
</div>
{{/if}}
... ...
... ... @@ -85,6 +85,24 @@
{{/each}}
</ul>
{{/ picLink}}
{{!-- 搜索推荐--}}
{{# allSuggest}}
<div class="sort-container">
{{# list}}
<ul class="sort-child-list suggest-list">
{{#each childList}}
<li>
<a href="{{href}}" title="{{name}}">
{{name}}
</a>
</li>
{{/each}}
</ul>
{{/ list}}
</div>
{{/ allSuggest}}
{{/ leftContent}}
{{# brandShopAd}}
... ...
... ... @@ -2,6 +2,7 @@
{{# filters}}
{{> product/filter-box}}
{{/ filters}}
{{log filters}}
{{#if phrase}}
<div class="phrase">
... ...
... ... @@ -63,7 +63,8 @@
.sort-child-list {
display: none;
&.new-sale {
&.new-sale,
&.suggest-list {
display: block;
}
... ...
'use strict';
const _ = require('lodash');
const utf8ToHex = (string) => {
var buf = new Buffer(string, 'utf8');
return _.toUpper(buf.toString('hex'));
};
const hexToUtf8 = (string) => {
let buf = new Buffer(string, 'hex');
return buf.toString('utf8');
};
module.exports = {
utf8ToHex,
hexToUtf8
};
... ...