Authored by hf

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

... ... @@ -142,20 +142,35 @@ class SearchData extends \LibModels\Wap\Product\SearchData
*/
public static function getSearchDataBySort(array $params, array $sortList)
{
$data = array();
foreach ($sortList as $v) {
if(empty($v['viewNum'])){
continue;
}
$searchParams = array_merge($params, $v);
$list = self::searchElasticByCondition($searchParams, true);
$productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list'];
if(count($productList) < $v['viewNum']){
continue;
}
$data = array_merge($data, $productList);
// $data = array();
// foreach ($sortList as $v) {
// if(empty($v['viewNum'])){
// continue;
// }
// $searchParams = array_merge($params, $v);
// $list = self::searchElasticByCondition($searchParams, true);
// $productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list'];
// if(count($productList) < $v['viewNum']){
// continue;
// }
// $data = array_merge($data, $productList);
// }
// 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'] . ',';
}
$params['viewNum'] = $viewNum;
$params['misort'] = rtrim($sortIds, ',');
$searchd = self::searchElasticByCondition($params);
if (empty($searchd['data']['product_list'])) {
return array();
}
return $data;
return $searchd['data']['product_list'];
}
/**
... ...
... ... @@ -226,6 +226,7 @@ class Helpers
if ($oneGoods['is_default'] === 'Y') {
$productData['default_images'] = self::procProductImg($oneGoods);
$flag = true;
break;
}
}
// 如果还未赋值,则取第一个skc产品的默认图片
... ... @@ -247,7 +248,7 @@ class Helpers
$result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y');
$result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_'
. $productData['goods_list'][0]['goods_id']
. '/' . $productData['cn_alphabet'] . '.html', 'item');
. '/' . $productData['cn_alphabet'] . '.html', array(), 'item');
// APP访问需要加附加的参数
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
if ($isApp) {
... ...
... ... @@ -49,8 +49,8 @@ class CommonController extends WebAction
HomeModel::COOKIE_NAME_LIFESTYLE
);
$channel = $this->post('type', '');
$pageIndex = intval($this->post('pageIndex', 0));
$pageCount = intval($this->post('pageCount', 8));
$pageIndex = (int) $this->post('pageIndex', 0);
$pageCount = (int) $this->post('pageCount', 8);
if (! in_array($channel, $channels)) {
break;
} else {
... ...
... ... @@ -247,11 +247,10 @@ class HomeModel
*/
public static function getNewArrival($channel)
{
$result = array();
$key = sprintf(WebCacheConfig::KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA.'_'.$channel);
$key = WebCacheConfig::KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA . '_' . $channel;
//缓存数据
$result = Cache::get($key);
if(empty($result)) {
if (empty($result)) {
$params = array(
'order' => 's_t_desc',
'shelve_time' => strtotime("-60 days") . ',' . time()
... ... @@ -270,9 +269,13 @@ class HomeModel
// 获取分类列表获取商品信息
$goodsList = SearchData::getSearchDataBySort($params, $sortList);
$pos = 1;
$val = array();
foreach ($goodsList as $goods) {
// 格式化数据
$val = Helpers::formatProduct($goods, true, true, true, 280, 373);
if (!$val) {
continue;
}
if ($val['price'] == false) {
$val['price'] = $val['salePrice'];
}
... ... @@ -287,13 +290,16 @@ class HomeModel
$val['tags']['isReNew'] = false;//$val['tags']['is_advance'];暂时不显示
unset($val['tags']['is_advance'], $val['tags']['is_discount'], $val['tags']['is_limited'], $val['tags']['is_new'],
$val['tags']['is_yohood'], $val['tags']['midYear'], $val['tags']['yearEnd']);
if (! empty($val)) {
$result[] = $val;
}
}
}
Cache::set($key, $result, 3600);
}
// 当一级缓存失效,并且接口异常时, 尝试从二级缓存获取数据
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
return $result;
}
}
\ No newline at end of file
... ...