Authored by yyq

article async

@@ -52,7 +52,7 @@ exports.index = (req, res, next) => { @@ -52,7 +52,7 @@ exports.index = (req, res, next) => {
52 res.set('Cache-Control', 'no-cache'); 52 res.set('Cache-Control', 'no-cache');
53 } 53 }
54 54
55 - res.render('list/shop-index', shopObj); 55 + res.render('shop/index', shopObj);
56 } else { // 基础模版 56 } else { // 基础模版
57 Object.assign(shopObj, {page: 'list'}); 57 Object.assign(shopObj, {page: 'list'});
58 58
@@ -85,6 +85,19 @@ exports.list = (req, res, next) => { @@ -85,6 +85,19 @@ exports.list = (req, res, next) => {
85 if (!result.shopTopBanner) { 85 if (!result.shopTopBanner) {
86 res.set('Cache-Control', 'no-cache'); 86 res.set('Cache-Control', 'no-cache');
87 } 87 }
88 - res.render('list/shop-list', result); 88 + res.render('shop/list', result);
  89 + }).catch(next);
  90 +};
  91 +
  92 +// 经典店铺推荐文章
  93 +exports.article = (req, res, next) => {
  94 + let brands = req.query.brands;
  95 +
  96 + if (!brands) {
  97 + return next();
  98 + }
  99 +
  100 + return shopModel.getShopArticleByBrandsAsync(brands).then(result => {
  101 + res.render('shop/article', Object.assign(result, {layout: false}));
89 }).catch(next); 102 }).catch(next);
90 }; 103 };
@@ -177,7 +177,6 @@ const _getShopData = (channel, params, shopInfo) => { @@ -177,7 +177,6 @@ const _getShopData = (channel, params, shopInfo) => {
177 sknList.push(value.productSkn); 177 sknList.push(value.productSkn);
178 }); 178 });
179 179
180 - let articleApiMethod = []; // 通过品牌获取相关文章接口  
181 let apiMethod = [ 180 let apiMethod = [
182 searchApi.getProductList({ 181 searchApi.getProductList({
183 viewNum: sknList.length, 182 viewNum: sknList.length,
@@ -191,16 +190,11 @@ const _getShopData = (channel, params, shopInfo) => { @@ -191,16 +190,11 @@ const _getShopData = (channel, params, shopInfo) => {
191 190
192 _.forEach(result.brands.data, value => { 191 _.forEach(result.brands.data, value => {
193 brands.push(value.brand_id); 192 brands.push(value.brand_id);
194 - articleApiMethod.push(  
195 - searchApi.getArticleByBrand(value.brand_id, 'udid') // 品牌推荐文章  
196 - );  
197 }); 193 });
198 194
199 resData.shopBrands = brands.join(','); 195 resData.shopBrands = brands.join(',');
200 } 196 }
201 197
202 - apiMethod = _.concat(apiMethod, articleApiMethod);  
203 -  
204 let subRes = yield Promise.all(apiMethod); 198 let subRes = yield Promise.all(apiMethod);
205 199
206 // 设置资源位商品封面图 200 // 设置资源位商品封面图
@@ -238,31 +232,7 @@ const _getShopData = (channel, params, shopInfo) => { @@ -238,31 +232,7 @@ const _getShopData = (channel, params, shopInfo) => {
238 } 232 }
239 } 233 }
240 234
241 - let articleList = [];  
242 -  
243 - for (let i = 2; i < subRes.length; i++) {  
244 - articleList = _.concat(articleList, _.get(subRes[i], 'data', []));  
245 - }  
246 -  
247 - if (articleList.length >= 3) {  
248 - let trendList = [];  
249 -  
250 - for (let i = 0; i < 3; i++) {  
251 - trendList.push({  
252 - href: helpers.urlFormat(`/guang/${articleList[i].id}.html`, null),  
253 - src: helpers.getForceSourceUrl(articleList[i].src) +  
254 - '?imageView2/1/w/{width}/h/{height}',  
255 - mainTitle: articleList[i].title,  
256 - Subtitle: articleList[i].intro  
257 - });  
258 - articleList = _.concat(articleList, _.get(subRes[i], 'data', []));  
259 - }  
260 -  
261 - resData.trendInfo = {  
262 - name: '潮流资讯 HOT ITEMS',  
263 - trendList: trendList  
264 - };  
265 - } 235 + resData.trendInfo = true; // 展示店铺推荐文章
266 236
267 return resData; 237 return resData;
268 })(); 238 })();
@@ -649,3 +619,40 @@ exports.queryShopByBrandIdAsync = (sid, bid) => { @@ -649,3 +619,40 @@ exports.queryShopByBrandIdAsync = (sid, bid) => {
649 return _.get(result, 'data[0]', {}); 619 return _.get(result, 'data[0]', {});
650 })(); 620 })();
651 }; 621 };
  622 +
  623 +exports.getShopArticleByBrandsAsync = (brands) => {
  624 + let resData = {};
  625 +
  626 + brands = _.split(brands, ',');
  627 +
  628 + if (!brands.length) {
  629 + return Promise.resolve(resData);
  630 + }
  631 +
  632 + return Promise.all(brands.map(value => searchApi.getArticleByBrand(value))).then(result => {
  633 + let articleList = [];
  634 +
  635 + for (let i = 0; i < result.length; i++) {
  636 + articleList = _.concat(articleList, _.get(result[i], 'data', []));
  637 + }
  638 +
  639 + if (articleList.length >= 3) {
  640 + articleList.length = 3;
  641 +
  642 + resData.trendInfo = {
  643 + name: '潮流资讯 HOT ITEMS',
  644 + trendList: articleList.map(value => {
  645 + return {
  646 + href: helpers.urlFormat(`/guang/${value.id}.html`, null),
  647 + src: helpers.getForceSourceUrl(value.src) +
  648 + '?imageView2/1/w/{width}/h/{height}',
  649 + mainTitle: value.title,
  650 + Subtitle: value.intro
  651 + }
  652 + })
  653 + };
  654 + }
  655 +
  656 + return resData;
  657 + });
  658 +};
