Authored by yyq

产品推广页By id

... ... @@ -200,6 +200,35 @@ const keyword = (req, res, next) => {
}).catch(next);
};
/**
* 搜索推荐列表页
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
const keyId = (req, res, next) => {
let params = req.query;
let id = req.params.id;
return search.getSearchKeywordDataById(id, params, req.yoho.channel).then(result => {
let query = result.queryKey;
Object.assign(result, {
pageNoFollow: true,
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(result, 'search.goods') || !_.get(result, 'search.goods').length) {
_.set(result, 'search.keyWord', query);
return res.render('search/no-result', result);
}
res.render('search/index', result);
}).catch(next);
};
module.exports = {
index,
suggest,
... ... @@ -207,6 +236,7 @@ module.exports = {
searchFilterBrands,
searchHistory, // 搜索历史记录
searchLessRecommend,
keyword
keyword,
keyId
};
... ...
... ... @@ -10,6 +10,7 @@ const api = global.yoho.API;
const Promise = require('bluebird');
const co = Promise.coroutine;
const helpers = global.yoho.helpers;
const redis = global.yoho.redis;
const saleApi = require('./sale-api');
const searchApi = require('./search-api');
const headerModel = require('../../../doraemon/models/header');
... ... @@ -401,3 +402,71 @@ exports.getSearchKeywordData = (params, channel) => {
return setSearchKeywordData(result, params, channel);
});
};
/**
* 获取搜索建议数据
* @id {[number]} origin [description]
* @param {[object]} origin [description]
* @channel {[string]} origin [description]
* @return {[object]} [description]
*/
exports.getSearchKeywordDataById = (id, params, channel) => {
return co(function * () {
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 redisData = yield redis.all([
['get', `golobal:yoho:seo:keywords:id:${id}`]
]);
if (!redisData[0]) {
return Promise.reject('get redis canpin keywords by id error!' +
`key: golobal:yoho:seo:keywords:id:${id} value: ${redisData[0]}`);
}
redisData = JSON.parse(redisData[0]);
searchParams.query = redisData.name;
let result = yield api.all([
headerModel.requestHeaderData(channel),
searchApi.getSuggest({keyword: searchParams.query.substring(0, 2)}),
searchApi.getProductList(searchParams, 'fuzzySearch')
]);
let resData = setSearchKeywordData(result, params, channel);
resData.queryKey = searchParams.query;
if (!_.isEmpty(redisData.data)) {
_.forEach(redisData.data, value => {
Object.assign({
name: value.keyword,
href: helpers.urlFormat(`/canpin/${value.root_id}.html`, null, 'www')
});
});
_.set(resData, 'search.allSuggest.list', redisData.data);
}
return resData;
})();
};
... ...
... ... @@ -103,6 +103,7 @@ 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('/search/canpin/:id', search.keyId);
// 商品分类列表页
router.get('/list/index', gbk2utf, list.index);
... ...
... ... @@ -77,6 +77,13 @@ module.exports = [
target: (req, match, p1) => `/product/search/keyword/${p1}`
},
// 推荐词id列表页
{
type: TYPE.rewrite,
origin: /^\/canpin\/(.*)\.html(.*)/,
target: (req, match, p1) => `/product/search/canpin/${p1}`
},
// erp2good
{
type: TYPE.rewrite,
... ...
const _ = require('lodash');
const redis = require('redis');
const bluebird = require('bluebird');
const config = require('../../config/common');
... ... @@ -9,6 +11,18 @@ try {
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
client.all = args => {
if (!client.connected) {
if (Array.isArray(args)) {
return Promise.resolve(_.fill(args, false));
} else {
return Promise.resolve(false);
}
}
return client.multi.call(client, args).execAsync();
};
client.on('error', function() {
global.yoho.redis = '';
});
... ... @@ -20,6 +34,4 @@ try {
global.yoho.redis = '';
}
module.exports = client;
... ...