Search.php 1.5 KB
<?php
use Action\WebAction;
use Product\SearchModel;
class SearchController extends WebAction
{
    public function indexAction()
    {
        //当前控制器
        $options['controller'] = 'Search';
        $options['action'] = 'index';
        //浏览记录数
        $options['reviewNum'] = 7;
        $searchData = SearchModel::searchData(array(),$options);
        $data = array(
            //初始化js
            'searchListPage' => true,
            'search' => $searchData
        );
        $this->setWebNavHeader();
        $this->_view->display('search', $data);
    }

    /**
     * 搜索提示
     */
    public function suggestAction()
    {
        $callback = $this->get('callback');
        $query = rawurldecode($this->get('query'));
        $size = rawurldecode($this->get('size',10));
        if (empty($query)) {
            $this->helpJsonCallbackResult($callback, 412, '搜索词为空');
        }
        if ($size > 50) {
            $size = 10;
        }
        if ($query) {
            $param['query'] = $query;
            $param['size'] = $size;
            $suggest = SearchModel::getSuggest($param);
        }
        $this->helpJsonCallbackResult($callback, 200, 'suggest', $suggest);
    }

    /**
     * 根据分类id,获取分类尺码
     */
    public function sortSizeAction()
    {
        if (!$this->isAjax()) {
            $condition['msort'] = $this->get('msort');
            $size = SearchModel::getSortSize($condition);
            $this->echoJson($size);
        }
    }
}