@@ -122,6 +122,7 @@ router.post('/index/getNodeContent', list.getNodeContent); // 品牌页水牌 @@ -122,6 +122,7 @@ 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', shop.list); // 店铺列表页 124 router.get('/shoplist', shop.list); // 店铺列表页
  125 +router.get('/shop/article', shop.article); // 店铺推荐文章
125 router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏 126 router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏
126 router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏品牌 127 router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏品牌
127 router.get('/brand/couponsync', list.brandCouponSync); 128 router.get('/brand/couponsync', list.brandCouponSync);
  1 +{{# trendInfo}}
  2 + <div class="trend-info clearfix">
  3 + {{> common/floor-header}}
  4 +
  5 + <ul class="trend-list">
  6 + {{#each trendList}}
  7 + <li>
  8 + <a href="{{href}}">
  9 + <img src="{{image2 src w=264 h=173}}" />
  10 + <div class="main-title">{{mainTitle}}</div>
  11 + <div class="sub-title">{{Subtitle}}</div>
  12 + </a>
  13 + </li>
  14 + {{/each}}
  15 + </ul>
  16 + </div>
  17 +{{/ trendInfo}}
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 6
7 <div class="list-left pull-left"> 7 <div class="list-left pull-left">
8 {{> list/shop-search}} 8 {{> list/shop-search}}
9 - 9 +
10 {{> product/left-content}} 10 {{> product/left-content}}
11 11
12 {{> list/shop-sidebar}} 12 {{> list/shop-sidebar}}
@@ -54,23 +54,9 @@ @@ -54,23 +54,9 @@
54 54
55 {{> list/shop-all-goods}} 55 {{> list/shop-all-goods}}
56 56
57 - {{#trendInfo}}  
58 - <div class="trend-info clearfix">  
59 - {{> common/floor-header}}  
60 -  
61 - <ul class="trend-list">  
62 - {{#each trendList}}  
63 - <li>  
64 - <a href="{{href}}">  
65 - <img src="{{image2 src w=264 h=173}}" />  
66 - <div class="main-title">{{mainTitle}}</div>  
67 - <div class="sub-title">{{Subtitle}}</div>  
68 - </a>  
69 - </li>  
70 - {{/each}}  
71 - </ul>  
72 - </div>  
73 - {{/trendInfo}} 57 + {{# trendInfo}}
  58 + <div class="trend-info" data-brands="{{shopBrands}}"></div>
  59 + {{/ trendInfo}}
74 </div> 60 </div>
75 </div> 61 </div>
76 </div> 62 </div>
@@ -201,3 +201,19 @@ $(window).on('scroll', function() { @@ -201,3 +201,19 @@ $(window).on('scroll', function() {
201 }); 201 });
202 } 202 }
203 }); 203 });
  204 +
  205 +// 获取店铺推荐文章
  206 +(function() {
  207 + var $trendInfo = $('.trend-info')
  208 + var brands = $trendInfo.data('brands');
  209 +
  210 + if (brands) {
  211 + $.ajax({
  212 + type: 'GET',
  213 + url: '/product/shop/article',
  214 + data: {brands: brands}
  215 + }).then(function(data) {
  216 + $trendInfo.replaceWith(data);
  217 + });
  218 + }
  219 +}());