Store.php 1.38 KB
<?php

/**
 * 店铺搜索
 * @author tongdesheng
 *
 */
class YHMSearch_Store extends YHMSearch_Core {

    private $_searchConditions = array('storetype', 'keyword', 'page', 'viewNum', 'searchuid', 'hasgoods', 'hasstock');
    private $_orderType = array('star:desc', "stock_number:desc", 'create_time:asc', 'create_time:desc');
    private $_urlPath = 'searchstore';

    public function getList($params) {
        $condParams = array();
        //筛选条件
        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';
            }
        }
        $retData = $this->req($this->_urlPath, $condParams);
        //{"searchstore":{"items":["1","0","7"]}}
        if (!empty($retData['searchstore']['items'])) {
            return $retData['searchstore']['items'];
        }
        return array();
    }

}