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
const hot = (req, res, next) => {
return req.ctx(seoModel).getHotKeywordDate(req.params.id, req.query, req.yoho.channel).then(result => {
if (!result) {
return next();
}
res.render('seo/hot', result);
}).catch(next);
};
... ...
... ... @@ -18,6 +18,7 @@ const crypto = global.yoho.crypto;
const _ = require('lodash');
const md5 = require('md5');
const redis = global.yoho.redis;
const cache = global.yoho.cache;
// const limitNum = 60; // 商品每页显示数目
const needParams = ['query', 'msort', 'misort', 'category_id', 'gender', 'shelveTime'];
... ... @@ -33,6 +34,20 @@ const positionId = 10;
// 获取分类左侧广告id
const sortAdsId = 79;
const sortCache = {
key: 'global:yoho:category:name:',
get(categoryId) {
if (!categoryId) {
return Promise.resolve(false);
}
return cache.get(this.key + categoryId);
},
set(categoryId, sortName) {
return cache.set(this.key + categoryId, sortName);
}
};
/**
* 获取商品分类列表数据
*/
... ... @@ -58,7 +73,8 @@ function getListData(params, channel) {
let apiMethod = [
this.headerModel.requestHeaderData(channel, true),
this.searchApi.getSortList({}, channel),
this.searchApi.getProductList(searchParams, 'categoryList')
this.searchApi.getProductList(searchParams, 'categoryList'),
sortCache.get(searchParams.category_id)
];
// 搜索分类介绍和广告
... ... @@ -125,13 +141,13 @@ function getListData(params, channel) {
}
// 分类介绍
if (result[3] && result[3].code === 200) {
finalResult.list.sortIntro = searchHandler.handleSortIntro(result[3].data);
if (result[4] && result[4].code === 200) {
finalResult.list.sortIntro = searchHandler.handleSortIntro(result[4].data);
}
// 分类广告
if (result[4] && result[4].code === 200) {
Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[4].data));
if (result[5] && result[5].code === 200) {
Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[5].data));
}
let sortName;
... ... @@ -150,7 +166,20 @@ function getListData(params, channel) {
}
});
const seo = seoHandler.getListSeo(sortList, checkedList);
let extendParam = {};
if (searchParams.category_id) {
let cacheSortName = result[3];
if (!sortName && cacheSortName) {
sortName = cacheSortName;
extendParam.sort = cacheSortName;
} else if (sortName && sortName !== cacheSortName) {
sortCache.set(searchParams.category_id, sortName);
}
}
const seo = seoHandler.getListSeo(sortList, checkedList, extendParam);
if (sortName) {
return redis.all([
... ...
... ... @@ -85,8 +85,8 @@ const listDefaultTdk = {
* @param checked
* @returns {{title: string, keywords: string, description: string}}
*/
const getListSeo = (sorts, checked) => {
let {brand, channel, color, style, sort} = getSeoCheckedParamsName(sorts, checked);
const getListSeo = (sorts, checked, extend = {}) => {
let {brand, channel, color, style, sort} = Object.assign(getSeoCheckedParamsName(sorts, checked), extend);
if (brand && _.indexOf(brand, '、') > -1) {
brand = '';
... ...
... ... @@ -13,6 +13,17 @@ const seoHandler = require('./seo-handler');
const utils = '../../../utils';
const productProcess = require(`${utils}/product-process-simple`);
const _handleImageUrl = (url) => {
if (url) {
let imgArr = _.split(url, '?', 1);
imgArr.push('imageView2/1/w/{width}/h/{height}/q/90');
url = imgArr.join('?');
}
return url;
};
const _setHotKeywordData = (result, params, channel) => {
let changeQuery = Object.assign({}, params);
let finalResult = {
... ... @@ -132,23 +143,26 @@ module.exports = class extends global.yoho.BaseModel {
}
if (!_.get(keyword, 'name')) {
return Promise.reject(`cannot find hot keywords by id(${id})`);
logger.error(`cannot find hot keywords by id(${id})`);
return false;
}
params.query = keyword.name;
return this.getSearchProduct(params, channel).then(result => {
const keyNum = 10;
let hotKeys = (keyword.data || []).map(val => {
val.href = helpers.urlFormat(`/hot/${val.id}.html`);
return val;
});
let seoTDK = seoHandler.getHotKeywordsSeo(keyword.name, _.get(result, 'product.totalCount', '多'));
keyword.list = _.take(hotKeys, 6);
keyword.goods_img = _handleImageUrl(keyword.goods_img);
keyword.list = _.take(hotKeys, keyNum);
keyword.describe = keyword.describe || seoTDK.description;
Object.assign(result, {
hotKeys: _.drop(hotKeys, 6),
hotKeys: _.drop(hotKeys, keyNum),
keyword: keyword
}, seoTDK);
... ...
... ... @@ -22,7 +22,7 @@
{{/if}}
</div>
</div>
<img class="thumb" src="{{image2 goods_img}}" alt="{{name}}">
<img class="thumb" src="{{image2 goods_img w=300 h=300}}" alt="{{name}}">
{{/ keyword}}
</div>
... ...
... ... @@ -43,6 +43,7 @@ module.exports = () => {
return (req, res, next) => {
let domain = 'm.yohobuy.com';
let proRegNew = /^\/product\/([\d]+).html(.*)/;
let hotReg = /^\/hot\/([\d]+).html(.*)/;
if (!req.xhr) {
let url = _.head(_.split(req.url, '?'));
... ... @@ -56,6 +57,8 @@ module.exports = () => {
data.mobileRefer = `//${domain}/guang?${queryString.stringify(req.query)}`;
} else if (proRegNew.test(url)) {
data.mobileRefer = url.replace(proRegNew, `//${domain}/product/$1.html$2`);
} else if (hotReg) {
data.mobileRefer = `//${domain}/mip${url}`;
}
// 设置不需要跳转页面
... ...
... ... @@ -12,7 +12,7 @@
position: relative;
.sort-intro {
width: 488px;
width: 650px;
height: 300px;
line-height: 300px;
border: 1px solid #eaeceb;
... ... @@ -21,7 +21,7 @@
.inline {
width: 100%;
padding: 0 50px;
padding: 0 30px;
line-height: 1;
text-align: center;
display: inline-block;
... ... @@ -53,7 +53,7 @@
margin-top: 30px;
> li {
width: 33.33%;
width: 20%;
text-align: center;
float: left;
font-size: 12px;
... ... @@ -67,7 +67,7 @@
}
.thumb {
width: 480px;
width: 300px;
height: 300px;
position: absolute;
top: 0;
... ...