Authored by 杨延青

Merge branch 'hotfix/hot' into 'release/0529'

Hotfix/hot



See merge request !290
@@ -9,6 +9,10 @@ const seoModel = require('../models/seo-service'); // seo 页 model @@ -9,6 +9,10 @@ const seoModel = require('../models/seo-service'); // seo 页 model
9 9
10 const hot = (req, res, next) => { 10 const hot = (req, res, next) => {
11 return req.ctx(seoModel).getHotKeywordDate(req.params.id, req.query, req.yoho.channel).then(result => { 11 return req.ctx(seoModel).getHotKeywordDate(req.params.id, req.query, req.yoho.channel).then(result => {
  12 + if (!result) {
  13 + return next();
  14 + }
  15 +
12 res.render('seo/hot', result); 16 res.render('seo/hot', result);
13 }).catch(next); 17 }).catch(next);
14 }; 18 };
@@ -18,6 +18,7 @@ const crypto = global.yoho.crypto; @@ -18,6 +18,7 @@ const crypto = global.yoho.crypto;
18 const _ = require('lodash'); 18 const _ = require('lodash');
19 const md5 = require('md5'); 19 const md5 = require('md5');
20 const redis = global.yoho.redis; 20 const redis = global.yoho.redis;
  21 +const cache = global.yoho.cache;
21 22
22 // const limitNum = 60; // 商品每页显示数目 23 // const limitNum = 60; // 商品每页显示数目
23 const needParams = ['query', 'msort', 'misort', 'category_id', 'gender', 'shelveTime']; 24 const needParams = ['query', 'msort', 'misort', 'category_id', 'gender', 'shelveTime'];
@@ -33,6 +34,20 @@ const positionId = 10; @@ -33,6 +34,20 @@ const positionId = 10;
33 // 获取分类左侧广告id 34 // 获取分类左侧广告id
34 const sortAdsId = 79; 35 const sortAdsId = 79;
35 36
  37 +const sortCache = {
  38 + key: 'global:yoho:category:name:',
  39 + get(categoryId) {
  40 + if (!categoryId) {
  41 + return Promise.resolve(false);
  42 + }
  43 +
  44 + return cache.get(this.key + categoryId);
  45 + },
  46 + set(categoryId, sortName) {
  47 + return cache.set(this.key + categoryId, sortName);
  48 + }
  49 +};
  50 +
36 /** 51 /**
37 * 获取商品分类列表数据 52 * 获取商品分类列表数据
38 */ 53 */
@@ -58,7 +73,8 @@ function getListData(params, channel) { @@ -58,7 +73,8 @@ function getListData(params, channel) {
58 let apiMethod = [ 73 let apiMethod = [
59 this.headerModel.requestHeaderData(channel, true), 74 this.headerModel.requestHeaderData(channel, true),
60 this.searchApi.getSortList({}, channel), 75 this.searchApi.getSortList({}, channel),
61 - this.searchApi.getProductList(searchParams, 'categoryList') 76 + this.searchApi.getProductList(searchParams, 'categoryList'),
  77 + sortCache.get(searchParams.category_id)
62 ]; 78 ];
63 79
64 // 搜索分类介绍和广告 80 // 搜索分类介绍和广告
@@ -125,13 +141,13 @@ function getListData(params, channel) { @@ -125,13 +141,13 @@ function getListData(params, channel) {
125 } 141 }
126 142
127 // 分类介绍 143 // 分类介绍
128 - if (result[3] && result[3].code === 200) {  
129 - finalResult.list.sortIntro = searchHandler.handleSortIntro(result[3].data); 144 + if (result[4] && result[4].code === 200) {
  145 + finalResult.list.sortIntro = searchHandler.handleSortIntro(result[4].data);
130 } 146 }
131 147
132 // 分类广告 148 // 分类广告
133 - if (result[4] && result[4].code === 200) {  
134 - Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[4].data)); 149 + if (result[5] && result[5].code === 200) {
  150 + Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[5].data));
