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 => { @@ -93,10 +93,27 @@ const getModelTryAsync = skn => {
93 }); 93 });
94 }; 94 };
95 95
  96 +/**
  97 + * 获取品牌Banner API
  98 + * @function getBrandBannerAsync
  99 + * @param { number } brandId 品牌id
  100 + * @return { Object } banner信息
  101 + */
  102 +const getBrandBannerAsync = brandId => {
  103 + return api.get('', {
  104 + method: 'web.brand.banner',
  105 + brand_id: brandId
  106 + }, {
  107 + cache: true,
  108 + code: 200
  109 + });
  110 +};
  111 +
96 module.exports = { 112 module.exports = {
97 getProductBaseAsync, // 获取商品基本信息 113 getProductBaseAsync, // 获取商品基本信息
98 getUserIsFav, // 获取商品用户收藏信息 114 getUserIsFav, // 获取商品用户收藏信息
99 getsizeInfoAsync, // 获取商品尺码信息 115 getsizeInfoAsync, // 获取商品尺码信息
100 getComfortAsync, // 获取商品材质信息 116 getComfortAsync, // 获取商品材质信息
101 - getModelTryAsync // 获取商品模特试穿信息 117 + getModelTryAsync, // 获取商品模特试穿信息
  118 + getBrandBannerAsync // 获取品牌Banner信息
102 }; 119 };
@@ -9,6 +9,23 @@ const _ = require('lodash'); @@ -9,6 +9,23 @@ const _ = require('lodash');
9 const helpers = global.yoho.helpers; 9 const helpers = global.yoho.helpers;
10 10
11 /** 11 /**
  12 + * 获取原图片路径
  13 + * @function _getForceSourceUrl
  14 + * @param { String } url 图片路径
  15 + * @return { String } 原图片路径
  16 + */
  17 +const _getForceSourceUrl = (url) => {
  18 + const str = ['?imageView', '?imageMogr2'];
  19 +
  20 + _.forEach(str, value => {
  21 + url = _.split(url, value, 1)[0];
  22 + });
  23 + url.replace('http:', '');
  24 +
  25 + return url;
  26 +};
  27 +
  28 +/**
12 * 使sizeBoList id以 sizeAttributeBos id顺序一样 29 * 使sizeBoList id以 sizeAttributeBos id顺序一样
13 * @function _sizeInfoBoSort 30 * @function _sizeInfoBoSort
14 * @param { Object } sizeInfoBo 尺码数据对象 31 * @param { Object } sizeInfoBo 尺码数据对象
@@ -232,22 +249,64 @@ const setPathNav = (data, name, channel) => { @@ -232,22 +249,64 @@ const setPathNav = (data, name, channel) => {
232 * @param { Object } brand 品牌相关数据 249 * @param { Object } brand 品牌相关数据
233 * @return { Object } 品牌banner 250 * @return { Object } 品牌banner
234 */ 251 */
235 -const setBrandBanner = brand => {  
236 - let data = {  
237 - brandId: brand.id, 252 +const setBrandBanner = (base, brand, shop) => {
  253 + let resData = {},
  254 + banner = {};
  255 +
  256 + if (base.brand) {
  257 + let info = base.brand;
  258 +
  259 + // 基础品牌数据
  260 + banner = {
  261 + brandId: info.id,
238 bgColor: '#000', 262 bgColor: '#000',
239 brandLogo: { 263 brandLogo: {
240 - link: `/product/shop/${brand.brandDomain}`, // 品牌跳转链接 -- 待处理  
241 - img: brand.brandIco 264 + link: `/product/shop/${info.brandDomain}`, // 品牌跳转链接
  265 + img: info.brandIco
242 }, 266 },
243 brandHome: { 267 brandHome: {
244 - link: `/product/shop/${brand.brandDomain}` // 品牌跳转链接 -- 待处理 268 + link: `/product/shop/${info.brandDomain}` // 品牌跳转链接
245 } 269 }
246 }; 270 };
247 271
248 - return {  
249 - brandBanner: data  
250 - }; 272 + // 品牌banner数据
  273 + if (brand) {
  274 + if (brand.colorValue) {
  275 + banner.bgColor = brand.colorValue;
  276 + }
  277 +
  278 + if (brand.bannerUrl) {
  279 + banner.bgImg = brand.bannerUrl;
  280 + }
  281 +
  282 + if (brand.logo) {
  283 + _.set(banner, 'brandLogo.img', _getForceSourceUrl(brand.logo));
  284 + }
  285 + }
  286 + }
  287 +
  288 + switch (_.toNumber(shop.type)) {
  289 + case 1:
  290 + // 多品店不显示
  291 + banner = {};
  292 + break;
  293 + case 2:
  294 + // 单品店显示新版的店铺banner
  295 + _.forEach(shop.list, value => {
  296 + if (value.resource_name === 'shopTopBanner') {
  297 + banner.bgImg = _.get(JSON.parse(value.resource_data), 'detailSrc', false);
  298 + }
  299 + });
  300 + break;
  301 + default:
  302 + break;
  303 + }
  304 +
  305 + if (!_.isEmpty(banner)) {
  306 + resData.brandBanner = banner;
  307 + }
  308 +
  309 + return resData;
251 }; 310 };
252 311
253 /** 312 /**
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 const _ = require('lodash'); 8 const _ = require('lodash');
9 const itemApi = require('./item-api'); 9 const itemApi = require('./item-api');
10 const brandApi = require('./brand-api'); 10 const brandApi = require('./brand-api');
  11 +const shopApi = require('./shop-api');
11 const itemFun = require('./item-handler'); 12 const itemFun = require('./item-handler');
12 13
13 const search = require('./search-api'); 14 const search = require('./search-api');
@@ -20,31 +21,55 @@ const search = require('./search-api'); @@ -20,31 +21,55 @@ const search = require('./search-api');
20 * @return { Object } 返回单个商品品牌、材质、尺码、描述、详情等信息 21 * @return { Object } 返回单个商品品牌、材质、尺码、描述、详情等信息
21 */ 22 */
22 const _getMultiResourceByBaseInfo = (base) => { 23 const _getMultiResourceByBaseInfo = (base) => {
23 - let productId = base.id;  
24 - let skn = base.erpProductId;  
25 - let brandId = base.brand.id ? base.brand.id : 0; 24 + const productId = base.id;
  25 + const skn = base.erpProductId;
  26 + const brandId = base.brandId || 0;
  27 + const brandDomain = _.get(base, 'brand.brandDomain', false);
  28 + const shopId = base.shopId || 0;
  29 + let apiIndex = {};
26 30
27 // 获取相关数据 31 // 获取相关数据
28 let promiseData = [ 32 let promiseData = [
29 itemApi.getsizeInfoAsync(skn), 33 itemApi.getsizeInfoAsync(skn),
30 itemApi.getComfortAsync(productId), 34 itemApi.getComfortAsync(productId),
31 itemApi.getModelTryAsync(skn), 35 itemApi.getModelTryAsync(skn),
32 - search.getSortAsync({sort: base.smallSortId}) 36 + search.getSortAsync({sort: base.smallSortId}),
  37 + itemApi.getBrandBannerAsync(brandId)
33 ]; 38 ];
34 39
35 if (base.uid) { 40 if (base.uid) {
  41 + apiIndex.productFav = promiseData.length;
36 promiseData.push(itemApi.getUserIsFav(base.uid, productId)); 42 promiseData.push(itemApi.getUserIsFav(base.uid, productId));
  43 + apiIndex.brandFav = promiseData.length;
37 promiseData.push(brandApi.getBrandInfo(brandId, base.uid)); 44 promiseData.push(brandApi.getBrandInfo(brandId, base.uid));
38 } 45 }
39 46
  47 + // 根据品牌名获取店铺信息
  48 + if (brandDomain) {
  49 + apiIndex.domainInfo = promiseData.length;
  50 + promiseData.push(brandApi.getDomainInfo(brandDomain));
  51 + }
  52 +
  53 + // 根据店铺ID获取店铺装修信息
  54 + if (shopId) {
  55 + apiIndex.shopDecorator = promiseData.length;
  56 + promiseData.push(shopApi.getShopDecorator(shopId));
  57 + }
  58 +
40 return Promise.all(promiseData).then(result => { 59 return Promise.all(promiseData).then(result => {
41 return { 60 return {
42 sizeInfo: result[0], 61 sizeInfo: result[0],
43 comfort: result[1].data, 62 comfort: result[1].data,
44 modelTry: result[2].data, 63 modelTry: result[2].data,
45 sort: result[3].data, 64 sort: result[3].data,
46 - productFav: (result[4] && result[4].data),  
47 - brandFav: (result[5] && result[5].data && result[5].data.is_favorite === 'Y') 65 + brandBanner: result[4].data,
  66 + productFav: (result[apiIndex.productFav] && result[apiIndex.productFav].data),
  67 + brandFav: (_.get(result[apiIndex.brandFav], 'data.is_favorite', 'N') === 'Y'),
  68 + shopInfo: Object.assign(
  69 + {},
  70 + {type: _.get(result[apiIndex.domainInfo], 'data.type', 0)},
  71 + {list: _.get(result[apiIndex.shopDecorator], 'data.list', [])}
  72 + )
48 }; 73 };
49 }); 74 });
50 }; 75 };
@@ -78,27 +103,28 @@ const getProductItemData = (params, url, uid) => { @@ -78,27 +103,28 @@ const getProductItemData = (params, url, uid) => {
78 // 商品基本信息 103 // 商品基本信息
79 data.goodInfo = itemFun.setProductData(result); 104 data.goodInfo = itemFun.setProductData(result);
80 105
  106 + // BRAND品牌简介
81 if (result.brand) { 107 if (result.brand) {
82 - Object.assign(  
83 - data,  
84 - itemFun.setBrandBanner(result.brand), // banner  
85 - itemFun.setBrandIntro(result.brand) // BRAND品牌简介  
86 - ); 108 + Object.assign(data, itemFun.setBrandIntro(result.brand));
87 } 109 }
88 110
89 return _getMultiResourceByBaseInfo(result).then(mulRes => { 111 return _getMultiResourceByBaseInfo(result).then(mulRes => {
90 112
91 - // 收藏状态  
92 - _.set(data, 'brandBanner.brandFav', mulRes.brandFav);  
93 - _.set(data, 'goodInfo.productFav', mulRes.productFav);  
94 -  
95 Object.assign(data, 113 Object.assign(data,
  114 + itemFun.setBrandBanner(result, mulRes.brandBanner, mulRes.shopInfo), // banner
96 itemFun.setPathNav(mulRes.sort, result.productName, params.channel), // 面包屑导航 115 itemFun.setPathNav(mulRes.sort, result.productName, params.channel), // 面包屑导航
97 itemFun.setDescriptionData(mulRes.sizeInfo, mulRes.comfort), // DESCRIPTION商品描述 116 itemFun.setDescriptionData(mulRes.sizeInfo, mulRes.comfort), // DESCRIPTION商品描述
98 itemFun.setMaterialData(mulRes.sizeInfo), // MATERIALS材料洗涤 117 itemFun.setMaterialData(mulRes.sizeInfo), // MATERIALS材料洗涤
99 itemFun.setSizeData(mulRes.sizeInfo, mulRes.modelTry), // SIZEINFO尺码信息 118 itemFun.setSizeData(mulRes.sizeInfo, mulRes.modelTry), // SIZEINFO尺码信息
100 itemFun.setDetailData(mulRes.sizeInfo) // DETAILS商品详情 119 itemFun.setDetailData(mulRes.sizeInfo) // DETAILS商品详情
101 ); 120 );
  121 +
  122 + // 收藏状态
  123 + _.set(data, 'goodInfo.productFav', mulRes.productFav);
  124 + if (data.brandBanner) {
  125 + _.set(data, 'brandBanner.brandFav', mulRes.brandFav);
  126 + }
  127 +
102 resData.content = data; 128 resData.content = data;
103 129
104 // 商品详情SEO 130 // 商品详情SEO
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 <div class="center-content clearfix"> 5 <div class="center-content clearfix">
6 {{# brandLogo}} 6 {{# brandLogo}}
7 <a href="{{link}}" class="brand-logo"> 7 <a href="{{link}}" class="brand-logo">
8 - <img src="{{image img 108 44}}"> 8 + <img src="{{image img 108 45}}">
9 </a> 9 </a>
10 {{/ brandLogo}} 10 {{/ brandLogo}}
11 <p class="opt right"> 11 <p class="opt right">
@@ -2,18 +2,17 @@ @@ -2,18 +2,17 @@
2 position: relative; 2 position: relative;
3 3
4 .banner-img { 4 .banner-img {
5 - min-height: 44px; 5 + min-height: 45px;
6 } 6 }
7 7
8 .opt-wrap { 8 .opt-wrap {
9 width: 100%; 9 width: 100%;
10 - height: 44px; 10 + height: 45px;
11 position: absolute; 11 position: absolute;
12 top: 50%; 12 top: 50%;
13 - margin-top: -22px; 13 + margin-top: -23px;
14 14
15 .brand-logo { 15 .brand-logo {
16 - width: 108px;  
17 display: inline-block; 16 display: inline-block;
18 } 17 }
19 18