Authored by yyq

chanpin page

  1 +/**
  2 + * chanpin controller
  3 + * @author: yyq<yanqing.yang@yoho.cn>
  4 + * @date: 2017/09/22
  5 + */
  6 +
  7 +const _ = require('lodash');
  8 +const helpers = global.yoho.helpers;
  9 +
  10 +const utils = '../../../utils';
  11 +const searchProcess = require(`${utils}/search-process`);
  12 +const stringCode = require(`${utils}/string-code`);
  13 +const chanpin = require('../models/chanpin');
  14 +const headerModel = require('../../../doraemon/models/header');
  15 +
  16 +// 关键词页
  17 +const keyword = (req, res, next) => {
  18 + let queryKey = stringCode.hexToUtf8(`${req.params.query}`);
  19 + let params = {
  20 + isSearch: true, // 搜索列表将最新改成默认的标识
  21 + cartUrl: helpers.urlFormat('/cart/index/index'),
  22 + query: queryKey
  23 + };
  24 +
  25 + params.isApp = req.yoho.isApp;
  26 + params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);
  27 +
  28 + // 唤起 APP 的路径
  29 + res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":${JSON.stringify(params)}}`;
  30 +
  31 + return req.ctx(chanpin).getSearchKeywordData(params, req.user.uid).then(result => {
  32 + res.render('search/list', {
  33 + _noLazy: true,
  34 + module: 'product',
  35 + page: 'chanpin',
  36 + pageHeader: headerModel.setNav({
  37 + navTitle: queryKey
  38 + }),
  39 + goodList: params,
  40 + firstPageGoods: result || [],
  41 + fuzzyWord: result.fuzzyWord,
  42 + title: `${queryKey}价格_图片_品牌_怎么样-YOHO!BUY有货`,
  43 + keywords: `${queryKey},${queryKey}价格,${queryKey}图片,${queryKey}怎么样,${queryKey}品牌,YOHO!BUY有货`,
  44 + description: `YOHO!BUY有货网yohobuy.com是国内专业的${queryKey}网上潮流购物商城,为您找到${_.get(result,
  45 + 'total', 0)}${queryKey}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${queryKey},就上YOHO!BUY有货`,
  46 + pageFooter: true
  47 + });
  48 + }).catch(next);
  49 +};
  50 +
  51 +// 关键词页with id
  52 +const keyId = (req, res, next) => {
  53 + let params = {
  54 + isSearch: true, // 搜索列表将最新改成默认的标识
  55 + cartUrl: helpers.urlFormat('/cart/index/index')
  56 + };
  57 +
  58 + params.isApp = req.yoho.isApp;
  59 + params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);
  60 +
  61 + return req.ctx(chanpin).getSearchKeywordDataById(req.params.id, params, req.user.uid).then(result => {
  62 + let queryKey = result.queryKey;
  63 +
  64 + if (!result) {
  65 + return next();
  66 + }
  67 +
  68 + // 唤起 APP 的路径
  69 + res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":${JSON.stringify(params)}}`;
  70 +
  71 + res.render('search/list', {
  72 + _noLazy: true,
  73 + module: 'product',
  74 + page: 'chanpin',
  75 + pageHeader: headerModel.setNav({
  76 + navTitle: queryKey
  77 + }),
  78 + goodList: params,
  79 + firstPageGoods: result || [],
  80 + fuzzyWord: result.fuzzyWord,
  81 + title: `${queryKey}价格_图片_品牌_怎么样-YOHO!BUY有货`,
  82 + keywords: `${queryKey},${queryKey}价格,${queryKey}图片,${queryKey}怎么样,${queryKey}品牌,YOHO!BUY有货`,
  83 + description: `YOHO!BUY有货网yohobuy.com是国内专业的${queryKey}网上潮流购物商城,为您找到${_.get(result,
  84 + 'total', 0)}${queryKey}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${queryKey},就上YOHO!BUY有货`,
  85 + pageFooter: true,
  86 + cononical: {
  87 + currentHref: `//www.yohobuy.com${req.originalUrl}`
  88 + }
  89 + });
  90 + }).catch(next);
  91 +};
  92 +
  93 +const searchGoods = (req, res, next) => {
  94 +
  95 + let params = Object.assign({}, req.query);
  96 + let uid = req.user.uid || 0;
  97 +
  98 + if (uid) {
  99 + params.uid = uid;
  100 + }
  101 +
  102 + params.isApp = req.yoho.isApp;
  103 + params.limit = 24;
  104 +
  105 + return req.ctx(chanpin).getSeoSearchData(params).then((result) => {
  106 + if (result.list && result.list.length > 0) {
  107 + res.render('search/page', {
  108 + layout: false,
  109 + new: result.list,
  110 + suggestion: result.suggestion || [],
  111 + total: result.total,
  112 + _noLazy: params.noLazy || false
  113 + });
  114 + } else {
  115 + res.json(result);
  116 + }
  117 + }).catch(next);
  118 +};
  119 +
  120 +module.exports = {
  121 + keyword,
  122 + keyId,
  123 + searchGoods
  124 +};
