Authored by 郭成尧

'data判断'

@@ -22,58 +22,73 @@ const getShopData = params => { @@ -22,58 +22,73 @@ const getShopData = params => {
22 22
23 return shopApi.getBrandInfoByDomain({domain: params.domain}).then(result => { 23 return shopApi.getBrandInfoByDomain({domain: params.domain}).then(result => {
24 24
25 - /* 品牌名称 */  
26 - Object.assign(finalResult, {  
27 - brandName: result.data.brand_name  
28 - }); 25 + if (result.data) {
29 26
30 - /* 品牌是否有店铺 */  
31 - if (result.data.shop_id) {  
32 -  
33 - /* 是 BLK 的店铺 */ 27 + /* 品牌名称 */
34 Object.assign(finalResult, { 28 Object.assign(finalResult, {
35 - isBlkShop: true,  
36 - shopId: result.data.shop_id 29 + brandName: result.data.brand_name
37 }); 30 });
38 31
39 - return shopApi.getShopInfoData({  
40 - shopId: result.data.shop_id,  
41 - uid: params.uid  
42 -  
43 - // uid: '8050882'  
44 - }).then(subResult => { 32 + /* 品牌是否有店铺 */
  33 + if (result.data.shop_id) {
45 34
46 - /* 取店铺的基本信息 */ 35 + /* 是 BLK 的店铺 */
47 Object.assign(finalResult, { 36 Object.assign(finalResult, {
48 - shopLogo: subResult.data.shop_logo,  
49 - shopName: subResult.data.shop_name,  
50 - shopIntro: subResult.data.shop_intro,  
51 - isFav: subResult.data.is_favorite === 'Y' 37 + isBlkShop: true,
  38 + shopId: result.data.shop_id
52 }); 39 });
53 40
54 - /* 取资源位店铺背景图 */  
55 - return shopApi.getShopsDecoratorList({shopId: result.data.shop_id}).then(thResult => {  
56 - _.forEach(thResult.data.list, value => {  
57 -  
58 - if (value.resource_name === 'shopTopBanner_app') {  
59 - Object.assign(finalResult, {  
60 - shopBg: JSON.parse(value.resource_data).shopSrc  
61 - });  
62 - }  
63 - });  
64 - 41 + return shopApi.getShopInfoData({
  42 + shopId: result.data.shop_id,
  43 + uid: params.uid
  44 +
  45 + // uid: '8050882'
  46 + }).then(subResult => {
  47 +
  48 + if (subResult.data) {
  49 +
  50 + /* 取店铺的基本信息 */
  51 + Object.assign(finalResult, {
  52 + shopLogo: subResult.data.shop_logo,
  53 + shopName: subResult.data.shop_name,
  54 + shopIntro: subResult.data.shop_intro,
  55 + isFav: subResult.data.is_favorite === 'Y'
  56 + });
  57 +
  58 + /* 取资源位店铺背景图 */
  59 + return shopApi.getShopsDecoratorList({shopId: result.data.shop_id}).then(thResult => {
  60 + if (thResult.data) {
  61 + _.forEach(thResult.data.list, value => {
  62 +
  63 + if (value.resource_name === 'shopTopBanner_app') {
  64 + Object.assign(finalResult, {
  65 + shopBg: JSON.parse(value.resource_data).shopSrc
  66 + });
  67 + }
  68 + });
  69 + } else {
  70 + logger.error('getShopsDecoratorList api no data');
  71 + }
  72 +
  73 + return finalResult;
  74 + });
  75 + } else {
  76 + logger.error('getShopInfoData api no data');
  77 + }
65 return finalResult; 78 return finalResult;
66 }); 79 });
  80 + } else {
67 81
68 - });  
69 - } else {  
70 -  
71 - /* 不是 BLK 的店铺 */  
72 - Object.assign(finalResult, {  
73 - isBlkShop: false  
74 - }); 82 + /* 不是 BLK 的店铺 */
  83 + Object.assign(finalResult, {
  84 + isBlkShop: false
  85 + });
75 86
76 - logger.info('brand has no shop'); 87 + logger.info('brand has no shop');
  88 + }
  89 + return finalResult;
  90 + } else {
  91 + logger.error('getBrandInfoByDomain api no data');
77 } 92 }
78 93
79 return finalResult; 94 return finalResult;
@@ -88,28 +103,33 @@ const getShopData = params => { @@ -88,28 +103,33 @@ const getShopData = params => {
88 const getBrandShopGoodsData = params => { 103 const getBrandShopGoodsData = params => {
89 let finalResult = {}; 104 let finalResult = {};
90 105
91 - return shopApi.getBrandInfoByDomain({ domain: params.domain }).then(result => {  
92 - return shopApi.getBrandShopGoodsOriginData(Object.assign(params, {  
93 - brand: result.data.id,  
94 - shopId: result.data.shop_id  
95 - })).then(subResult => {  
96 - if (subResult.data) {  
97 - prettyFilter(subResult.data.filter);  
98 - finalResult = {  
99 - data: {  
100 - productList: processProductList(subResult.data.product_list),  
101 - filter: subResult.data.filter,  
102 - page: subResult.data.page,  
103 - pageTotal: subResult.data.page_total  
104 - },  
105 - code: 200  
106 - };  
107 - } else {  
108 - logger.error('getBrandShopGoodsOriginData api no data');  
109 - } 106 + return shopApi.getBrandInfoByDomain({domain: params.domain}).then(result => {
110 107
111 - return camelCase(finalResult);  
112 - }); 108 + if (result.data) {
  109 + return shopApi.getBrandShopGoodsOriginData(Object.assign(params, {
  110 + brand: result.data.id,
  111 + shopId: result.data.shop_id
  112 + })).then(subResult => {
  113 + if (subResult.data) {
  114 + prettyFilter(subResult.data.filter);
  115 + finalResult = {
  116 + data: {
  117 + productList: processProductList(subResult.data.product_list),
  118 + filter: subResult.data.filter,
  119 + page: subResult.data.page,
  120 + pageTotal: subResult.data.page_total
  121 + },
  122 + code: 200
  123 + };
  124 + } else {
  125 + logger.error('getBrandShopGoodsOriginData api no data');
  126 + }
  127 + return camelCase(finalResult);
  128 + });
  129 + } else {
  130 + logger.error('getBrandInfoByDomain api no data');
  131 + }
  132 + return camelCase(finalResult);
113 }); 133 });
114 }; 134 };
115 135