Authored by yyq

chanpin page

/**
* chanpin controller
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2017/09/22
*/
const _ = require('lodash');
const helpers = global.yoho.helpers;
const utils = '../../../utils';
const searchProcess = require(`${utils}/search-process`);
const stringCode = require(`${utils}/string-code`);
const chanpin = require('../models/chanpin');
const headerModel = require('../../../doraemon/models/header');
// 关键词页
const keyword = (req, res, next) => {
let queryKey = stringCode.hexToUtf8(`${req.params.query}`);
let params = {
isSearch: true, // 搜索列表将最新改成默认的标识
cartUrl: helpers.urlFormat('/cart/index/index'),
query: queryKey
};
params.isApp = req.yoho.isApp;
params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":${JSON.stringify(params)}}`;
return req.ctx(chanpin).getSearchKeywordData(params, req.user.uid).then(result => {
res.render('search/list', {
_noLazy: true,
module: 'product',
page: 'chanpin',
pageHeader: headerModel.setNav({
navTitle: queryKey
}),
goodList: params,
firstPageGoods: result || [],
fuzzyWord: result.fuzzyWord,
title: `${queryKey}价格_图片_品牌_怎么样-YOHO!BUY有货`,
keywords: `${queryKey},${queryKey}价格,${queryKey}图片,${queryKey}怎么样,${queryKey}品牌,YOHO!BUY有货`,
description: `YOHO!BUY有货网yohobuy.com是国内专业的${queryKey}网上潮流购物商城,为您找到${_.get(result,
'total', 0)}${queryKey}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${queryKey},就上YOHO!BUY有货`,
pageFooter: true
});
}).catch(next);
};
// 关键词页with id
const keyId = (req, res, next) => {
let params = {
isSearch: true, // 搜索列表将最新改成默认的标识
cartUrl: helpers.urlFormat('/cart/index/index')
};
params.isApp = req.yoho.isApp;
params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);
return req.ctx(chanpin).getSearchKeywordDataById(req.params.id, params, req.user.uid).then(result => {
let queryKey = result.queryKey;
if (!result) {
return next();
}
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":${JSON.stringify(params)}}`;
res.render('search/list', {
_noLazy: true,
module: 'product',
page: 'chanpin',
pageHeader: headerModel.setNav({
navTitle: queryKey
}),
goodList: params,
firstPageGoods: result || [],
fuzzyWord: result.fuzzyWord,
title: `${queryKey}价格_图片_品牌_怎么样-YOHO!BUY有货`,
keywords: `${queryKey},${queryKey}价格,${queryKey}图片,${queryKey}怎么样,${queryKey}品牌,YOHO!BUY有货`,
description: `YOHO!BUY有货网yohobuy.com是国内专业的${queryKey}网上潮流购物商城,为您找到${_.get(result,
'total', 0)}${queryKey}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${queryKey},就上YOHO!BUY有货`,
pageFooter: true,
cononical: {
currentHref: `//www.yohobuy.com${req.originalUrl}`
}
});
}).catch(next);
};
const searchGoods = (req, res, next) => {
let params = Object.assign({}, req.query);
let uid = req.user.uid || 0;
if (uid) {
params.uid = uid;
}
params.isApp = req.yoho.isApp;
params.limit = 24;
return req.ctx(chanpin).getSeoSearchData(params).then((result) => {
if (result.list && result.list.length > 0) {
res.render('search/page', {
layout: false,
new: result.list,
suggestion: result.suggestion || [],
total: result.total,
_noLazy: params.noLazy || false
});
} else {
res.json(result);
}
}).catch(next);
};
module.exports = {
keyword,
keyId,
searchGoods
};
... ...
... ... @@ -13,7 +13,6 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
const searchProcess = require(`${utils}/search-process`);
const productProcess = require(`${utils}/product-process`);
const stringCode = require(`${utils}/string-code`);
const co = require('bluebird').coroutine;
/**
... ... @@ -271,83 +270,6 @@ let filter = (req, res, next) => {
}).catch(next);
};
// 关键词页
const keyword = (req, res, next) => {
let queryKey = stringCode.hexToUtf8(`${req.params.query}`);
let params = {
isSearch: true, // 搜索列表将最新改成默认的标识
cartUrl: helpers.urlFormat('/cart/index/index'),
query: queryKey
};
params.isApp = req.yoho.isApp;
params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":${JSON.stringify(params)}}`;
return searchModel.getSearchKeywordData(params, req.user.uid).then(result => {
res.render('search/list', {
_noLazy: true,
module: 'product',
page: 'search-list',
pageHeader: headerModel.setNav({
navTitle: queryKey
}),
goodList: params,
firstPageGoods: result || [],
fuzzyWord: result.fuzzyWord,
title: `${queryKey}价格_图片_品牌_怎么样-YOHO!BUY有货`,
keywords: `${queryKey},${queryKey}价格,${queryKey}图片,${queryKey}怎么样,${queryKey}品牌,YOHO!BUY有货`,
description: `YOHO!BUY有货网yohobuy.com是国内专业的${queryKey}网上潮流购物商城,为您找到${_.get(result,
'total', 0)}${queryKey}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${queryKey},就上YOHO!BUY有货`,
pageFooter: true
});
}).catch(next);
};
// 关键词页with id
const keyId = (req, res, next) => {
let params = {
isSearch: true, // 搜索列表将最新改成默认的标识
cartUrl: helpers.urlFormat('/cart/index/index')
};
params.isApp = req.yoho.isApp;
params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);
return searchModel.getSearchKeywordDataById(req.params.id, params, req.user.uid).then(result => {
let queryKey = result.queryKey;
if (!result) {
return next();
}
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.list","params":${JSON.stringify(params)}}`;
res.render('search/list', {
_noLazy: true,
module: 'product',
page: 'search-list',
pageHeader: headerModel.setNav({
navTitle: queryKey
}),
goodList: params,
firstPageGoods: result || [],
fuzzyWord: result.fuzzyWord,
title: `${queryKey}价格_图片_品牌_怎么样-YOHO!BUY有货`,
keywords: `${queryKey},${queryKey}价格,${queryKey}图片,${queryKey}怎么样,${queryKey}品牌,YOHO!BUY有货`,
description: `YOHO!BUY有货网yohobuy.com是国内专业的${queryKey}网上潮流购物商城,为您找到${_.get(result,
'total', 0)}${queryKey}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${queryKey},就上YOHO!BUY有货`,
pageFooter: true,
cononical: {
currentHref: `//www.yohobuy.com${req.originalUrl}`
}
});
}).catch(next);
};
/**
* 搜索品牌下的商品
*/
... ... @@ -410,8 +332,6 @@ module.exports = {
search,
index,
fuzzyDatas,
keyword,
keyId,
searchBrandGoods,
searchShopGoods
};
... ...
/**
* chanpin model
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2017/09/22
*/
const _ = require('lodash');
const helpers = global.yoho.helpers;
const utils = '../../../utils';
const redis = require(`${utils}/redis`);
const searchProcess = require(`${utils}/search-process`);
const productProcess = require(`${utils}/product-process`);
const stringCode = require(`${utils}/string-code`);
/**
* 封面图
* @type {{boys: string, gilrs: string}}
*/
const _coverChannel = {
boys: '1,3',
gilrs: '2,3'
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getFuzzyDatas(params) {
return this.get({
data: {
method: 'app.search.fuzzy',
keyword: params
},
param: {cache: true}
}).then((result) => {
return _.get(result, 'data', []);
});
}
getSeoSearchData(params) {
let finalParams = {
method: 'app.search.li',
};
finalParams = _.assign(finalParams, searchProcess.getSearchParamsWithoutMethod(params));
return this.get({data: finalParams}).then(result => {
let resData = {};
resData.list = productProcess.processProductList(_.get(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
});
return resData;
});
}
getSearchKeywordData(params, uid) {
// 获取第一页数据做服务端渲染
let initialData = _.assign({
type: 'default',
order: '0',
page: 1,
limit: 24
}, params);
if (uid) {
initialData.uid = uid;
}
return Promise.all([
this.getFuzzyDatas(`${params.query}`.substr(0, 2)),
this.getSeoSearchData(initialData)
]).then(result => {
let resData = result[1];
let fuzzy = [];
if (_.isEmpty(result[0])) {
result[0] = [];
}
_.forEach(_.slice(result[0], 0, 12), value => {
if (value.keyword === params.query) {
return;
}
fuzzy.push({
name: value.keyword,
link: helpers.urlFormat(`/so/${stringCode.utf8ToHex(value.keyword)}.html`),
});
});
if (!_.isEmpty(fuzzy)) {
resData.fuzzyWord = fuzzy;
}
return resData;
});
}
getSearchKeywordDataById(id, params, uid) {
return redis.all([
['get', `global:yoho:seo:keywords:id:${id}`]
]).then(redisData => {
if (!redisData[0]) {
return false;
}
redisData = JSON.parse(redisData[0]);
params.query = redisData.name;
return this.getSearchKeywordData(params, uid).then(result => {
result.queryKey = params.query;
let fuzzyWord = [];
if (!_.isEmpty(redisData.data)) {
_.forEach(_.slice(redisData.data, 0, 12), value => {
if (!value) {
return;
}
fuzzyWord.push(Object.assign(value, {
name: value.keyword,
link: helpers.urlFormat(`/chanpin/${value.id}.html`, null)
}));
});
_.set(result, 'fuzzyWord', fuzzyWord);
}
return result;
});
});
}
};
... ...
... ... @@ -7,13 +7,11 @@
const utils = '../../../utils';
const productProcess = require(`${utils}/product-process`);
const searchProcess = require(`${utils}/search-process`);
const stringCode = require(`${utils}/string-code`);
const _ = require('lodash');
const logger = global.yoho.logger;
const api = global.yoho.API;
const cache = require('memory-cache');
const helpers = global.yoho.helpers;
const redis = require(`${utils}/redis`);
const co = require('bluebird').coroutine;
/**
... ... @@ -540,84 +538,6 @@ const getBrandDomain = (query) => {
}
};
const getSearchKeywordData = (params, uid) => {
// 获取第一页数据做服务端渲染
let initialData = _.assign({
type: 'default',
order: '0',
page: 1,
limit: 24
}, params);
if (uid) {
initialData.uid = uid;
}
return Promise.all([
getFuzzyDatas(`${params.query}`.substr(0, 2)),
getSearchData(initialData)
]).then(result => {
let fuzzy = [];
if (_.isEmpty(result[0])) {
result[0] = [];
}
_.forEach(_.slice(result[0], 0, 12), value => {
if (value.keyword === params.query) {
return;
}
fuzzy.push({
name: value.keyword,
link: helpers.urlFormat(`/so/${stringCode.utf8ToHex(value.keyword)}.html`),
});
});
if (!_.isEmpty(fuzzy)) {
result[1].fuzzyWord = fuzzy;
}
return result[1];
});
};
const getSearchKeywordDataById = (id, params, uid) => {
return redis.all([
['get', `global:yoho:seo:keywords:id:${id}`]
]).then(redisData => {
if (!redisData[0]) {
return false;
}
redisData = JSON.parse(redisData[0]);
params.query = redisData.name;
return getSearchKeywordData(params, uid).then(result => {
result.queryKey = params.query;
if (!_.isEmpty(redisData.data)) {
_.forEach(redisData.data, value => {
if (!value) {
return;
}
Object.assign(value, {
name: value.keyword,
link: helpers.urlFormat(`/chanpin/${value.id}.html`, null)
});
});
_.set(result, 'fuzzyWord', redisData.data);
}
return result;
});
});
};
/**
* 通过 skn 搜索商品
* @param productSkn
... ... @@ -643,8 +563,6 @@ module.exports = {
getFuzzyDatas,
searchKeyActivity,
getBrandDomain,
getSearchKeywordData,
getSearchKeywordDataById,
getSearchGoods,
getBrandGoods,
getShopGoods,
... ...
... ... @@ -59,6 +59,9 @@ const globalPro = require(`${cRoot}/global`);
// 找相似
const similar = require(`${cRoot}/similar`);
// seo推广
const chanpin = require(`${cRoot}/chanpin`);
// routers
// /pro_136349_455445/HEARTSOFARMianMaShuJiaoXiuXianKuPS1684.html
... ... @@ -135,8 +138,9 @@ router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表
router.get('/search/index', search.index);
// 推广落地页
router.get('/search/so/:query.html', rewrite.sortParams, search.keyword);
router.get('/search/chanpin/:id.html', rewrite.sortParams, search.keyId);
router.get('/search/so/:query.html', rewrite.sortParams, chanpin.keyword);
router.get('/search/chanpin/:id.html', rewrite.sortParams, chanpin.keyId);
router.get('/search/chanpin/goods', chanpin.searchGoods); // 搜索的商品
// 搜索落地页
router.get('/search/list', rewrite.sortParams, search.list);
... ...
... ... @@ -106,7 +106,7 @@ module.exports = {
jsSdk: '//cdn.yoho.cn/js-sdk/1.2.2/jssdk.js',
redis: {
connect: {
host: '127.0.0.1',
host: '192.168.102.49',
port: '6379',
retry_strategy(options) {
if (options.error && options.error.code === 'ECONNREFUSED') {
... ...
/**
* seo推广落地页
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/7/21
*/
require('product/search/list.page.css');
const $ = require('yoho-jquery');
const ProductListWithFilter = require('product/list/product-list-with-filter');
require('common/footer');
new ProductListWithFilter({
query: $.trim($('.nav-title').text()),
page: 2, // 首页服务端已经渲染
}, 'product/search/chanpin/goods').getFilter();
... ...
... ... @@ -17,8 +17,8 @@ class ProductListWithFilter {
constructor(filterParams, searchUrl, extra) {
this.scrollActived = true; // 是否激活滚动加载,默认激活
this.filterParams = filterParams;
this.searchUrl = location.protocol + '//m.yohobuy.com/' + (searchUrl || 'product/search/search');
this.filterUrl = location.protocol + '//m.yohobuy.com/product/search/filter';
this.searchUrl = '/' + (searchUrl || 'product/search/search');
this.filterUrl = '/product/search/filter';
this.goodsTotal = extra && extra.goodsTotal; // YAS 需要数据
this.view = {
goodsContainer: $('#goods-container'),
... ...
... ... @@ -100,6 +100,10 @@ const getListSeoData = (gender, sort_name) => {
const getSearchParamsWithoutMethod = (params) => {
let finalParams = {};
if (params.query) {
finalParams.query = params.query;
}
if (params.yh_channel) {
finalParams.yh_channel = params.yh_channel;
}
... ...