@@ -13,7 +13,6 @@ const _ = require('lodash'); @@ -13,7 +13,6 @@ const _ = require('lodash');
13 const helpers = global.yoho.helpers; 13 const helpers = global.yoho.helpers;
14 const searchProcess = require(`${utils}/search-process`); 14 const searchProcess = require(`${utils}/search-process`);
15 const productProcess = require(`${utils}/product-process`); 15 const productProcess = require(`${utils}/product-process`);
16 -const stringCode = require(`${utils}/string-code`);  
17 const co = require('bluebird').coroutine; 16 const co = require('bluebird').coroutine;
18 17
19 /** 18 /**
@@ -271,83 +270,6 @@ let filter = (req, res, next) => { @@ -271,83 +270,6 @@ let filter = (req, res, next) => {
271 }).catch(next); 270 }).catch(next);
272 }; 271 };
273 272
274 -// 关键词页  
275 -const keyword = (req, res, next) => {  
276 - let queryKey = stringCode.hexToUtf8(`${req.params.query}`);  
277 - let params = {  
278 - isSearch: true, // 搜索列表将最新改成默认的标识  
279 - cartUrl: helpers.urlFormat('/cart/index/index'),  
280 - query: queryKey  
281 - };  
282 -  
283 - params.isApp = req.yoho.isApp;  
284 - params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);  
285 -  
286 - // 唤起 APP 的路径  
287 - res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":${JSON.stringify(params)}}`;  
288 -  
289 - return searchModel.getSearchKeywordData(params, req.user.uid).then(result => {  
290 - res.render('search/list', {  
291 - _noLazy: true,  
292 - module: 'product',  
293 - page: 'search-list',  
294 - pageHeader: headerModel.setNav({  
295 - navTitle: queryKey  
296 - }),  
297 - goodList: params,  
298 - firstPageGoods: result || [],  
299 - fuzzyWord: result.fuzzyWord,  
300 - title: `${queryKey}价格_图片_品牌_怎么样-YOHO!BUY有货`,  
301 - keywords: `${queryKey},${queryKey}价格,${queryKey}图片,${queryKey}怎么样,${queryKey}品牌,YOHO!BUY有货`,  
302 - description: `YOHO!BUY有货网yohobuy.com是国内专业的${queryKey}网上潮流购物商城,为您找到${_.get(result,  
303 - 'total', 0)}${queryKey}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${queryKey},就上YOHO!BUY有货`,  
304 - pageFooter: true  
305 - });  
306 - }).catch(next);  
307 -};  
308 -  
309 -// 关键词页with id  
310 -const keyId = (req, res, next) => {  
311 - let params = {  
312 - isSearch: true, // 搜索列表将最新改成默认的标识  
313 - cartUrl: helpers.urlFormat('/cart/index/index')  
314 - };  
315 -  
316 - params.isApp = req.yoho.isApp;  
317 - params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);  
318 -  
319 - return searchModel.getSearchKeywordDataById(req.params.id, params, req.user.uid).then(result => {  
320 - let queryKey = result.queryKey;  
321 -  
322 - if (!result) {  
323 - return next();  
324 - }  
325 -  
326 - // 唤起 APP 的路径  
327 - res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":${JSON.stringify(params)}}`;  
328 -  
329 - res.render('search/list', {  
330 - _noLazy: true,  
331 - module: 'product',  
332 - page: 'search-list',  
333 - pageHeader: headerModel.setNav({  
334 - navTitle: queryKey  
335 - }),  
336 - goodList: params,  
337 - firstPageGoods: result || [],  
338 - fuzzyWord: result.fuzzyWord,  
339 - title: `${queryKey}价格_图片_品牌_怎么样-YOHO!BUY有货`,  
340 - keywords: `${queryKey},${queryKey}价格,${queryKey}图片,${queryKey}怎么样,${queryKey}品牌,YOHO!BUY有货`,  
341 - description: `YOHO!BUY有货网yohobuy.com是国内专业的${queryKey}网上潮流购物商城,为您找到${_.get(result,  
342 - 'total', 0)}${queryKey}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${queryKey},就上YOHO!BUY有货`,  
343 - pageFooter: true,  
344 - cononical: {  
345 - currentHref: `//www.yohobuy.com${req.originalUrl}`  
346 - }  
347 - });  
348 - }).catch(next);  
349 -};  
350 -  
351 /** 273 /**
352 * 搜索品牌下的商品 274 * 搜索品牌下的商品
353 */ 275 */
@@ -410,8 +332,6 @@ module.exports = { @@ -410,8 +332,6 @@ module.exports = {
410 search, 332 search,
411 index, 333 index,
412 fuzzyDatas, 334 fuzzyDatas,
413 - keyword,  
414 - keyId,  
415 searchBrandGoods, 335 searchBrandGoods,
416 searchShopGoods 336 searchShopGoods
417 }; 337 };
  1 +/**
  2 + * chanpin model
  3 + * @author: yyq<yanqing.yang@yoho.cn>
  4 + * @date: 2017/09/22
  5 + */
  6 +
  7 +const _ = require('lodash');
  8 +const helpers = global.yoho.helpers;
  9 +
  10 +const utils = '../../../utils';
  11 +const redis = require(`${utils}/redis`);
  12 +const searchProcess = require(`${utils}/search-process`);
  13 +const productProcess = require(`${utils}/product-process`);
  14 +const stringCode = require(`${utils}/string-code`);
  15 +
  16 +/**
  17 + * 封面图
  18 + * @type {{boys: string, gilrs: string}}
  19 + */
  20 +const _coverChannel = {
  21 + boys: '1,3',
  22 + gilrs: '2,3'
  23 +};
  24 +
  25 +module.exports = class extends global.yoho.BaseModel {
  26 + constructor(ctx) {
  27 + super(ctx);
  28 + }
  29 +
  30 + getFuzzyDatas(params) {
  31 + return this.get({
  32 + data: {
  33 + method: 'app.search.fuzzy',
  34 + keyword: params
  35 + },
  36 + param: {cache: true}
  37 + }).then((result) => {
  38 + return _.get(result, 'data', []);
  39 + });
  40 + }
  41 +
  42 + getSeoSearchData(params) {
  43 + let finalParams = {
  44 + method: 'app.search.li',
  45 + };
  46 +
  47 + finalParams = _.assign(finalParams, searchProcess.getSearchParamsWithoutMethod(params));
  48 +
  49 + return this.get({data: finalParams}).then(result => {
  50 + let resData = {};
  51 +
  52 + resData.list = productProcess.processProductList(_.get(result, 'data.product_list', []), {
  53 + isApp: params.isApp || (params.appVersion && params.appVersion !== 'false'),
  54 + gender: _coverChannel[params.coverChannel],
  55 + showSimilar: params.shop_id || params.material === 'true' ? false : true
  56 + });
  57 +
  58 + return resData;
  59 + });
  60 + }
  61 +
  62 + getSearchKeywordData(params, uid) {
  63 +
  64 + // 获取第一页数据做服务端渲染
  65 + let initialData = _.assign({
  66 + type: 'default',
  67 + order: '0',
  68 + page: 1,
  69 + limit: 24
  70 + }, params);
  71 +
  72 + if (uid) {
  73 + initialData.uid = uid;
  74 + }
  75 +
  76 +
  77 + return Promise.all([
  78 + this.getFuzzyDatas(`${params.query}`.substr(0, 2)),
  79 + this.getSeoSearchData(initialData)
  80 + ]).then(result => {
  81 + let resData = result[1];
  82 + let fuzzy = [];
  83 +
  84 + if (_.isEmpty(result[0])) {
  85 + result[0] = [];
  86 + }
  87 +
  88 + _.forEach(_.slice(result[0], 0, 12), value => {
  89 + if (value.keyword === params.query) {
  90 + return;
  91 + }
  92 +
  93 + fuzzy.push({
  94 + name: value.keyword,
  95 + link: helpers.urlFormat(`/so/${stringCode.utf8ToHex(value.keyword)}.html`),
  96 + });
  97 + });
  98 +
  99 + if (!_.isEmpty(fuzzy)) {
  100 + resData.fuzzyWord = fuzzy;
  101 + }
  102 +
  103 + return resData;
  104 + });
  105 + }
  106 +
  107 + getSearchKeywordDataById(id, params, uid) {
  108 + return redis.all([
  109 + ['get', `global:yoho:seo:keywords:id:${id}`]
  110 + ]).then(redisData => {
  111 + if (!redisData[0]) {
  112 + return false;
  113 + }
  114 +
  115 + redisData = JSON.parse(redisData[0]);
  116 + params.query = redisData.name;
  117 +
  118 + return this.getSearchKeywordData(params, uid).then(result => {
  119 + result.queryKey = params.query;
  120 +
  121 + let fuzzyWord = [];
  122 +
  123 + if (!_.isEmpty(redisData.data)) {
  124 + _.forEach(_.slice(redisData.data, 0, 12), value => {
  125 + if (!value) {
  126 + return;
  127 + }
  128 +
  129 + fuzzyWord.push(Object.assign(value, {
  130 + name: value.keyword,
  131 + link: helpers.urlFormat(`/chanpin/${value.id}.html`, null)
  132 + }));
  133 + });
  134 +
  135 + _.set(result, 'fuzzyWord', fuzzyWord);
  136 + }
  137 +
  138 + return result;
  139 + });
  140 + });
  141 + }
  142 +};
