Authored by 郭成尧

'search-data-and-filter-data-one-api'

@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 * @date: 2016/07/21 4 * @date: 2016/07/21
5 */ 5 */
6 'use strict'; 6 'use strict';
  7 +const utils = '../../../utils';
7 const logger = global.yoho.logger; 8 const logger = global.yoho.logger;
8 const crypto = global.yoho.crypto; 9 const crypto = global.yoho.crypto;
9 const camelCase = global.yoho.camelCase; 10 const camelCase = global.yoho.camelCase;
@@ -11,6 +12,7 @@ const _ = require('lodash'); @@ -11,6 +12,7 @@ const _ = require('lodash');
11 const helpers = global.yoho.helpers; 12 const helpers = global.yoho.helpers;
12 const api = global.yoho.API; 13 const api = global.yoho.API;
13 const searchModel = require('./search'); 14 const searchModel = require('./search');
  15 +const productProcess = require(`${utils}/product-process`);
14 16
15 /** 17 /**
16 * 频道 18 * 频道
@@ -527,12 +529,7 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -527,12 +529,7 @@ const getShopData = (req, shopId, uid, isApp) => {
527 529
528 return Promise.all([ 530 return Promise.all([
529 _getShopDecorator(shopId), 531 _getShopDecorator(shopId),
530 - searchModel.getFilterData({  
531 - shop_id: shopId,  
532 - gender: req.query.gender || '1,3',  
533 - channel: channel  
534 - }),  
535 - searchModel.getSearchData({ 532 + searchModel.getFilterSearchData({
536 shop_id: shopId, 533 shop_id: shopId,
537 gender: req.query.gender || '1,3', 534 gender: req.query.gender || '1,3',
538 channel: channel 535 channel: channel
@@ -544,8 +541,19 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -544,8 +541,19 @@ const getShopData = (req, shopId, uid, isApp) => {
544 shopInfo: shopInfoResult // 店铺信息 541 shopInfo: shopInfoResult // 店铺信息
545 }; 542 };
546 543
  544 + /* 获取一次分类和商品数据 */
  545 + let shopFilterSearchData = {
  546 + filter: [],
  547 + goods: []
  548 + };
  549 +
  550 + if (result[1]) {
  551 + shopFilterSearchData.filter = productProcess.processFilter(result[1].filter || []);
  552 + shopFilterSearchData.goods = productProcess.processProductList(result[1].product_list || []);
  553 + }
  554 +
547 /* 店鋪優惠券 */ 555 /* 店鋪優惠券 */
548 - let shopCoupons = result[3] || []; 556 + let shopCoupons = result[2] || [];
549 557
550 // 店铺分类 558 // 店铺分类
551 return _getShopCategory(shopId, channel).then((shopCategory) => { 559 return _getShopCategory(shopId, channel).then((shopCategory) => {
@@ -554,14 +562,16 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -554,14 +562,16 @@ const getShopData = (req, shopId, uid, isApp) => {
554 }, shopData); 562 }, shopData);
555 563
556 // noinspection JSCheckFunctionSignatures 564 // noinspection JSCheckFunctionSignatures
557 - return Object.assign(_formShopData(shopData, shopId, isApp), {  
558 - filter: result[1],  
559 - goods: result[2],  
560 - shopId: shopId,  
561 - coverChannel: channel,  
562 - shopCoupons: shopCoupons,  
563 - shopCouponsOne: shopCoupons.length === 1  
564 - }); 565 + return Object.assign(
  566 + _formShopData(shopData, shopId, isApp),
  567 + shopFilterSearchData,
  568 + {
  569 + shopId: shopId,
  570 + coverChannel: channel,
  571 + shopCoupons: shopCoupons,
  572 + shopCouponsOne: shopCoupons.length === 1
  573 + }
  574 + );
565 }); 575 });
566 }); 576 });
567 577
@@ -573,10 +583,9 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -573,10 +583,9 @@ const getShopData = (req, shopId, uid, isApp) => {
573 * @param req 583 * @param req
574 * @param shopId 584 * @param shopId
575 * @param uid 585 * @param uid
576 - * @param isApp  
577 * @returns {Promise.<TResult>|*} 586 * @returns {Promise.<TResult>|*}
578 */ 587 */
579 -const getShopFav = (req, shopId, uid, isApp) => { 588 +const getShopFav = (req, shopId, uid) => {
580 return _getShopInfo(shopId, uid).then(shopInfoResult => { 589 return _getShopInfo(shopId, uid).then(shopInfoResult => {
581 return shopInfoResult; 590 return shopInfoResult;
582 }); 591 });
@@ -144,6 +144,22 @@ const getFilterData = (params) => { @@ -144,6 +144,22 @@ const getFilterData = (params) => {
144 }; 144 };
145 145
146 /** 146 /**
  147 + * 获取筛选数据
  148 + * @param {[object]} params
  149 + * @return {[array]}
  150 + */
  151 +const getFilterSearchData = (params) => {
  152 + return _searchGoods(params).then((result) => {
  153 + if (result && result.code === 200) {
  154 + return result.data;
  155 + } else {
  156 + logger.error('get filter data api return code is not 200');
  157 + return [];
  158 + }
  159 + });
  160 +};
  161 +
  162 +/**
147 * 获取所有的品类名称 163 * 获取所有的品类名称
148 **/ 164 **/
149 const getClassNames = () => { 165 const getClassNames = () => {
@@ -235,6 +251,7 @@ const searchKeyActivity = (params) => { @@ -235,6 +251,7 @@ const searchKeyActivity = (params) => {
235 module.exports = { 251 module.exports = {
236 getSearchData, 252 getSearchData,
237 getFilterData, 253 getFilterData,
  254 + getFilterSearchData,
238 getAllBrandNames, 255 getAllBrandNames,
239 getClassNames, 256 getClassNames,
240 getSearchIndex, 257 getSearchIndex,