Authored by 毕凯

Merge branch 'feature/recList2.0' into 'master'

Feature/rec list2.0



See merge request !698
@@ -304,11 +304,47 @@ const keyword = (req, res, next) => { @@ -304,11 +304,47 @@ const keyword = (req, res, next) => {
304 }).catch(next); 304 }).catch(next);
305 }; 305 };
306 306
  307 +// 关键词页with id
  308 +const keyId = (req, res, next) => {
  309 + let params = {
  310 + isSearch: true, // 搜索列表将最新改成默认的标识
  311 + cartUrl: helpers.urlFormat('/cart/index/index')
  312 + };
  313 +
  314 + params.isApp = req.yoho.isApp;
  315 + params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);
  316 +
  317 + return searchModel.getSearchKeywordDataById(req.params.id, params, req.user.uid).then(result => {
  318 + let queryKey = result.queryKey;
  319 +
  320 + // 唤起 APP 的路径
  321 + res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":${JSON.stringify(params)}}`;
  322 +
  323 + res.render('search/list', {
  324 + _noLazy: true,
  325 + module: 'product',
  326 + page: 'search-list',
  327 + pageHeader: headerModel.setNav({
  328 + navTitle: queryKey
  329 + }),
  330 + goodList: params,
  331 + firstPageGoods: result || [],
  332 + fuzzyWord: result.fuzzyWord,
  333 + title: `${queryKey}价格_图片_品牌_怎么样-YOHO!BUY有货`,
  334 + keywords: `${queryKey},${queryKey}价格,${queryKey}图片,${queryKey}怎么样,${queryKey}品牌,YOHO!BUY有货`,
  335 + description: `YOHO!BUY有货网yohobuy.com是国内专业的${queryKey}网上潮流购物商城,为您找到${_.get(result,
  336 + 'total', 0)}${queryKey}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${queryKey},就上YOHO!BUY有货`,
  337 + pageFooter: true
  338 + });
  339 + }).catch(next);
  340 +};
  341 +
307 module.exports = { 342 module.exports = {
308 list, 343 list,
309 filter, 344 filter,
310 search, 345 search,
311 index, 346 index,
312 fuzzyDatas, 347 fuzzyDatas,
313 - keyword 348 + keyword,
  349 + keyId
314 }; 350 };
@@ -13,6 +13,7 @@ const logger = global.yoho.logger; @@ -13,6 +13,7 @@ const logger = global.yoho.logger;
13 const api = global.yoho.API; 13 const api = global.yoho.API;
14 const cache = require('memory-cache'); 14 const cache = require('memory-cache');
15 const helpers = global.yoho.helpers; 15 const helpers = global.yoho.helpers;
  16 +const redis = global.yoho.redis;
16 17
17 /** 18 /**
18 * 封面图 19 * 封面图
@@ -539,6 +540,41 @@ const getSearchKeywordData = (params, uid) => { @@ -539,6 +540,41 @@ const getSearchKeywordData = (params, uid) => {
539 }); 540 });
540 }; 541 };
541 542
  543 +const getSearchKeywordDataById = (id, params, uid) => {
  544 + return redis.all([
  545 + ['get', `golobal:yoho:seo:keywords:id:${id}`]
  546 + ]).then(redisData => {
  547 + if (!redisData[0]) {
  548 + return Promise.reject('get redis canpin keywords by id error!' +
  549 + `key: golobal:yoho:seo:keywords:id:${id} value: ${redisData[0]}`);
  550 + }
  551 +
  552 + redisData = JSON.parse(redisData[0]);
  553 + params.query = redisData.name;
  554 +
  555 + return getSearchKeywordData(params, uid).then(result => {
  556 + result.queryKey = params.query;
  557 +
  558 + if (!_.isEmpty(redisData.data)) {
  559 + _.forEach(redisData.data, value => {
  560 + if (!value) {
  561 + return;
  562 + }
  563 +
  564 + Object.assign(value, {
  565 + name: value.keyword,
  566 + link: helpers.urlFormat(`/chanpin/${value.id}.html`, null)
  567 + });
  568 + });
  569 +
  570 + _.set(result, 'fuzzyWord', redisData.data);
  571 + }
  572 +
  573 + return result;
  574 + });
  575 + });
  576 +};
  577 +
542 module.exports = { 578 module.exports = {
543 getSearchData, 579 getSearchData,
544 getFilterData, 580 getFilterData,
@@ -549,5 +585,6 @@ module.exports = { @@ -549,5 +585,6 @@ module.exports = {
549 getFuzzyDatas, 585 getFuzzyDatas,
550 searchKeyActivity, 586 searchKeyActivity,
551 getBrandDomain, 587 getBrandDomain,
552 - getSearchKeywordData 588 + getSearchKeywordData,
  589 + getSearchKeywordDataById
553 }; 590 };
@@ -134,8 +134,9 @@ router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表 @@ -134,8 +134,9 @@ router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表
134 // 搜索主页 134 // 搜索主页
135 router.get('/search/index', search.index); 135 router.get('/search/index', search.index);
136 136
137 -// 搜索落地页 137 +// 推广落地页
138 router.get('/search/keyword/:query', rewrite.sortParams, search.keyword); 138 router.get('/search/keyword/:query', rewrite.sortParams, search.keyword);
  139 +router.get('/search/chanpin/:id', rewrite.sortParams, search.keyId);
139 140
140 // 搜索落地页 141 // 搜索落地页
141 router.get('/search/list', rewrite.sortParams, search.list); 142 router.get('/search/list', rewrite.sortParams, search.list);
  1 +
  2 +const _ = require('lodash');
1 const redis = require('redis'); 3 const redis = require('redis');
2 const bluebird = require('bluebird'); 4 const bluebird = require('bluebird');
3 const config = require('../../config/common'); 5 const config = require('../../config/common');
@@ -9,6 +11,18 @@ try { @@ -9,6 +11,18 @@ try {
9 bluebird.promisifyAll(redis.RedisClient.prototype); 11 bluebird.promisifyAll(redis.RedisClient.prototype);
10 bluebird.promisifyAll(redis.Multi.prototype); 12 bluebird.promisifyAll(redis.Multi.prototype);
11 13
  14 + client.all = args => {
  15 + if (!client.ready) {
  16 + if (Array.isArray(args)) {
  17 + return Promise.resolve(_.fill(args, false));
  18 + } else {
  19 + return Promise.resolve(false);
  20 + }
  21 + }
  22 +
  23 + return client.multi.call(client, args).execAsync();
  24 + };
  25 +
12 client.on('error', function() { 26 client.on('error', function() {
13 global.yoho.redis = ''; 27 global.yoho.redis = '';
14 }); 28 });
@@ -86,10 +86,14 @@ module.exports = () => { @@ -86,10 +86,14 @@ module.exports = () => {
86 } 86 }
87 } else { 87 } else {
88 let soReg = /\/so\/(.*).html/; 88 let soReg = /\/so\/(.*).html/;
  89 + let chanpinReg = /\/chanpin\/(.*).html/;
89 90
90 if (soReg.test(req.path)) { 91 if (soReg.test(req.path)) {
91 soReg.exec(req.url); 92 soReg.exec(req.url);
92 req.url = `/product/search/keyword/${RegExp.$1}`; 93 req.url = `/product/search/keyword/${RegExp.$1}`;
  94 + } else if (chanpinReg.test(req.path)) {
  95 + chanpinReg.exec(req.url);
  96 + req.url = `/product/search/chanpin/${RegExp.$1}`;
93 } 97 }
94 } 98 }
95 next(); 99 next();