Authored by htoooth

Merge remote-tracking branch 'origin/release/5.5' into release/5.5

@@ -24,6 +24,78 @@ exports.getKeyActivity = (query) => { @@ -24,6 +24,78 @@ exports.getKeyActivity = (query) => {
24 }); 24 });
25 }; 25 };
26 26
  27 +const setSearchData = (result, params, channel) => {
  28 + let changeQuery = Object.assign({}, params);
  29 + let finalResult = {
  30 + headerData: Object.assign(result[0].headerData, {
  31 + header: true
  32 + }),
  33 + search: {}
  34 + };
  35 +
  36 + // 获取左侧类目数据
  37 + if (result[1].code === 200) {
  38 + let dps = {};
  39 +
  40 + _.forEach(needParams, (value) => {
  41 + if (params[value]) {
  42 + dps[value] = params[value];
  43 + }
  44 + });
  45 +
  46 + finalResult.search = {
  47 + leftContent: searchHandler.handleSortData(result[1].data.sort, dps, params),
  48 + isSearch: true
  49 + };
  50 + }
  51 +
  52 + // 获取商品数据和顶部筛选条件
  53 + if (result[2].code === 200) {
  54 +
  55 + // 搜索推荐词,获取对应的参数值
  56 + let termsSuggestion = _.get(result[2], 'data.suggestion.terms_suggestion', []);
  57 +
  58 + // 推荐词 获取无商品,首次搜索,通过isChangedQuery做开关
  59 + if (result[2].data.isChangedQuery === 'Y') {
  60 + Object.assign(changeQuery, {query: termsSuggestion[0]});
  61 + }
  62 +
  63 + let filters = Object.assign(searchHandler.handleFilterDataAll(result[2].data, changeQuery),
  64 + finalResult.search.leftContent.sort);
  65 +
  66 + filters.checkedConditions.conditions = _.concat(filters.checkedConditions.conditions,
  67 + finalResult.search.leftContent.checked);
  68 +
  69 + Object.assign(finalResult.search,
  70 + searchHandler.handlePathNavData({total: result[2].data.total }, params, 'search', channel),
  71 + {
  72 + filters: filters,
  73 + opts: searchHandler.handleOptsData(changeQuery, result[2].data.total, result[2].data.filter),
  74 + totalCount: result[2].data.total,
  75 + footPager: searchHandler.handlePagerData(result[2].data.total, changeQuery),
  76 + goods: productProcess.processProductList(result[2].data.product_list,
  77 + Object.assign({showDiscount: false, from: {type: 'search', params: params}}, params)),
  78 + latestWalk: 6,
  79 + hasNextPage: searchHandler.handleNextPage(changeQuery, result[2].data.total),
  80 + shopEntry: result[3],
  81 + name: params.query,
  82 + suggest: (termsSuggestion.length !== 0) ? termsSuggestion.slice(0, 3) : false,
  83 + changedQuery: result[2].data.isChangedQuery === 'Y',
  84 + suggestFirst: finalResult.search.suggestFirst,
  85 + suggestSecond: finalResult.search.suggestSecond
  86 + });
  87 +
  88 + if (finalResult.search.changedQuery) {
  89 +
  90 + finalResult.search.suggestFirst = finalResult.search.suggest[0];
  91 + finalResult.search.suggestSecond = _.slice(termsSuggestion, 1, termsSuggestion.length).splice(0, 3);
  92 + }
  93 +
  94 + finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.search, 'goods'))};
  95 + }
  96 + return finalResult;
  97 +}
  98 +
