1
|
<?php
|
1
|
<?php
|
2
|
namespace Product;
|
2
|
namespace Product;
|
3
|
|
3
|
|
|
|
4
|
+use Api\Yohobuy;
|
|
|
5
|
+use Plugin\Helpers;
|
4
|
use Plugin\HelperSearch;
|
6
|
use Plugin\HelperSearch;
|
5
|
use \LibModels\Web\Product\SearchData;
|
7
|
use \LibModels\Web\Product\SearchData;
|
6
|
|
8
|
|
|
@@ -17,40 +19,141 @@ class SearchModel |
|
@@ -17,40 +19,141 @@ class SearchModel |
17
|
{
|
19
|
{
|
18
|
|
20
|
|
19
|
/**
|
21
|
/**
|
20
|
- * 根据条件获取搜索数据
|
|
|
21
|
- *
|
|
|
22
|
- * @param $condition 搜索数据的条件
|
|
|
23
|
- * @param $options Array([imgSize]
|
|
|
24
|
- * => Array([0] => 235[1] => 314)[minImgSize] => Array([0] => 60[1] => 80)[gender] => 1[needPd] => Y[rowNum] => 5[viewNum] => 60)
|
|
|
25
|
- * @author sefon 2015-12-17 16:12:18
|
|
|
26
|
- * @return array
|
22
|
+ * 搜索相关页面公共条件处理
|
|
|
23
|
+ * @param $param
|
|
|
24
|
+ * @param $option
|
|
|
25
|
+ * @return mixed
|
27
|
*/
|
26
|
*/
|
28
|
- public static function getSearchData($condition, $options)
|
27
|
+ public static function SearchCondition($param, $option)
|
29
|
{
|
28
|
{
|
30
|
- $data = array();
|
|
|
31
|
- // 调用接口查询商品数据
|
|
|
32
|
- $result = SearchData::searchElasticByCondition($condition);
|
|
|
33
|
- if (isset($result['code']) && $result['code'] === 200) {
|
|
|
34
|
- // 调用分类信息
|
|
|
35
|
- $category = SearchData::getClassesData($condition);
|
|
|
36
|
- if (isset($category['code']) && $category['code'] === 200) {
|
|
|
37
|
- $result['data']['filter']['group_sort'] = $category['data']['sort'];
|
29
|
+ /* 过滤请求参数 */
|
|
|
30
|
+ $condition = filter_input_array(INPUT_GET, array(
|
|
|
31
|
+ 'query' => FILTER_SANITIZE_STRING,
|
|
|
32
|
+ 'brand' => FILTER_VALIDATE_INT,
|
|
|
33
|
+ 'sort' => FILTER_VALIDATE_INT,
|
|
|
34
|
+ 'msort' => FILTER_VALIDATE_INT,
|
|
|
35
|
+ 'misort' => FILTER_VALIDATE_INT,
|
|
|
36
|
+ 'color' => FILTER_VALIDATE_INT,
|
|
|
37
|
+ 'size' => FILTER_DEFAULT,
|
|
|
38
|
+ 'style' => FILTER_DEFAULT,
|
|
|
39
|
+ 'price' => FILTER_DEFAULT,
|
|
|
40
|
+ 'gender' => FILTER_SANITIZE_STRING,
|
|
|
41
|
+ 'p_d' => FILTER_DEFAULT,
|
|
|
42
|
+ 'shelve_time' => FILTER_DEFAULT,
|
|
|
43
|
+ 'isNew' => FILTER_DEFAULT,
|
|
|
44
|
+ 'specialoffer' => FILTER_DEFAULT,
|
|
|
45
|
+ 'limited' => FILTER_DEFAULT,
|
|
|
46
|
+ 'order' => FILTER_DEFAULT,
|
|
|
47
|
+ 'viewNum' => FILTER_VALIDATE_INT,
|
|
|
48
|
+ 'rowNum' => FILTER_VALIDATE_INT,
|
|
|
49
|
+ 'page' => FILTER_VALIDATE_INT), false);
|
|
|
50
|
+ //关键字
|
|
|
51
|
+ if (isset($condition['query']) && !empty($condition['query'])) {
|
|
|
52
|
+ $condition['query'] = rawurldecode($condition['query']);
|
|
|
53
|
+ }
|
|
|
54
|
+ //性别
|
|
|
55
|
+ if (isset($condition['gender']) && !empty($condition['gender'])) {
|
|
|
56
|
+ $condition['gender'] = rawurldecode($condition['gender']);
|
|
|
57
|
+ }
|
|
|
58
|
+ else {
|
|
|
59
|
+ $condition['gender'] = Helpers::getGenderByCookie();
|
|
|
60
|
+ }
|
|
|
61
|
+ //每页显示商品数
|
|
|
62
|
+ $viewNumArray = array(60, 100, 200);
|
|
|
63
|
+ if(!isset($condition['viewNum']) || empty($condition['viewNum'])){
|
|
|
64
|
+ $condition['viewNum'] =60;
|
|
|
65
|
+ }
|
|
|
66
|
+ if (!in_array($condition['viewNum'], $viewNumArray)) {
|
|
|
67
|
+ $condition['viewNum'] = 60;
|
|
|
68
|
+ }
|
|
|
69
|
+ //每行显示的商品数量
|
|
|
70
|
+ if(!isset($condition['rowNum']) || empty($condition['rowNum'])){
|
|
|
71
|
+ $condition['rowNum'] =5;
|
|
|
72
|
+ }
|
|
|
73
|
+ if ($condition['rowNum'] == 6) {
|
|
|
74
|
+ $imgSize = array(195, 260);
|
|
|
75
|
+ $minImgSize = array(50, 67);
|
|
|
76
|
+ }
|
|
|
77
|
+ else {
|
|
|
78
|
+ $condition['rowNum'] = 5;
|
|
|
79
|
+ $imgSize = array(235, 314);
|
|
|
80
|
+ $minImgSize = array(60, 80);
|
|
|
81
|
+ }
|
|
|
82
|
+ //自定义搜索价格
|
|
|
83
|
+ if (isset($condition['price']) && !empty($condition['price'])) {
|
|
|
84
|
+ $price = explode(',', $condition['price']);
|
|
|
85
|
+ if (!$price[0]) {
|
|
|
86
|
+ $price[0] = 0;
|
38
|
}
|
87
|
}
|
39
|
- // 调用折扣区间
|
|
|
40
|
- $discount = SearchData::getDiscount();
|
|
|
41
|
- if (isset($discount['code']) && $discount['code'] === 200) {
|
|
|
42
|
- $result['data']['filter']['discount'] = $discount['data']['discount'];
|
88
|
+ if (!$price[1]) {
|
|
|
89
|
+ $price[1] = 99999;
|
43
|
}
|
90
|
}
|
44
|
- // 调用最新上架
|
|
|
45
|
- $recent = SearchData::recentShelve();
|
|
|
46
|
- if (isset($discount['code']) && $discount['code'] === 200) {
|
|
|
47
|
- $result['data']['filter']['recent'] = $recent['data']['recent'];
|
91
|
+ $condition['price'] = implode(',', $price);
|
|
|
92
|
+ }
|
|
|
93
|
+ //返回搜索条件
|
|
|
94
|
+ $condition['needFilter'] = 1;
|
|
|
95
|
+ //过滤赠品
|
|
|
96
|
+ $condition['attribute_not'] = 2;
|
|
|
97
|
+ //默认排序
|
|
|
98
|
+ if (!isset($condition['order']) || empty($condition['order'])) {
|
|
|
99
|
+ $condition['order'] = 's_n_desc';
|
|
|
100
|
+ }
|
|
|
101
|
+ if (!isset($condition['p_d']) || empty($condition['p_d'])) {
|
|
|
102
|
+ $condition['p_d'] = '0,0.9';
|
|
|
103
|
+ }
|
|
|
104
|
+ $options = array(
|
|
|
105
|
+ 'imgSize' => $imgSize,
|
|
|
106
|
+ 'minImgSize' => $minImgSize,
|
|
|
107
|
+ 'rowNum' =>$condition['rowNum'],
|
|
|
108
|
+ 'viewNum' =>$condition['viewNum'],
|
|
|
109
|
+ );
|
|
|
110
|
+ //接收高级选项
|
|
|
111
|
+ foreach ($_GET as $key =>$val) {
|
|
|
112
|
+ if (strpos('parameter_',$key) !== false) {
|
|
|
113
|
+ $condition[$key] = (int) $val;
|
48
|
}
|
114
|
}
|
49
|
- //用户浏览记录
|
|
|
50
|
- $result['data']['filter']['review'] = SearchData::getRecentReview();
|
|
|
51
|
- // 组织模板数据
|
|
|
52
|
- $data = HelperSearch::getList($result, $options);
|
|
|
53
|
}
|
115
|
}
|
|
|
116
|
+ //每页记录数减1,下一页占位
|
|
|
117
|
+ $condition['viewNum'] = $condition['viewNum'] - 1;
|
|
|
118
|
+ $condition = array_merge($condition, $param);
|
|
|
119
|
+ $options = array_merge($options, $option);
|
|
|
120
|
+ $data['condition'] = $condition;
|
|
|
121
|
+ $data['options'] = $options;
|
|
|
122
|
+ return $data;
|
|
|
123
|
+ }
|
|
|
124
|
+
|
|
|
125
|
+ /**
|
|
|
126
|
+ * 根据条件获取搜索数据
|
|
|
127
|
+ * @param array $customCondition
|
|
|
128
|
+ * @param array $customOptions
|
|
|
129
|
+ * @return array
|
|
|
130
|
+ */
|
|
|
131
|
+ public static function getSearchData($customCondition = array(), $customOptions = array())
|
|
|
132
|
+ {
|
|
|
133
|
+ $data = array();
|
|
|
134
|
+ $searchCondition = self::searchCondition($customCondition, $customOptions);
|
|
|
135
|
+ // 调用接口查询商品数据
|
|
|
136
|
+ $urlList['productUrl'] = HelperSearch::getProductUrl($searchCondition['condition']);
|
|
|
137
|
+ // 调用分类信息
|
|
|
138
|
+ $urlList['sortUrl'] = HelperSearch::getSortUrl($searchCondition['condition']);
|
|
|
139
|
+// $result['data']['filter']['group_sort'] = $category['data']['sort'];
|
|
|
140
|
+
|
|
|
141
|
+ // 调用折扣区间
|
|
|
142
|
+ $urlList['discountUrl'] = HelperSearch::getDiscountUrl($searchCondition['condition']);
|
|
|
143
|
+// $result['data']['filter']['discount'] = $discount['data']['discount'];
|
|
|
144
|
+ // 调用最新上架
|
|
|
145
|
+ $urlList['recentUrl'] = HelperSearch::getRecentUrl($searchCondition['condition']);
|
|
|
146
|
+// $result['data']['filter']['recent'] = $recent['data']['recent'];
|
|
|
147
|
+
|
|
|
148
|
+ //用户浏览记录
|
|
|
149
|
+ //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);
|
|
|
150
|
+
|
|
|
151
|
+ $result = Yohobuy::getMulti($urlList, array(), true);
|
|
|
152
|
+
|
|
|
153
|
+
|
|
|
154
|
+
|
|
|
155
|
+ // 组织模板数据
|
|
|
156
|
+ $data = HelperSearch::getList($result, $searchCondition['options']);
|
54
|
return $data;
|
157
|
return $data;
|
55
|
}
|
158
|
}
|
56
|
|
159
|
|
|
@@ -60,7 +163,8 @@ class SearchModel |
|
@@ -60,7 +163,8 @@ class SearchModel |
60
|
* @param $options
|
163
|
* @param $options
|
61
|
* @return array
|
164
|
* @return array
|
62
|
*/
|
165
|
*/
|
63
|
- public static function searchData($condition, $options){
|
166
|
+ public static function searchData($condition, $options)
|
|
|
167
|
+ {
|
64
|
$data = self::getSearchData($condition, $options);
|
168
|
$data = self::getSearchData($condition, $options);
|
65
|
//获取品牌店铺信息
|
169
|
//获取品牌店铺信息
|
66
|
if (isset($condition['query'])) {
|
170
|
if (isset($condition['query'])) {
|