@@ -7,13 +7,11 @@ @@ -7,13 +7,11 @@
7 const utils = '../../../utils'; 7 const utils = '../../../utils';
8 const productProcess = require(`${utils}/product-process`); 8 const productProcess = require(`${utils}/product-process`);
9 const searchProcess = require(`${utils}/search-process`); 9 const searchProcess = require(`${utils}/search-process`);
10 -const stringCode = require(`${utils}/string-code`);  
11 const _ = require('lodash'); 10 const _ = require('lodash');
12 const logger = global.yoho.logger; 11 const logger = global.yoho.logger;
13 const api = global.yoho.API; 12 const api = global.yoho.API;
14 const cache = require('memory-cache'); 13 const cache = require('memory-cache');
15 const helpers = global.yoho.helpers; 14 const helpers = global.yoho.helpers;
16 -const redis = require(`${utils}/redis`);  
17 const co = require('bluebird').coroutine; 15 const co = require('bluebird').coroutine;
18 16
19 /** 17 /**
@@ -540,84 +538,6 @@ const getBrandDomain = (query) => { @@ -540,84 +538,6 @@ const getBrandDomain = (query) => {
540 } 538 }
541 }; 539 };
542 540
543 -  
544 -const getSearchKeywordData = (params, uid) => {  
545 -  
546 - // 获取第一页数据做服务端渲染  
547 - let initialData = _.assign({  
548 - type: 'default',  
549 - order: '0',  
550 - page: 1,  
551 - limit: 24  
552 - }, params);  
553 -  
554 - if (uid) {  
555 - initialData.uid = uid;  
556 - }  
557 -  
558 - return Promise.all([  
559 - getFuzzyDatas(`${params.query}`.substr(0, 2)),  
560 - getSearchData(initialData)  
561 - ]).then(result => {  
562 - let fuzzy = [];  
563 -  
564 - if (_.isEmpty(result[0])) {  
565 - result[0] = [];  
566 - }  
567 -  
568 - _.forEach(_.slice(result[0], 0, 12), value => {  
569 - if (value.keyword === params.query) {  
570 - return;  
571 - }  
572 -  
573 - fuzzy.push({  
574 - name: value.keyword,  
575 - link: helpers.urlFormat(`/so/${stringCode.utf8ToHex(value.keyword)}.html`),  
576 - });  
577 - });  
578 -  
579 - if (!_.isEmpty(fuzzy)) {  
580 - result[1].fuzzyWord = fuzzy;  
581 - }  
582 -  
583 - return result[1];  
584 - });  
585 -};  
586 -  
587 -const getSearchKeywordDataById = (id, params, uid) => {  
588 - return redis.all([  
589 - ['get', `global:yoho:seo:keywords:id:${id}`]  
590 - ]).then(redisData => {  
591 - if (!redisData[0]) {  
592 - return false;  
593 - }  
594 -  
595 - redisData = JSON.parse(redisData[0]);  
596 - params.query = redisData.name;  
597 -  
598 - return getSearchKeywordData(params, uid).then(result => {  
599 - result.queryKey = params.query;  
600 -  
601 - if (!_.isEmpty(redisData.data)) {  
602 - _.forEach(redisData.data, value => {  
603 - if (!value) {  
604 - return;  
605 - }  
606 -  
607 - Object.assign(value, {  
608 - name: value.keyword,  
609 - link: helpers.urlFormat(`/chanpin/${value.id}.html`, null)  
610 - });  
611 - });  
612 -  
613 - _.set(result, 'fuzzyWord', redisData.data);  
614 - }  
615 -  
616 - return result;  
617 - });  
618 - });  
619 -};  
620 -  
621 /** 541 /**
622 * 通过 skn 搜索商品 542 * 通过 skn 搜索商品
623 * @param productSkn 543 * @param productSkn
@@ -643,8 +563,6 @@ module.exports = { @@ -643,8 +563,6 @@ module.exports = {
643 getFuzzyDatas, 563 getFuzzyDatas,
644 searchKeyActivity, 564 searchKeyActivity,
645 getBrandDomain, 565 getBrandDomain,
646 - getSearchKeywordData,  
647 - getSearchKeywordDataById,  
648 getSearchGoods, 566 getSearchGoods,
649 getBrandGoods, 567 getBrandGoods,
650 getShopGoods, 568 getShopGoods,
@@ -59,6 +59,9 @@ const globalPro = require(`${cRoot}/global`); @@ -59,6 +59,9 @@ const globalPro = require(`${cRoot}/global`);
59 // 找相似 59 // 找相似
60 const similar = require(`${cRoot}/similar`); 60 const similar = require(`${cRoot}/similar`);
61 61
  62 +// seo推广
  63 +const chanpin = require(`${cRoot}/chanpin`);
  64 +
62 // routers 65 // routers
63 66
64 // /pro_136349_455445/HEARTSOFARMianMaShuJiaoXiuXianKuPS1684.html 67 // /pro_136349_455445/HEARTSOFARMianMaShuJiaoXiuXianKuPS1684.html
@@ -135,8 +138,9 @@ router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表 @@ -135,8 +138,9 @@ router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表
135 router.get('/search/index', search.index); 138 router.get('/search/index', search.index);
136 139
137 // 推广落地页 140 // 推广落地页
138 -router.get('/search/so/:query.html', rewrite.sortParams, search.keyword);  
139 -router.get('/search/chanpin/:id.html', rewrite.sortParams, search.keyId); 141 +router.get('/search/so/:query.html', rewrite.sortParams, chanpin.keyword);
  142 +router.get('/search/chanpin/:id.html', rewrite.sortParams, chanpin.keyId);
  143 +router.get('/search/chanpin/goods', chanpin.searchGoods); // 搜索的商品
140 144
141 // 搜索落地页 145 // 搜索落地页
142 router.get('/search/list', rewrite.sortParams, search.list); 146 router.get('/search/list', rewrite.sortParams, search.list);
@@ -106,7 +106,7 @@ module.exports = { @@ -106,7 +106,7 @@ module.exports = {
106 jsSdk: '//cdn.yoho.cn/js-sdk/1.2.2/jssdk.js', 106 jsSdk: '//cdn.yoho.cn/js-sdk/1.2.2/jssdk.js',
107 redis: { 107 redis: {
108 connect: { 108 connect: {
109 - host: '127.0.0.1', 109 + host: '192.168.102.49',
110 port: '6379', 110 port: '6379',
111 retry_strategy(options) { 111 retry_strategy(options) {
112 if (options.error && options.error.code === 'ECONNREFUSED') { 112 if (options.error && options.error.code === 'ECONNREFUSED') {
  1 +/**
  2 + * seo推广落地页
  3 + * @author: yyq<yanqing.yang@yoho.cn>
  4 + * @date: 2016/7/21
  5 + */
  6 +
  7 +require('product/search/list.page.css');
  8 +
  9 +const $ = require('yoho-jquery');
  10 +const ProductListWithFilter = require('product/list/product-list-with-filter');
  11 +
  12 +require('common/footer');
  13 +
  14 +new ProductListWithFilter({
  15 + query: $.trim($('.nav-title').text()),
  16 + page: 2, // 首页服务端已经渲染
  17 +}, 'product/search/chanpin/goods').getFilter();
