Search.php
5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
use Action\AbstractAction;
use LibModels\Wap\Product\SearchData;
/**
* 搜索页
*/
class SearchController extends AbstractAction
{
/**
* 搜索首页
*/
public function indexAction()
{
$data = array(
array(
'hot' => array(
array(
'name' => '夹克',
'url' => 'm.yohobuy.com'
),
array(
'name' => '休闲运动鞋',
'url' => 'm.yohobuy.com'
),
array(
'name' => 'Into the Rainbow',
'url' => 'm.yohobuy.com'
)
),
'history' => array(
array(
'name' => 'what',
'url' => 'm.yohobuy.com'
),
array(
'name' => 'the',
'url' => 'm.yohobuy.com'
),
array(
'name' => 'fuck',
'url' => 'm.yohobuy.com'
)
)
)
);
$this->_view->display('index', array(
'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;
}
// 如果存在搜索字符串就显示搜索栏
if(!is_null($query) && $classFlag === false)
{
$data['search'] = array(
'default' => $query
);
}
// 转换性别
$this->genderTrans($gender);
// 查询数据
$listData = SearchData::searchLiDatas($query, $brand, $gender, $p_d, $misort, $msort);
// 处理返回的数据
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);
}
$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);
// 转换排序方式
$order = $this->get('order', null);
$type = $this->get('type', '');
switch ($type) {
case 'price':
$order = ($order == 0) ? 's_p_desc' : 's_p_asc';
break;
case 'discount':
$order = ($order == 0) ? 'p_d_desc' : 'p_d_asc';
break;
case 'newest':
default:
$order = ($order == 0) ? 's_t_desc' : 's_t_asc';
break;
}
$data = array();
// 查询数据
$listData = SearchData::searchLiDatas($query, $brand, $gender, $color, $size, $price, $p_d, $sort, $order);
// 处理返回的数据
if (isset($listData['code']) && $listData['code'] === 200) {
$tmpData = $listData['data'];
unset($tmpData['filter']);// 不要筛选条件的数据
$data = ListProcess::getListData($tmpData);
}
if(empty($data))
{
echo ' ';
}
else
{
$this->_view->display('page', $data);
}
}
}
/**
* 模糊搜索指定字符
*
* @return array 模糊搜索的结果
*/
public function fuzzysearch()
{
if($this->isAjax())
{
$keyword = $this->post('keyword', '');
$result = SearchData::searchFuzzyDatas($keyword);
$this->echoJson($result);
}
}
}