Authored by yyq

canpin page

... ... @@ -304,11 +304,47 @@ const keyword = (req, res, next) => {
}).catch(next);
};
// 关键词页with id
const keyId = (req, res, next) => {
let params = {
isSearch: true, // 搜索列表将最新改成默认的标识
cartUrl: helpers.urlFormat('/cart/index/index')
};
params.isApp = req.yoho.isApp;
params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);
return searchModel.getSearchKeywordDataById(req.params.id, params, req.user.uid).then(result => {
let queryKey = result.queryKey;
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":${JSON.stringify(params)}}`;
res.render('search/list', {
_noLazy: true,
module: 'product',
page: 'search-list',
pageHeader: headerModel.setNav({
navTitle: queryKey
}),
goodList: params,
firstPageGoods: result || [],
fuzzyWord: result.fuzzyWord,
title: `${queryKey}价格_图片_品牌_怎么样-YOHO!BUY有货`,
keywords: `${queryKey},${queryKey}价格,${queryKey}图片,${queryKey}怎么样,${queryKey}品牌,YOHO!BUY有货`,
description: `YOHO!BUY有货网yohobuy.com是国内专业的${queryKey}网上潮流购物商城,为您找到${_.get(result,
'total', 0)}${queryKey}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${queryKey},就上YOHO!BUY有货`,
pageFooter: true
});
}).catch(next);
};
module.exports = {
list,
filter,
search,
index,
fuzzyDatas,
keyword
keyword,
keyId
};
... ...
... ... @@ -13,6 +13,7 @@ const logger = global.yoho.logger;
const api = global.yoho.API;
const cache = require('memory-cache');
const helpers = global.yoho.helpers;
const redis = global.yoho.redis;
/**
* 封面图
... ... @@ -539,6 +540,41 @@ const getSearchKeywordData = (params, uid) => {
});
};
const getSearchKeywordDataById = (id, params, uid) => {
return redis.all([
['get', `golobal:yoho:seo:keywords:id:${id}`]
]).then(redisData => {
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]);
params.query = redisData.name;
return getSearchKeywordData(params, uid).then(result => {
result.queryKey = params.query;
if (!_.isEmpty(redisData.data)) {
_.forEach(redisData.data, value => {
if (!value) {
return;
}
Object.assign(value, {
name: value.keyword,
href: helpers.urlFormat(`/canpin/${value.id}.html`, null)
});
});
_.set(result, 'fuzzyWord', redisData.data);
}
return result;
});
});
};
module.exports = {
getSearchData,
getFilterData,
... ... @@ -549,5 +585,6 @@ module.exports = {
getFuzzyDatas,
searchKeyActivity,
getBrandDomain,
getSearchKeywordData
getSearchKeywordData,
getSearchKeywordDataById
};
... ...
... ... @@ -134,8 +134,9 @@ router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表
// 搜索主页
router.get('/search/index', search.index);
// 搜索落地页
// 推广落地页
router.get('/search/keyword/:query', rewrite.sortParams, search.keyword);
router.get('/search/canpin/:id', rewrite.sortParams, search.keyword);
// 搜索落地页
router.get('/search/list', rewrite.sortParams, search.list);
... ...
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 = '';
});
... ...
... ... @@ -86,10 +86,14 @@ module.exports = () => {
}
} else {
let soReg = /\/so\/(.*).html/;
let canpinReg = /\/canpin\/(.*).html/;
if (soReg.test(req.path)) {
soReg.exec(req.url);
req.url = `/product/search/keyword/${RegExp.$1}`;
} else if (canpinReg.test(req.path)) {
canpinReg.exec(req.url);
req.url = `/product/search/canpin/${RegExp.$1}`;
}
}
next();
... ...