Authored by hongweigao

对brandsAPI接口,做code判断

@@ -90,12 +90,12 @@ const getBrandViewTop = channel => { @@ -90,12 +90,12 @@ const getBrandViewTop = channel => {
90 brandAds = [], 90 brandAds = [],
91 brandLogos = []; 91 brandLogos = [];
92 92
93 - if (res.code !== 200) { 93 + if (res.data === 'false' || res.code !== 200 ) {
94 return result; 94 return result;
95 } 95 }
96 96
97 // 头部10个品牌小图块 url 97 // 头部10个品牌小图块 url
98 - if (res.data[1].data && res.data[1].data.list) { 98 + if (res.data && res.data instanceof Array && res.data[1].data && res.data[1].data.list) {
99 _.forEach(res.data[1].data.list, subValue => { 99 _.forEach(res.data[1].data.list, subValue => {
100 brandAds.push({ 100 brandAds.push({
101 name: subValue.name, 101 name: subValue.name,
@@ -106,7 +106,7 @@ const getBrandViewTop = channel => { @@ -106,7 +106,7 @@ const getBrandViewTop = channel => {
106 } 106 }
107 107
108 // 头部品牌图块,广告位 108 // 头部品牌图块,广告位
109 - if (res.data[0].data) { 109 + if (res.data && res.data instanceof Array && res.data[0].data) {
110 _.forEach(res.data[0].data, (subValue, k) => { 110 _.forEach(res.data[0].data, (subValue, k) => {
111 let srcUrl; 111 let srcUrl;
112 112
@@ -151,8 +151,11 @@ const getBrandViewList = (channel, start, length) => { @@ -151,8 +151,11 @@ const getBrandViewList = (channel, start, length) => {
151 let result = [], 151 let result = [],
152 navigation = []; 152 navigation = [];
153 153
  154 + if (res.data === 'false' || res.code !== 200) {
  155 + return result;
  156 + }
154 // 品牌list A-Z 0-9 157 // 品牌list A-Z 0-9
155 - if (res.data.brands) { 158 + if (res.data && res.data.brands) {
156 159
157 _.forEach(res.data.brands, (subValue, key) => { 160 _.forEach(res.data.brands, (subValue, key) => {
158 let listTmp = []; 161 let listTmp = [];
@@ -193,9 +196,13 @@ const getBrandViewList = (channel, start, length) => { @@ -193,9 +196,13 @@ const getBrandViewList = (channel, start, length) => {
193 // 只取部分数据 196 // 只取部分数据
194 let begin; 197 let begin;
195 198
196 - begin = (start - 1) ? (start - 1) : 0;  
197 - begin = (begin > 0) ? begin : 0;  
198 - result = length ? result.slice(begin, length + begin) : result.slice(begin); 199 +
  200 + if (start) {
  201 + begin = (start - 1) ? (start - 1) : 0;
  202 + begin = (begin > 0) ? begin : 0;
  203 + result = length ? result.slice(begin, length + begin) : result.slice(begin);
  204 + }
  205 +
199 result.navigation = navigation; 206 result.navigation = navigation;
200 207
201 return result; 208 return result;
@@ -217,11 +224,17 @@ const getBrandInfo = (brandId, uid) => { @@ -217,11 +224,17 @@ const getBrandInfo = (brandId, uid) => {
217 // 获取品牌简介 224 // 获取品牌简介
218 let res = yield brandApi.getBrandIntro(brandId, uid); 225 let res = yield brandApi.getBrandIntro(brandId, uid);
219 226
  227 + if (res.data === 'false' || res.code !== 200) {
  228 + return data;
  229 + }
220 if (res.data) { 230 if (res.data) {
221 // 获取品牌下的产品信息 231 // 获取品牌下的产品信息
222 let proInfo = yield brandApi.getProductByBrand(brandId, 3); 232 let proInfo = yield brandApi.getProductByBrand(brandId, 3);
223 233
224 - let proInfoTmp = proInfo.data.product_list; 234 + if (proInfo.data === 'false' || proInfo.code !== 200) {
  235 + return data;
  236 + }
  237 + let proInfoTmp = proInfo.data.product_list ? proInfo.data.product_list : [];
225 238
226 if (!_.isEmpty(proInfoTmp)) { 239 if (!_.isEmpty(proInfoTmp)) {
227 _.forEach(proInfoTmp, subValue => { 240 _.forEach(proInfoTmp, subValue => {
@@ -253,12 +266,15 @@ const getBrandInfo = (brandId, uid) => { @@ -253,12 +266,15 @@ const getBrandInfo = (brandId, uid) => {
253 */ 266 */
254 const getBrandInfoByIds = (brandIds) => { 267 const getBrandInfoByIds = (brandIds) => {
255 return co(function*() { 268 return co(function*() {
256 - let data = yield brandApi.getBrandInfoByIds(brandIds); 269 + let res = yield brandApi.getBrandInfoByIds(brandIds);
257 270
258 let brandsInfo = {}; 271 let brandsInfo = {};
259 272
260 - if (data.data && data.code === 200) {  
261 - _.forEach(data.data, (subValue, k) => { 273 + if (res.data === 'false' || res.code !== 200) {
  274 + return brandsInfo;
  275 + }
  276 + if (res.data && res.code === 200) {
  277 + _.forEach(res.data, (subValue, k) => {
262 subValue.desc = _.trim(subValue.brand_intro.replace('/[\r\n\t ]/g', '')); 278 subValue.desc = _.trim(subValue.brand_intro.replace('/[\r\n\t ]/g', ''));
263 subValue.url = subValue.brand_domain; 279 subValue.url = subValue.brand_domain;
264 delete subValue.brand_intro; 280 delete subValue.brand_intro;
@@ -286,6 +302,9 @@ const getPlusstarBrandListItem = (channel) => { @@ -286,6 +302,9 @@ const getPlusstarBrandListItem = (channel) => {
286 302
287 let items = []; 303 let items = [];
288 304
  305 + if (resource.data === 'false' || resource.code !== 200) {
  306 + return items;
  307 + }
289 if (resource.data && resource.code === 200) { 308 if (resource.data && resource.code === 200) {
290 items[0] = {name: '所有品牌', src: '', url: helpers.urlFormat('/brands', ''), brandType: ''}; 309 items[0] = {name: '所有品牌', src: '', url: helpers.urlFormat('/brands', ''), brandType: ''};
291 items[1] = {name: '设计新潮', src: '', url: '', brandType: 4}; 310 items[1] = {name: '设计新潮', src: '', url: '', brandType: 4};
@@ -327,12 +346,15 @@ const getPlustarList = (brandType, gender) => { @@ -327,12 +346,15 @@ const getPlustarList = (brandType, gender) => {
327 346
328 let brandList = {}, 347 let brandList = {},
329 data = {}, 348 data = {},
330 - brandsIds = []; 349 + brandsIds = [],
  350 + result = {brandsIds: [], data: {}};
331 351
332 - if (list.data.data.list) { 352 + if (list.data === 'false' || list.code !== 200 ) {
  353 + return result;
  354 + }
  355 + if (list.data && list.data.data && list.data.data.list) {
333 brandList = list.data.data.list[0]; 356 brandList = list.data.data.list[0];
334 } 357 }
335 -  
336 if (brandList.data) { 358 if (brandList.data) {
337 _.forEach(brandList.data, brand => { 359 _.forEach(brandList.data, brand => {
338 let src = ''; 360 let src = '';
@@ -350,9 +372,12 @@ const getPlustarList = (brandType, gender) => { @@ -350,9 +372,12 @@ const getPlustarList = (brandType, gender) => {
350 }; 372 };
351 brandsIds.push(brand.brand_id); 373 brandsIds.push(brand.brand_id);
352 }); 374 });
  375 +
  376 + result.brandsIds = brandsIds;
  377 + result.data = data;
353 } 378 }
354 379
355 - return {brandsIds: brandsIds, data: data}; 380 + return result;
356 })(); 381 })();
357 }; 382 };
358 383