...
|
...
|
@@ -2,11 +2,15 @@ |
|
|
|
|
|
use Action\AbstractAction;
|
|
|
use LibModels\Wap\Product\SearchData;
|
|
|
use Plugin\DataProcess\ListProcess;
|
|
|
use Plugin\Helpers;
|
|
|
|
|
|
/**
|
|
|
* 搜索页
|
|
|
*/
|
|
|
class SearchController extends AbstractAction
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 搜索首页
|
|
|
*/
|
...
|
...
|
@@ -45,107 +49,173 @@ class SearchController extends AbstractAction |
|
|
)
|
|
|
);
|
|
|
$this->_view->display('index', array(
|
|
|
'search' => $data,
|
|
|
'searchPage' => true,
|
|
|
'search' => $data,
|
|
|
'searchPage' => true,
|
|
|
'pageFooter' => true
|
|
|
));
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 搜索列表页
|
|
|
*/
|
|
|
public function listAction()
|
|
|
{
|
|
|
$query = $this->get('query', null);
|
|
|
$brand = $this->get('brand', null);
|
|
|
$gender = $this->getCookie('_Channel', 'boys');
|
|
|
$p_d = $this->get('p_d', null);
|
|
|
$misort = $this->get('misort', null);
|
|
|
$msort = $this->get('msort', null);
|
|
|
|
|
|
$data = array(
|
|
|
'pageHeader' => array(
|
|
|
'navBack' => true,
|
|
|
'navTitle' => '搜索',
|
|
|
'navHome' => '/'
|
|
|
),
|
|
|
'goodListPage' => true,
|
|
|
'goodList' => array(
|
|
|
'brand' => 0,
|
|
|
'msort' => 0,
|
|
|
'gender' => $gender,
|
|
|
'price' => 0,
|
|
|
'size' => 0,
|
|
|
'discount' => ''
|
|
|
)
|
|
|
);
|
|
|
|
|
|
// 首先查询是否属于内置品类
|
|
|
$classes = ClassModel::getClassesArr();
|
|
|
$classFlag = array_search($query, $classes);
|
|
|
if($classFlag !== false)// 属于内部品类
|
|
|
{
|
|
|
$data['pageHeader']['navTitle'] = '所有'.$query;
|
|
|
// 过滤请求参数
|
|
|
$condition = filter_input_array(INPUT_GET, array(
|
|
|
'query' => FILTER_DEFAULT,
|
|
|
'brand' => FILTER_VALIDATE_INT,
|
|
|
'sort' => FILTER_DEFAULT,
|
|
|
'msort' => FILTER_VALIDATE_INT,
|
|
|
'misort' => FILTER_VALIDATE_INT,
|
|
|
'color' => FILTER_VALIDATE_INT,
|
|
|
'size' => FILTER_VALIDATE_INT,
|
|
|
'price' => FILTER_VALIDATE_INT,
|
|
|
'discount' => FILTER_VALIDATE_INT,
|
|
|
'gender' => FILTER_DEFAULT,
|
|
|
'p_d' => FILTER_DEFAULT,), false);
|
|
|
|
|
|
$query = isset($condition['query']) ? strtolower(trim($condition['query'])) : null;
|
|
|
|
|
|
// 标识用户是否有输入搜索内容
|
|
|
$haveQuery = $query !== null;
|
|
|
// 标识用户搜的是不是一级品类
|
|
|
$isQueryFirstClass = false;
|
|
|
// 标识用户搜的是不是二级品类
|
|
|
$isQuerySecondClass = false;
|
|
|
|
|
|
/* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框) */
|
|
|
if ($haveQuery) {
|
|
|
$domain = null;
|
|
|
$brandNames = Product\ListModel::getAllBrandNames();
|
|
|
|
|
|
do {
|
|
|
/* 精确查品牌域名 */
|
|
|
if (isset($brandNames[$query])) {
|
|
|
$domain = $query;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/* 精确查品牌名称 */
|
|
|
$domains = array_keys($brandNames, $query, true);
|
|
|
if (isset($domains[0])) {
|
|
|
$domain = $domains[0];
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/* 模糊查品牌域名 */
|
|
|
foreach ($brandNames as $key => $domains) {
|
|
|
if (strpos($key, $query) !== false) {
|
|
|
$domain = $key;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
} while (false);
|
|
|
|
|
|
// 清空变量做释放
|
|
|
$brandNames = array();
|
|
|
|
|
|
// 跳转到品牌商品列表页
|
|
|
if ($domain !== null) {
|
|
|
$url = Helpers::url('', array(
|
|
|
'from' => 'search',
|
|
|
'query' => $query,
|
|
|
'gender' => $condition['gender']
|
|
|
), $domain);
|
|
|
$this->go($url);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/* 判断是不是品类, 是品类加导航标题(不显示搜索框) */
|
|
|
if ($haveQuery) {
|
|
|
$classNames = Category\ClassModel::getClassNames();
|
|
|
|
|
|
// 如果存在搜索字符串就显示搜索栏
|
|
|
if(!is_null($query) && $classFlag === false)
|
|
|
{
|
|
|
$data['search'] = array(
|
|
|
'default' => $query
|
|
|
);
|
|
|
do {
|
|
|
/* 精确查一级品类 */
|
|
|
$sorts = array_keys($classNames['first'], $query, true);
|
|
|
if (isset($sorts[0])) {
|
|
|
$isQueryFirstClass = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/* 精确查二级品类 */
|
|
|
$sorts = array_keys($classNames['second'], $query, true);
|
|
|
if (isset($sorts[0])) {
|
|
|
$isQuerySecondClass = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
while (false);
|
|
|
|
|
|
$classNames = array();
|
|
|
}
|
|
|
|
|
|
// 转换性别
|
|
|
$this->genderTrans($gender);
|
|
|
|
|
|
$data = array();
|
|
|
// 搜索是一级品类
|
|
|
if ($isQueryFirstClass) {
|
|
|
$this->setTitle('全部' . $query);
|
|
|
$this->setNavHeader('全部' . $query, true, SITE_MAIN);
|
|
|
}
|
|
|
// 搜索是二级品类
|
|
|
elseif ($isQuerySecondClass) {
|
|
|
$this->setTitle($query);
|
|
|
$this->setNavHeader($query, true, SITE_MAIN);
|
|
|
}
|
|
|
// 搜索其它内容
|
|
|
else {
|
|
|
if ($haveQuery) {
|
|
|
$data['goodList']['search']['default'] = $query;
|
|
|
$data['goodList']['search']['default'] = $query;
|
|
|
}
|
|
|
$this->setTitle('搜索');
|
|
|
$this->setNavHeader('搜索', true, SITE_MAIN);
|
|
|
}
|
|
|
|
|
|
$data['goodListPage'] = true;
|
|
|
$data['goodList'] = $condition;
|
|
|
|
|
|
// 查询数据
|
|
|
$listData = SearchData::searchLiDatas($query, $brand, $gender, $p_d, $misort, $msort);
|
|
|
$listData = SearchData::searchByCondition($condition);
|
|
|
// 处理返回的数据
|
|
|
if (isset($listData['code']) && $listData['code'] === 200) {
|
|
|
$tmpData = $listData['data'];
|
|
|
|
|
|
// 如果存在品牌信息就显示品牌字段
|
|
|
if(isset($tmpData['brand']) && !empty($tmpData['brand']))
|
|
|
{
|
|
|
$brandData = $tmpData['brand'];
|
|
|
$data['brandWay'] = array(
|
|
|
'url' => '/product/list/brand?brand='.$brandData['id'],
|
|
|
'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40),
|
|
|
'name' => $brandData['brand_name']
|
|
|
);
|
|
|
|
|
|
// 设置品牌默认值
|
|
|
$data['goodList']['brand'] = $brandData['id'];
|
|
|
}
|
|
|
|
|
|
$data['goodList'] += ListProcess::getListData($tmpData);
|
|
|
if (!empty($listData['data']['brand'])) {
|
|
|
$brandData = $listData['data']['brand'];
|
|
|
$data['brandWay'] = array(
|
|
|
'url' => 'http://'. $brandData['brand_domain'] . SUB_DOMAIN,
|
|
|
'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40),
|
|
|
'name' => $brandData['brand_name']
|
|
|
);
|
|
|
// 设置品牌默认值
|
|
|
$data['goodList']['brand'] = $brandData['id'];
|
|
|
$data['goodList'] += ListProcess::getListData($listData['data']);
|
|
|
}
|
|
|
$listData = array();
|
|
|
|
|
|
$this->_view->display('list', $data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
/**
|
|
|
* Ajax异步筛选请求
|
|
|
*/
|
|
|
public function searchAction()
|
|
|
{
|
|
|
if($this->isAjax())
|
|
|
{
|
|
|
$query = $this->get('query', null);
|
|
|
$brand = $this->get('brand', null);
|
|
|
$gender = $this->get('gender', null);
|
|
|
$color = $this->get('color', null);
|
|
|
$size = $this->get('size', null);
|
|
|
$price = $this->get('price', null);
|
|
|
$p_d = $this->get('discount', null);
|
|
|
$sort = $this->get('msort', null);
|
|
|
|
|
|
// 转换性别
|
|
|
$this->genderTrans($gender);
|
|
|
if ($this->isAjax()) {
|
|
|
// 过滤请求参数
|
|
|
$condition = filter_input_array(INPUT_GET, array(
|
|
|
'query' => FILTER_DEFAULT,
|
|
|
'brand' => FILTER_VALIDATE_INT,
|
|
|
'sort' => FILTER_VALIDATE_INT,
|
|
|
'msort' => FILTER_VALIDATE_INT,
|
|
|
'misort' => FILTER_VALIDATE_INT,
|
|
|
'color' => FILTER_VALIDATE_INT,
|
|
|
'size' => FILTER_VALIDATE_INT,
|
|
|
'price' => FILTER_VALIDATE_INT,
|
|
|
'discount' => FILTER_DEFAULT,
|
|
|
'gender' => FILTER_DEFAULT,
|
|
|
'p_d' => FILTER_DEFAULT, ), false);
|
|
|
|
|
|
// 转换排序方式
|
|
|
$order = $this->get('order', null);
|
|
|
$page = $this->get('page', 1);
|
|
|
$order = $this->get('order', 0);
|
|
|
$type = $this->get('type', '');
|
|
|
switch ($type) {
|
|
|
case 'price':
|
...
|
...
|
@@ -162,21 +232,19 @@ class SearchController extends AbstractAction |
|
|
|
|
|
$data = array();
|
|
|
// 查询数据
|
|
|
$listData = SearchData::searchLiDatas($query, $brand, $gender, $color, $size, $price, $p_d, $sort, $order);
|
|
|
$listData = SearchData::searchByCondition($condition, $order, $page);
|
|
|
// 处理返回的数据
|
|
|
if (isset($listData['code']) && $listData['code'] === 200) {
|
|
|
$tmpData = $listData['data'];
|
|
|
|
|
|
unset($tmpData['filter']);// 不要筛选条件的数据
|
|
|
$data = ListProcess::getListData($tmpData);
|
|
|
if (isset($listData['data'])) {
|
|
|
if (isset($listData['data']['filter'])) {
|
|
|
unset($listData['data']['filter']);
|
|
|
}
|
|
|
$data = ListProcess::getListData($listData['data']);
|
|
|
}
|
|
|
$listData = array();
|
|
|
|
|
|
if(empty($data))
|
|
|
{
|
|
|
if (empty($data)) {
|
|
|
echo ' ';
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
} else {
|
|
|
$this->_view->display('page', $data);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -189,8 +257,7 @@ class SearchController extends AbstractAction |
|
|
*/
|
|
|
public function fuzzysearch()
|
|
|
{
|
|
|
if($this->isAjax())
|
|
|
{
|
|
|
if ($this->isAjax()) {
|
|
|
$keyword = $this->post('keyword', '');
|
|
|
|
|
|
$result = SearchData::searchFuzzyDatas($keyword);
|
...
|
...
|
@@ -198,4 +265,5 @@ class SearchController extends AbstractAction |
|
|
$this->echoJson($result);
|
|
|
}
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
|
|
|
|
|
} |
...
|
...
|
|