Authored by 陈峰

逛和商品详情优化路由

... ... @@ -233,7 +233,7 @@ exports.index = (req, res, next) => {
value.cn_alphabet = productNameProcess(value.cn_alphabet);
}
value.url = helpers.urlFormat(`/product/p${value.product_id}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`;
value.url = helpers.urlFormat(`/product/${value.product_skn}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`; // 商品url改版
return value;
});
... ... @@ -431,7 +431,7 @@ exports.verifystudent = (req, res, next) => {
value.cn_alphabet = productNameProcess(value.cn_alphabet);
}
value.url = helpers.urlFormat(`/product/p${value.product_id}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`;
value.url = helpers.urlFormat(`/product/${value.product_skn}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`; // 商品url改版
return value;
});
return getUser(uid).then((user) => {
... ...
... ... @@ -146,7 +146,7 @@ const _formatOrderGoods = (orderGoods, count, haveLink, tickets) => {
/* 商品链接 */
if (haveLink && value.product_skn) {
Object.assign(goods, {
link: helpers.urlFormat('/product/show_' + value.product_skn + '.html')
link: helpers.urlFormat('/product/' + value.product_skn + '.html') // 商品url改版
});
}
... ...
... ... @@ -42,7 +42,7 @@ const getProductData = (params) => {
return '';
} else {
_.forEach(result.data, (item) => {
item.url = helpers.urlFormat(`/product/p${item.product_id}.html`); // eslint-disable-line
item.url = helpers.urlFormat(`/product/${item.productSkn}.html`); // 商品url改版 // eslint-disable-line
item.url = helpers.appUrlFormat(item.url, 'go.productDetail', {
product_skn: item.productSkn
});
... ...
... ... @@ -61,7 +61,7 @@ exports.ensure = (req, res, next) => {
page: 'seckill',
pageHeader: headerModel.setNav({
navTitle: '确认订单',
backUrl: '/product/show_' + skn + '.html'
backUrl: '/product/' + skn + '.html' // 商品url改版
}),
}, view));
}
... ... @@ -106,7 +106,7 @@ exports.ensure = (req, res, next) => {
page: 'seckill',
pageHeader: headerModel.setNav({
navTitle: '确认订单',
backUrl: '/product/show_' + skn + '.html'
backUrl: '/product/' + skn + '.html' // 商品url改版
}),
cartToken: crypto.encryption(SLAT, [sku, activityId].join(''))
}, view));
... ...
... ... @@ -102,7 +102,7 @@ const editorRedirect = (req, res, next) => {
if (param) {
param = '?' + param;
}
redirectUrl += `-${id}${param}/`;
redirectUrl += `-${id}/${param}/`;
res.redirect(redirectUrl);
} else {
return next();
... ...
... ... @@ -185,7 +185,7 @@ const getNewProduct = (brandId, gender, url, isApp) => {
list.cn_alphabet = productNameProcess(list.cn_alphabet);
}
let productUrl = '//m.yohobuy.com/product/p' + list.product_id + '.html';
let productUrl = '//m.yohobuy.com/product/' + list.product_skn + '.html'; // 商品url改版
if (isApp) {
productUrl += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${list.product_skn}"}}`;
... ...
... ... @@ -53,7 +53,7 @@ const favProduct = (uid, page, limit) => {
if (val.goodsId && val.cnAlphabet) {
obj = _.assign(obj, {
link: config.siteUrl + '/product/p' + val.productId + '.html'
link: config.siteUrl + '/product/' + val.productSkn + '.html' // 商品url改版
});
} else {
obj = _.assign(obj, {
... ... @@ -175,7 +175,7 @@ const favfavBrand = (uid, page, limit) => {
_.forEach(val.newProduct, function(data, key) {
obj.productList.push({
link: '/product/p' + data.productId + '.html',
link: '/product/' + data.productSkn + '.html', // 商品url改版
imgUrl: data.defaultImages,
price: '¥' + Number(data.marketPrice).toFixed(2),
discount: data.marketPrice > data.salesPrice ? '¥' + Number(data.salesPrice).toFixed(2) : false,
... ...
... ... @@ -258,7 +258,7 @@ const recordContent = (uid, udid, page, limit) => {
product_skn: val.product_skn,
storage: val.storage,
image: val.image,
link: '/product/show_' + val.product_skn + '.html',
link: '/product/' + val.product_skn + '.html', // 商品url改版
sales_price: val.sales_price,
market_price: (val.market_price - val.sales_price) > 0 ? val.market_price : false,
invalidGoods: val.status === 0
... ...
... ... @@ -51,7 +51,7 @@ const _formatOrderGoods = (orderGoods, count, haveLink, tickets) => {
/* 商品链接 */
if (haveLink && value.product_skn) {
Object.assign(goods, {
link: helpers.urlFormat('/product/show_' + value.product_skn + '.html')
link: helpers.urlFormat('/product/' + value.product_skn + '.html') // 商品url改版
});
}
... ...
... ... @@ -239,7 +239,7 @@ const orderDetailData = (uid, orderCode) => {
if (data.productSkn) {
obj = _.assign(obj, {
link: '/product/show_' + data.productSkn + '.html'
link: '/product/' + data.productSkn + '.html' // 商品url改版
});
}
... ...
... ... @@ -64,21 +64,33 @@ const newDetail = {
// 301到新路由
indexRedirect(req, res, next) {
if (req.params[0] && req.params[1]) {
let redirectUrl = '/product/';
let param = qs.stringify(req.query);
if (req.yoho.channel !== req.cookies._Channel) {
redirectUrl += `${req.yoho.channel}-`;
if (param) {
param = '?' + param;
}
return new Promise((resolve, reject) => {
if (req.params[0] && req.params[1]) {
newDetailModel.getProductData({
id: req.params[0],
ua: req.get('user-agent') || ''
}).then(result => {
if (_.isEmpty(result)) {
return reject();
}
resolve(result.productSkn);
}).catch(next);
} else if (req.params[0]) {
resolve(req.params[0]);
} else {
reject();
}
let param = qs.stringify(req.query);
}).then(skn => {
return res.redirect(`/product/${skn}.html${param}`);
}, () => {
return next();
});
if (param) {
param = '?' + param;
}
redirectUrl += `p${req.params[0]}.html${param}`;
return res.redirect(redirectUrl);
}
next();
},
... ...
... ... @@ -596,7 +596,7 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => {
// 用户未登录时
if (!uid) {
dest.loginUrl = helpers.urlFormat('/signin.html', {
refer: helpers.urlFormat('/product/show_' + origin.product_skn + '.html')
refer: helpers.urlFormat('/product/' + origin.product_skn + '.html') // 商品url改版
});
}
... ...
... ... @@ -104,7 +104,7 @@ const selectHotrank = (yhChannel, gender, sort, tabId, limit, page, notab) => {
}
one = _.assign(one, {
url: '/product/p' + data.product_id + '.html',
url: '/product/' + data.product_skn + '.html', // 商品url改版
thumb: data.default_images,
rank: limit * (page - 1) + index + 1,
name: data.product_name,
... ...
... ... @@ -16,7 +16,6 @@ const yhchannelMap = {
kids: '3',
lifestyle: '4'
};
const proUrlReg = /\/pro_(\d+)_\d+\//;
module.exports = (data) => {
return api.get('', {
... ... @@ -31,10 +30,10 @@ module.exports = (data) => {
goodThumb.each(function(index, domEle) {
let href = $(domEle).attr('href').split('?')[0];
let matchs = href.match(proUrlReg);
let skn = $(domEle).closest('.good-info').data('id');
if (matchs) {
href = helpers.urlFormat(`/product/p${matchs[1]}.html`);
if (skn) {
href = helpers.urlFormat(`/product/${skn}.html`); // 商品url改版
}
$(domEle).attr('href', href);
});
... ...
... ... @@ -34,7 +34,7 @@ const getPreferenceData = (data) => {
product_name: value.product_name,
default_images: value.default_images,
is_soon_sold_out: value.is_soon_sold_out === 'Y',
url: helpers.urlFormat(`/product/p${value.product_id}.html`),
url: helpers.urlFormat(`/product/${value.product_skn}.html`), // 商品url改版
market_price: value.market_price,
sales_price: value.sales_price
};
... ...
... ... @@ -160,7 +160,7 @@ const _getLimitCodeUrl = (productCode, skn, ua) => {
// if (!uid) {
// let params = {};
// params.refer = helpers.urlFormat('/product/show_' + origin.erpProductId + '.html');
// params.refer = helpers.urlFormat('/product/' + origin.erpProductId + '.html');
// dest.loginUrl = helpers.urlFormat('/signin.html', params);
// }
... ... @@ -579,7 +579,7 @@ const _getLimitCodeUrl = (productCode, skn, ua) => {
// // 用户未登录时
// if (!uid) {
// dest.loginUrl = helpers.urlFormat('/signin.html', {
// refer: helpers.urlFormat('/product/show_' + origin.productSkn + '.html')
// refer: helpers.urlFormat('/product/' + origin.productSkn + '.html')
// });
// }
... ... @@ -1151,7 +1151,7 @@ const _detailDataPkg = (origin, ua) => {
// 用户未登录时 pagecache重构
// if (!uid) {
// dest.loginUrl = helpers.urlFormat('/signin.html', {
// refer: helpers.urlFormat('/product/show_' + origin.product_skn + '.html')
// refer: helpers.urlFormat('/product/' + origin.product_skn + '.html')
// });
// }
... ... @@ -1539,7 +1539,7 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => {
// 用户未登录时
if (!uid) {
dest.loginUrl = helpers.urlFormat('/signin.html', {
refer: helpers.urlFormat('/product/show_' + origin.product_skn + '.html')
refer: helpers.urlFormat('/product/' + origin.product_skn + '.html') // 商品url改版
});
}
... ...
... ... @@ -60,10 +60,10 @@ const bundle = require(`${cRoot}/bundle`);
// 因为正则匹配原因,秒杀详情页路由要放在普通详情页前面,待解决
router.get(/^\/seckill\/show_([\d]+)/, seckillDetail.indexSkn); // 秒杀商品详情页 SKN 进入
router.get(/^\/seckill\/pro_([\d]+)_([\d]+)/, seckillDetail.index); // 秒杀商品详情页进入
router.get(/^\/pro_([\d]+)_([\d]+)/, rewrite.channel, newDetail.indexRedirect); // 商品详情页
router.get(/^\/pro_([\d]+)_([\d]+)/, newDetail.indexRedirect); // 商品详情页
// /show_51047967.html
router.get(/^\/show_([\d]+)/, newDetail.index); // 商品详情页 SKN 进入
router.get(/^\/(.*?-)?p(\d+)\.html/, rewrite.resolve, newDetail.index); // 商品详情页 进入 SEO优化
router.get(/^\/show_([\d]+)/, newDetail.indexRedirect); // 商品详情页 SKN 进入
router.get(/^\/(\d+)\.html/, newDetail.index); // 商品详情页 SKN 进入 SEO优化
router.get('/detail/sknData.json', newDetail.sknData); // 商品咨询,评价,店铺
router.get('/detail/intro/:productskn', detail.intro); // 商品内嵌页
... ...
... ... @@ -6,7 +6,8 @@
<ul>
{{#list}}
<li class="hot-single-goods">
<a href="//m.yohobuy.com/product/show_{{product_skn}}">
<a href="//m.yohobuy.com/product/{{product_skn}}.html">
{{!--商品url改版 --}}
<img src="{{image2 default_images w=153 h=206 q=60}}" alt="goods" class="goods-pic">
<div class="goods-info">
<h3 class="price">&yen; {{sales_price}}</h3>
... ...
... ... @@ -7,7 +7,8 @@
<ul>
{{#list}}
<li class="new-user-good">
<a href="//m.yohobuy.com/product/show_{{product_skn}}">
<a href="//m.yohobuy.com/product/{{product_skn}}.html">
{{!--商品url改版 --}}
<img src="{{image default_images 128 171}}" alt="goods-pic" class="goods-pic" />
<div class="goods-info">
<h3 class="title">{{product_name}}</h3>
... ...
... ... @@ -7,7 +7,8 @@
<div class="vip-only-goods-list" {{#background}} style="background-image: url({{image src 640 330}})" {{/background}}>
<ul>
{{#list}}
<a href="//m.yohobuy.com/product/show_{{product_skn}}">
<a href="//m.yohobuy.com/product/{{product_skn}}.html">
{{!--商品url改版 --}}
<li class="vip-only-goods">
<img src="{{image default_images 153 206}}" alt="goods" class="goods-pic">
<div class="goods-info">
... ...
... ... @@ -6,7 +6,8 @@
<ul>
{{#list}}
<li class="hot-single-goods">
<a href="//m.yohobuy.com/product/show_{{product_skn}}">
<a href="//m.yohobuy.com/product/{{product_skn}}.html">
{{!--商品url改版 --}}
<img src="{{image2 default_images w=153 h=206 q=60}}" alt="goods" class="goods-pic">
<div class="goods-info">
<h3 class="price">&yen; {{sales_price}}</h3>
... ...
... ... @@ -7,7 +7,8 @@
<ul>
{{#list}}
<li class="new-user-good">
<a href="//m.yohobuy.com/product/show_{{product_skn}}">
<a href="//m.yohobuy.com/product/{{product_skn}}.html">
{{!--商品url改版 --}}
<img src="{{image default_images 128 171}}" alt="goods-pic" class="goods-pic" />
<div class="goods-info">
<h3 class="title">{{product_name}}</h3>
... ...
... ... @@ -7,7 +7,8 @@
<div class="vip-only-goods-list" {{#background}} style="background-image: url({{image src 640 400}})" {{/background}}>
<ul>
{{#list}}
<a href="//m.yohobuy.com/product/show_{{product_skn}}">
<a href="//m.yohobuy.com/product/{{product_skn}}.html">
{{!--商品url改版 --}}
<li class="vip-only-goods">
<img src="{{image default_images 153 206}}" alt="goods" class="goods-pic">
<div class="goods-info">
... ...
... ... @@ -86,7 +86,7 @@ $(
success: function(data) {
// 秒杀是否结束
if (data == '' || data.status === 0 || data.status === 3) {
window.location.replace('/product/show_' + $('#productSkn').val() + '.html');
window.location.replace('/product/' + $('#productSkn').val() + '.html'); // 商品url改版
// $('.sold-out').hide();
// $('.cart-bar a:first').append('<a href="javascript:;" class="sold-out">已售罄</a>');
... ...
... ... @@ -153,7 +153,7 @@ const formatCartGoods = (goodData, isAdvanceCart, isValid, inValidLow) => {
}
// 商品链接
result.link = helpers.urlFormat(`/product/show_${goodData.product_skn}.html`);
result.link = helpers.urlFormat(`/product/${goodData.product_skn}.html`); // 商品url改版
return result;
};
const procPriceGiftData = (data, promotionType) => {
... ...
... ... @@ -286,7 +286,7 @@ const formatProduct = (productData, showTags, showNew, showSale, width, height,
productData.cn_alphabet = productNameProcess(productData.cn_alphabet);
}
let url = encodeURI(helpers.urlFormat(`/product/p${productData.product_id}.html`));
let url = encodeURI(helpers.urlFormat(`/product/${productData.product_skn}.html`));// 商品url改版
result.url = url.replace('http://', '//');
... ...
... ... @@ -165,7 +165,7 @@ exports.processProductList = (list, options) => {
product.cn_alphabet = productNameProcess(product.cn_alphabet);
}
product.url = helpers.urlFormat(`/product/p${product.product_id}.html`); // eslint-disable-line
product.url = helpers.urlFormat(`/product/${product.product_skn}.html`); // 商品url改版 // eslint-disable-line
// APP访问需要加附加的参数
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
... ...