Authored by yyq

新品到着伪静态

... ... @@ -67,9 +67,10 @@ exports.index = (req, res, next) => {
exports.new = (req, res, next) => {
let resData = {};
req.ctx(list).getListNewDataPre(Object.assign({order: 's_t_desc'}, req.query), req.yoho.channel).then(result => {
req.ctx(list).getListNewData(Object.assign({order: 's_t_desc'}, req.query), req.yoho.channel).then(result => {
Object.assign(resData, result, {
hideInfo: {from: 'newProduct'}
hideInfo: {from: 'newProduct'},
pageClass: 'static-list-page'
});
// 查询结果为空则不cache
... ... @@ -88,10 +89,12 @@ exports.new = (req, res, next) => {
* @return {[type]} [description]
*/
exports.newWithChannel = (req, res, next) => {
let channel = req.params[0];
let channel = req.pathChannel;
req.query = req.query || {};
req.yoho.channel = channel;
// 根据 XXXX-new 中的频道处理查询参数
switch (channel) {
case 'boys':
... ...
... ... @@ -108,6 +108,10 @@ const suggest4Old = (req, res, next) => {
const searchFilterBrands = (req, res, next) => {
let params = req.query;
const callback = req.query.callback;
_.unset(params, 'callback');
_.unset(params, '_');
if (params.pathname) {
let path = _.last(_.compact(_.split(params.pathname, '/')));
... ... @@ -125,7 +129,7 @@ const searchFilterBrands = (req, res, next) => {
};
res.type('text/javascript');
res.send(req.query.callback + '(' + JSON.stringify(dest) + ')');
res.send(callback + '(' + JSON.stringify(dest) + ')');
}).catch(next);
};
... ...
... ... @@ -384,7 +384,7 @@ class FilterTools {
}
});
if (brandsShow.length > 10) {
if (brandsShow.length > 9) {
_.assign(brands, {
showMore: true,
showMulti: true,
... ... @@ -822,11 +822,49 @@ const handlePagerData = (total, params, noNextBtn, baseUrl) => {
return {tip, prePage, nextPage, pages};
};
/**
* 一周新品上架
* @type {[type]}
*/
const handleWeekNew = (data, params, baseUrl) => {
let list = [];
let dest = {
newSales: {
name: '',
list: []
}
};
const href = handleFilterUrl(baseUrl, params, {shelveTime: '{shelveTime}'});
_.forEach(data.recent, function(value, key) {
let t = _.split(key, '-'),
dayStart = new Date(t[0], _.parseInt(t[1]) - 1, t[2]).getTime() / 1000,
day = `${dayStart},${dayStart + 86400}`;
list.push({
name: `${t[1] || ''}${t[2] || ''}日`,
href: href.replace('{shelveTime}', day),
active: day === params.shelveTime,
sort: +t.join('')
});
});
_.set(dest, 'newSales.list', _.sortBy(list, function(o) {
return -o.sort;
}));
return dest;
};
module.exports = {
handlePathNavData,
handleSortData,
handleFilterData,
handleOptsData,
handleNextPage,
handlePagerData
handlePagerData,
handleWeekNew
};
... ...
... ... @@ -15,11 +15,7 @@ const shopHandler = require('./shop-handler');
const helpers = global.yoho.helpers;
const crypto = global.yoho.crypto;
const _ = require('lodash');
const Fn = require('lodash/fp');
const md5 = require('md5');
const cache = global.yoho.cache;
const config = global.yoho.config;
const logger = global.yoho.logger;
const redis = global.yoho.redis;
// const limitNum = 60; // 商品每页显示数目
... ... @@ -36,15 +32,6 @@ const positionId = 10;
// 获取分类左侧广告id
const sortAdsId = 79;
const CACHE_TIME_S = 60;
function _getCacheKey(params, page) {
let sortByKey = Fn.pipe(Fn.toPairs, Fn.sortBy(0), Fn.flatten);
let genKey = Fn.pipe(Fn.cloneDeep, sortByKey, Fn.join('_'));
return `render_cache_${page}_${md5(genKey(params))}`;
}
/**
* 获取商品分类列表数据
*/
... ... @@ -198,6 +185,8 @@ function getListNewData(params, channel) {
};
let dps = {};
const baseUrl = `/${_.toLower(channel)}-new`; // 查询参数静态化base uri
_.forEach(needParams, (value) => {
if (params[value]) {
dps[value] = params[value];
... ... @@ -206,15 +195,13 @@ function getListNewData(params, channel) {
// 获取左侧类目数据
if (result[1].code === 200) {
finalResult.list = Object.assign(
searchHandler.handlePathNavData(result[1].data, params, 'new', channel), {
leftContent: searchHandler.handleSortData(result[1].data, dps, params)
});
finalResult.list = listHandler.handlePathNavData(result[1].data, params, 'new', channel, baseUrl);
finalResult.list.leftContent = listHandler.handleSortData(result[1].data, dps, params, baseUrl);
}
// 获取商品数据和顶部筛选条件
if (result[2].code === 200) {
let filters = Object.assign(searchHandler.handleFilterDataAll(result[2].data, params),
let filters = Object.assign(listHandler.handleFilterData(result[2].data, params, baseUrl),
finalResult.list.leftContent.sort);
filters.checkedConditions.conditions = _.concat(filters.checkedConditions.conditions,
... ... @@ -222,15 +209,15 @@ function getListNewData(params, channel) {
Object.assign(finalResult.list, {
filters: filters,
opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
opts: listHandler.handleOptsData(params, result[2].data.total, result[2].data.filter, baseUrl),
totalCount: result[2].data.total,
footPager: searchHandler.handlePagerData(result[2].data.total, params),
footPager: listHandler.handlePagerData(result[2].data.total, params, false, baseUrl),
goods: productProcess.processProductList(result[2].data.product_list,
Object.assign({
showDiscount: false, showNew: false,
from: {type: 'listNew', params: params}
}, params)),
hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
hasNextPage: listHandler.handleNextPage(params, result[2].data.total, baseUrl),
// 最近浏览记录
latestWalk: 7
... ... @@ -239,7 +226,7 @@ function getListNewData(params, channel) {
// 新品上架
if (result[3] && result[3].code === 200) {
Object.assign(finalResult.list.leftContent, searchHandler.handleWeekNew(result[3].data, dps));
Object.assign(finalResult.list.leftContent, listHandler.handleWeekNew(result[3].data, dps, baseUrl));
}
finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.list, 'goods'))};
... ... @@ -251,49 +238,6 @@ function getListNewData(params, channel) {
});
}
function getListNewDataPre(params, channel) {
let cKey = _getCacheKey(Object.assign({channel: channel}, params), 'listnew');
let getOriginData = () => {
return this.getListNewData(params, channel).then(result => {
// 查询结果为空则不cache
if (config.useCache && !_.isEmpty(_.get(result, 'list.goods', []))) {
cache.set(cKey, result, CACHE_TIME_S)
.catch(err => logger.debug(`list_new render cache data save fail:${err.toString()}`));
}
return result;
});
};
if (config.useCache) {
return cache.get(cKey).catch(err => {
logger.debug(`get list_new render cache data fail:${err.toString()}`);
return getOriginData();
}).then(cdata => {
let hasCache = false;
if (cdata) {
try {
cdata = JSON.parse(cdata);
hasCache = true;
} catch (e) {
logger.debug('list_new render cache data parse fail.');
}
}
if (hasCache) {
return cdata;
} else {
return getOriginData();
}
});
}
return getOriginData();
}
/**
* 根据品牌域名查询品牌信息
*/
... ... @@ -668,7 +612,6 @@ module.exports = class extends global.yoho.BaseModel {
this.getListData = getListData.bind(this);
this.getListNewData = getListNewData.bind(this);
this.getListNewDataPre = getListNewDataPre.bind(this);
this.getBrandInfo = getBrandInfo.bind(this);
this.getBrandData = getBrandData.bind(this);
this.getBrandAbout = getBrandAbout.bind(this);
... ...
... ... @@ -106,7 +106,7 @@ router.get(/\/global\/([\d]+)(.*)/, globalCtrl.detail);
// router.get(/\/global\/([\d]+)(.*)/, globalCtrl.detail); // 全球购商品详情页
// 搜索
router.get('/search/index', gbk2utf, search.index);
router.get('/search', gbk2utf, search.index);
router.get('/search/filter/brands', search.searchFilterBrands);
router.get('/search/suggest', search.suggest); // 搜索提示
router.get('/api/suggest', search.suggest4Old);
... ... @@ -116,8 +116,8 @@ router.get('/search/keyword/:id', search.keyword);
router.get('/search/chanpin/:id', search.keyId);
// 新品到着
router.get('/list/new', list.new);
router.get(/\/list\/(.*)-new/, list.newWithChannel);
router.get('/list/new', list.newWithChannel);
router.get('/list/new/:pathQs', paramParse, list.newWithChannel);
// 商品分类列表页
router.get('/list', gbk2utf, list.index);
... ...
... ... @@ -5,7 +5,7 @@
'use strict';
// const _ = require('lodash');
// const helpers = global.yoho.helpers;
const helpers = global.yoho.helpers;
// const mapSort = require(`${global.utils}/map-sort`);
const TYPE = require('../type');
... ... @@ -138,15 +138,18 @@ module.exports = [
target: '/product/list/index'
},
{
type: TYPE.rewrite,
origin: /\/(.*)-new/,
target: (req, match, channel) => {
return `/product/list/${channel}-new`;
}
type: TYPE.redirect,
origin: /^\/(boys|girls|kids|lifestyle)-new(\/*)/,
target: req => helpers.urlFormat(req.url)
},
{
type: TYPE.rewrite,
origin: req => req.path === '/new',
target: '/product/list/new'
type: TYPE.redirect,
origin: req => {
return req.path === '/new' || req.path === '/new/';
},
target: req => {
console.log(helpers.urlFormat(`/list${req.url}`));
return helpers.urlFormat(`/list${req.url}`);
}
}
];
... ...
'use strict';
const TYPE = require('../type');
const helpers = global.yoho.helpers;
module.exports = [
{
type: TYPE.redirect,
origin: /.*/,
target: req => helpers.urlFormat(`/search${req.url}`)
}
];
... ...
... ... @@ -104,7 +104,8 @@ module.exports = [
type: TYPE.rewrite,
origin: /^\/(boys|girls|kids|lifestyle)-new/,
target: (req, match, channel) => {
return `/product/list/${channel}-new`;
req.pathChannel = channel;
return '/product/list/new';
}
},
... ... @@ -185,5 +186,12 @@ module.exports = [
req.query.shopId = id;
return '/product/index/about';
}
}
},
{
type: TYPE.rewrite,
origin: /^\/(list|search|new|sale|shop)(.*)$/,
target: (req) => {
return `/product${req.url}`;
}
},
];
... ...
... ... @@ -13,15 +13,6 @@ module.exports = () => {
switch (req.subdomains[0]) {
case 'www': // 主站
case 'cdnsrcwww': // 主站的回源地址
{ // eslint-disable-line
let shopReg = /^\/shop\/(.*)\.html(.*)$/;
if (shopReg.test(req.path) || listReg.test(req.path)) {
req.url = `/product${req.url}`;
}
break;
}
case 'shop': // 商家入驻
case 'new':
case 'item':// 商品详情页
... ...
... ... @@ -119,7 +119,7 @@
{{/unless}}
<ul class="search-suggest-history"></ul>
<div class="search-2016">
<form action="//search.yohobuy.com" method="get" id="search-form">
<form action="//www.yohobuy.com/search" method="get" id="search-form">
<input type="hidden" id="defaultsearch" value="{{defaultSearch}}">
<input class="search-key" type="text" name="query" id="query-key" autocomplete="off" x-webkit-speech="" lang="zh-CN" x-webkit-grammar="builtin:translate" value="" maxlength="30">
<a class="search-btn" href="javascript:submitSearch();"></a>
... ... @@ -290,4 +290,4 @@
<h5 class="code-title">下载手机客户端</h5>
<i class="iconfont icon-del"></i>
</div>
{{/ headerData}}
\ No newline at end of file
{{/ headerData}}
... ...
... ... @@ -345,7 +345,7 @@ function searchSuggest(key) {
keyword: key
};
$.getJSON('//search.yohobuy.com/product/search/suggest?callback=?', param, function(jsonData) {
$.getJSON('/product/search/suggest?callback=?', param, function(jsonData) {
var searchSuggestHtml;
if (jsonData.code === 200) {
... ... @@ -365,7 +365,7 @@ function submitSearch() {
searchKey = $.trim(searchKey.toLowerCase());
if (reg.test(searchKey) && searchKey !== '') {
location.href = '//search.yohobuy.com/error?query=' + searchKey;
location.href = '/error?query=' + searchKey;
} else {
if (searchKey === '') {
$('#query-key').val(defaultSearch);
... ...
... ... @@ -13,36 +13,37 @@ const queryString = require('querystring');
const minToFullMap = {
ag: 'age_level',
cn: 'channel',
gd: 'gender',
sn: 'sort_name',
bd: 'brand',
cc: 'coupon_code',
cd: 'coupon_id',
ci: 'category_id',
so: 'sort',
ms: 'msort',
mi: 'misort',
tp: 'type',
sz: 'size',
cl: 'color',
pc: 'price',
bd: 'brand',
qr: 'query',
lt: 'limit',
cn: 'channel',
fp: 'filter_poolId',
gd: 'gender',
ld: 'limited',
od: 'order',
lt: 'limit',
mi: 'misort',
ms: 'msort',
nw: 'new',
od: 'order',
ol: 'outlets',
pc: 'price',
pd: 'p_d',
pg: 'page',
st: 'style',
pm: 'promotion',
pp: 'productPool',
qr: 'query',
sd: 'standard',
si: 'specialsale_id',
se: 'shelveTime',
sf: 'specialoffer',
fp: 'filter_poolId',
pp: 'productPool',
pm: 'promotion',
sh: 'shop_id',
cc: 'coupon_code',
cd: 'coupon_id',
pd: 'p_d',
ol: 'outlets'
si: 'specialsale_id',
sn: 'sort_name',
so: 'sort',
st: 'style',
sz: 'size',
tp: 'type'
};
const fullToMinMap = _.transform(minToFullMap, (result, value, key) => {
... ...