27 /** 99 /**
28 * 转换价格 100 * 转换价格
29 * 101 *
@@ -40,9 +112,7 @@ const transPrice = (price) => { @@ -40,9 +112,7 @@ const transPrice = (price) => {
40 * @return {[type]} [description] 112 * @return {[type]} [description]
41 */ 113 */
42 exports.getSearchData = (params, channel) => { 114 exports.getSearchData = (params, channel) => {
43 -  
44 let searchParams = searchHandler.getSearchParams(params); 115 let searchParams = searchHandler.getSearchParams(params);
45 - let changeQuery = Object.assign({}, params);  
46 116
47 switch (channel) { 117 switch (channel) {
48 case 'boys': 118 case 'boys':
@@ -70,74 +140,17 @@ exports.getSearchData = (params, channel) => { @@ -70,74 +140,17 @@ exports.getSearchData = (params, channel) => {
70 ]; 140 ];
71 141
72 return api.all(apiMethod).then(result => { 142 return api.all(apiMethod).then(result => {
73 - let finalResult = {  
74 - headerData: Object.assign(result[0].headerData, {  
75 - header: true  
76 - }),  
77 - search: {}  
78 - };  
79 -  
80 - // 获取左侧类目数据  
81 - if (result[1].code === 200) {  
82 - let dps = {}; 143 + if (_.get(result, '[2].data.isChangedQuery', '') === 'Y') {
  144 + return searchApi.getSortList(Object.assign({}, searchParams, {msort: '',
  145 + query: _.get(result, '[2]data.suggestion.terms_suggestion[0]', ''),
  146 + misort: '', sort: ''})).then(subRes => {
  147 + result[1] = subRes;
83 148
84 - _.forEach(needParams, (value) => {  
85 - if (params[value]) {  
86 - dps[value] = params[value];  
87 - } 149 + return setSearchData(result, params, channel);
88 }); 150 });
89 -  
90 - finalResult.search = {  
91 - leftContent: searchHandler.handleSortData(result[1].data.sort, dps, params),  
92 - isSearch: true  
93 - };  
94 } 151 }
95 152
96 - // 获取商品数据和顶部筛选条件  
97 - if (result[2].code === 200) {  
98 -  
99 - // 搜索推荐词,获取对应的参数值  
100 - let termsSuggestion = _.get(result[2], 'data.suggestion.terms_suggestion', []);  
101 -  
102 - // 推荐词 获取无商品,首次搜索,通过isChangedQuery做开关  
103 - if (result[2].data.isChangedQuery === 'Y') {  
104 - Object.assign(changeQuery, {query: termsSuggestion[0]});  
105 - }  
106 -  
107 - let filters = Object.assign(searchHandler.handleFilterDataAll(result[2].data, changeQuery),  
108 - finalResult.search.leftContent.sort);  
109 -  
110 - filters.checkedConditions.conditions = _.concat(filters.checkedConditions.conditions,  
111 - finalResult.search.leftContent.checked);  
112 -  
113 - Object.assign(finalResult.search,  
114 - searchHandler.handlePathNavData({total: result[2].data.total }, params, 'search', channel),  
115 - {  
116 - filters: filters,  
117 - opts: searchHandler.handleOptsData(changeQuery, result[2].data.total, result[2].data.filter),  
118 - totalCount: result[2].data.total,  
119 - footPager: searchHandler.handlePagerData(result[2].data.total, changeQuery),  
120 - goods: productProcess.processProductList(result[2].data.product_list,  
121 - Object.assign({showDiscount: false, from: {type: 'search', params: params}}, params)),  
122 - latestWalk: 6,  
123 - hasNextPage: searchHandler.handleNextPage(changeQuery, result[2].data.total),  
124 - shopEntry: result[3],  
125 - name: params.query,  
126 - suggest: (termsSuggestion.length !== 0) ? termsSuggestion.slice(0, 3) : false,  
127 - changedQuery: result[2].data.isChangedQuery === 'Y',  
128 - suggestFirst: finalResult.search.suggestFirst,  
129 - suggestSecond: finalResult.search.suggestSecond  
130 - });  
131 -  
132 - if (finalResult.search.changedQuery) {  
133 -  
134 - finalResult.search.suggestFirst = finalResult.search.suggest[0];  
135 - finalResult.search.suggestSecond = _.slice(termsSuggestion, 1, termsSuggestion.length).splice(0, 3);  
136 - }  
137 -  
138 - finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.search, 'goods'))};  
139 - }  
140 - return finalResult; 153 + return setSearchData(result, params, channel);
141 }); 154 });
142 }; 155 };
143 156