Authored by hf

code review by fei.hong: do format new arrival codes

... ... @@ -133,6 +133,7 @@ class SearchData extends \LibModels\Wap\Product\SearchData
return Yohobuy::get(self::getUrl('search'), $param, $cache);
}
/**
* 根据分类列表获取商品信息
*
... ... @@ -157,20 +158,48 @@ class SearchData extends \LibModels\Wap\Product\SearchData
// }
// return $data;
/* 2016/01/26 code review by fei.hong: 优化合并misort参数, 减少调用搜索的次数 */
$sortIds = '';
$viewNum = 0;
foreach ($sortList as $value) {
$viewNum += intval($value['viewNum']);
$sortIds .= $value['misort'] . ',';
/* code review by fei.hong: 2016/01/26 优化合并misort参数, 减少调用搜索接口的次数 */
$data = array();
// 按照时间降序排的参数
$params['order'] = 'shelve_time:desc';
// 获取新品的接口URL,以数组列表返回
$urlList = self::getNewArrivalUrl($sortList, $params);
// 并行调用搜索新品接口
$searchd = Yohobuy::getMulti($urlList);
// 该变量用于记录数组最后一个值的索引
$lastIndex = 0;
// 业务逻辑:按照指定品类排序显示
foreach ($sortList as $key => $value) {
$lastIndex = $value['viewNum'] - 1;
// 业务逻辑:一个品类不满指定个数时,前台不显示
if (!empty($searchd[$key]) && isset($searchd[$key]['product_list'][$lastIndex])) {
$data = array_merge($data, $searchd[$key]['product_list']);
}
}
$params['viewNum'] = $viewNum;
$params['misort'] = rtrim($sortIds, ',');
$searchd = self::searchElasticByCondition($params);
if (empty($searchd['data']['product_list'])) {
return array();
// 用完清空不使用的变量
$searchd = array();
return $data;
}
/**
* 获取推荐新品的接口URL列表
*
* @param array $sortList 分类列表
* @param array $params 附加参数
* @return arary
*/
public static function getNewArrivalUrl($sortList, $params)
{
$urlList = array();
$option = array();
foreach ($sortList as $key => $value) {
$option = $params + $value;
$urlList[$key] = Yohobuy::httpBuildQuery(self::getUrl('search'), $option);
}
return $searchd['data']['product_list'];
return $urlList;
}
/**
... ...