@@ -17,8 +17,8 @@ class ProductListWithFilter { @@ -17,8 +17,8 @@ class ProductListWithFilter {
17 constructor(filterParams, searchUrl, extra) { 17 constructor(filterParams, searchUrl, extra) {
18 this.scrollActived = true; // 是否激活滚动加载,默认激活 18 this.scrollActived = true; // 是否激活滚动加载,默认激活
19 this.filterParams = filterParams; 19 this.filterParams = filterParams;
20 - this.searchUrl = location.protocol + '//m.yohobuy.com/' + (searchUrl || 'product/search/search');  
21 - this.filterUrl = location.protocol + '//m.yohobuy.com/product/search/filter'; 20 + this.searchUrl = '/' + (searchUrl || 'product/search/search');
  21 + this.filterUrl = '/product/search/filter';
22 this.goodsTotal = extra && extra.goodsTotal; // YAS 需要数据 22 this.goodsTotal = extra && extra.goodsTotal; // YAS 需要数据
23 this.view = { 23 this.view = {
24 goodsContainer: $('#goods-container'), 24 goodsContainer: $('#goods-container'),
@@ -100,6 +100,10 @@ const getListSeoData = (gender, sort_name) => { @@ -100,6 +100,10 @@ const getListSeoData = (gender, sort_name) => {
100 const getSearchParamsWithoutMethod = (params) => { 100 const getSearchParamsWithoutMethod = (params) => {
101 let finalParams = {}; 101 let finalParams = {};
102 102
  103 + if (params.query) {
  104 + finalParams.query = params.query;
  105 + }
  106 +
103 if (params.yh_channel) { 107 if (params.yh_channel) {
104 finalParams.yh_channel = params.yh_channel; 108 finalParams.yh_channel = params.yh_channel;
105 } 109 }