...
|
...
|
@@ -10,12 +10,26 @@ const mRoot = '../models'; |
|
|
const headerModel = require('../../../doraemon/models/header');
|
|
|
const listModel = require(`${mRoot}/list`);
|
|
|
const _ = require('lodash');
|
|
|
const md5 = require('yoho-md5');
|
|
|
const co = Promise.coroutine;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
const searchModel = require(`${mRoot}/search`);
|
|
|
const shopModel = require(`${mRoot}/shop`);
|
|
|
const searchProcess = require(`${utils}/search-process`);
|
|
|
const stringProcess = require(`${utils}/string-process`);
|
|
|
const listParamsProcess = require(`${utils}/list-params-process`);
|
|
|
const redis = require(`${utils}/redis`);
|
|
|
const logger = global.yoho.logger;
|
|
|
|
|
|
/**
|
|
|
* 封面图
|
|
|
* @type {{boys: string, gilrs: string}}
|
|
|
*/
|
|
|
const _coverChannel = {
|
|
|
boys: '1,3',
|
|
|
gilrs: '2,3'
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 从 useragent 获取 uid
|
...
|
...
|
@@ -212,6 +226,7 @@ const category = (req, res, next) => { |
|
|
}
|
|
|
|
|
|
let params = Object.assign({}, req.query);
|
|
|
let seoTitle = decodeURIComponent(req.query.title || req.query.sort_name || '商品列表');
|
|
|
|
|
|
/* 勿修改,唤起 APP 使用 */
|
|
|
let appParams = Object.assign({}, req.query, {
|
...
|
...
|
@@ -248,8 +263,12 @@ const category = (req, res, next) => { |
|
|
_noLazy: true, // 首屏不使用lazyload
|
|
|
module: 'product',
|
|
|
page: 'search-list',
|
|
|
|
|
|
// canonical: {
|
|
|
// currentHref: 'https://www.yohobuy.com/list?' // TODO
|
|
|
// },
|
|
|
pageHeader: headerModel.setNav({
|
|
|
navTitle: req.query.title || req.query.sort_name
|
|
|
navTitle: seoTitle
|
|
|
}),
|
|
|
goodList: params,
|
|
|
firstPageGoods: firstPageGoods || [],
|
...
|
...
|
@@ -260,7 +279,154 @@ const category = (req, res, next) => { |
|
|
localCss: true,
|
|
|
appPath: appPath,
|
|
|
introText: req.query.intro_text
|
|
|
}, searchProcess.getListSeoData(req.query.gender, req.query.title || req.query.sort_name)));
|
|
|
}, searchProcess.getListSeoData(req.query.gender, seoTitle)));
|
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 品类落地页 SEO 友好的新路由
|
|
|
*/
|
|
|
const listNew = (req, res, next) => {
|
|
|
req.query = listParamsProcess.getParams(req.url);
|
|
|
|
|
|
if (req.query) {
|
|
|
_.forEach(req.query, (perParam, index) => {
|
|
|
req.query[index] = stringProcess.paramsFilter(perParam);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let params = Object.assign({}, req.query);
|
|
|
|
|
|
/* 勿修改,唤起 APP 使用 */
|
|
|
let appParams = Object.assign({}, req.query, {
|
|
|
title: req.query.title || req.query.sort_name || '',
|
|
|
productPool: req.query.filter_poolId,
|
|
|
actiontype: req.query.actiontype || '1'
|
|
|
});
|
|
|
|
|
|
delete appParams.filter_poolId;
|
|
|
|
|
|
let appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":' +
|
|
|
JSON.stringify(appParams) +
|
|
|
'}';
|
|
|
|
|
|
let uid = req.user.uid || 0;
|
|
|
|
|
|
// 获取第一页数据做服务端渲染
|
|
|
let initialData = _.assign({
|
|
|
gender: params.gender,
|
|
|
type: 'default',
|
|
|
order: '0',
|
|
|
page: 1,
|
|
|
limit: 24,
|
|
|
isApp: params.app_version
|
|
|
}, params);
|
|
|
|
|
|
if (uid) {
|
|
|
initialData.uid = uid;
|
|
|
}
|
|
|
co(function* () {
|
|
|
let result = yield req.ctx(searchModel).getCategoryGoods(initialData);
|
|
|
let categoryIntroRedis = [];
|
|
|
|
|
|
let responseResult = {
|
|
|
list: productProcess.processProductList(result.data.product_list || [], {
|
|
|
isApp: params.isApp || (params.appVersion && params.appVersion !== 'false'),
|
|
|
gender: _coverChannel[params.coverChannel],
|
|
|
showSimilar: params.shop_id || params.material === 'true' ? false : true
|
|
|
})
|
|
|
};
|
|
|
|
|
|
let seoTitle = _.get(result, 'data.filter.group_sort[0].sub[0].category_name');
|
|
|
|
|
|
if (!seoTitle || !initialData.category_id) {
|
|
|
seoTitle = '商品列表';
|
|
|
}
|
|
|
|
|
|
if (params.sort_name) {
|
|
|
try {
|
|
|
seoTitle = decodeURIComponent(params.sort_name);
|
|
|
} catch (e) {
|
|
|
logger.error('decodeURIComponent seoTitle: ' + e);
|
|
|
return res.redirect('/');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
categoryIntroRedis =
|
|
|
yield redis.hmgetAsync(`category:description:${md5(seoTitle)}`, 'category', 'description').timeout(200);
|
|
|
} catch (e) {
|
|
|
logger.error('redis.hmgetAsync.category.description:' + e);
|
|
|
}
|
|
|
|
|
|
let categoryIntro = categoryIntroRedis[1] ? {
|
|
|
title: categoryIntroRedis[0],
|
|
|
desc: categoryIntroRedis[1]
|
|
|
} : null;
|
|
|
|
|
|
res.render('search/goods-list', Object.assign({
|
|
|
_noLazy: true, // 首屏不使用lazyload
|
|
|
module: 'product',
|
|
|
page: 'search-list-new',
|
|
|
canonical: {
|
|
|
currentHref: `https://www.yohobuy.com${req.url}`
|
|
|
},
|
|
|
pageHeader: headerModel.setNav({
|
|
|
navTitle: seoTitle
|
|
|
}),
|
|
|
goodList: params,
|
|
|
firstPageGoods: responseResult || [],
|
|
|
showDownloadApp: true,
|
|
|
pageFooter: true,
|
|
|
category: true,
|
|
|
localCss: true,
|
|
|
appPath: appPath,
|
|
|
categoryIntro: categoryIntro
|
|
|
}, searchProcess.getListSeoData(req.query.gender, seoTitle)));
|
|
|
})().catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 品类落地页异步获取商品数据
|
|
|
*/
|
|
|
const getCategoryGoods = (req, res, next) => {
|
|
|
let allowOrigin = _.get(req, 'headers.origin', null) ?
|
|
|
req.headers.origin : req.protocol + '://' + req.headers.host;
|
|
|
|
|
|
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
|
|
|
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
|
|
|
|
let currentUrlParams = listParamsProcess.getParams(req.query.currentUrl);
|
|
|
|
|
|
delete req.query.currentUrl;
|
|
|
|
|
|
let params = _.assign({}, currentUrlParams, req.query);
|
|
|
let uid = req.user.uid || 0;
|
|
|
|
|
|
if (uid) {
|
|
|
params.uid = uid;
|
|
|
}
|
|
|
|
|
|
params.isApp = req.yoho.isApp;
|
|
|
params.limit = 24;
|
|
|
|
|
|
req.ctx(searchModel).getCategoryGoods(params).then((result) => {
|
|
|
if (result.data.product_list && result.data.product_list.length > 0) {
|
|
|
|
|
|
let product_list = productProcess.processProductList(result.data.product_list || [], {
|
|
|
isApp: params.isApp || (params.appVersion && params.appVersion !== 'false'),
|
|
|
gender: _coverChannel[params.coverChannel],
|
|
|
showSimilar: params.shop_id || params.material === 'true' ? false : true
|
|
|
});
|
|
|
|
|
|
res.render('search/page', {
|
|
|
layout: false,
|
|
|
new: product_list,
|
|
|
total: result.data.total,
|
|
|
});
|
|
|
} else {
|
|
|
res.json({});
|
|
|
}
|
|
|
}).catch(next);
|
|
|
};
|
|
|
|
...
|
...
|
@@ -543,5 +709,7 @@ module.exports = { |
|
|
shopFav,
|
|
|
baseShopFav,
|
|
|
shopCategory,
|
|
|
getBrandCouponsList
|
|
|
getBrandCouponsList,
|
|
|
listNew,
|
|
|
getCategoryGoods
|
|
|
}; |
...
|
...
|
|