Search.php 2.89 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);
        }
    }

    /**
     * 搜索错误页
     */
    public function errorAction()
    {
        $keyword = $this->get('query');
        $data = array(
            //初始化js
            'searchListPage' => true,
            'search' => array(
                'keyWord' => $keyword,
                'searchActionUrl' => 'http:://search.yohobuy.com',
                'latestWalk' => 7,
                'pathNav' => Array(
                    '0'=>array(
                        'href' => '/',
                        'name' => '首页'
                    ),
                    '1'=>array(
                        'name' => '搜索“<span id="nav_keyword">'.$keyword.'</span>”共<span id="nav_keyword_count">0</span>个结果'
                    )
                )
            )
        );
        $this->setTitle('潮流商品搜索 | YOHO!有货');
        $this->setKeywords('Yoho! 有货,潮流,时尚,流行,购物,B2C,正品,购物网站,网上购物,货到付款,品牌服饰,男士护肤,黑框眼镜,匡威,板鞋,i.t,izzue,5cm,eastpak,vans,lylescott,g-shock,new balance,lacoste,melissa,casio,卡西欧手表,舒雅,jasonwood,odm,AAAA,香港购物,日本潮流');
        $this->setDescription('潮流商品搜索,上衣,衬衫,TEE,卫衣,冲锋衣,风衣,羽绒服,裤子,休闲鞋,板鞋,配饰,复古眼镜');
        $this->setWebNavHeader();
        $this->_view->display('search', $data);
    }
}