Search.php 3.97 KB
<?php
use Action\WebAction;
use Product\SearchModel;
class SearchController extends WebAction
{
    public function indexAction()
    {
        $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();

        $list = SearchModel::searchData(array(), array(
        'controller' => 'Search',
        'action' => 'index',
        'reviewNum' => 7, //浏览记录数
        ));

        //统计前三个商品
        $skn=array();
        $arr=array();
        if (isset($list['goods']) && !empty($list['goods'])) {
            $arr = array_slice($list['goods'],0,3);
            foreach ($arr as $key=>$value) {
                $skn[] = $value['skn'];
            }
            $arr = array('skn'=>$skn);
        }else{
            $arr = array('skn'=>array());
        }

        $data = array(
            'productListPage' => true, //初始化js
            'list' => $list,
            'criteo' => $arr
        );
        $data['list']['searchPage'] = true; //设置搜素页面标识,区分列表页-->特有的搜索页导航样式
        if (isset($data['list']['goods']) && empty($data['list']['goods'])) {
            $searchData['productListPage'] = true;
            $searchData['search']['pathNav'] = isset($data['list']['pathNav']) ? $data['list']['pathNav'] : '';
            $searchData['search']['keyWord'] = isset($data['list']['keyWord']) ? $data['list']['keyWord'] : '';
            $searchData['search']['searchActionUrl'] = isset($data['list']['searchActionUrl']) ? $data['list']['searchActionUrl'] : '';
            $searchData['search']['latestWalk'] = 7;
            $searchData['criteo'] = array('skn'=>array());
            $this->_view->display('no-result', $searchData);
            exit;
        }
        $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 = SearchModel::searchError($keyword);
        $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('no-result', $data);
    }
}