Goods.php 2.51 KB
<?php

/**
 * 搜索商品
 * @author tongdesheng
 *
 */
class YHMSearch_Goods extends YHMSearch_Core {

    /**
     * 搜索条件,sales_price是以逗号分隔
     * @var string
     */
    private $_searchConditions = array('gender', 'quality', 'msort', 'storeid','stocknumber',
        'identity', 'price', 'keyword', 'page', 'viewNum', 'brand', 'searchuid', 'storetype');

    /**
     * keyword需要搜索的字段
     * @var string
     */
    private $_keywordFields = 'goods_name';

    /**
     * 支持的排序方式
     * @var string
     */
    private $_orderType = array('hot_number:asc', 'hot_number:desc', "stock_number:desc", 'create_time:asc', 'create_time:desc');

    /**
     * 搜索的路径
     * @var string
     */
    private $_urlPath = 'search';

    public function getList($params) {
        $condParams = array(
                //		'field' => $this->_keywordFields   //暂时不需要指定搜索的field
        );
        //筛选条件
        if (!empty($params)) {
            foreach ($this->_searchConditions as $cond) {
                if (isset($params[$cond])) {
                    $condParams[$cond] = $params[$cond];
                }
            }
        }
        if (isset($params['order_type']))
        {    
            $typearr = explode(",", $params['order_type']);
            $newtype = array_intersect($typearr, $this->_orderType);
            //排序方式
            if (!empty($params['order_type']) && (count($typearr) == count($newtype))) {
                $condParams['order'] = $params['order_type'];
            }
        }else {
                $condParams['order'] = 'create_time:desc';
            }
        // print_r($condParams);
        //  $condParams['order'] = $params['order_type'];
        //{"search":{"result":{"size":10,"skcs":{"153805":"NIKE LUNARFLY 306 男子运动鞋","126232":"NIKE AF1 TRUCK TEE 男子印花短袖T恤","126240":"NIKE TEE-LIFE IS SHORT 女子短袖T恤","156814":"NIKE ROSHE RUN LIBERTY 印花运动鞋","152328":"NIKE ROSHERUN NM BREEZE男子运动鞋","156818":"NIKE INTERNATIONALIST LIBERTY 印花运动鞋","153188":"NIKE ROSHERUN NM BREEZE男子运动鞋","153804":"NIKE LUNARFLY 306 男子运动鞋","126273":"NIKE SB FREMONT STRETCH 5-PKT PANT男子休闲裤","126247":"NIKE 男子圆领logo短袖T恤"}}}}
        $retData = $this->req($this->_urlPath, $condParams);
        if (empty($retData['search']['result']['skcs'])) {
            return array();
        }
        return $retData['search']['result']['skcs'];  //返回skc列表
    }

}