code review by fei.hong: do format new arrival codes
Showing
1 changed file
with
41 additions
and
12 deletions
@@ -133,6 +133,7 @@ class SearchData extends \LibModels\Wap\Product\SearchData | @@ -133,6 +133,7 @@ class SearchData extends \LibModels\Wap\Product\SearchData | ||
133 | 133 | ||
134 | return Yohobuy::get(self::getUrl('search'), $param, $cache); | 134 | return Yohobuy::get(self::getUrl('search'), $param, $cache); |
135 | } | 135 | } |
136 | + | ||
136 | /** | 137 | /** |
137 | * 根据分类列表获取商品信息 | 138 | * 根据分类列表获取商品信息 |
138 | * | 139 | * |
@@ -157,20 +158,48 @@ class SearchData extends \LibModels\Wap\Product\SearchData | @@ -157,20 +158,48 @@ class SearchData extends \LibModels\Wap\Product\SearchData | ||
157 | // } | 158 | // } |
158 | // return $data; | 159 | // return $data; |
159 | 160 | ||
160 | - /* 2016/01/26 code review by fei.hong: 优化合并misort参数, 减少调用搜索的次数 */ | ||
161 | - $sortIds = ''; | ||
162 | - $viewNum = 0; | ||
163 | - foreach ($sortList as $value) { | ||
164 | - $viewNum += intval($value['viewNum']); | ||
165 | - $sortIds .= $value['misort'] . ','; | 161 | + /* code review by fei.hong: 2016/01/26 优化合并misort参数, 减少调用搜索接口的次数 */ |
162 | + $data = array(); | ||
163 | + | ||
164 | + // 按照时间降序排的参数 | ||
165 | + $params['order'] = 'shelve_time:desc'; | ||
166 | + // 获取新品的接口URL,以数组列表返回 | ||
167 | + $urlList = self::getNewArrivalUrl($sortList, $params); | ||
168 | + // 并行调用搜索新品接口 | ||
169 | + $searchd = Yohobuy::getMulti($urlList); | ||
170 | + | ||
171 | + // 该变量用于记录数组最后一个值的索引 | ||
172 | + $lastIndex = 0; | ||
173 | + // 业务逻辑:按照指定品类排序显示 | ||
174 | + foreach ($sortList as $key => $value) { | ||
175 | + $lastIndex = $value['viewNum'] - 1; | ||
176 | + // 业务逻辑:一个品类不满指定个数时,前台不显示 | ||
177 | + if (!empty($searchd[$key]) && isset($searchd[$key]['product_list'][$lastIndex])) { | ||
178 | + $data = array_merge($data, $searchd[$key]['product_list']); | ||
179 | + } | ||
166 | } | 180 | } |
167 | - $params['viewNum'] = $viewNum; | ||
168 | - $params['misort'] = rtrim($sortIds, ','); | ||
169 | - $searchd = self::searchElasticByCondition($params); | ||
170 | - if (empty($searchd['data']['product_list'])) { | ||
171 | - return array(); | 181 | + // 用完清空不使用的变量 |
182 | + $searchd = array(); | ||
183 | + | ||
184 | + return $data; | ||
185 | + } | ||
186 | + | ||
187 | + /** | ||
188 | + * 获取推荐新品的接口URL列表 | ||
189 | + * | ||
190 | + * @param array $sortList 分类列表 | ||
191 | + * @param array $params 附加参数 | ||
192 | + * @return arary | ||
193 | + */ | ||
194 | + public static function getNewArrivalUrl($sortList, $params) | ||
195 | + { | ||
196 | + $urlList = array(); | ||
197 | + $option = array(); | ||
198 | + foreach ($sortList as $key => $value) { | ||
199 | + $option = $params + $value; | ||
200 | + $urlList[$key] = Yohobuy::httpBuildQuery(self::getUrl('search'), $option); | ||
172 | } | 201 | } |
173 | - return $searchd['data']['product_list']; | 202 | + return $urlList; |
174 | } | 203 | } |
175 | 204 | ||
176 | /** | 205 | /** |
-
Please register or login to post a comment