|
|
|
|
|
|
|
|
const redis = global.yoho.redis;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const logger = global.yoho.logger;
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
const headerModel = require('../../../doraemon/models/header');
|
|
|
|
|
|
const SearchApi = require('./search-api');
|
|
|
|
|
|
const searchHandler = require('./search-handler');
|
|
|
const utils = '../../../utils';
|
|
|
const productProcess = require(`${utils}/product-process-simple`);
|
...
|
...
|
@@ -31,8 +34,7 @@ const _setHotKeywordData = (result, params, channel) => { |
|
|
totalCount: data.total,
|
|
|
footPager: searchHandler.handlePagerData(data.total, changeQuery),
|
|
|
goods: productProcess.processProductList(data.product_list,
|
|
|
Object.assign({showDiscount: false, from: {type: 'search', params: params}}, params)),
|
|
|
latestWalk: 6,
|
|
|
Object.assign({showDiscount: false, from: {type: 'hot', params: params}}, params)),
|
|
|
hasNextPage: searchHandler.handleNextPage(changeQuery, data.total)
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -41,16 +43,24 @@ const _setHotKeywordData = (result, params, channel) => { |
|
|
finalResult.hotBrands = _.get(data, 'filter.brand', []);
|
|
|
|
|
|
finalResult.hotBrands.forEach((val) => {
|
|
|
val.href = '#'; // TODO
|
|
|
val.href = helpers.urlFormat(`/list/bd${val.id}.html`);
|
|
|
|
|
|
return val;
|
|
|
});
|
|
|
|
|
|
console.log(_.get(data, 'filter.brand', []));
|
|
|
|
|
|
// finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.search, 'goods'))};
|
|
|
finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.search, 'goods'))};
|
|
|
}
|
|
|
|
|
|
// console.log(finalResult);
|
|
|
|
|
|
if (result[2].code === 200) {
|
|
|
let data = result[2].data;
|
|
|
|
|
|
finalResult.latestWalkExtra = [{
|
|
|
extraTabName: '相关推荐',
|
|
|
extraGoodsList: productProcess.processProductList(data.product_list,
|
|
|
Object.assign({showDiscount: false, from: {type: 'hot', params: params}}, params))
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
return finalResult;
|
|
|
};
|
...
|
...
|
@@ -62,7 +72,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
this.searchApi = new SearchApi(ctx);
|
|
|
}
|
|
|
|
|
|
getHotKeywordDate(params, channel) {
|
|
|
getSearchProduct(params, channel) {
|
|
|
let searchParams = searchHandler.getSearchParams(params);
|
|
|
|
|
|
switch (channel) {
|
...
|
...
|
@@ -83,12 +93,47 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
}
|
|
|
|
|
|
searchParams.need_filter = 'yes';
|
|
|
searchParams.query = '夹克';
|
|
|
|
|
|
return Promise.all([
|
|
|
headerModel.requestHeaderData(channel),
|
|
|
this.searchApi.getSeoProductList(searchParams, 'fuzzySearch')
|
|
|
this.searchApi.getSeoProductList(searchParams, 'fuzzySearch'),
|
|
|
this.searchApi.getSeoProductList(Object.assign(searchParams, {
|
|
|
order: 's_n_desc',
|
|
|
limit: 5
|
|
|
}), 'fuzzySearch'),
|
|
|
]).then(result => {
|
|
|
return _setHotKeywordData(result, params, channel);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
getHotKeywordDate(id, params, channel) {
|
|
|
return redis.all([
|
|
|
['get', `global:yoho:seo:hot:keywords:id:${id}`]
|
|
|
]).then(redisData => {
|
|
|
let keyword = redisData[0];
|
|
|
|
|
|
try {
|
|
|
keyword = JSON.parse(keyword);
|
|
|
} catch (e) {
|
|
|
logger.debug('getProductList cache data parse fail.');
|
|
|
}
|
|
|
|
|
|
if (!_.get(keyword, 'name')) {
|
|
|
return Promise.reject(`cannot find hot keywords by id(${id})`);
|
|
|
}
|
|
|
params.query = keyword.name;
|
|
|
|
|
|
return this.getSearchProduct(params, channel).then(result => {
|
|
|
result.hotKeys = (keyword.data || []).map(val => {
|
|
|
val.href = helpers.urlFormat(`/hot/${val.id}.html`);
|
|
|
return val;
|
|
|
});
|
|
|
|
|
|
result.keyword = keyword;
|
|
|
result.latestWalk = 5;
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
})
|
|
|
}
|
|
|
}; |
...
|
...
|
|