Search.php
13.5 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php
use Action\AbstractAction;
use LibModels\Wap\Product\SearchData;
use Plugin\DataProcess\ListProcess;
use Plugin\Helpers;
/**
* 搜索页
*/
class SearchController extends AbstractAction
{
/**
* 搜索首页
*/
public function indexAction()
{
$this->setNavHeader('搜索', true, SITE_MAIN);
//$this->_view->html('search');
$this->_view->display('index', array(
'search' => array('url' => Helpers::url('', null, 'search')),
'showDownloadApp' => true,
'searchPage' => true,
'pageFooter' => true
));
}
/**
* 搜索列表页
*
* tar mark
*/
public function listAction()
{
// 过滤请求参数
$condition = filter_input_array(INPUT_GET, array(
'shop_id' => FILTER_DEFAULT,
'categoryId' => FILTER_DEFAULT,
'subCategoryId' => FILTER_DEFAULT,
'title' => FILTER_DEFAULT,
'query' => FILTER_DEFAULT,
'brand' => FILTER_DEFAULT,
'sort' => FILTER_DEFAULT,
'msort' => FILTER_DEFAULT,
'misort' => FILTER_DEFAULT,
'color' => FILTER_DEFAULT,
'size' => FILTER_DEFAULT,
'style' => FILTER_DEFAULT,
'price' => FILTER_DEFAULT,
'discount' => FILTER_DEFAULT,
'gender' => FILTER_DEFAULT,
'p_d' => FILTER_DEFAULT,), false);
$condition['shopId'] = $condition['shop_id'];
$query = empty($condition['query']) ? null : strtolower(trim($condition['query']));
if (isset($condition['discount'])) {
$condition['p_d'] = rawurldecode($condition['discount']);
// unset($condition['discount']); 为了兼容js中传参的discount
}
// 为了兼容现在运营在用的p_d
if (isset($condition['p_d'])) {
$condition['discount'] = rawurldecode($condition['p_d']);
}
if (isset($condition['query'])) {
$condition['query'] = rawurlencode($condition['query']);
}
// 标识用户是否有输入搜索内容
$haveQuery = $query !== '';
// 标识用户搜的是不是一级品类
$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 && empty($condition['shop_id'])) {
$url = Helpers::url('', array(
'from' => 'search',
'query' => $query
), $domain);
$this->go($url);
}
}
/* 判断是不是品类, 是品类加导航标题(不显示搜索框) */
if ($haveQuery) {
$classNames = Category\ClassModel::getClassNames();
do {
// 品类名称为空时跳出
if (empty($classNames)) {
break;
}
/* 精确查一级品类 */
$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();
} else {
$condition['query'] = '';
}
$data = array();
$data['goodListPage'] = true;
$data['goodList'] = $condition;
$data['query'] = $query;
// 搜索是一级品类
if ($isQueryFirstClass) {
$this->setTitle('全部' . $query);
$this->setNavHeader('全部' . $query, true, SITE_MAIN);
} // 搜索是二级品类
elseif ($isQuerySecondClass) {
$this->setTitle($query);
$this->setNavHeader($query, true, SITE_MAIN);
} // 搜索其它内容
else {
$from = $this->get('from');
if ($haveQuery || $from) {
$data['goodList']['search']['default'] = empty($query) ? false : $query;
$data['goodList']['search']['url'] = Helpers::url('', null, 'search');
}
$this->setTitle('搜索');
$this->setNavHeader('搜索', true, SITE_MAIN);
}
// 右下角的购物车链接
$data['goodList']['cartUrl'] = Helpers::url('/cart/index/index', null);
// 显示底部悬浮下载
$data['showDownloadApp'] = true;
// 显示页面底部登录信息
$data['pageFooter'] = true;
// 查询数据
if (!isset($condition['query'])) {
$data['goodList'] += Product\ListModel::getClassData($condition);
} else {
$listData = SearchData::searchByCondition($condition);
// 处理返回的数据
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();
}
if(isset($condition['title'])){
$this->setTitle($condition['title']);
$this->setNavHeader($condition['title'], true, SITE_MAIN);
}
$this->_view->display('list', $data);
}
/**
* Ajax异步筛选请求
*/
public function searchAction()
{
$data = array();
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 过滤请求参数 */
$condition = filter_input_array(INPUT_GET, array(
'shop_id' => FILTER_DEFAULT,
'query' => FILTER_DEFAULT,
'specialsale_id' => FILTER_DEFAULT,
'promotion' => FILTER_DEFAULT,
'brand' => FILTER_DEFAULT,
'sort' => FILTER_DEFAULT,
'msort' => FILTER_DEFAULT,
'misort' => FILTER_DEFAULT,
'color' => FILTER_DEFAULT,
'size' => FILTER_DEFAULT,
'style' => FILTER_DEFAULT,
'price' => FILTER_DEFAULT,
'discount' => FILTER_DEFAULT,
'gender' => FILTER_DEFAULT,
'p_d' => FILTER_DEFAULT,
'page' => FILTER_VALIDATE_INT,), false);
if(!empty($condition['shop_id'])){
$condition['shop'] = $condition['shop_id'];
}
// 转义分类
if (isset($condition['sort'])) {
$condition['sort'] = rawurldecode($condition['sort']);
}
// 转义分类
if (isset($condition['msort'])) {
$condition['msort'] = rawurldecode($condition['msort']);
}
// 转义分类
if (isset($condition['misort'])) {
$condition['misort'] = rawurldecode($condition['misort']);
}
// 转义活动ID
if (isset($condition['specialsale_id'])) {
$condition['specialsale_id'] = rawurldecode($condition['specialsale_id']);
}
if (isset($condition['promotion'])) {
$condition['promotion'] = rawurldecode($condition['promotion']);
}
// 转义颜色
if (isset($condition['color'])) {
$condition['color'] = rawurldecode($condition['color']);
}
// 转义价格
if (isset($condition['price'])) {
$condition['price'] = rawurldecode($condition['price']);
}
// 转义风格
if (isset($condition['style'])) {
$condition['style'] = rawurldecode($condition['style']);
}
// 为了兼容现在运营在用的p_d
if (isset($condition['p_d'])) {
$condition['p_d'] = rawurldecode($condition['p_d']);
} // 转换折扣
elseif (isset($condition['discount'])) {
$condition['p_d'] = rawurldecode($condition['discount']);
unset($condition['discount']);
}
// 转义性别
if (isset($condition['gender'])) {
$condition['gender'] = rawurldecode($condition['gender']);
}
if (isset($condition['query'])) {
$condition['query'] = rawurldecode($condition['query']);
}
// 转换排序方式
$type = $this->get('type', '');
$order = $this->get('order', 0);
$condition['order'] = Helpers::transOrder($order, $type);
// 过滤掉值为空的条件
$condition = array_filter($condition);
// /* 模糊搜索关键词 */
// if (isset($condition['query'])) {
// $data = Product\SearchModel::getSearchData($condition);
// break;
// }
//
// /* 精确搜索品牌 */
// if (isset($condition['brand'])) {
// $title = '';
// $data = Product\ListModel::getBrandData($condition, $title);
// break;
// }
//
// /* 精确搜索品类 */
// $data = Product\ListModel::getClassData($condition);
$data = Product\SearchModel::getSearchData($condition);
} while (false);
if (empty($data['new'])) {
echo ' ';
} else {
$this->_view->display('page', $data);
}
}
/**
* Ajax异步获取筛选数据
* @return array 筛选数据
*/
public function filterAction()
{
$data = array();
if ($this->isAjax()) {
// 过滤请求参数
$condition = filter_input_array(INPUT_GET, array(
'query' => FILTER_DEFAULT,
'brand' => FILTER_DEFAULT,
'shop_id' => FILTER_DEFAULT,
'sort' => FILTER_DEFAULT,
'msort' => FILTER_DEFAULT,
'misort' => FILTER_DEFAULT,
'color' => FILTER_DEFAULT,
'size' => FILTER_DEFAULT,
'style' => FILTER_DEFAULT,
'price' => FILTER_DEFAULT,
'discount' => FILTER_DEFAULT,
'gender' => FILTER_DEFAULT,
'p_d' => FILTER_DEFAULT,), false);
// 转义分类
if (isset($condition['sort'])) {
$condition['sort'] = rawurldecode($condition['sort']);
}
// 转义分类
if (isset($condition['msort'])) {
$condition['msort'] = rawurldecode($condition['msort']);
}
// 转义分类
if (isset($condition['misort'])) {
$condition['misort'] = rawurldecode($condition['misort']);
}
// 转义颜色
if (isset($condition['color'])) {
$condition['color'] = rawurldecode($condition['color']);
}
// 为了兼容现在运营在用的p_d
if (isset($condition['p_d'])) {
$condition['p_d'] = rawurldecode($condition['p_d']);
} // 转换折扣
elseif (isset($condition['discount'])) {
$condition['p_d'] = rawurldecode($condition['discount']);
unset($condition['discount']);
}
// 转义性别
if (isset($condition['gender'])) {
$condition['gender'] = rawurldecode($condition['gender']);
}
// 转义价格
if (isset($condition['price'])) {
$condition['price'] = rawurldecode($condition['price']);
}
// 转义风格
if (isset($condition['style'])) {
$condition['style'] = rawurldecode($condition['style']);
}
// 区别各种列表页面的筛选数据
$data = Product\SearchModel::getFilterData($condition);
}
if (empty($data)) {
echo ' ';
} else {
$this->_view->display('filter', $data);
}
}
}