Authored by 郭成尧

Merge branch 'hotfix/shopdomain' into 'gray'

Hotfix/shopdomain



See merge request !1227
@@ -26,7 +26,8 @@ @@ -26,7 +26,8 @@
26 "type": "node", 26 "type": "node",
27 "request": "launch", 27 "request": "launch",
28 "name": "Node", 28 "name": "Node",
29 - "program": "${workspaceFolder}/app.js" 29 + "program": "${workspaceFolder}/app.js",
  30 + "console":"integratedTerminal"
30 } 31 }
31 ] 32 ]
32 } 33 }
@@ -78,6 +78,18 @@ const shop = { @@ -78,6 +78,18 @@ const shop = {
78 }, 78 },
79 79
80 /** 80 /**
  81 + * 解析店铺的参数
  82 + */
  83 + resolveShopParams(req, res, next) {
  84 + if (req.params.shopParams) {
  85 + req.query.shop_id = _.last(_.split(req.params.shopParams, '-'));
  86 + req.query.domain = req.params.shopParams.replace(`-${req.query.shop_id}`, '');
  87 + }
  88 +
  89 + return next();
  90 + },
  91 +
  92 + /**
81 * 店铺统一入口 93 * 店铺统一入口
82 */ 94 */
83 entry(req, res, next) { 95 entry(req, res, next) {
@@ -258,12 +258,29 @@ exports.filter = (req, res, next) => { @@ -258,12 +258,29 @@ exports.filter = (req, res, next) => {
258 let params = {}; 258 let params = {};
259 let currentUrlParams = {}; // 页面链接伪静态固定参数 259 let currentUrlParams = {}; // 页面链接伪静态固定参数
260 260
261 - if (req.query.currentUrl) { 261 + if (req.query.isShopList === 'Y') {
  262 + let shopId;
  263 + let pathSplitArr = _.compact(_.split(req.query.currentUrl, '/'));
  264 + let pathParams = _.last(pathSplitArr);
  265 +
  266 + if (pathSplitArr.length === 2) {
  267 + shopId = _.last(_.split(pathParams, '-'));
  268 + } else {
  269 + currentUrlParams = listParamsProcess.getParams(pathParams);
  270 +
  271 + let shopInfoPath = _.replace(req.query.currentUrl, `/${pathParams}`, '');
  272 +
  273 + shopId = _.last(_.split(shopInfoPath, '-'));
  274 + }
  275 +
  276 + _.assign(req.query, currentUrlParams, {shop_id: shopId});
  277 + } else {
262 currentUrlParams = listParamsProcess.getParams(req.query.currentUrl); 278 currentUrlParams = listParamsProcess.getParams(req.query.currentUrl);
263 - delete req.query.currentUrl;  
264 - delete req.query.page;  
265 } 279 }
266 280
  281 + delete req.query.currentUrl;
  282 + delete req.query.page;
  283 +
267 _.assign(params, currentUrlParams, req.query); 284 _.assign(params, currentUrlParams, req.query);
268 285
269 let uid = req.user.uid || 0; 286 let uid = req.user.uid || 0;
@@ -167,13 +167,22 @@ router.get('/index/shopFav', list.shopFav); @@ -167,13 +167,22 @@ router.get('/index/shopFav', list.shopFav);
167 router.get('/index/category', list.shopCategory); 167 router.get('/index/category', list.shopCategory);
168 router.get('/index/getBrandCouponsList', list.getBrandCouponsList); 168 router.get('/index/getBrandCouponsList', list.getBrandCouponsList);
169 169
170 -router.get('/shop', newShop.redirect); // 老路由重定向前置处理  
171 -router.get('/shop/:domain-:shop_id.html', newShop.entry); // 新入口  
172 -router.get('/shop/:domain-(:shop_id)(/:pathParams)?', rewrite.resolvePathParams, newShop.goodsList); // 店铺商品列表  
173 router.get('/shop/goodslist', 170 router.get('/shop/goodslist',
174 cors, 171 cors,
175 rewrite.resolveShopPathParamsAjax, 172 rewrite.resolveShopPathParamsAjax,
176 newShop.goodsListAjax); // 店铺商品列表异步查询 173 newShop.goodsListAjax); // 店铺商品列表异步查询
  174 +router.get('/shop/:shopParams.html',
  175 + newShop.resolveShopParams,
  176 + newShop.entry); // 新入口
  177 +router.get('/shop/:shopParams',
  178 + rewrite.resolvePathParams,
  179 + newShop.resolveShopParams,
  180 + newShop.goodsList); // 店铺商品列表
  181 +router.get('/shop/:shopParams/:pathParams',
  182 + rewrite.resolvePathParams,
  183 + newShop.resolveShopParams,
  184 + newShop.goodsList); // 店铺商品列表
  185 +router.get('/shop', newShop.redirect); // 老路由重定向前置处理
177 186
178 router.get('/index/brand', newShop.entry); // 旧的路由,走到新的 controller 187 router.get('/index/brand', newShop.entry); // 旧的路由,走到新的 controller
179 router.get('/index/brandFav', newShop.brandFav); 188 router.get('/index/brandFav', newShop.brandFav);
@@ -162,10 +162,20 @@ const resolvePathParamsAjax = (req, res, next) => { @@ -162,10 +162,20 @@ const resolvePathParamsAjax = (req, res, next) => {
162 * 解析 Path 类型店铺商品列表异步请求中 URL 的参数 162 * 解析 Path 类型店铺商品列表异步请求中 URL 的参数
163 */ 163 */
164 const resolveShopPathParamsAjax = (req, res, next) => { 164 const resolveShopPathParamsAjax = (req, res, next) => {
165 - let pathParams = _.last(_.split(req.query.currentUrl, '/'));  
166 - let currentUrlParams = listParamsProcess.getParams(pathParams);  
167 - let shopInfoPath = _.replace(req.query.currentUrl, `/${pathParams}`, '');  
168 - let shopId = _.last(_.split(shopInfoPath, '-')); 165 + let shopId;
  166 + let currentUrlParams;
  167 + let pathSplitArr = _.compact(_.split(req.query.currentUrl, '/'));
  168 + let pathParams = _.last(pathSplitArr);
  169 +
  170 + if (pathSplitArr.length === 2) {
  171 + shopId = _.last(_.split(pathParams, '-'));
  172 + } else {
  173 + currentUrlParams = listParamsProcess.getParams(pathParams);
  174 +
  175 + let shopInfoPath = _.replace(req.query.currentUrl, `/${pathParams}`, '');
  176 +
  177 + shopId = _.last(_.split(shopInfoPath, '-'));
  178 + }
169 179
170 delete req.query.currentUrl; 180 delete req.query.currentUrl;
171 181
@@ -3,15 +3,21 @@ @@ -3,15 +3,21 @@
3 * @author: wsl<shuiling.wang@yoho.cn> 3 * @author: wsl<shuiling.wang@yoho.cn>
4 * @date: 2016/7/21 4 * @date: 2016/7/21
5 */ 5 */
  6 +require('product/search/list.page.css');
6 7
  8 +const qs = require('yoho-qs');
7 const ProductListWithFilter = require('./list/product-list-with-filter'); 9 const ProductListWithFilter = require('./list/product-list-with-filter');
8 10
9 -require('product/search/list.page.css'); 11 +let initParams = {
  12 + page: 2,
  13 + currentUrl: location.pathname
  14 +};
  15 +
  16 +if (qs) {
  17 + $.extend(initParams, qs);
  18 +}
  19 +
  20 +new ProductListWithFilter(initParams, 'product/search/category');
  21 +
10 require('common/footer'); 22 require('common/footer');
11 require('./shop/coupon'); 23 require('./shop/coupon');
12 -  
13 -new ProductListWithFilter({  
14 - page: 2,  
15 - currentUrl: location.pathname,  
16 - isNewList: 'Y'  
17 -}, 'product/search/category');  
@@ -10,5 +10,5 @@ require('common/footer'); @@ -10,5 +10,5 @@ require('common/footer');
10 new ProductListWithFilter({ 10 new ProductListWithFilter({
11 page: 2, 11 page: 2,
12 currentUrl: location.pathname, 12 currentUrl: location.pathname,
13 - isNewList: 'Y' 13 + isShopList: 'Y'
14 }, 'product/shop/goodslist'); 14 }, 'product/shop/goodslist');