...
|
...
|
@@ -12,233 +12,6 @@ const _ = require('lodash'); |
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
/**
|
|
|
* 组织店铺页面数据
|
|
|
* @param {array} data 接口返回的店铺页所需数据
|
|
|
* @param {int} shopId 店铺id
|
|
|
* @param {int} isApp app版本
|
|
|
* @return array
|
|
|
*/
|
|
|
const _formShopData = (data, shopId, isApp) => {
|
|
|
let formatData = {
|
|
|
shopId: shopId,
|
|
|
appVersion: isApp
|
|
|
},
|
|
|
single = false;
|
|
|
let brandId;
|
|
|
|
|
|
// 组织店铺装修
|
|
|
if (data.decorator) {
|
|
|
_.forEach(data.decorator.list, (floor) => {
|
|
|
let resData = JSON.parse(floor.resourceData);
|
|
|
|
|
|
floor[_.camelCase(floor.resourceName)] = true;
|
|
|
|
|
|
// 店铺banner
|
|
|
if (floor.shopTopBannerApp) {
|
|
|
formatData.branerImg = resData[0].shopSrc;
|
|
|
}
|
|
|
|
|
|
// 资源位小图 接口返回两组,取每组第一张
|
|
|
if (floor.oneRowTwoColImagesApp) {
|
|
|
let spring = [];
|
|
|
|
|
|
_.forEach(resData, (item) => {
|
|
|
if (item.data) {
|
|
|
spring.push({
|
|
|
url: isApp ? listModel.modifyAppUrl(item.data[0], shopId) :
|
|
|
listModel.modifyWapUrl(item.data[0], shopId),
|
|
|
springType: helpers.image(item.data[0].src)
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
formatData.spring = spring;
|
|
|
}
|
|
|
|
|
|
|
|
|
// 店铺品牌一览
|
|
|
if (floor.brandBrowse) {
|
|
|
let brandNumber = resData.length;
|
|
|
let brand = {
|
|
|
list: []
|
|
|
};
|
|
|
|
|
|
brandId = '';
|
|
|
|
|
|
// 少于2个不展示 单品店:单品店根据品牌id查询
|
|
|
if (brandNumber < 2) {
|
|
|
brandId = formatData.brand = resData[0].id;
|
|
|
single = true;
|
|
|
} else {
|
|
|
_.forEach(resData, (item) => {
|
|
|
if (item.brandDomain) {
|
|
|
brand.list.push({
|
|
|
url: helpers.urlFormat('', '', item.brandDomain) + (isApp ? `?openby:yohobuy={"action":"go.brand","params":{"shop_id":${shopId},"brand_id":${item.id}}}` : ''), //eslint-disable-line
|
|
|
img: helpers.image(item.brandIco, 640, 400),
|
|
|
brandName: item.brandName
|
|
|
});
|
|
|
brandId += item.id + ',';
|
|
|
}
|
|
|
});
|
|
|
|
|
|
formatData.brandList = brand;
|
|
|
|
|
|
// 大于5个返回更多品牌链接
|
|
|
if (brandNumber > 5) {
|
|
|
formatData.brandList.url = helpers.urlFormat('/product/index/allBrand', {
|
|
|
shop_id: shopId
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 资源位大图幻灯
|
|
|
if (floor.largeSlideImgApp) {
|
|
|
let bannerTop = {
|
|
|
data: []
|
|
|
};
|
|
|
|
|
|
_.forEach(resData, (item) => {
|
|
|
if (item.data[0]) {
|
|
|
bannerTop.data.push({
|
|
|
url: isApp ? listModel.modifyAppUrl(item.data[0], shopId) :
|
|
|
listModel.modifyWapUrl(item.data[0], shopId),
|
|
|
src: item.data[0].src
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
formatData.bannerTop = bannerTop;
|
|
|
}
|
|
|
|
|
|
// 热门品类
|
|
|
if (floor.recommendApp) {
|
|
|
let hotCategory = {
|
|
|
data: {
|
|
|
title: {
|
|
|
title: '热门品类'
|
|
|
},
|
|
|
list: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
_.forEach(resData, (cate) => {
|
|
|
hotCategory.data.list.push({
|
|
|
url: cate.url,
|
|
|
src: helpers.image(cate.src)
|
|
|
});
|
|
|
});
|
|
|
|
|
|
formatData.hotCategory = hotCategory;
|
|
|
}
|
|
|
|
|
|
// 人气单品
|
|
|
if (floor.hotProductsApp) {
|
|
|
let goods = [];
|
|
|
|
|
|
_.forEach(resData, (item) => {
|
|
|
let url = '//item.yohobuy.com/product/pro_';
|
|
|
|
|
|
if (!item.cnAlphabet) {
|
|
|
item.cnAlphabet = 'goods.html';
|
|
|
}
|
|
|
url += item.productId + '_' + item.goodsId + '/' + item.cnAlphabet + '.html';
|
|
|
goods.push({
|
|
|
url: url + (isApp ? `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${item.productSkn}}}` : ''),//eslint-disable-line
|
|
|
img: helpers.image(item.src, 235, 314),
|
|
|
productName: item.productName,
|
|
|
salesPrice: item.salesPrice,
|
|
|
presentPrice: item.salesPrice
|
|
|
});
|
|
|
});
|
|
|
|
|
|
formatData.hotList = goods;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 店铺基本信息
|
|
|
if (data.shopInfo) {
|
|
|
let allGoodsParam = {
|
|
|
title: '全部商品'
|
|
|
};
|
|
|
|
|
|
formatData = _.assign({
|
|
|
logoImg: data.shopInfo.shopLogo,
|
|
|
storeName: (data.shopInfo.isShowShopName === 'Y') ? data.shopInfo.shopName : '',
|
|
|
collect: data.shopInfo.isFavorite === 'Y',
|
|
|
url: helpers.urlFormat('', {
|
|
|
shop_id: shopId
|
|
|
}, 'search'), // 搜索链接
|
|
|
more_url: helpers.urlFormat('', {
|
|
|
shop_id: shopId,
|
|
|
order: 's_n_d',
|
|
|
title: '人气单品'
|
|
|
}, 'search') // 人气单品的链接
|
|
|
}, formatData);
|
|
|
|
|
|
if (single) { // 单品点
|
|
|
allGoodsParam.brand = brandId;
|
|
|
} else { // 店铺id
|
|
|
formatData.shopId = shopId;
|
|
|
allGoodsParam.shopId = shopId;
|
|
|
}
|
|
|
|
|
|
if (!isApp) {
|
|
|
formatData = _.assign({
|
|
|
allGoods: helpers.urlFormat('', allGoodsParam, 'search'),
|
|
|
shopIntroHref: helpers.urlFormat('/product/index/intro', {
|
|
|
shop_id: shopId
|
|
|
}) // 店铺简介页地址
|
|
|
}, formatData);
|
|
|
} else {
|
|
|
formatData = _.assign({
|
|
|
allGoods: `${helpers.urlFormat('', allGoodsParam, 'search')}&openby:yohobuy={"action":"go.list","params":{"title":"全部商品", "actiontype":"0","shop_id":${shopId},"page":"1"}}`,//eslint-disable-line
|
|
|
shopIntroHref: helpers.urlFormat('/product/index/intro', {
|
|
|
shop_id: shopId,
|
|
|
app_version: isApp
|
|
|
}),
|
|
|
more_url: formatData.more_url + `?openby:yohobuy={"action":"go.list","params":{"shop_id":${shopId},"title":"人气单品"}}`//eslint-disable-line
|
|
|
}, formatData);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 店铺下面的所有分类
|
|
|
if (data.shopCategory) {
|
|
|
let total = data.shopCategory.length;
|
|
|
let shopCategory = {
|
|
|
list: []
|
|
|
};
|
|
|
|
|
|
if (total > 6) {
|
|
|
shopCategory.url = helpers.urlFormat('/product/index/category', {
|
|
|
shop_id: shopId
|
|
|
});
|
|
|
} else {
|
|
|
_.forEach(data.shopCategory, (item) => {
|
|
|
shopCategory.list.push({
|
|
|
url: helpers.urlFormat('', {
|
|
|
shop_id: shopId,
|
|
|
sort: item.relationParameter.sort
|
|
|
}, 'search'),
|
|
|
categoryId: item.categoryId,
|
|
|
name: item.categoryName
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
formatData.shopCategory = shopCategory;
|
|
|
}
|
|
|
|
|
|
if (single) {
|
|
|
formatData.favId = shopId;
|
|
|
formatData.shopId = '';
|
|
|
}
|
|
|
|
|
|
return formatData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 新店铺首页
|
|
|
* @param {object} req
|
|
|
* @param {int} shopId 店铺id
|
...
|
...
|
@@ -246,29 +19,30 @@ const _formShopData = (data, shopId, isApp) => { |
|
|
* @param {string} isApp app版本
|
|
|
*/
|
|
|
const _getShopData = (req, shopId, uid, isApp) => {
|
|
|
let data = {};
|
|
|
let shopData = {};
|
|
|
let channel = req.yoho.channel;
|
|
|
|
|
|
return Promise.all([listModel.getShopDecorator(shopId), listModel.getShopInfo(shopId, uid)]).then((result) => {
|
|
|
data = {
|
|
|
shopData = {
|
|
|
decorator: result[0], // 店铺装修资源数据
|
|
|
shopInfo: result[1] // 店铺信息
|
|
|
};
|
|
|
|
|
|
// 店铺使用基础模板,返回品牌页面
|
|
|
if (data.shopInfo.shopTemplateType && data.shopInfo.shopTemplateType === '1') {
|
|
|
if (shopData.shopInfo.shopTemplateType && shopData.shopInfo.shopTemplateType === '1') {
|
|
|
return {
|
|
|
goBrand: data.shopInfo
|
|
|
goBrand: shopData.shopInfo
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 店铺分类
|
|
|
return listModel.getShopCategory(shopId, channel).then((shopCategory) => {
|
|
|
data = _.assign({
|
|
|
shopData = _.assign({
|
|
|
shopCategory: shopCategory
|
|
|
}, data);
|
|
|
}, shopData);
|
|
|
|
|
|
return _formShopData(data, shopId, isApp); // 组织楼层数据
|
|
|
//noinspection JSCheckFunctionSignatures
|
|
|
return listModel.formShopData(shopData, shopId, isApp); // 组织楼层数据
|
|
|
});
|
|
|
});
|
|
|
};
|
...
|
...
|
|