code review by fei.hong: do format search new arrival codes
Showing
4 changed files
with
43 additions
and
21 deletions
@@ -142,20 +142,35 @@ class SearchData extends \LibModels\Wap\Product\SearchData | @@ -142,20 +142,35 @@ class SearchData extends \LibModels\Wap\Product\SearchData | ||
142 | */ | 142 | */ |
143 | public static function getSearchDataBySort(array $params, array $sortList) | 143 | public static function getSearchDataBySort(array $params, array $sortList) |
144 | { | 144 | { |
145 | - $data = array(); | ||
146 | - foreach ($sortList as $v) { | ||
147 | - if(empty($v['viewNum'])){ | ||
148 | - continue; | ||
149 | - } | ||
150 | - $searchParams = array_merge($params, $v); | ||
151 | - $list = self::searchElasticByCondition($searchParams, true); | ||
152 | - $productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list']; | ||
153 | - if(count($productList) < $v['viewNum']){ | ||
154 | - continue; | ||
155 | - } | ||
156 | - $data = array_merge($data, $productList); | 145 | +// $data = array(); |
146 | +// foreach ($sortList as $v) { | ||
147 | +// if(empty($v['viewNum'])){ | ||
148 | +// continue; | ||
149 | +// } | ||
150 | +// $searchParams = array_merge($params, $v); | ||
151 | +// $list = self::searchElasticByCondition($searchParams, true); | ||
152 | +// $productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list']; | ||
153 | +// if(count($productList) < $v['viewNum']){ | ||
154 | +// continue; | ||
155 | +// } | ||
156 | +// $data = array_merge($data, $productList); | ||
157 | +// } | ||
158 | +// return $data; | ||
159 | + | ||
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'] . ','; | ||
166 | + } | ||
167 | + $params['viewNum'] = $viewNum; | ||
168 | + $params['misort'] = rtrim($sortIds, ','); | ||
169 | + $searchd = self::searchElasticByCondition($params); | ||
170 | + if (empty($searchd['data']['product_list'])) { | ||
171 | + return array(); | ||
157 | } | 172 | } |
158 | - return $data; | 173 | + return $searchd['data']['product_list']; |
159 | } | 174 | } |
160 | 175 | ||
161 | /** | 176 | /** |
@@ -226,6 +226,7 @@ class Helpers | @@ -226,6 +226,7 @@ class Helpers | ||
226 | if ($oneGoods['is_default'] === 'Y') { | 226 | if ($oneGoods['is_default'] === 'Y') { |
227 | $productData['default_images'] = self::procProductImg($oneGoods); | 227 | $productData['default_images'] = self::procProductImg($oneGoods); |
228 | $flag = true; | 228 | $flag = true; |
229 | + break; | ||
229 | } | 230 | } |
230 | } | 231 | } |
231 | // 如果还未赋值,则取第一个skc产品的默认图片 | 232 | // 如果还未赋值,则取第一个skc产品的默认图片 |
@@ -247,7 +248,7 @@ class Helpers | @@ -247,7 +248,7 @@ class Helpers | ||
247 | $result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y'); | 248 | $result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y'); |
248 | $result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_' | 249 | $result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_' |
249 | . $productData['goods_list'][0]['goods_id'] | 250 | . $productData['goods_list'][0]['goods_id'] |
250 | - . '/' . $productData['cn_alphabet'] . '.html', 'item'); | 251 | + . '/' . $productData['cn_alphabet'] . '.html', array(), 'item'); |
251 | // APP访问需要加附加的参数 | 252 | // APP访问需要加附加的参数 |
252 | // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护 | 253 | // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护 |
253 | if ($isApp) { | 254 | if ($isApp) { |
@@ -49,8 +49,8 @@ class CommonController extends WebAction | @@ -49,8 +49,8 @@ class CommonController extends WebAction | ||
49 | HomeModel::COOKIE_NAME_LIFESTYLE | 49 | HomeModel::COOKIE_NAME_LIFESTYLE |
50 | ); | 50 | ); |
51 | $channel = $this->post('type', ''); | 51 | $channel = $this->post('type', ''); |
52 | - $pageIndex = intval($this->post('pageIndex', 0)); | ||
53 | - $pageCount = intval($this->post('pageCount', 8)); | 52 | + $pageIndex = (int) $this->post('pageIndex', 0); |
53 | + $pageCount = (int) $this->post('pageCount', 8); | ||
54 | if (! in_array($channel, $channels)) { | 54 | if (! in_array($channel, $channels)) { |
55 | break; | 55 | break; |
56 | } else { | 56 | } else { |
@@ -247,11 +247,10 @@ class HomeModel | @@ -247,11 +247,10 @@ class HomeModel | ||
247 | */ | 247 | */ |
248 | public static function getNewArrival($channel) | 248 | public static function getNewArrival($channel) |
249 | { | 249 | { |
250 | - $result = array(); | ||
251 | - $key = sprintf(WebCacheConfig::KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA.'_'.$channel); | 250 | + $key = WebCacheConfig::KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA . '_' . $channel; |
252 | //缓存数据 | 251 | //缓存数据 |
253 | $result = Cache::get($key); | 252 | $result = Cache::get($key); |
254 | - if(empty($result)) { | 253 | + if (empty($result)) { |
255 | $params = array( | 254 | $params = array( |
256 | 'order' => 's_t_desc', | 255 | 'order' => 's_t_desc', |
257 | 'shelve_time' => strtotime("-60 days") . ',' . time() | 256 | 'shelve_time' => strtotime("-60 days") . ',' . time() |
@@ -270,9 +269,13 @@ class HomeModel | @@ -270,9 +269,13 @@ class HomeModel | ||
270 | // 获取分类列表获取商品信息 | 269 | // 获取分类列表获取商品信息 |
271 | $goodsList = SearchData::getSearchDataBySort($params, $sortList); | 270 | $goodsList = SearchData::getSearchDataBySort($params, $sortList); |
272 | $pos = 1; | 271 | $pos = 1; |
272 | + $val = array(); | ||
273 | foreach ($goodsList as $goods) { | 273 | foreach ($goodsList as $goods) { |
274 | // 格式化数据 | 274 | // 格式化数据 |
275 | $val = Helpers::formatProduct($goods, true, true, true, 280, 373); | 275 | $val = Helpers::formatProduct($goods, true, true, true, 280, 373); |
276 | + if (!$val) { | ||
277 | + continue; | ||
278 | + } | ||
276 | if ($val['price'] == false) { | 279 | if ($val['price'] == false) { |
277 | $val['price'] = $val['salePrice']; | 280 | $val['price'] = $val['salePrice']; |
278 | } | 281 | } |
@@ -287,13 +290,16 @@ class HomeModel | @@ -287,13 +290,16 @@ class HomeModel | ||
287 | $val['tags']['isReNew'] = false;//$val['tags']['is_advance'];暂时不显示 | 290 | $val['tags']['isReNew'] = false;//$val['tags']['is_advance'];暂时不显示 |
288 | unset($val['tags']['is_advance'], $val['tags']['is_discount'], $val['tags']['is_limited'], $val['tags']['is_new'], | 291 | unset($val['tags']['is_advance'], $val['tags']['is_discount'], $val['tags']['is_limited'], $val['tags']['is_new'], |
289 | $val['tags']['is_yohood'], $val['tags']['midYear'], $val['tags']['yearEnd']); | 292 | $val['tags']['is_yohood'], $val['tags']['midYear'], $val['tags']['yearEnd']); |
290 | - if (! empty($val)) { | ||
291 | $result[] = $val; | 293 | $result[] = $val; |
292 | } | 294 | } |
293 | } | 295 | } |
294 | - } | ||
295 | Cache::set($key, $result, 3600); | 296 | Cache::set($key, $result, 3600); |
296 | } | 297 | } |
298 | + // 当一级缓存失效,并且接口异常时, 尝试从二级缓存获取数据 | ||
299 | + if (empty($result)) { | ||
300 | + $result = Cache::get($key, 'slave'); | ||
301 | + } | ||
302 | + | ||
297 | return $result; | 303 | return $result; |
298 | } | 304 | } |
299 | } | 305 | } |
-
Please register or login to post a comment