Search.php 3.22 KB
<?php
class QLibView_Search {
	private static $page = 1;
	private static $params;
	private static $rows = 100;
	private static $gender = '1,3';
	private static $num = '';
	public static function getSearch($params, $type = 'newProduct') {
                $match = new QINSearch_Tyr_Match ( $project = 'search_sort', $index = 'search_sort' );
                if ($type == 'newProduct' || $type == 'favoriteTotal' || $type == 'newProductRecom') {
                        if (empty ( $params ['day'] )) {
                                $dayList = $match->getNewProduct ( array('gender'=>$params['gender']) );
                                $arrayKeys = array_keys ( $dayList );
                                $start_time = strtotime ( date ( 'Y-m-d', array_pop ( $arrayKeys ) ) );
                                $end_time = strtotime ( date ( 'Y-m-d', array_shift ( $arrayKeys ) ) ) + 86400 - 1;
                                $params ['shelve_time'] = $start_time . ',' . $end_time;
                        }
                }
                if ($type == 'saleFavoriteTotal' || $type == 'saleFavoriteProduct') {
                        if (empty ( $params ['p_d'] )) {
                                $params ['p_d'] = '0.1,0.9';
                        }
                }
                if (! empty ( $params ['page'] )) {
                        self::$page = $params ['page'];
                }
                if (! empty ( $params ['rows'] )) {
                        self::$rows = $params ['rows'];
                }
                if (!empty ( $params ['gender'] )) {
                        self::$gender = $params ['gender'];
                }
                $match = new QINSearch_Tyr_Match ( $project = 'search_sort', $index = 'search_sort' );
                $search = $match->search ();
                $search->setSortModes ( $params );
                if ($type == 'favoriteTotal' || $type == 'saleFavoriteTotal') {
                        if (isset($params['brand'])) {
                                unset($params['brand']);
                        }
                        $_result = $match->getGoodsNumByBrand($params);
                }
                 elseif ($type == 'saleProduct' || $type == 'newProductRecom') {
                        $_result = $search->setFilters ( $params )->setLimits ( 0, 100, 100 )->query ();
                } else {
                        $_result = $search->setFilters ( $params )->setLimits ( (self::$page - 1) * self::$rows, ( int ) self::$rows, 300 )->query ();
                }
                return $_result;
        }
        
        public static function getNewProductNum($params){
        	$match = new QINSearch_Tyr_Match ( $project = 'search_sort', $index = 'search_sort' );
        	$dayList = $match->getNewProduct ();
        	$arrayKeys = array_keys ( $dayList );
        	$start_time = strtotime ( date ( 'Y-m-d', array_pop ( $arrayKeys ) ) );
        	$end_time = strtotime ( date ( 'Y-m-d', array_shift ( $arrayKeys ) ) ) + 86400 - 1;
        	$params ['shelve_time'] = $start_time . ',' . $end_time;
        	$search = $match->search ();
        	$_result = $search->setFilters ( $params )->setLimits ( (self::$page - 1) * self::$rows, ( int ) self::$rows)->query ();
        	return $_result;
        }
}?>