Authored by yyq

article async

... ... @@ -52,7 +52,7 @@ exports.index = (req, res, next) => {
res.set('Cache-Control', 'no-cache');
}
res.render('list/shop-index', shopObj);
res.render('shop/index', shopObj);
} else { // 基础模版
Object.assign(shopObj, {page: 'list'});
... ... @@ -85,6 +85,19 @@ exports.list = (req, res, next) => {
if (!result.shopTopBanner) {
res.set('Cache-Control', 'no-cache');
}
res.render('list/shop-list', result);
res.render('shop/list', result);
}).catch(next);
};
// 经典店铺推荐文章
exports.article = (req, res, next) => {
let brands = req.query.brands;
if (!brands) {
return next();
}
return shopModel.getShopArticleByBrandsAsync(brands).then(result => {
res.render('shop/article', Object.assign(result, {layout: false}));
}).catch(next);
};
... ...
... ... @@ -177,7 +177,6 @@ const _getShopData = (channel, params, shopInfo) => {
sknList.push(value.productSkn);
});
let articleApiMethod = []; // 通过品牌获取相关文章接口
let apiMethod = [
searchApi.getProductList({
viewNum: sknList.length,
... ... @@ -191,16 +190,11 @@ const _getShopData = (channel, params, shopInfo) => {
_.forEach(result.brands.data, value => {
brands.push(value.brand_id);
articleApiMethod.push(
searchApi.getArticleByBrand(value.brand_id, 'udid') // 品牌推荐文章
);
});
resData.shopBrands = brands.join(',');
}
apiMethod = _.concat(apiMethod, articleApiMethod);
let subRes = yield Promise.all(apiMethod);
// 设置资源位商品封面图
... ... @@ -238,31 +232,7 @@ const _getShopData = (channel, params, shopInfo) => {
}
}
let articleList = [];
for (let i = 2; i < subRes.length; i++) {
articleList = _.concat(articleList, _.get(subRes[i], 'data', []));
}
if (articleList.length >= 3) {
let trendList = [];
for (let i = 0; i < 3; i++) {
trendList.push({
href: helpers.urlFormat(`/guang/${articleList[i].id}.html`, null),
src: helpers.getForceSourceUrl(articleList[i].src) +
'?imageView2/1/w/{width}/h/{height}',
mainTitle: articleList[i].title,
Subtitle: articleList[i].intro
});
articleList = _.concat(articleList, _.get(subRes[i], 'data', []));
}
resData.trendInfo = {
name: '潮流资讯 HOT ITEMS',
trendList: trendList
};
}
resData.trendInfo = true; // 展示店铺推荐文章
return resData;
})();
... ... @@ -649,3 +619,40 @@ exports.queryShopByBrandIdAsync = (sid, bid) => {
return _.get(result, 'data[0]', {});
})();
};
exports.getShopArticleByBrandsAsync = (brands) => {
let resData = {};
brands = _.split(brands, ',');
if (!brands.length) {
return Promise.resolve(resData);
}
return Promise.all(brands.map(value => searchApi.getArticleByBrand(value))).then(result => {
let articleList = [];
for (let i = 0; i < result.length; i++) {
articleList = _.concat(articleList, _.get(result[i], 'data', []));
}
if (articleList.length >= 3) {
articleList.length = 3;
resData.trendInfo = {
name: '潮流资讯 HOT ITEMS',
trendList: articleList.map(value => {
return {
href: helpers.urlFormat(`/guang/${value.id}.html`, null),
src: helpers.getForceSourceUrl(value.src) +
'?imageView2/1/w/{width}/h/{height}',
mainTitle: value.title,
Subtitle: value.intro
}
})
};
}
return resData;
});
};
... ...
... ... @@ -122,6 +122,7 @@ router.post('/index/getNodeContent', list.getNodeContent); // 品牌页水牌
router.post('/index/getAdnav', list.getAdnav); // 品牌页系列
router.get('/shop', shop.index); // 店铺首页
router.get('/shoplist', shop.list); // 店铺列表页
router.get('/shop/article', shop.article); // 店铺推荐文章
router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏
router.post('/index/isFavoriteShop', favorite.isFavShop); // 判断用户是否收藏品牌
router.get('/brand/couponsync', list.brandCouponSync);
... ...
{{# trendInfo}}
<div class="trend-info clearfix">
{{> common/floor-header}}
<ul class="trend-list">
{{#each trendList}}
<li>
<a href="{{href}}">
<img src="{{image2 src w=264 h=173}}" />
<div class="main-title">{{mainTitle}}</div>
<div class="sub-title">{{Subtitle}}</div>
</a>
</li>
{{/each}}
</ul>
</div>
{{/ trendInfo}}
... ...
... ... @@ -6,7 +6,7 @@
<div class="list-left pull-left">
{{> list/shop-search}}
{{> product/left-content}}
{{> list/shop-sidebar}}
... ... @@ -54,23 +54,9 @@
{{> list/shop-all-goods}}
{{#trendInfo}}
<div class="trend-info clearfix">
{{> common/floor-header}}
<ul class="trend-list">
{{#each trendList}}
<li>
<a href="{{href}}">
<img src="{{image2 src w=264 h=173}}" />
<div class="main-title">{{mainTitle}}</div>
<div class="sub-title">{{Subtitle}}</div>
</a>
</li>
{{/each}}
</ul>
</div>
{{/trendInfo}}
{{# trendInfo}}
<div class="trend-info" data-brands="{{shopBrands}}"></div>
{{/ trendInfo}}
</div>
</div>
</div>
... ...
... ... @@ -201,3 +201,19 @@ $(window).on('scroll', function() {
});
}
});
// 获取店铺推荐文章
(function() {
var $trendInfo = $('.trend-info')
var brands = $trendInfo.data('brands');
if (brands) {
$.ajax({
type: 'GET',
url: '/product/shop/article',
data: {brands: brands}
}).then(function(data) {
$trendInfo.replaceWith(data);
});
}
}());
... ...