添加一些搜索参数,price,style等,同时支持区间查询
Showing
2 changed files
with
109 additions
and
27 deletions
@@ -35,13 +35,14 @@ class SearchController extends AbstractAction | @@ -35,13 +35,14 @@ class SearchController extends AbstractAction | ||
35 | // 过滤请求参数 | 35 | // 过滤请求参数 |
36 | $condition = filter_input_array(INPUT_GET, array( | 36 | $condition = filter_input_array(INPUT_GET, array( |
37 | 'query' => FILTER_DEFAULT, | 37 | 'query' => FILTER_DEFAULT, |
38 | - 'brand' => FILTER_VALIDATE_INT, | 38 | + 'brand' => FILTER_DEFAULT, |
39 | 'sort' => FILTER_DEFAULT, | 39 | 'sort' => FILTER_DEFAULT, |
40 | 'msort' => FILTER_DEFAULT, | 40 | 'msort' => FILTER_DEFAULT, |
41 | 'misort' => FILTER_DEFAULT, | 41 | 'misort' => FILTER_DEFAULT, |
42 | - 'color' => FILTER_VALIDATE_INT, | ||
43 | - 'size' => FILTER_VALIDATE_INT, | ||
44 | - 'price' => FILTER_VALIDATE_INT, | 42 | + 'color' => FILTER_DEFAULT, |
43 | + 'size' => FILTER_DEFAULT, | ||
44 | + 'style' => FILTER_DEFAULT, | ||
45 | + 'price' => FILTER_DEFAULT, | ||
45 | 'discount' => FILTER_DEFAULT, | 46 | 'discount' => FILTER_DEFAULT, |
46 | 'gender' => FILTER_DEFAULT, | 47 | 'gender' => FILTER_DEFAULT, |
47 | 'p_d' => FILTER_DEFAULT,), false); | 48 | 'p_d' => FILTER_DEFAULT,), false); |
@@ -49,7 +50,7 @@ class SearchController extends AbstractAction | @@ -49,7 +50,7 @@ class SearchController extends AbstractAction | ||
49 | $query = empty($condition['query']) ? null : strtolower(trim($condition['query'])); | 50 | $query = empty($condition['query']) ? null : strtolower(trim($condition['query'])); |
50 | if (isset($condition['discount'])) { | 51 | if (isset($condition['discount'])) { |
51 | $condition['p_d'] = rawurldecode($condition['discount']); | 52 | $condition['p_d'] = rawurldecode($condition['discount']); |
52 | - unset($condition['discount']); | 53 | + // unset($condition['discount']); 为了兼容js中传参的discount |
53 | } | 54 | } |
54 | if (isset($condition['query'])) { | 55 | if (isset($condition['query'])) { |
55 | $condition['query'] = rawurlencode($condition['query']); | 56 | $condition['query'] = rawurlencode($condition['query']); |
@@ -200,13 +201,14 @@ class SearchController extends AbstractAction | @@ -200,13 +201,14 @@ class SearchController extends AbstractAction | ||
200 | /* 过滤请求参数 */ | 201 | /* 过滤请求参数 */ |
201 | $condition = filter_input_array(INPUT_GET, array( | 202 | $condition = filter_input_array(INPUT_GET, array( |
202 | 'query' => FILTER_DEFAULT, | 203 | 'query' => FILTER_DEFAULT, |
203 | - 'brand' => FILTER_VALIDATE_INT, | 204 | + 'brand' => FILTER_DEFAULT, |
204 | 'sort' => FILTER_DEFAULT, | 205 | 'sort' => FILTER_DEFAULT, |
205 | 'msort' => FILTER_DEFAULT, | 206 | 'msort' => FILTER_DEFAULT, |
206 | 'misort' => FILTER_DEFAULT, | 207 | 'misort' => FILTER_DEFAULT, |
207 | - 'color' => FILTER_VALIDATE_INT, | ||
208 | - 'size' => FILTER_VALIDATE_INT, | ||
209 | - 'price' => FILTER_VALIDATE_INT, | 208 | + 'color' => FILTER_DEFAULT, |
209 | + 'size' => FILTER_DEFAULT, | ||
210 | + 'style' => FILTER_DEFAULT, | ||
211 | + 'price' => FILTER_DEFAULT, | ||
210 | 'discount' => FILTER_DEFAULT, | 212 | 'discount' => FILTER_DEFAULT, |
211 | 'gender' => FILTER_DEFAULT, | 213 | 'gender' => FILTER_DEFAULT, |
212 | 'p_d' => FILTER_DEFAULT, | 214 | 'p_d' => FILTER_DEFAULT, |
@@ -223,6 +225,10 @@ class SearchController extends AbstractAction | @@ -223,6 +225,10 @@ class SearchController extends AbstractAction | ||
223 | if (isset($condition['misort'])) { | 225 | if (isset($condition['misort'])) { |
224 | $condition['misort'] = rawurldecode($condition['misort']); | 226 | $condition['misort'] = rawurldecode($condition['misort']); |
225 | } | 227 | } |
228 | + // 转义价格 | ||
229 | + if (isset($condition['price'])) { | ||
230 | + $condition['price'] = rawurldecode($condition['price']); | ||
231 | + } | ||
226 | // 转换折扣 | 232 | // 转换折扣 |
227 | if (isset($condition['discount'])) { | 233 | if (isset($condition['discount'])) { |
228 | $condition['p_d'] = rawurldecode($condition['discount']); | 234 | $condition['p_d'] = rawurldecode($condition['discount']); |
@@ -282,13 +288,14 @@ class SearchController extends AbstractAction | @@ -282,13 +288,14 @@ class SearchController extends AbstractAction | ||
282 | // 过滤请求参数 | 288 | // 过滤请求参数 |
283 | $condition = filter_input_array(INPUT_GET, array( | 289 | $condition = filter_input_array(INPUT_GET, array( |
284 | 'query' => FILTER_DEFAULT, | 290 | 'query' => FILTER_DEFAULT, |
285 | - 'brand' => FILTER_VALIDATE_INT, | 291 | + 'brand' => FILTER_DEFAULT, |
286 | 'sort' => FILTER_DEFAULT, | 292 | 'sort' => FILTER_DEFAULT, |
287 | - 'msort' => FILTER_VALIDATE_INT, | ||
288 | - 'misort' => FILTER_VALIDATE_INT, | ||
289 | - 'color' => FILTER_VALIDATE_INT, | ||
290 | - 'size' => FILTER_VALIDATE_INT, | ||
291 | - 'price' => FILTER_VALIDATE_INT, | 293 | + 'msort' => FILTER_DEFAULT, |
294 | + 'misort' => FILTER_DEFAULT, | ||
295 | + 'color' => FILTER_DEFAULT, | ||
296 | + 'size' => FILTER_DEFAULT, | ||
297 | + 'style' => FILTER_DEFAULT, | ||
298 | + 'price' => FILTER_DEFAULT, | ||
292 | 'discount' => FILTER_DEFAULT, | 299 | 'discount' => FILTER_DEFAULT, |
293 | 'gender' => FILTER_DEFAULT, | 300 | 'gender' => FILTER_DEFAULT, |
294 | 'p_d' => FILTER_DEFAULT,), false); | 301 | 'p_d' => FILTER_DEFAULT,), false); |
@@ -306,6 +313,10 @@ class SearchController extends AbstractAction | @@ -306,6 +313,10 @@ class SearchController extends AbstractAction | ||
306 | if (isset($condition['gender'])) { | 313 | if (isset($condition['gender'])) { |
307 | $condition['gender'] = rawurldecode($condition['gender']); | 314 | $condition['gender'] = rawurldecode($condition['gender']); |
308 | } | 315 | } |
316 | + // 转义价格 | ||
317 | + if (isset($condition['price'])) { | ||
318 | + $condition['price'] = rawurldecode($condition['price']); | ||
319 | + } | ||
309 | 320 | ||
310 | // 区别各种列表页面的筛选数据 | 321 | // 区别各种列表页面的筛选数据 |
311 | $data = Product\SearchModel::getFilterData($condition); | 322 | $data = Product\SearchModel::getFilterData($condition); |
@@ -25,17 +25,54 @@ class IndexController extends AbstractAction | @@ -25,17 +25,54 @@ class IndexController extends AbstractAction | ||
25 | { | 25 | { |
26 | // 过滤请求参数 | 26 | // 过滤请求参数 |
27 | $condition = filter_input_array(INPUT_GET, array( | 27 | $condition = filter_input_array(INPUT_GET, array( |
28 | - 'brand' => FILTER_VALIDATE_INT, | 28 | + 'brand' => FILTER_DEFAULT, |
29 | 'sort' => FILTER_DEFAULT, | 29 | 'sort' => FILTER_DEFAULT, |
30 | 'msort' => FILTER_DEFAULT, | 30 | 'msort' => FILTER_DEFAULT, |
31 | 'misort' => FILTER_DEFAULT, | 31 | 'misort' => FILTER_DEFAULT, |
32 | - 'color' => FILTER_VALIDATE_INT, | ||
33 | - 'size' => FILTER_VALIDATE_INT, | ||
34 | - 'price' => FILTER_VALIDATE_INT, | ||
35 | - 'discount' => FILTER_VALIDATE_INT, | 32 | + 'color' => FILTER_DEFAULT, |
33 | + 'size' => FILTER_DEFAULT, | ||
34 | + 'style' => FILTER_DEFAULT, | ||
35 | + 'price' => FILTER_DEFAULT, | ||
36 | + 'discount' => FILTER_DEFAULT, | ||
36 | 'gender' => FILTER_DEFAULT, | 37 | 'gender' => FILTER_DEFAULT, |
37 | 'p_d' => FILTER_DEFAULT,), false); | 38 | 'p_d' => FILTER_DEFAULT,), false); |
38 | 39 | ||
40 | + // 转义品牌 | ||
41 | + if (isset($condition['brand'])) { | ||
42 | + $condition['brand'] = rawurldecode($condition['brand']); | ||
43 | + } | ||
44 | + // 转义分类 | ||
45 | + if (isset($condition['sort'])) { | ||
46 | + $condition['sort'] = rawurldecode($condition['sort']); | ||
47 | + } | ||
48 | + // 转义一级分类 | ||
49 | + if (isset($condition['msort'])) { | ||
50 | + $condition['msort'] = rawurldecode($condition['msort']); | ||
51 | + } | ||
52 | + // 转义二级分类 | ||
53 | + if (isset($condition['misort'])) { | ||
54 | + $condition['misort'] = rawurldecode($condition['misort']); | ||
55 | + } | ||
56 | + // 转义颜色 | ||
57 | + if (isset($condition['color'])) { | ||
58 | + $condition['color'] = rawurldecode($condition['color']); | ||
59 | + } | ||
60 | + // 转义尺码 | ||
61 | + if (isset($condition['size'])) { | ||
62 | + $condition['size'] = rawurldecode($condition['size']); | ||
63 | + } | ||
64 | + // 转义风格 | ||
65 | + if (isset($condition['style'])) { | ||
66 | + $condition['style'] = rawurldecode($condition['style']); | ||
67 | + } | ||
68 | + // 转义价格 | ||
69 | + if (isset($condition['price'])) { | ||
70 | + $condition['price'] = rawurldecode($condition['price']); | ||
71 | + } | ||
72 | + // 转换折扣 | ||
73 | + if (isset($condition['discount'])) { | ||
74 | + $condition['p_d'] = rawurldecode($condition['discount']); | ||
75 | + } | ||
39 | // 性别参数,不传则从COOKIE获取 | 76 | // 性别参数,不传则从COOKIE获取 |
40 | if (!isset($condition['gender'])) { | 77 | if (!isset($condition['gender'])) { |
41 | $condition['gender'] = Helpers::getGenderByCookie(); | 78 | $condition['gender'] = Helpers::getGenderByCookie(); |
@@ -54,6 +91,7 @@ class IndexController extends AbstractAction | @@ -54,6 +91,7 @@ class IndexController extends AbstractAction | ||
54 | if (!$condition) { | 91 | if (!$condition) { |
55 | $condition = array(); | 92 | $condition = array(); |
56 | } | 93 | } |
94 | + print_r($condition); | ||
57 | $goodList = $condition; | 95 | $goodList = $condition; |
58 | $goodList['cartUrl'] = Helpers::url('/cart/index/index', null); | 96 | $goodList['cartUrl'] = Helpers::url('/cart/index/index', null); |
59 | 97 | ||
@@ -112,16 +150,49 @@ class IndexController extends AbstractAction | @@ -112,16 +150,49 @@ class IndexController extends AbstractAction | ||
112 | /* 过滤请求参数 */ | 150 | /* 过滤请求参数 */ |
113 | $condition = filter_input_array(INPUT_GET, array( | 151 | $condition = filter_input_array(INPUT_GET, array( |
114 | 'sort' => FILTER_DEFAULT, | 152 | 'sort' => FILTER_DEFAULT, |
115 | - 'msort' => FILTER_VALIDATE_INT, | ||
116 | - 'misort' => FILTER_VALIDATE_INT, | ||
117 | - 'color' => FILTER_VALIDATE_INT, | ||
118 | - 'size' => FILTER_VALIDATE_INT, | ||
119 | - 'price' => FILTER_VALIDATE_INT, | ||
120 | - 'discount' => FILTER_VALIDATE_INT, | 153 | + 'msort' => FILTER_DEFAULT, |
154 | + 'misort' => FILTER_DEFAULT, | ||
155 | + 'color' => FILTER_DEFAULT, | ||
156 | + 'size' => FILTER_DEFAULT, | ||
157 | + 'style' => FILTER_DEFAULT, | ||
158 | + 'price' => FILTER_DEFAULT, | ||
159 | + 'discount' => FILTER_DEFAULT, | ||
121 | 'gender' => FILTER_DEFAULT, | 160 | 'gender' => FILTER_DEFAULT, |
122 | 'p_d' => FILTER_DEFAULT,), false); | 161 | 'p_d' => FILTER_DEFAULT,), false); |
123 | $condition['brand'] = $brandId; | 162 | $condition['brand'] = $brandId; |
124 | - | 163 | + |
164 | + // 转义分类 | ||
165 | + if (isset($condition['sort'])) { | ||
166 | + $condition['sort'] = rawurldecode($condition['sort']); | ||
167 | + } | ||
168 | + // 转义一级分类 | ||
169 | + if (isset($condition['msort'])) { | ||
170 | + $condition['msort'] = rawurldecode($condition['msort']); | ||
171 | + } | ||
172 | + // 转义二级分类 | ||
173 | + if (isset($condition['misort'])) { | ||
174 | + $condition['misort'] = rawurldecode($condition['misort']); | ||
175 | + } | ||
176 | + // 转义颜色 | ||
177 | + if (isset($condition['color'])) { | ||
178 | + $condition['color'] = rawurldecode($condition['color']); | ||
179 | + } | ||
180 | + // 转义尺码 | ||
181 | + if (isset($condition['size'])) { | ||
182 | + $condition['size'] = rawurldecode($condition['size']); | ||
183 | + } | ||
184 | + // 转义风格 | ||
185 | + if (isset($condition['style'])) { | ||
186 | + $condition['style'] = rawurldecode($condition['style']); | ||
187 | + } | ||
188 | + // 转义价格 | ||
189 | + if (isset($condition['price'])) { | ||
190 | + $condition['price'] = rawurldecode($condition['price']); | ||
191 | + } | ||
192 | + // 转换折扣 | ||
193 | + if (isset($condition['discount'])) { | ||
194 | + $condition['p_d'] = rawurldecode($condition['discount']); | ||
195 | + } | ||
125 | if ($brandId === 0) { | 196 | if ($brandId === 0) { |
126 | $condition['query'] = $domain; | 197 | $condition['query'] = $domain; |
127 | } | 198 | } |
-
Please register or login to post a comment