Authored by whb

search model

1 -<?php  
2 -namespace Product;  
3 -  
4 -use Api\Yohobuy;  
5 -use Plugin\Helpers;  
6 -use Plugin\HelperSearch;  
7 -use \LibModels\Web\Product\SearchData;  
8 -  
9 -/**  
10 - * sale首页模板数据模型  
11 - *  
12 - * @name SaleModel  
13 - * @package models  
14 - * @copyright yoho.inc  
15 - * @version 1.0 (2015-12-17 13:54:56)  
16 - * @author sefon  
17 - */  
18 -class SearchModel  
19 -{  
20 -  
21 - /**  
22 - * 搜索相关页面公共条件处理  
23 - * @param $param  
24 - * @param $option  
25 - * @return mixed  
26 - */  
27 - public static function searchCondition($param, $option)  
28 - {  
29 - /* 过滤请求参数 */  
30 - $condition = filter_input_array(INPUT_GET, array(  
31 - 'query' => FILTER_SANITIZE_STRING,  
32 - 'brand' => FILTER_SANITIZE_STRING,  
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['brand']) && !empty($condition['brand'])) {  
56 - $condition['brand'] = rawurldecode($condition['brand']);  
57 - }  
58 - //性别  
59 - if (isset($condition['gender']) && !empty($condition['gender'])) {  
60 - $condition['gender'] = rawurldecode($condition['gender']);  
61 - }  
62 - else {  
63 - $condition['gender'] = Helpers::getGenderByCookie();  
64 - }  
65 - //每页显示商品数  
66 - $viewNumArray = array(60, 100, 200);  
67 - if(!isset($condition['viewNum']) || empty($condition['viewNum'])){  
68 - $condition['viewNum'] =60;  
69 - }  
70 - if (!in_array($condition['viewNum'], $viewNumArray)) {  
71 - $condition['viewNum'] = 60;  
72 - }  
73 - //每行显示的商品数量  
74 - if(!isset($condition['rowNum']) || empty($condition['rowNum'])){  
75 - $condition['rowNum'] =5;  
76 - }  
77 - if ($condition['rowNum'] == 6) {  
78 - $imgSize = array(195, 260);  
79 - $minImgSize = array(50, 67);  
80 - }  
81 - else {  
82 - $condition['rowNum'] = 5;  
83 - $imgSize = array(235, 314);  
84 - $minImgSize = array(60, 80);  
85 - }  
86 - //自定义搜索价格  
87 - if (isset($condition['price']) && !empty($condition['price'])) {  
88 - $price = explode(',', $condition['price']);  
89 - if (!$price[0]) {  
90 - $price[0] = 0;  
91 - }  
92 - if (!$price[1]) {  
93 - $price[1] = 99999;  
94 - }  
95 - $condition['price'] = implode(',', $price);  
96 - }  
97 - //返回搜索条件  
98 - $condition['needFilter'] = 1;  
99 - //过滤赠品  
100 - $condition['attribute_not'] = 2;  
101 - //默认排序  
102 - if (!isset($condition['order']) || empty($condition['order'])) {  
103 - $condition['order'] = 's_n_desc';  
104 - }  
105 - if (!isset($condition['p_d']) || empty($condition['p_d'])) {  
106 - $condition['p_d'] = '0,0.9';  
107 - }  
108 - $options = array(  
109 - 'imgSize' => $imgSize,  
110 - 'minImgSize' => $minImgSize,  
111 - 'rowNum' =>$condition['rowNum'],  
112 - 'viewNum' =>$condition['viewNum'],  
113 - );  
114 - //接收高级选项  
115 - foreach ($_GET as $key =>$val) {  
116 - if (strpos('parameter_',$key) !== false) {  
117 - $condition[$key] = (int) $val;  
118 - }  
119 - }  
120 - //每页记录数减1,下一页占位  
121 - $condition['viewNum'] = $condition['viewNum'] - 1;  
122 - $condition = array_merge($condition, $param);  
123 - $options = array_merge($options, $option);  
124 - $data['condition'] = $condition;  
125 - $data['options'] = $options;  
126 - return $data;  
127 - }  
128 -  
129 - /**  
130 - * 根据条件获取搜索数据  
131 - * @param array $customCondition  
132 - * @param array $customOptions  
133 - * @return array  
134 - */  
135 - public static function getListData($customCondition = array(), $customOptions = array())  
136 - {  
137 - $urlList = array();  
138 - $searchCondition = self::searchCondition($customCondition, $customOptions);  
139 - // 组合搜索商品url  
140 - $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);  
141 - // 组合搜索分类url  
142 - $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']);  
143 - // 组合搜索折扣区间url  
144 - $urlList['discount'] = HelperSearch::getDiscountUrl($searchCondition['condition']);  
145 - // 组合搜索最新上架url  
146 - $urlList['recent'] = HelperSearch::getRecentShelveUrl($searchCondition['condition']);  
147 - //用户浏览记录  
148 - //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);  
149 -  
150 - $result = Yohobuy::getMulti($urlList, array(), true);  
151 - // 组织模板数据  
152 - $data = HelperSearch::getList($result, $searchCondition['options']);  
153 - return $data;  
154 - }  
155 -  
156 - /**  
157 - * 搜索页面获取搜索数据  
158 - * @param $customCondition  
159 - * @param $customOptions  
160 - * @return array  
161 - */  
162 - public static function searchData($customCondition, $customOptions)  
163 - {  
164 - $urlList = array();  
165 - $searchCondition = self::searchCondition($customCondition, $customOptions);  
166 - // 组合搜索商品url  
167 - $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);  
168 - // 组合搜索分类url  
169 - $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']);  
170 - // 组合搜索店铺url  
171 - $param['keyword'] = $searchCondition['condition']['query'];  
172 - $urlList['shop'] = HelperSearch::getShopUrl($param);  
173 - //用户浏览记录  
174 - //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);  
175 - $result = Yohobuy::getMulti($urlList, array(), true);  
176 - // 组织模板数据  
177 - $data = HelperSearch::getList($result, $searchCondition['options']);  
178 - return $data;  
179 - }  
180 - /**  
181 - * 根据product_sn查询产品图片信息  
182 - * @param $product_sn  
183 - * @param $options  
184 - * @author sefon 2015-12-28 18:09:28  
185 - * @return array  
186 - */  
187 - public static function getProductPic($product_sn, $options)  
188 - {  
189 - $condition['query'] = $product_sn;  
190 - //返回搜索条件  
191 - $condition['needFilter'] = 0;  
192 - //获取产品数据  
193 - $data = SearchData::searchElasticByCondition($condition);  
194 - if (isset($data['code']) && $data['code'] === 200 && isset($data['data']['product_list']) && !empty($data['data']['product_list'])) {  
195 - //组织数据结构  
196 - $data = HelperSearch::getProductPic($data['data']['product_list'], $options);  
197 - }  
198 - echo json_encode($data);  
199 - } 1 +<?php
  2 +namespace Product;
  3 +
  4 +use Api\Yohobuy;
  5 +use Plugin\Helpers;
  6 +use Plugin\HelperSearch;
  7 +use \LibModels\Web\Product\SearchData;
  8 +
  9 +/**
  10 + * sale首页模板数据模型
  11 + *
  12 + * @name SaleModel
  13 + * @package models
  14 + * @copyright yoho.inc
  15 + * @version 1.0 (2015-12-17 13:54:56)
  16 + * @author sefon
  17 + */
  18 +class SearchModel
  19 +{
  20 +
  21 + /**
  22 + * 搜索相关页面公共条件处理
  23 + * @param $param
  24 + * @param $option
  25 + * @return mixed
  26 + */
  27 + public static function searchCondition($param, $option)
  28 + {
  29 + /* 过滤请求参数 */
  30 + $condition = filter_input_array(INPUT_GET, array(
  31 + 'query' => FILTER_SANITIZE_STRING,
  32 + 'brand' => FILTER_SANITIZE_STRING,
  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['brand']) && !empty($condition['brand'])) {
  56 + $condition['brand'] = rawurldecode($condition['brand']);
  57 + }
  58 + //性别
  59 + if (isset($condition['gender']) && !empty($condition['gender'])) {
  60 + $condition['gender'] = rawurldecode($condition['gender']);
  61 + }
  62 + else {
  63 + $condition['gender'] = Helpers::getGenderByCookie();
  64 + }
  65 + //每页显示商品数
  66 + $viewNumArray = array(60, 100, 200);
  67 + if(!isset($condition['viewNum']) || empty($condition['viewNum'])){
  68 + $condition['viewNum'] =60;
  69 + }
  70 + if (!in_array($condition['viewNum'], $viewNumArray)) {
  71 + $condition['viewNum'] = 60;
  72 + }
  73 + //每行显示的商品数量
  74 + if(!isset($condition['rowNum']) || empty($condition['rowNum'])){
  75 + $condition['rowNum'] =5;
  76 + }
  77 + if ($condition['rowNum'] == 6) {
  78 + $imgSize = array(195, 260);
  79 + $minImgSize = array(50, 67);
  80 + }
  81 + else {
  82 + $condition['rowNum'] = 5;
  83 + $imgSize = array(235, 314);
  84 + $minImgSize = array(60, 80);
  85 + }
  86 + //自定义搜索价格
  87 + if (isset($condition['price']) && !empty($condition['price'])) {
  88 + $price = explode(',', $condition['price']);
  89 + if (!$price[0]) {
  90 + $price[0] = 0;
  91 + }
  92 + if (!$price[1]) {
  93 + $price[1] = 99999;
  94 + }
  95 + $condition['price'] = implode(',', $price);
  96 + }
  97 + //返回搜索条件
  98 + $condition['needFilter'] = 1;
  99 + //过滤赠品
  100 + $condition['attribute_not'] = 2;
  101 + //默认排序
  102 + if (!isset($condition['order']) || empty($condition['order'])) {
  103 + $condition['order'] = 's_n_desc';
  104 + }
  105 + $options = array(
  106 + 'imgSize' => $imgSize,
  107 + 'minImgSize' => $minImgSize,
  108 + 'rowNum' =>$condition['rowNum'],
  109 + 'viewNum' =>$condition['viewNum'],
  110 + );
  111 + //接收高级选项
  112 + foreach ($_GET as $key =>$val) {
  113 + if (strpos('parameter_',$key) !== false) {
  114 + $condition[$key] = (int) $val;
  115 + }
  116 + }
  117 + //每页记录数减1,下一页占位
  118 + $condition['viewNum'] = $condition['viewNum'] - 1;
  119 + $condition = array_merge($condition, $param);
  120 + $options = array_merge($options, $option);
  121 + $data['condition'] = $condition;
  122 + $data['options'] = $options;
  123 + return $data;
  124 + }
  125 +
  126 + /**
  127 + * 根据条件获取搜索数据
  128 + * @param array $customCondition
  129 + * @param array $customOptions
  130 + * @return array
  131 + */
  132 + public static function getListData($customCondition = array(), $customOptions = array())
  133 + {
  134 + $urlList = array();
  135 + $searchCondition = self::searchCondition($customCondition, $customOptions);
  136 + // 组合搜索商品url
  137 + $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);
  138 + // 组合搜索分类url
  139 + $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']);
  140 + // 组合搜索折扣区间url
  141 + $urlList['discount'] = HelperSearch::getDiscountUrl($searchCondition['condition']);
  142 + // 组合搜索最新上架url
  143 + $urlList['recent'] = HelperSearch::getRecentShelveUrl($searchCondition['condition']);
  144 + //用户浏览记录
  145 + //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);
  146 +
  147 + $result = Yohobuy::getMulti($urlList, array(), true);
  148 + // 组织模板数据
  149 + $data = HelperSearch::getList($result, $searchCondition['options']);
  150 + return $data;
  151 + }
  152 +
  153 + /**
  154 + * 搜索页面获取搜索数据
  155 + * @param $customCondition
  156 + * @param $customOptions
  157 + * @return array
  158 + */
  159 + public static function searchData($customCondition, $customOptions)
  160 + {
  161 + $urlList = array();
  162 + $searchCondition = self::searchCondition($customCondition, $customOptions);
  163 + // 组合搜索商品url
  164 + $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);
  165 + // 组合搜索分类url
  166 + $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']);
  167 + // 组合搜索店铺url
  168 + if (isset($param['keyword'])) {
  169 + $param['keyword'] = $searchCondition['condition']['query'];
  170 + $urlList['shop'] = HelperSearch::getShopUrl($param);
  171 + }
  172 + //用户浏览记录
  173 + //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);
  174 + $result = Yohobuy::getMulti($urlList, array(), true);
  175 + // 组织模板数据
  176 + $data = HelperSearch::getList($result, $searchCondition['options']);
  177 + return $data;
  178 + }
  179 + /**
  180 + * 根据product_sn查询产品图片信息
  181 + * @param $product_sn
  182 + * @param $options
  183 + * @author sefon 2015-12-28 18:09:28
  184 + * @return array
  185 + */
  186 + public static function getProductPic($product_sn, $options)
  187 + {
  188 + $condition['query'] = $product_sn;
  189 + //返回搜索条件
  190 + $condition['needFilter'] = 0;
  191 + //获取产品数据
  192 + $data = SearchData::searchElasticByCondition($condition);
  193 + if (isset($data['code']) && $data['code'] === 200 && isset($data['data']['product_list']) && !empty($data['data']['product_list'])) {
  194 + //组织数据结构
  195 + $data = HelperSearch::getProductPic($data['data']['product_list'], $options);
  196 + }
  197 + echo json_encode($data);
  198 + }
200 } 199 }