...
|
...
|
@@ -19,19 +19,51 @@ const co = require('bluebird').coroutine; |
|
|
|
|
|
const shop = {
|
|
|
|
|
|
onlyDomain(req, res, next) {
|
|
|
req.query.domain = req.params.domain;
|
|
|
shop.entry(req, res, next);
|
|
|
},
|
|
|
/**
|
|
|
* 老路由处理,查数据,拼链接
|
|
|
*/
|
|
|
redirect(req, res, next) {
|
|
|
let shopId = _.parseInt(stringProcess.paramsFilter(req.query.shop_id));
|
|
|
let domain = stringProcess.paramsFilter(req.query.domain);
|
|
|
let brandId = _.parseInt(stringProcess.paramsFilter(req.query.brand_id));
|
|
|
|
|
|
onlyShopId(req, res, next) {
|
|
|
req.query.shop_id = req.params[0];
|
|
|
shop.entry(req, res, next);
|
|
|
co(function* () {
|
|
|
if (shopId && domain) {
|
|
|
return res.redirect(301, `/shop/${domain}-${shopId}.html`);
|
|
|
}
|
|
|
|
|
|
if (shopId) {
|
|
|
let shopInfoApi = (yield req.ctx(shopModel).getShopInfo(shopId)) || {};
|
|
|
|
|
|
return res.redirect(301, `/shop/${_.get(shopInfoApi, 'data.shop_domain')}-${shopId}.html`);
|
|
|
}
|
|
|
|
|
|
if (domain) {
|
|
|
let domainInfo = (yield req.ctx(shopModel).getBrandLogoByDomain(domain)) || {}; // 通过域名查询店铺类型,或者品牌信息
|
|
|
|
|
|
if (domainInfo.shopId && domainInfo.type === '2') {
|
|
|
return res.redirect(301, `/shop/${domain}-${_.get(domainInfo, 'shopId')}.html`);
|
|
|
} else {
|
|
|
return res.redirect(301, helpers.urlFormat('/index/brand', {
|
|
|
brand_id: _.get(domainInfo, 'id')
|
|
|
}));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (brandId) {
|
|
|
return res.redirect(301, helpers.urlFormat('/index/brand', { brand_id: brandId }));
|
|
|
}
|
|
|
})().catch(next);
|
|
|
},
|
|
|
|
|
|
rewrite(req, res, next) {
|
|
|
req.query.domain = req.params.domain;
|
|
|
req.query.shop_id = req.params.shop_id;
|
|
|
/**
|
|
|
* 新路由承接页,参数解析
|
|
|
*/
|
|
|
resolveParams(req, res, next) {
|
|
|
let pathParams = _.last(_.split(req.url.replace('.html', ''), '/'));
|
|
|
let shopId = _.last(_.split(pathParams, '-'));
|
|
|
|
|
|
req.query.domain = pathParams.replace(`-${shopId}`, '');
|
|
|
shop.entry(req, res, next);
|
|
|
},
|
|
|
|
...
|
...
|
|