Authored by 周少峰

Merge branch 'feature/shopName' into release/5.4

@@ -13,7 +13,6 @@ const config = global.yoho.config; @@ -13,7 +13,6 @@ const config = global.yoho.config;
13 const helpers = global.yoho.helpers; 13 const helpers = global.yoho.helpers;
14 const cache = global.yoho.cache; 14 const cache = global.yoho.cache;
15 const logger = global.yoho.logger; 15 const logger = global.yoho.logger;
16 -const images = require('../../../utils/images.js');  
17 16
18 const getSortByConditionAsync = (condition) => { 17 const getSortByConditionAsync = (condition) => {
19 return api.get('', Object.assign({ 18 return api.get('', Object.assign({
@@ -288,191 +287,49 @@ const getBrandCouponAsync = (brandId, uid) => { @@ -288,191 +287,49 @@ const getBrandCouponAsync = (brandId, uid) => {
288 */ 287 */
289 const getBrandShop = (query) => { 288 const getBrandShop = (query) => {
290 let finalParams = { 289 let finalParams = {
291 - // method: 'web.regular.groupsort'  
292 - method: 'web.search.shopInfo' 290 + method: 'web.search.shopNewInfo'
293 }; 291 };
294 292
295 - Object.assign(finalParams, {keyword: query});  
296 -  
297 - let cKey = getSearchCacheKey(finalParams);  
298 -  
299 - return cache.get(cKey)  
300 - .catch(err => logger.debug(`product query save cache data fail:${err.toString()}`))  
301 - .then(cdata => {  
302 - let retObj;  
303 -  
304 - try {  
305 - if (cdata) {  
306 - retObj = JSON.parse(cdata);  
307 - }  
308 - } catch (e) {  
309 - logger.debug('getBrandShop cache data parse fail.');  
310 - }  
311 -  
312 - if (retObj) {  
313 - return retObj;  
314 - } else {  
315 - return api.get('', finalParams).then(ret => {  
316 - if (ret && ret.code === 200) {  
317 -  
318 - saveCache(cKey, ret.data, CACHE_TIME_S);  
319 - return ret.data;  
320 - }  
321 - return null;  
322 - });  
323 - }  
324 - }); 293 + return api.get('', Object.assign(finalParams, {keyword: query}), config.apiCache);
325 }; 294 };
326 295
327 /** 296 /**
328 - * 根据品牌ID获取品牌下的店铺  
329 - * @return  
330 - */  
331 -const getShopsByBrandId = bid => {  
332 - let finalParams = {  
333 - method: 'app.shop.queryShopsByBrandId',  
334 - brand_id: bid  
335 - };  
336 -  
337 - let cKey = getSearchCacheKey(finalParams);  
338 -  
339 - return cache.get(cKey)  
340 - .catch(err => logger.debug(`product query save cache data fail:${err.toString()}`))  
341 - .then(cdata => {  
342 - let cdataObj;  
343 -  
344 - if (cdata) {  
345 - try {  
346 - cdataObj = JSON.parse(cdata);  
347 - } catch (e) {  
348 - logger.debug('getShopsByBrandId cache data parse fail.');  
349 - }  
350 - }  
351 -  
352 - if (cdataObj) {  
353 - return cdataObj;  
354 - } else {  
355 - return api.get('', finalParams).then(ret => {  
356 - if (ret && ret.code === 200) {  
357 -  
358 - saveCache(cKey, ret.data, CACHE_TIME_S);  
359 - return ret.data;  
360 - }  
361 - return null;  
362 - });  
363 - }  
364 - });  
365 -};  
366 -  
367 -const shopFormat = shopDatas => {  
368 - let shopEntry = [];  
369 -  
370 - _.forEach(shopDatas, val => {  
371 - let sorts = [];  
372 - let shopId = _.get(val, 'shop.shop_id', '');  
373 - let url = helpers.urlFormat('', {shopId: shopId}, val.shop.brand_domain);  
374 -  
375 - if (val.shopSort) {  
376 - for (let ss of val.shopSort) {  
377 - if (!ss.sub) {  
378 - continue;  
379 - }  
380 -  
381 - let isFull = false;  
382 -  
383 - for (let misort of ss.sub) {  
384 - if (sorts.length >= 10) {  
385 - isFull = true;  
386 - break;  
387 - }  
388 -  
389 - sorts.push({  
390 - href: `${url}&msort=${ss.sort_id}&misort=${misort.sort_id}`,  
391 - name: misort.sort_name  
392 - });  
393 - }  
394 - if (isFull) {  
395 - break;  
396 - }  
397 - }  
398 - }  
399 -  
400 - shopEntry.push({  
401 - home: url,  
402 - logo: images.getImageUrl(val.shop.brand_ico, 80, 50, 1, 'brandLogo'),  
403 - shopName: val.shop.brand_name,  
404 - sort: sorts  
405 - });  
406 - });  
407 -  
408 - return shopEntry;  
409 -};  
410 -  
411 -/**  
412 - * 根据搜索得到店铺/品牌 列表 297 + * 根据搜索得到店铺/品牌
413 */ 298 */
414 const getShopList = params => { 299 const getShopList = params => {
415 -  
416 if (!params || !params.query) { 300 if (!params || !params.query) {
417 return; 301 return;
418 } 302 }
419 303
420 - let brandShop;  
421 - let brandShops;  
422 -  
423 - return getBrandShop(params.query).then(shop => { // 获取品牌,并根据品牌获取品牌下的所有店铺  
424 -  
425 - if (!shop || !shop.id) {  
426 - return;  
427 - }  
428 -  
429 - brandShop = shop;  
430 - return getShopsByBrandId(shop.id).then(shops => {  
431 - if (shops && shops.length) {  
432 - return shops;  
433 - } else {  
434 - return shop;  
435 - }  
436 - });  
437 - }).then(shops => { // 获取品牌/品牌店下所有的分类  
438 -  
439 - if (_.isArray(shops)) {  
440 - brandShops = shops; 304 + return getBrandShop(params.query).then(shops => {
  305 + let shopEntry = {},
  306 + sort = _.get(shops, 'data.sortInfo.sort', {}),
  307 + shopInfo = _.get(shops, 'data.shopBrandInfo.shopInfo', {}) ||
  308 + _.get(shops, 'data.shopBrandInfo.brandInfo', {});
441 309
442 - let promises = [];  
443 -  
444 - for (let s of shops) {  
445 - promises.push(getSortList({  
446 - brand: s.brand_id || brandShop.id  
447 - }));  
448 - }  
449 -  
450 - return Promise.all(promises);  
451 - } else if (shops && shops.id) {  
452 - return getSortList({  
453 - brand: shops.id  
454 - }); 310 + if (_.isEmpty(shopInfo)) {
  311 + return shopEntry;
455 } 312 }
456 313
457 - }).then(sorts => { // 数组则为品牌店列表,否则为品牌  
458 - let shopData = [];  
459 -  
460 - if (_.isArray(sorts)) {  
461 -  
462 - _.forEach(sorts, (val, index) => {  
463 - shopData.push({  
464 - shop: brandShops[index],  
465 - shopSort: val && val.data && !_.isFunction(val.data.sort) && val.data.sort 314 + shopEntry = {
  315 + home: helpers.urlFormat('', '', shopInfo.shop_domain || shopInfo.brand_domain),
  316 + logo: shopInfo.shop_logo || shopInfo.brand_ico,
  317 + shopName: shopInfo.shop_name || shopInfo.brand_name,
  318 + sort: []
  319 + };
  320 +
  321 + // 店铺/品牌的小分类
  322 + _.forEach(sort, (sortInfo) => {
  323 + _.forEach(_.get(sortInfo, 'sub', []), (subSort) => {
  324 + shopEntry.sort.push({
  325 + href: helpers.urlFormat('', {sort: subSort.sort_id}, 'list'),
  326 + name: subSort.sort_name
466 }); 327 });
467 }); 328 });
468 - } else if (sorts && sorts.code === 200 && sorts.data) {  
469 - shopData.push({  
470 - shop: brandShop,  
471 - shopSort: !_.isFunction(sorts.data.sort) && sorts.data.sort  
472 - });  
473 - }  
474 329
475 - return shopFormat(shopData); 330 + });
  331 +
  332 + return shopEntry;
476 }); 333 });
477 }; 334 };
478 335
@@ -37,11 +37,6 @@ exports.getSearchData = (params, channel) => { @@ -37,11 +37,6 @@ exports.getSearchData = (params, channel) => {
37 searchApi.getShopList(params) 37 searchApi.getShopList(params)
38 ]; 38 ];
39 39
40 - // 搜索店铺  
41 - /* if (params.query) {  
42 - apiMethod.push(searchApi.getBrandShop(params.query));  
43 - }*/  
44 -  
45 return api.all(apiMethod).then(result => { 40 return api.all(apiMethod).then(result => {
46 let finalResult = { 41 let finalResult = {
47 headerData: Object.assign(result[0].headerData, { 42 headerData: Object.assign(result[0].headerData, {
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 {{# shopEntry}} 2 {{# shopEntry}}
3 <div class="shop-entry clearfix"> 3 <div class="shop-entry clearfix">
4 <a class="pull-left" href="{{home}}"> 4 <a class="pull-left" href="{{home}}">
5 - <img class="logo" src="{{image2 logo}}"> 5 + <img class="logo" src="{{image2 logo w=80 h=50}}">
6 </a> 6 </a>
7 7
8 <div class="name pull-left"> 8 <div class="name pull-left">