135 } 151 }
136 152
137 let sortName; 153 let sortName;
@@ -150,7 +166,20 @@ function getListData(params, channel) { @@ -150,7 +166,20 @@ function getListData(params, channel) {
150 } 166 }
151 }); 167 });
152 168
153 - const seo = seoHandler.getListSeo(sortList, checkedList); 169 + let extendParam = {};
  170 +
  171 + if (searchParams.category_id) {
  172 + let cacheSortName = result[3];
  173 +
  174 + if (!sortName && cacheSortName) {
  175 + sortName = cacheSortName;
  176 + extendParam.sort = cacheSortName;
  177 + } else if (sortName && sortName !== cacheSortName) {
  178 + sortCache.set(searchParams.category_id, sortName);
  179 + }
  180 + }
  181 +
  182 + const seo = seoHandler.getListSeo(sortList, checkedList, extendParam);
154 183
155 if (sortName) { 184 if (sortName) {
156 return redis.all([ 185 return redis.all([
@@ -85,8 +85,8 @@ const listDefaultTdk = { @@ -85,8 +85,8 @@ const listDefaultTdk = {
85 * @param checked 85 * @param checked
86 * @returns {{title: string, keywords: string, description: string}} 86 * @returns {{title: string, keywords: string, description: string}}
87 */ 87 */
88 -const getListSeo = (sorts, checked) => {  
89 - let {brand, channel, color, style, sort} = getSeoCheckedParamsName(sorts, checked); 88 +const getListSeo = (sorts, checked, extend = {}) => {
  89 + let {brand, channel, color, style, sort} = Object.assign(getSeoCheckedParamsName(sorts, checked), extend);
90 90
91 if (brand && _.indexOf(brand, '、') > -1) { 91 if (brand && _.indexOf(brand, '、') > -1) {
92 brand = ''; 92 brand = '';
@@ -13,6 +13,17 @@ const seoHandler = require('./seo-handler'); @@ -13,6 +13,17 @@ const seoHandler = require('./seo-handler');
13 const utils = '../../../utils'; 13 const utils = '../../../utils';
14 const productProcess = require(`${utils}/product-process-simple`); 14 const productProcess = require(`${utils}/product-process-simple`);
15 15
  16 +const _handleImageUrl = (url) => {
  17 + if (url) {
  18 + let imgArr = _.split(url, '?', 1);
  19 +
  20 + imgArr.push('imageView2/1/w/{width}/h/{height}/q/90');
  21 + url = imgArr.join('?');
  22 + }
  23 +
  24 + return url;
  25 +};
  26 +
16 const _setHotKeywordData = (result, params, channel) => { 27 const _setHotKeywordData = (result, params, channel) => {
17 let changeQuery = Object.assign({}, params); 28 let changeQuery = Object.assign({}, params);
18 let finalResult = { 29 let finalResult = {
@@ -132,23 +143,26 @@ module.exports = class extends global.yoho.BaseModel { @@ -132,23 +143,26 @@ module.exports = class extends global.yoho.BaseModel {
132 } 143 }
133 144
134 if (!_.get(keyword, 'name')) { 145 if (!_.get(keyword, 'name')) {
135 - return Promise.reject(`cannot find hot keywords by id(${id})`); 146 + logger.error(`cannot find hot keywords by id(${id})`);
  147 + return false;
136 } 148 }
137 149
138 params.query = keyword.name; 150 params.query = keyword.name;
139 151
140 return this.getSearchProduct(params, channel).then(result => { 152 return this.getSearchProduct(params, channel).then(result => {
  153 + const keyNum = 10;
141 let hotKeys = (keyword.data || []).map(val => { 154 let hotKeys = (keyword.data || []).map(val => {
142 val.href = helpers.urlFormat(`/hot/${val.id}.html`); 155 val.href = helpers.urlFormat(`/hot/${val.id}.html`);
143 return val; 156 return val;
144 }); 157 });
145 let seoTDK = seoHandler.getHotKeywordsSeo(keyword.name, _.get(result, 'product.totalCount', '多')); 158 let seoTDK = seoHandler.getHotKeywordsSeo(keyword.name, _.get(result, 'product.totalCount', '多'));
146 159
147 - keyword.list = _.take(hotKeys, 6); 160 + keyword.goods_img = _handleImageUrl(keyword.goods_img);
  161 + keyword.list = _.take(hotKeys, keyNum);
148 keyword.describe = keyword.describe || seoTDK.description; 162 keyword.describe = keyword.describe || seoTDK.description;
149 163
150 Object.assign(result, { 164 Object.assign(result, {
151 - hotKeys: _.drop(hotKeys, 6), 165 + hotKeys: _.drop(hotKeys, keyNum),
152 keyword: keyword 166 keyword: keyword
153 }, seoTDK); 167 }, seoTDK);
154 168
@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 {{/if}} 22 {{/if}}
23 </div> 23 </div>
24 </div> 24 </div>
25 - <img class="thumb" src="{{image2 goods_img}}" alt="{{name}}"> 25 + <img class="thumb" src="{{image2 goods_img w=300 h=300}}" alt="{{name}}">
26 {{/ keyword}} 26 {{/ keyword}}
27 </div> 27 </div>
28 28
@@ -43,6 +43,7 @@ module.exports = () => { @@ -43,6 +43,7 @@ module.exports = () => {
43 return (req, res, next) => { 43 return (req, res, next) => {
44 let domain = 'm.yohobuy.com'; 44 let domain = 'm.yohobuy.com';
45 let proRegNew = /^\/product\/([\d]+).html(.*)/; 45 let proRegNew = /^\/product\/([\d]+).html(.*)/;
  46 + let hotReg = /^\/hot\/([\d]+).html(.*)/;
46 47
47 if (!req.xhr) { 48 if (!req.xhr) {
48 let url = _.head(_.split(req.url, '?')); 49 let url = _.head(_.split(req.url, '?'));
@@ -56,6 +57,8 @@ module.exports = () => { @@ -56,6 +57,8 @@ module.exports = () => {
56 data.mobileRefer = `//${domain}/guang?${queryString.stringify(req.query)}`; 57 data.mobileRefer = `//${domain}/guang?${queryString.stringify(req.query)}`;
57 } else if (proRegNew.test(url)) { 58 } else if (proRegNew.test(url)) {
58 data.mobileRefer = url.replace(proRegNew, `//${domain}/product/$1.html$2`); 59 data.mobileRefer = url.replace(proRegNew, `//${domain}/product/$1.html$2`);
  60 + } else if (hotReg) {
  61 + data.mobileRefer = `//${domain}/mip${url}`;
59 } 62 }
60 63
61 // 设置不需要跳转页面 64 // 设置不需要跳转页面
@@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
12 position: relative; 12 position: relative;
13 13
14 .sort-intro { 14 .sort-intro {
15 - width: 488px; 15 + width: 650px;
16 height: 300px; 16 height: 300px;
17 line-height: 300px; 17 line-height: 300px;
18 border: 1px solid #eaeceb; 18 border: 1px solid #eaeceb;
@@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
21 21
22 .inline { 22 .inline {
23 width: 100%; 23 width: 100%;
24 - padding: 0 50px; 24 + padding: 0 30px;
25 line-height: 1; 25 line-height: 1;
26 text-align: center; 26 text-align: center;
27 display: inline-block; 27 display: inline-block;
@@ -53,7 +53,7 @@ @@ -53,7 +53,7 @@
53 margin-top: 30px; 53 margin-top: 30px;
54 54
55 > li { 55 > li {
56 - width: 33.33%; 56 + width: 20%;
57 text-align: center; 57 text-align: center;
58 float: left; 58 float: left;
59 font-size: 12px; 59 font-size: 12px;
@@ -67,7 +67,7 @@ @@ -67,7 +67,7 @@
67 } 67 }
68 68
69 .thumb { 69 .thumb {
70 - width: 480px; 70 + width: 300px;
71 height: 300px; 71 height: 300px;
72 position: absolute; 72 position: absolute;
73 top: 0; 73 top: 0;