Authored by biao

Merge branch 'release/1.0' of http://git.yoho.cn/fe/yoho-blk into release/1.0

... ... @@ -93,10 +93,27 @@ const getModelTryAsync = skn => {
});
};
/**
* 获取品牌Banner API
* @function getBrandBannerAsync
* @param { number } brandId 品牌id
* @return { Object } banner信息
*/
const getBrandBannerAsync = brandId => {
return api.get('', {
method: 'web.brand.banner',
brand_id: brandId
}, {
cache: true,
code: 200
});
};
module.exports = {
getProductBaseAsync, // 获取商品基本信息
getUserIsFav, // 获取商品用户收藏信息
getsizeInfoAsync, // 获取商品尺码信息
getComfortAsync, // 获取商品材质信息
getModelTryAsync // 获取商品模特试穿信息
getModelTryAsync, // 获取商品模特试穿信息
getBrandBannerAsync // 获取品牌Banner信息
};
... ...
... ... @@ -9,6 +9,23 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
/**
* 获取原图片路径
* @function _getForceSourceUrl
* @param { String } url 图片路径
* @return { String } 原图片路径
*/
const _getForceSourceUrl = (url) => {
const str = ['?imageView', '?imageMogr2'];
_.forEach(str, value => {
url = _.split(url, value, 1)[0];
});
url.replace('http:', '');
return url;
};
/**
* 使sizeBoList id以 sizeAttributeBos id顺序一样
* @function _sizeInfoBoSort
* @param { Object } sizeInfoBo 尺码数据对象
... ... @@ -232,22 +249,64 @@ const setPathNav = (data, name, channel) => {
* @param { Object } brand 品牌相关数据
* @return { Object } 品牌banner
*/
const setBrandBanner = brand => {
let data = {
brandId: brand.id,
const setBrandBanner = (base, brand, shop) => {
let resData = {},
banner = {};
if (base.brand) {
let info = base.brand;
// 基础品牌数据
banner = {
brandId: info.id,
bgColor: '#000',
brandLogo: {
link: `/product/shop/${brand.brandDomain}`, // 品牌跳转链接 -- 待处理
img: brand.brandIco
link: `/product/shop/${info.brandDomain}`, // 品牌跳转链接
img: info.brandIco
},
brandHome: {
link: `/product/shop/${brand.brandDomain}` // 品牌跳转链接 -- 待处理
link: `/product/shop/${info.brandDomain}` // 品牌跳转链接
}
};
return {
brandBanner: data
};
// 品牌banner数据
if (brand) {
if (brand.colorValue) {
banner.bgColor = brand.colorValue;
}
if (brand.bannerUrl) {
banner.bgImg = brand.bannerUrl;
}
if (brand.logo) {
_.set(banner, 'brandLogo.img', _getForceSourceUrl(brand.logo));
}
}
}
switch (_.toNumber(shop.type)) {
case 1:
// 多品店不显示
banner = {};
break;
case 2:
// 单品店显示新版的店铺banner
_.forEach(shop.list, value => {
if (value.resource_name === 'shopTopBanner') {
banner.bgImg = _.get(JSON.parse(value.resource_data), 'detailSrc', false);
}
});
break;
default:
break;
}
if (!_.isEmpty(banner)) {
resData.brandBanner = banner;
}
return resData;
};
/**
... ...
... ... @@ -8,6 +8,7 @@
const _ = require('lodash');
const itemApi = require('./item-api');
const brandApi = require('./brand-api');
const shopApi = require('./shop-api');
const itemFun = require('./item-handler');
const search = require('./search-api');
... ... @@ -20,31 +21,55 @@ const search = require('./search-api');
* @return { Object } 返回单个商品品牌、材质、尺码、描述、详情等信息
*/
const _getMultiResourceByBaseInfo = (base) => {
let productId = base.id;
let skn = base.erpProductId;
let brandId = base.brand.id ? base.brand.id : 0;
const productId = base.id;
const skn = base.erpProductId;
const brandId = base.brandId || 0;
const brandDomain = _.get(base, 'brand.brandDomain', false);
const shopId = base.shopId || 0;
let apiIndex = {};
// 获取相关数据
let promiseData = [
itemApi.getsizeInfoAsync(skn),
itemApi.getComfortAsync(productId),
itemApi.getModelTryAsync(skn),
search.getSortAsync({sort: base.smallSortId})
search.getSortAsync({sort: base.smallSortId}),
itemApi.getBrandBannerAsync(brandId)
];
if (base.uid) {
apiIndex.productFav = promiseData.length;
promiseData.push(itemApi.getUserIsFav(base.uid, productId));
apiIndex.brandFav = promiseData.length;
promiseData.push(brandApi.getBrandInfo(brandId, base.uid));
}
// 根据品牌名获取店铺信息
if (brandDomain) {
apiIndex.domainInfo = promiseData.length;
promiseData.push(brandApi.getDomainInfo(brandDomain));
}
// 根据店铺ID获取店铺装修信息
if (shopId) {
apiIndex.shopDecorator = promiseData.length;
promiseData.push(shopApi.getShopDecorator(shopId));
}
return Promise.all(promiseData).then(result => {
return {
sizeInfo: result[0],
comfort: result[1].data,
modelTry: result[2].data,
sort: result[3].data,
productFav: (result[4] && result[4].data),
brandFav: (result[5] && result[5].data && result[5].data.is_favorite === 'Y')
brandBanner: result[4].data,
productFav: (result[apiIndex.productFav] && result[apiIndex.productFav].data),
brandFav: (_.get(result[apiIndex.brandFav], 'data.is_favorite', 'N') === 'Y'),
shopInfo: Object.assign(
{},
{type: _.get(result[apiIndex.domainInfo], 'data.type', 0)},
{list: _.get(result[apiIndex.shopDecorator], 'data.list', [])}
)
};
});
};
... ... @@ -78,27 +103,28 @@ const getProductItemData = (params, url, uid) => {
// 商品基本信息
data.goodInfo = itemFun.setProductData(result);
// BRAND品牌简介
if (result.brand) {
Object.assign(
data,
itemFun.setBrandBanner(result.brand), // banner
itemFun.setBrandIntro(result.brand) // BRAND品牌简介
);
Object.assign(data, itemFun.setBrandIntro(result.brand));
}
return _getMultiResourceByBaseInfo(result).then(mulRes => {
// 收藏状态
_.set(data, 'brandBanner.brandFav', mulRes.brandFav);
_.set(data, 'goodInfo.productFav', mulRes.productFav);
Object.assign(data,
itemFun.setBrandBanner(result, mulRes.brandBanner, mulRes.shopInfo), // banner
itemFun.setPathNav(mulRes.sort, result.productName, params.channel), // 面包屑导航
itemFun.setDescriptionData(mulRes.sizeInfo, mulRes.comfort), // DESCRIPTION商品描述
itemFun.setMaterialData(mulRes.sizeInfo), // MATERIALS材料洗涤
itemFun.setSizeData(mulRes.sizeInfo, mulRes.modelTry), // SIZEINFO尺码信息
itemFun.setDetailData(mulRes.sizeInfo) // DETAILS商品详情
);
// 收藏状态
_.set(data, 'goodInfo.productFav', mulRes.productFav);
if (data.brandBanner) {
_.set(data, 'brandBanner.brandFav', mulRes.brandFav);
}
resData.content = data;
// 商品详情SEO
... ...
... ... @@ -5,7 +5,7 @@
<div class="center-content clearfix">
{{# brandLogo}}
<a href="{{link}}" class="brand-logo">
<img src="{{image img 108 44}}">
<img src="{{image img 108 45}}">
</a>
{{/ brandLogo}}
<p class="opt right">
... ...
... ... @@ -2,18 +2,17 @@
position: relative;
.banner-img {
min-height: 44px;
min-height: 45px;
}
.opt-wrap {
width: 100%;
height: 44px;
height: 45px;
position: absolute;
top: 50%;
margin-top: -22px;
margin-top: -23px;
.brand-logo {
width: 108px;
display: inline-block;
}
... ...