Authored by 郭成尧

'店铺支持ID直接访问'

... ... @@ -16,7 +16,8 @@ module.exports = {
res.render('shop/index', {
module: 'product',
page: 'shop',
domain: req.params.domain
domain: req.params.domain,
shopId: req.query.id
});
},
... ... @@ -24,6 +25,7 @@ module.exports = {
getShopInfo: (req, res, next) => {
shopModel.getShopData({
domain: req.query.domain,
shopId: req.query.id,
uid: req.user.uid
}).then(result => {
res.json(result);
... ... @@ -39,7 +41,7 @@ module.exports = {
channel: req.query.channel || 'men',
gender: req.query.gender || '1,2,3',
brand: req.query.brand,
shopId: req.query.shopId,
shopId: req.query.id,
order: req.query.order || 's_t_desc',
limit: req.query.limit || '60',
color: req.query.color,
... ...
... ... @@ -13,6 +13,76 @@ const _ = require('lodash');
const prettyFilter = require(`${global.utils}/beautify/filters`);
/**
* 获取店铺数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const _getShopInfoData = (finalResult, params) => {
return shopApi.getShopInfoData({
shopId: params.shopId,
uid: params.uid
}).then(subResult => {
if (subResult.data) {
/* 取店铺的基本信息 */
Object.assign(finalResult, {
shopLogo: subResult.data.shop_logo,
shopName: subResult.data.shop_name,
shopIntro: subResult.data.shop_intro,
isFav: subResult.data.is_favorite === 'Y'
});
/* 取资源位店铺背景图 */
return shopApi.getShopsDecoratorList({
shopId: params.shopId
}).then(thResult => {
if (thResult.data) {
_.forEach(thResult.data.list, value => {
if (value.resource_name === 'shopTopBanner_app') {
Object.assign(finalResult, {
shopBg: JSON.parse(value.resource_data).shopSrc
});
}
});
}
return finalResult;
});
}
return finalResult;
});
};
/**
* 获取品牌店铺商品数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const _getGoodsList = params => {
let finalResult = {};
return shopApi.getBrandShopGoodsOriginData(Object.assign(params, {
shopId: params.shopId
})).then(subResult => {
if (subResult.data) {
prettyFilter(subResult.data.filter);
finalResult = {
data: {
productList: processProductList(subResult.data.product_list, { gender: params.gender }),
filter: subResult.data.filter,
page: subResult.data.page,
pageTotal: subResult.data.page_total
},
code: 200
};
}
return camelCase(finalResult);
});
};
/**
* 获取品牌店铺数据
* @param params
* @returns {*|Promise.<TResult>}
... ... @@ -20,111 +90,70 @@ const prettyFilter = require(`${global.utils}/beautify/filters`);
const getShopData = params => {
let finalResult = {};
return shopApi.getBrandInfoByDomain({
domain: params.domain
}).then(result => {
// 如果有店铺 ID,直接取店铺信息
if (params.shopId) {
if (result.data) {
/* 是 BLK 的店铺 */
Object.assign(finalResult, {
isBlkShop: true,
shopId: params.shopId
});
/* 品牌名称 */
Object.assign(finalResult, {
brandName: result.data.brand_name,
brandId: result.data.id
});
return _getShopInfoData(finalResult, params);
} else {
return shopApi.getBrandInfoByDomain({
domain: params.domain
}).then(result => {
/* 品牌是否有店铺 */
if (result.data.shop_id) {
if (result.data) {
/* 是 BLK 的店铺 */
/* 品牌名称 */
Object.assign(finalResult, {
isBlkShop: true,
shopId: result.data.shop_id
brandName: result.data.brand_name,
brandId: result.data.id
});
return shopApi.getShopInfoData({
shopId: result.data.shop_id,
uid: params.uid
}).then(subResult => {
if (subResult.data) {
/* 取店铺的基本信息 */
Object.assign(finalResult, {
shopLogo: subResult.data.shop_logo,
shopName: subResult.data.shop_name,
shopIntro: subResult.data.shop_intro,
isFav: subResult.data.is_favorite === 'Y'
});
/* 取资源位店铺背景图 */
return shopApi.getShopsDecoratorList({
shopId: result.data.shop_id
}).then(thResult => {
if (thResult.data) {
_.forEach(thResult.data.list, value => {
if (value.resource_name === 'shopTopBanner_app') {
Object.assign(finalResult, {
shopBg: JSON.parse(value.resource_data).shopSrc
});
}
});
}
return finalResult;
});
}
return finalResult;
});
} else {
/* 品牌是否有店铺 */
if (result.data.shop_id) {
/* 不是 BLK 的店铺 */
Object.assign(finalResult, {
isBlkShop: false
});
/* 是 BLK 的店铺 */
Object.assign(finalResult, {
isBlkShop: true,
shopId: result.data.shop_id
});
return _getShopInfoData(finalResult, Object.assign(params, {shopId: result.data.shop_id}));
} else {
logger.info('brand has no shop');
/* 不是 BLK 的店铺 */
Object.assign(finalResult, {
isBlkShop: false
});
logger.info('brand has no shop');
}
return finalResult;
}
return finalResult;
}
return finalResult;
});
return finalResult;
});
}
};
/**
* 获取品牌店铺商品数据
* 获取品牌店铺商品
* @param params
* @returns {*|Promise.<TResult>}
*/
const getBrandShopGoodsData = params => {
let finalResult = {};
return shopApi.getBrandInfoByDomain({
domain: params.domain
}).then(result => {
if (result.data) {
return shopApi.getBrandShopGoodsOriginData(Object.assign(params, {
brand: result.data.id,
shopId: result.data.shop_id
})).then(subResult => {
if (subResult.data) {
prettyFilter(subResult.data.filter);
finalResult = {
data: {
productList: processProductList(subResult.data.product_list, {gender: params.gender}),
filter: subResult.data.filter,
page: subResult.data.page,
pageTotal: subResult.data.page_total
},
code: 200
};
}
return camelCase(finalResult);
});
}
return camelCase(finalResult);
});
if (params.shopId) {
return _getGoodsList(params);
} else {
return shopApi.getBrandInfoByDomain({
domain: params.domain
}).then(result => {
return _getGoodsList(Object.assign(params, {shopId: result.data.shop_id}));
});
}
};
/**
... ...
... ... @@ -36,8 +36,8 @@ router.get('/brand', shop.index); // 品牌 集合页
router.get('/product/shop/info.json', shop.getShopInfo); // 店铺介绍
router.get('/product/shop/goods.json', shop.getBrandShopGoods); // 店铺商品列表
router.post('/product/shop/collect.json', shop.collectShop); // 收藏品牌店铺
router.get('/product/shop/:domain/', shop.index); // 品牌店铺页
router.get('/product/shop/:domain/share', shop.shopShare); // 品牌店铺页
router.get('/product/shop/:domain', shop.index); // 品牌店铺页
router.get('/product/shop/:domain/share', shop.shopShare); // 品牌店铺页分享
// 商品详情controller
const detail = require(`${cRoot}/detail`);
... ...
<div id="shop" data-domain="{{domain}}">
<div id="shop" data-domain="{{domain}}" data-shopid = "{{shopId}}">
<shop-box></shop-box>
</div>
... ...
... ... @@ -75,7 +75,8 @@
$.get({
url: '/product/shop/info.json',
data: {
domain: $shop.data('domain')
domain: $shop.data('domain'),
id: $shop.data('shopid') // 店铺 ID
}
}).done(result => {
if (result) {
... ...