Showing
5 changed files
with
140 additions
and
173 deletions
@@ -134,36 +134,6 @@ exports.brandAbout = (req, res, next) => { | @@ -134,36 +134,6 @@ exports.brandAbout = (req, res, next) => { | ||
134 | }; | 134 | }; |
135 | 135 | ||
136 | /** | 136 | /** |
137 | - * 店铺商品列表页 | ||
138 | - * @param {[type]} req [description] | ||
139 | - * @param {[type]} res [description] | ||
140 | - * @return {[type]} [description] | ||
141 | - */ | ||
142 | -exports.shopList = (req, res, next) => { | ||
143 | - let shopId = req.query.shopId; | ||
144 | - | ||
145 | - if (!shopId) { | ||
146 | - return next(); | ||
147 | - } | ||
148 | - | ||
149 | - list.getShopListData(req.yoho.channel, req.query, req.user.uid).then(result => { | ||
150 | - Object.assign(result, { | ||
151 | - page: 'shop', | ||
152 | - shopId: shopId | ||
153 | - }); | ||
154 | - if (req.query.query) { | ||
155 | - result.shopKey = req.query.query; | ||
156 | - } | ||
157 | - | ||
158 | - // 店铺装修为空则不cache | ||
159 | - if (!result.shopTopBanner) { | ||
160 | - res.set('Cache-Control', 'no-cache'); | ||
161 | - } | ||
162 | - res.render('list/shop-list', result); | ||
163 | - }).catch(next); | ||
164 | -}; | ||
165 | - | ||
166 | -/** | ||
167 | * ajax调用品牌页左侧水牌 | 137 | * ajax调用品牌页左侧水牌 |
168 | * @param {[type]} req [description] | 138 | * @param {[type]} req [description] |
169 | * @param {[type]} res [description] | 139 | * @param {[type]} res [description] |
@@ -5,6 +5,7 @@ const mRoot = '../models'; | @@ -5,6 +5,7 @@ const mRoot = '../models'; | ||
5 | const shopModel = require(`${mRoot}/shop-service`); | 5 | const shopModel = require(`${mRoot}/shop-service`); |
6 | const tdk = require('../../../utils/getTDK'); | 6 | const tdk = require('../../../utils/getTDK'); |
7 | 7 | ||
8 | +// 店铺首页(经典&基础) | ||
8 | exports.index = (req, res, next) => { | 9 | exports.index = (req, res, next) => { |
9 | let domain = req.query.domain; | 10 | let domain = req.query.domain; |
10 | let shopId = req.query.shopId; | 11 | let shopId = req.query.shopId; |
@@ -23,7 +24,7 @@ exports.index = (req, res, next) => { | @@ -23,7 +24,7 @@ exports.index = (req, res, next) => { | ||
23 | }); | 24 | }); |
24 | } | 25 | } |
25 | 26 | ||
26 | - Promise.all([ | 27 | + return Promise.all([ |
27 | tdk('shop', shopId, req), | 28 | tdk('shop', shopId, req), |
28 | shopModel.getShopInfoAsync(domain, req.yoho.channel, req.query) | 29 | shopModel.getShopInfoAsync(domain, req.yoho.channel, req.query) |
29 | ]).then(result => { | 30 | ]).then(result => { |
@@ -64,3 +65,26 @@ exports.index = (req, res, next) => { | @@ -64,3 +65,26 @@ exports.index = (req, res, next) => { | ||
64 | } | 65 | } |
65 | }).catch(next); | 66 | }).catch(next); |
66 | }; | 67 | }; |
68 | + | ||
69 | +// 经典店铺列表 | ||
70 | +exports.list = (req, res, next) => { | ||
71 | + let shopId = req.query.shopId; | ||
72 | + | ||
73 | + if (!shopId) { | ||
74 | + return next(); | ||
75 | + } | ||
76 | + | ||
77 | + return shopModel.getShopListInfoAsync(req.yoho.channel, req.query).then(result => { | ||
78 | + Object.assign(result, { | ||
79 | + page: 'shop', | ||
80 | + shopId: shopId, | ||
81 | + shopKey: req.query.query || '' | ||
82 | + }); | ||
83 | + | ||
84 | + // 店铺装修为空则不cache | ||
85 | + if (!result.shopTopBanner) { | ||
86 | + res.set('Cache-Control', 'no-cache'); | ||
87 | + } | ||
88 | + res.render('list/shop-list', result); | ||
89 | + }).catch(next); | ||
90 | +}; |
@@ -23,34 +23,12 @@ const brandFolderSeries = '经典系列'; | @@ -23,34 +23,12 @@ const brandFolderSeries = '经典系列'; | ||
23 | const folderTitle = '经典款型'; | 23 | const folderTitle = '经典款型'; |
24 | const seriesTitle = '经典系列'; | 24 | const seriesTitle = '经典系列'; |
25 | 25 | ||
26 | -// 经典店铺list url | ||
27 | -const shopListUrl = '/product/shoplist'; | ||
28 | - | ||
29 | // 搜索分类信息需要的参数 | 26 | // 搜索分类信息需要的参数 |
30 | const positionId = 10; | 27 | const positionId = 10; |
31 | 28 | ||
32 | // 获取分类左侧广告id | 29 | // 获取分类左侧广告id |
33 | const sortAdsId = 79; | 30 | const sortAdsId = 79; |
34 | 31 | ||
35 | - | ||
36 | -const _getGender = (channel) => { | ||
37 | - let gender; | ||
38 | - | ||
39 | - switch (channel) { | ||
40 | - case 'boys': | ||
41 | - gender = '1,3'; | ||
42 | - break; | ||
43 | - case 'girls': | ||
44 | - gender = '2,3'; | ||
45 | - break; | ||
46 | - default: | ||
47 | - gender = '1,2,3'; | ||
48 | - break; | ||
49 | - } | ||
50 | - | ||
51 | - return gender; | ||
52 | -}; | ||
53 | - | ||
54 | /** | 32 | /** |
55 | * 获取商品分类列表数据 | 33 | * 获取商品分类列表数据 |
56 | */ | 34 | */ |
@@ -566,124 +544,6 @@ const getShopInfo = (shopId, uid) => { | @@ -566,124 +544,6 @@ const getShopInfo = (shopId, uid) => { | ||
566 | }); | 544 | }); |
567 | }; | 545 | }; |
568 | 546 | ||
569 | -const getShopListData = (channel, params, uid) => { | ||
570 | - let gender = _getGender(channel), | ||
571 | - shopId = params.shopId, | ||
572 | - navBar = params.navBar || 1; | ||
573 | - let apiArr = [ | ||
574 | - headerModel.requestHeaderData(channel), // 头部数据 | ||
575 | - searchApi.getShopDecorator(shopId), // 店铺装修数据 | ||
576 | - searchApi.getShopInfo(shopId, uid), // 店铺介绍 | ||
577 | - searchApi.getProductList(Object.assign({shop_id: shopId}, params, | ||
578 | - {limit: (params.limit || 60) - 1}), 'shop'), // 搜索店铺商品 | ||
579 | - searchApi.getSortList({shop_id: shopId}) // 店铺分类 | ||
580 | - ]; | ||
581 | - | ||
582 | - if (_.has(params, 'query')) { | ||
583 | - // 如果有店内搜索,则并行查询店铺所有商品,搜索不到商品则显示所有商品 | ||
584 | - apiArr.push(searchApi.getProductList(Object.assign({shop_id: shopId}, | ||
585 | - params, {query: ''}), 'shop')); // 搜索店铺所有商品 | ||
586 | - } | ||
587 | - | ||
588 | - | ||
589 | - return Promise.all(apiArr).then(result => { | ||
590 | - let finalResult = { | ||
591 | - headerData: Object.assign(result[0].headerData, {header: true}) | ||
592 | - }; | ||
593 | - | ||
594 | - // 面包屑导航 | ||
595 | - Object.assign(finalResult, searchHandler.handlePathNavData({}, params, 'shop', channel)); | ||
596 | - | ||
597 | - // 店铺装修 | ||
598 | - if (result[1].code === 200) { | ||
599 | - Object.assign(finalResult, shopHandler.getShopDecorator(result[1].data, params, shopId)); | ||
600 | - | ||
601 | - // 设置shop nav选中状态 | ||
602 | - _.set(finalResult, `navigationBar[${navBar}].current`, true); | ||
603 | - | ||
604 | - if (result[2].code === 200) { | ||
605 | - let data = _.get(result[2], 'data', {}); | ||
606 | - | ||
607 | - _.set(finalResult, 'shopTopBanner.brandIntro', { | ||
608 | - shopId: shopId, | ||
609 | - brandName: data.shop_name || '', | ||
610 | - isFavorite: data.is_favorite === 'Y', | ||
611 | - brandCont: data.shop_intro || '' | ||
612 | - }); | ||
613 | - | ||
614 | - // 店铺SEO | ||
615 | - Object.assign(finalResult, searchHandler.getBrandShopSeo(channel, { | ||
616 | - shopName: data.shop_name | ||
617 | - }, params)); | ||
618 | - } | ||
619 | - } else { | ||
620 | - return Promise.reject('No ShopDecorator data'); | ||
621 | - } | ||
622 | - | ||
623 | - // 获取商品数据和顶部筛选条件 | ||
624 | - if (result[3].code === 200) { | ||
625 | - let info = result[3]; | ||
626 | - let goodsList = _.get(info, 'data.product_list', []); | ||
627 | - | ||
628 | - if (goodsList.length) { | ||
629 | - let totalPage = _.get(info, 'data.total', 1); | ||
630 | - | ||
631 | - Object.assign(finalResult, { | ||
632 | - filters: searchHandler.handleFilterDataAll(info.data, params), | ||
633 | - opts: searchHandler.handleOptsData(params, totalPage), | ||
634 | - goods: productProcess.processProductList(goodsList, { | ||
635 | - newCoverSort: true, | ||
636 | - showDiscount: false, | ||
637 | - gender: _getGender(channel), | ||
638 | - query: params.query | ||
639 | - }), | ||
640 | - hasNextPage: searchHandler.handleNextPage(params, totalPage), | ||
641 | - footPager: searchHandler.handlePagerData(totalPage, params) | ||
642 | - }); | ||
643 | - | ||
644 | - _.set(finalResult, 'filters.checkedConditions.clearUrl', | ||
645 | - `?navBar=${params.navBar}&shopId=${params.shopId}`); | ||
646 | - } else { | ||
647 | - finalResult.searchEmpty = true; | ||
648 | - | ||
649 | - if (result[5] && result[5].code === 200) { | ||
650 | - let allGoods = { | ||
651 | - name: '全部商品 ALL', | ||
652 | - sort: searchHandler.handleOptsData(params, _.get(result[5], 'data.total', 0)), | ||
653 | - list: productProcess.processProductList(_.get(result[5], 'data.product_list', []), { | ||
654 | - newCoverSort: true, | ||
655 | - showDiscount: false, | ||
656 | - gender: gender | ||
657 | - }) | ||
658 | - }; | ||
659 | - | ||
660 | - _.set(allGoods, 'sort.newPage', true); // 启用新的分页导航 | ||
661 | - | ||
662 | - finalResult.allGoods = allGoods; | ||
663 | - } | ||
664 | - } | ||
665 | - } | ||
666 | - | ||
667 | - if (result[4].code === 200) { | ||
668 | - | ||
669 | - let groupSort = _.get(result[4], 'data', []), | ||
670 | - noPageQs = Object.assign({}, params, {page: 1}); | ||
671 | - | ||
672 | - finalResult.leftContent = searchHandler.handleSortData(groupSort, noPageQs, params); | ||
673 | - | ||
674 | - _.set(finalResult, 'brandShopAd', {baseUrl: shopListUrl}); | ||
675 | - | ||
676 | - if (finalResult.allGoods) { | ||
677 | - Object.assign(finalResult.allGoods, searchHandler.setShopSort(groupSort, noPageQs)); | ||
678 | - } | ||
679 | - } | ||
680 | - | ||
681 | - finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult, 'goods'))}; | ||
682 | - | ||
683 | - return finalResult; | ||
684 | - }); | ||
685 | -}; | ||
686 | - | ||
687 | const getUserCoupunStatus = (id, uid, type) => { | 547 | const getUserCoupunStatus = (id, uid, type) => { |
688 | if (type === 'shop') { | 548 | if (type === 'shop') { |
689 | return shopApi.shopCouponListAsync(id, uid).then(result => { | 549 | return shopApi.shopCouponListAsync(id, uid).then(result => { |
@@ -726,6 +586,5 @@ module.exports = { | @@ -726,6 +586,5 @@ module.exports = { | ||
726 | getNodeContentData, | 586 | getNodeContentData, |
727 | getAdnav, | 587 | getAdnav, |
728 | getShopInfo, | 588 | getShopInfo, |
729 | - getShopListData, | ||
730 | getUserCoupunStatus | 589 | getUserCoupunStatus |
731 | }; | 590 | }; |
@@ -441,6 +441,120 @@ exports.getShopInfoAsync = (domain, channel, params) => { | @@ -441,6 +441,120 @@ exports.getShopInfoAsync = (domain, channel, params) => { | ||
441 | })(); | 441 | })(); |
442 | }; | 442 | }; |
443 | 443 | ||
444 | +exports.getShopListInfoAsync = (channel, params) => { | ||
445 | + let gender = _getGender(channel), | ||
446 | + shopId = params.shopId, | ||
447 | + navBar = params.navBar || 1; | ||
448 | + | ||
449 | + let searchParams = searchHandler.getSearchParams(params); | ||
450 | + | ||
451 | + return co(function * () { | ||
452 | + let result = yield Promise.props({ | ||
453 | + header: headerModel.requestHeaderData(channel), // 头部数据 | ||
454 | + shopInfo: api.getShopInfo(shopId), // 店铺介绍 | ||
455 | + decorator: searchApi.getShopDecorator(shopId), // 店铺装修数据 | ||
456 | + sort: searchApi.getSortList({shop_id: shopId}), | ||
457 | + product: searchApi.getProductList(Object.assign(searchParams, | ||
458 | + {shop_id: shopId}), 'shop'), // 搜索店铺商品 | ||
459 | + | ||
460 | + // 如果有店内搜索,则并行查询店铺所有商品,搜索不到商品则显示所有商品 | ||
461 | + allProduct: params.query ? searchApi.getProductList(Object.assign(searchParams, | ||
462 | + {shop_id: shopId, query: ''}), 'shop') : Promise.resolve({}) | ||
463 | + }); | ||
464 | + | ||
465 | + let resData = {headerData: Object.assign(result.header.headerData, {header: true})}; | ||
466 | + | ||
467 | + Object.assign(resData, searchHandler.handlePathNavData({}, params, 'shop', channel)); | ||
468 | + | ||
469 | + // 店铺装修 | ||
470 | + if (result.decorator.code === 200) { | ||
471 | + Object.assign(resData, shopHandler.getShopDecorator(result.decorator.data, params, shopId)); | ||
472 | + | ||
473 | + // 设置shop nav选中状态 | ||
474 | + _.set(resData, `navigationBar[${navBar}].current`, true); | ||
475 | + | ||
476 | + if (result.shopInfo.code === 200) { | ||
477 | + let data = _.get(result, 'shopInfo.data', {}); | ||
478 | + | ||
479 | + _.set(resData, 'shopTopBanner.brandIntro', { | ||
480 | + shopId: shopId, | ||
481 | + brandName: data.shop_name || '', | ||
482 | + brandCont: data.shop_intro || '' | ||
483 | + }); | ||
484 | + | ||
485 | + // 店铺SEO | ||
486 | + Object.assign(resData, searchHandler.getBrandShopSeo(channel, { | ||
487 | + shopName: data.shop_name | ||
488 | + }, params)); | ||
489 | + } | ||
490 | + } else { | ||
491 | + return Promise.reject('No ShopDecorator data'); | ||
492 | + } | ||
493 | + | ||
494 | + // 获取商品数据和顶部筛选条件 | ||
495 | + if (result.product.code === 200) { | ||
496 | + let info = result.product; | ||
497 | + let goodsList = _.get(info, 'data.product_list', []); | ||
498 | + | ||
499 | + if (goodsList.length) { | ||
500 | + let totalPage = _.get(info, 'data.total', 1); | ||
501 | + | ||
502 | + Object.assign(resData, { | ||
503 | + filters: searchHandler.handleFilterDataAll(info.data, params), | ||
504 | + opts: searchHandler.handleOptsData(params, totalPage), | ||
505 | + goods: productProcess.processProductList(goodsList, { | ||
506 | + newCoverSort: true, | ||
507 | + showDiscount: false, | ||
508 | + gender: _getGender(channel), | ||
509 | + query: params.query | ||
510 | + }), | ||
511 | + hasNextPage: searchHandler.handleNextPage(params, totalPage), | ||
512 | + footPager: searchHandler.handlePagerData(totalPage, params) | ||
513 | + }); | ||
514 | + | ||
515 | + _.set(resData, 'filters.checkedConditions.clearUrl', | ||
516 | + `?navBar=${params.navBar}&shopId=${params.shopId}`); | ||
517 | + } else { | ||
518 | + resData.searchEmpty = true; | ||
519 | + | ||
520 | + let data = _.get(result, 'allProduct.data.total', 0); | ||
521 | + let plist = _.get(data, 'product_list', []); | ||
522 | + | ||
523 | + if (params.query && plist.length) { | ||
524 | + resData.allGoods = { | ||
525 | + name: '全部商品 ALL', | ||
526 | + sort: searchHandler.handleOptsData(params, data.total || 0), | ||
527 | + list: productProcess.processProductList(plist, { | ||
528 | + newCoverSort: true, | ||
529 | + showDiscount: false, | ||
530 | + gender: gender | ||
531 | + }) | ||
532 | + }; | ||
533 | + | ||
534 | + _.set(resData.allGoods, 'sort.newPage', true); // 启用新的分页导航 | ||
535 | + } | ||
536 | + } | ||
537 | + } | ||
538 | + | ||
539 | + if (result.sort.code === 200) { | ||
540 | + let groupSort = _.get(result.sort, 'data', []), | ||
541 | + noPageQs = Object.assign({}, params, {page: 1}); | ||
542 | + | ||
543 | + resData.leftContent = searchHandler.handleSortData(groupSort, noPageQs, params); | ||
544 | + | ||
545 | + _.set(resData, 'brandShopAd', {baseUrl: shopListUrl}); | ||
546 | + | ||
547 | + if (resData.allGoods) { | ||
548 | + Object.assign(resData.allGoods, searchHandler.setShopSort(groupSort, noPageQs)); | ||
549 | + } | ||
550 | + } | ||
551 | + | ||
552 | + resData.criteo = {skn: searchHandler.getCriteo(_.get(resData, 'goods'))}; | ||
553 | + | ||
554 | + return resData; | ||
555 | + })(); | ||
556 | +}; | ||
557 | + | ||
444 | exports.getShopGoodsData = (shopId, channel, params) => { | 558 | exports.getShopGoodsData = (shopId, channel, params) => { |
445 | let gender = _getGender(channel); | 559 | let gender = _getGender(channel); |
446 | let resData = {}; | 560 | let resData = {}; |
@@ -121,7 +121,7 @@ router.post('/index/isFavoriteBrand', list.isFavoriteBrand); // 判断用户是 | @@ -121,7 +121,7 @@ router.post('/index/isFavoriteBrand', list.isFavoriteBrand); // 判断用户是 | ||
121 | router.post('/index/getNodeContent', list.getNodeContent); // 品牌页水牌 | 121 | router.post('/index/getNodeContent', list.getNodeContent); // 品牌页水牌 |
122 | router.post('/index/getAdnav', list.getAdnav); // 品牌页系列 | 122 | router.post('/index/getAdnav', list.getAdnav); // 品牌页系列 |
123 | router.get('/shop', shop.index); // 店铺首页 | 123 | router.get('/shop', shop.index); // 店铺首页 |
124 | -router.get('/shoplist', list.shopList); // 店铺列表页 | 124 | +router.get('/shoplist', shop.list); // 店铺列表页 |
125 | router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏 | 125 | router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏 |
126 | router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏品牌 | 126 | router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏品牌 |
127 | router.get('/brand/couponsync', list.brandCouponSync); | 127 | router.get('/brand/couponsync', list.brandCouponSync); |
-
Please register or login to post a comment