Authored by 周少峰

搜索分类调整、条件分类调整,选中条件高亮,全部折扣,排序按钮调整

@@ -11,25 +11,20 @@ use Api\Sign; @@ -11,25 +11,20 @@ use Api\Sign;
11 */ 11 */
12 class HelperSearch 12 class HelperSearch
13 { 13 {
14 - /**  
15 - * 请求时用的所有参数  
16 - */ 14 + //请求时用的所有参数
17 public static $params = array(); 15 public static $params = array();
18 16
19 public static $options = array(); 17 public static $options = array();
20 //当前页 18 //当前页
21 public static $page = 1; 19 public static $page = 1;
  20 + public static $pageTotal;
  21 + public static $filter;
22 22
23 - /**  
24 - * 选中的条件  
25 - */ 23 + //选中的条件
26 public static $selected = array(); 24 public static $selected = array();
27 25
28 - /**  
29 - * list分类面包屑  
30 - * @var array  
31 - */  
32 - public static $listnav = array(); 26 + //list分类面包屑
  27 + public static $listNav = array();
33 28
34 //设置导航 29 //设置导航
35 private static function setListNav() 30 private static function setListNav()
@@ -41,11 +36,11 @@ class HelperSearch @@ -41,11 +36,11 @@ class HelperSearch
41 }else{ 36 }else{
42 $initNav = '列表'; 37 $initNav = '列表';
43 } 38 }
44 - self::$listnav[0] = array( 39 + self::$listNav[0] = array(
45 'href' => '', 40 'href' => '',
46 'name' => $cookieChannel 41 'name' => $cookieChannel
47 ); 42 );
48 - self::$listnav[1] = array( 43 + self::$listNav[1] = array(
49 'href' => '', 44 'href' => '',
50 'name' => $initNav 45 'name' => $initNav
51 ); 46 );
@@ -63,46 +58,20 @@ class HelperSearch @@ -63,46 +58,20 @@ class HelperSearch
63 self::$options = $options; 58 self::$options = $options;
64 unset(self::$params['/']); 59 unset(self::$params['/']);
65 unset(self::$params['page']); 60 unset(self::$params['page']);
66 - unset(self::$params['/sale']);  
67 - unset(self::$params['sale']);  
68 - $filter = $data['product']['filter']; 61 + self::$filter = $data['product']['filter'];
69 //产品列表 62 //产品列表
70 $result['goods'] = self::getProductList($data['product']['product_list'], $options['imgSize']); 63 $result['goods'] = self::getProductList($data['product']['product_list'], $options['imgSize']);
71 //总页数 64 //总页数
72 $result['page_total'] = $data['product']['page_total']; 65 $result['page_total'] = $data['product']['page_total'];
  66 + self::$pageTotal = $data['product']['page_total'];
73 //当前页 67 //当前页
74 $result['page'] = $data['product']['page']; 68 $result['page'] = $data['product']['page'];
75 self::$page = $result['page']; 69 self::$page = $result['page'];
76 - //清除选中  
77 - $result['filters']['checkedConditions']['clearUrl'] = self::current();  
78 - //频道  
79 - $result['filters']['channel'] = self::gender($filter);  
80 - //品牌  
81 - $result['filters']['brand'] = self::brand($filter);  
82 - //价格  
83 - $result['filters']['price'] = self::price($filter);  
84 - $result['filters']['customPrice'] = self::customPrice($filter);  
85 - //颜色  
86 - $result['filters']['color'] = self::color($filter);  
87 - //尺寸  
88 - $result['filters']['size'] = self::size($filter);  
89 - //高级选项  
90 - $result['filters']['seniorChose'] = self::seniorChose($filter);  
91 - //排序方式  
92 - $result['opts']['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount());  
93 - //特殊:新品、特价、限量  
94 - $result['opts']['checks'] = array(self::isnew(),self::specialoffer(),self::limited());  
95 - //每行显示5个产品  
96 - $result['opts']['fivePerLine'] = true;  
97 - //每行显示6个产品  
98 - $result['opts']['sixPerLineHref'] = true;  
99 - //每页显示的数量  
100 - $result['opts']['countPerPage'] = $options['viewNum'];  
101 - //可选每页显示数量  
102 - $result['opts']['pageCounts'] = self::viewNum();  
103 - $result['opts']['curPage'] = self::$page;  
104 - $result['opts']['pageCount'] = $data['product']['page_total'];  
105 - $result['opts']['nextHref'] = ($next = self::next($data['product']['page_total'],$data['product']['filter'])) ? $next['href'] : ''; 70 + //筛选条件
  71 + $result['filters'] = self::filter();
  72 + //排序方式、显示数量等其他选项
  73 + $result['opts'] = self::getOpts();
  74 + //下一页
106 $result['hasNextPage'] = self::next($data['product']['page_total']); 75 $result['hasNextPage'] = self::next($data['product']['page_total']);
107 //全部折扣 76 //全部折扣
108 $result['leftContent'][]['allDiscount'] = isset($data['discount']) ? self::getDiscount($data['discount']['discount']) : array(); 77 $result['leftContent'][]['allDiscount'] = isset($data['discount']) ? self::getDiscount($data['discount']['discount']) : array();
@@ -121,17 +90,15 @@ class HelperSearch @@ -121,17 +90,15 @@ class HelperSearch
121 //分页 90 //分页
122 $result['pager'] = self::pager($result['totalCount'],$options['viewNum']-1); 91 $result['pager'] = self::pager($result['totalCount'],$options['viewNum']-1);
123 //选中条件 92 //选中条件
124 - if (self::getSelected()) {  
125 - $result['filters']['checkedConditions']['conditions'] = self::getSelected();  
126 - }  
127 - //没有选中  
128 - else{  
129 - $result['filters']['checkedConditions'] = array();  
130 - } 93 + $result['filters']['checkedConditions'] = self::getSelected();
131 if (isset($options['controller']) && $options['controller'] == 'Search') { 94 if (isset($options['controller']) && $options['controller'] == 'Search') {
132 self::setSearchNav($data['product']['total']); 95 self::setSearchNav($data['product']['total']);
133 } 96 }
134 - $result['pathNav'] = isset($options['controller']) && $options['controller'] == 'Sale' ? array() : self::$listnav; 97 + if (empty($result['goods'])) {
  98 + $result['filters'] = array();
  99 + $result['opts'] = array();
  100 + }
  101 + $result['pathNav'] = isset($options['controller']) && $options['controller'] == 'Sale' ? array() : self::$listNav;
135 return $result; 102 return $result;
136 } 103 }
137 104
@@ -295,7 +262,7 @@ class HelperSearch @@ -295,7 +262,7 @@ class HelperSearch
295 if (isset($params['msort']) && $params['msort'] == $val['sort_id']) { 262 if (isset($params['msort']) && $params['msort'] == $val['sort_id']) {
296 //是否有品牌 263 //是否有品牌
297 $navIndex = isset($option['brandName']) && $option['brandName'] ? 2 : 1; 264 $navIndex = isset($option['brandName']) && $option['brandName'] ? 2 : 1;
298 - self::$listnav[$navIndex] = array( 265 + self::$listNav[$navIndex] = array(
299 'name' => $val['sort_name'], 266 'name' => $val['sort_name'],
300 'href' => self::buildUrl(array( 267 'href' => self::buildUrl(array(
301 'msort' => $val['sort_id'], 268 'msort' => $val['sort_id'],
@@ -336,13 +303,14 @@ class HelperSearch @@ -336,13 +303,14 @@ class HelperSearch
336 $result[$key]['name'] = $val['sort_name']; 303 $result[$key]['name'] = $val['sort_name'];
337 if (isset($val['sub']) && !empty($val['sub'])) { 304 if (isset($val['sub']) && !empty($val['sub'])) {
338 foreach ($val['sub'] as $k => $v) { 305 foreach ($val['sub'] as $k => $v) {
339 - $result[$key]['sub'][$k]['href'] = self::buildUrl(array('msort' => $val['sort_id'], 'misort' => $v['sort_id'])); 306 + $result[$key]['sub'][$k]['href'] = self::buildUrl(array_merge($params,array('msort' => $val['sort_id'], 'misort' => $v['sort_id'])));
340 $result[$key]['sub'][$k]['name'] = $v['sort_name']; 307 $result[$key]['sub'][$k]['name'] = $v['sort_name'];
341 if (isset($params['misort']) && $params['misort'] == $v['sort_id']) { 308 if (isset($params['misort']) && $params['misort'] == $v['sort_id']) {
  309 + unset($params['msort']);
342 unset($params['misort']); 310 unset($params['misort']);
343 self::$selected['sort'] = array( 311 self::$selected['sort'] = array(
344 'name' => $v['sort_name'], 312 'name' => $v['sort_name'],
345 - 'href' => self::buildUrl() 313 + 'href' => self::buildUrl($params)
346 ); 314 );
347 } 315 }
348 316
@@ -846,8 +814,8 @@ class HelperSearch @@ -846,8 +814,8 @@ class HelperSearch
846 $url = self::buildUrl(array_merge($params, array( 814 $url = self::buildUrl(array_merge($params, array(
847 'order' => 's_p_asc' 815 'order' => 's_p_asc'
848 ))); 816 )));
849 - $desc = '';  
850 - $active = ''; 817 + $desc = false;
  818 + $active = true;
851 } 819 }
852 $result = array( 820 $result = array(
853 'name' => '价格', 821 'name' => '价格',
@@ -875,29 +843,29 @@ class HelperSearch @@ -875,29 +843,29 @@ class HelperSearch
875 $url = self::buildUrl(array_merge($params, array( 843 $url = self::buildUrl(array_merge($params, array(
876 'order' => 'p_d_asc' 844 'order' => 'p_d_asc'
877 ))); 845 )));
878 - $asc = '';  
879 - $desc = ''; 846 + $desc = false;
  847 + $active = true;
880 } 848 }
881 else if (self::$params['order'] == 'p_d_asc') { 849 else if (self::$params['order'] == 'p_d_asc') {
882 $url = self::buildUrl(array_merge($params, array( 850 $url = self::buildUrl(array_merge($params, array(
883 'order' => 'p_d_desc' 851 'order' => 'p_d_desc'
884 ))); 852 )));
885 - $asc = true;  
886 - $desc = ''; 853 + $desc = false;
  854 + $active = true;
887 } 855 }
888 else { 856 else {
889 $url = self::buildUrl(array_merge($params, array( 857 $url = self::buildUrl(array_merge($params, array(
890 'order' => 'p_d_asc' 858 'order' => 'p_d_asc'
891 ))); 859 )));
892 - $asc = ''; 860 + $active = true;
893 $desc = true; 861 $desc = true;
894 } 862 }
895 $result = array( 863 $result = array(
896 'name' => '折扣', 864 'name' => '折扣',
897 - 'hasSortOrient' => true,  
898 'href' => $url, 865 'href' => $url,
899 - 'asc' => $asc,  
900 - 'desc' => $desc 866 + 'hasSortOrient' => true,
  867 + 'active' => $active,
  868 + 'desc' => $desc,
901 ); 869 );
902 870
903 return $result; 871 return $result;
@@ -935,6 +903,7 @@ class HelperSearch @@ -935,6 +903,7 @@ class HelperSearch
935 public static function getSelected() 903 public static function getSelected()
936 { 904 {
937 $result = array(); 905 $result = array();
  906 + $data = array();
938 $is_array_key = array( 907 $is_array_key = array(
939 'brand', 908 'brand',
940 'style' 909 'style'
@@ -942,13 +911,16 @@ class HelperSearch @@ -942,13 +911,16 @@ class HelperSearch
942 foreach (self::$selected as $key => $val) { 911 foreach (self::$selected as $key => $val) {
943 if (in_array($key, $is_array_key)) { 912 if (in_array($key, $is_array_key)) {
944 foreach ($val as $k => $v) { 913 foreach ($val as $k => $v) {
945 - $result[] = $v; 914 + $data[] = $v;
946 } 915 }
947 } 916 }
948 else { 917 else {
949 - $result[] = $val; 918 + $data[] = $val;
950 } 919 }
951 } 920 }
  921 + if ($data) {
  922 + $result['conditions'] = $data;
  923 + }
952 return $result; 924 return $result;
953 } 925 }
954 926
@@ -1015,7 +987,7 @@ class HelperSearch @@ -1015,7 +987,7 @@ class HelperSearch
1015 public static function current() 987 public static function current()
1016 { 988 {
1017 $url = explode('?', $_SERVER['REQUEST_URI']); 989 $url = explode('?', $_SERVER['REQUEST_URI']);
1018 - self::$listnav[0]['href'] = $url[0]; 990 + self::$listNav[0]['href'] = $url[0];
1019 return $url[0]; 991 return $url[0];
1020 } 992 }
1021 /** 993 /**
@@ -1136,19 +1108,19 @@ class HelperSearch @@ -1136,19 +1108,19 @@ class HelperSearch
1136 */ 1108 */
1137 public static function setSearchNav($total) 1109 public static function setSearchNav($total)
1138 { 1110 {
1139 - self::$listnav[0] = array( 1111 + self::$listNav[0] = array(
1140 'href' => '/', 1112 'href' => '/',
1141 'name' => '首页' 1113 'name' => '首页'
1142 ); 1114 );
1143 $param = self::$params; 1115 $param = self::$params;
1144 $options = self::$options; 1116 $options = self::$options;
1145 if (isset($options['controller']) && $options['controller'] == 'Search' && isset($param['query'])) { 1117 if (isset($options['controller']) && $options['controller'] == 'Search' && isset($param['query'])) {
1146 - self::$listnav[1] = array( 1118 + self::$listNav[1] = array(
1147 'href' => '', 1119 'href' => '',
1148 'name' => "".$param['query']." ".$total."个结果" 1120 'name' => "".$param['query']." ".$total."个结果"
1149 ); 1121 );
1150 }else{ 1122 }else{
1151 - self::$listnav[1] = array( 1123 + self::$listNav[1] = array(
1152 'href' => '', 1124 'href' => '',
1153 'name' => '所有商品' 1125 'name' => '所有商品'
1154 ); 1126 );
@@ -1184,7 +1156,6 @@ class HelperSearch @@ -1184,7 +1156,6 @@ class HelperSearch
1184 $param['status'] = 1; // 是否上架,1表示在架,2表示不在 1156 $param['status'] = 1; // 是否上架,1表示在架,2表示不在
1185 $param['sales'] = 'Y'; // 只搜索销售的产品 1157 $param['sales'] = 'Y'; // 只搜索销售的产品
1186 $param['stocknumber'] = 1; // 过滤掉已售罄的商品 1158 $param['stocknumber'] = 1; // 过滤掉已售罄的商品
1187 - // $param['needFilter'] = 1; // 是否需要返回筛选条件  
1188 if (!isset($condition['order'])) { 1159 if (!isset($condition['order'])) {
1189 $param['order'] = $orderMaps['s_t_desc']; 1160 $param['order'] = $orderMaps['s_t_desc'];
1190 } else { 1161 } else {
@@ -1335,7 +1306,7 @@ class HelperSearch @@ -1335,7 +1306,7 @@ class HelperSearch
1335 elseif ($type == 'shop') { 1306 elseif ($type == 'shop') {
1336 return 'http://101.200.31.165/yohosearch/shops.json'; 1307 return 'http://101.200.31.165/yohosearch/shops.json';
1337 } 1308 }
1338 - return 'http://101.200.31.165/yohosearch/search.json'; 1309 + return 'http://192.168.10.64:8080/yohosearch/search-once.json';
1339 } 1310 }
1340 } 1311 }
1341 1312
@@ -1370,4 +1341,50 @@ class HelperSearch @@ -1370,4 +1341,50 @@ class HelperSearch
1370 'banner' => $bannerImg 1341 'banner' => $bannerImg
1371 ); 1342 );
1372 } 1343 }
  1344 +
  1345 + /**
  1346 + * 搜索条件
  1347 + */
  1348 + public static function filter()
  1349 + {
  1350 + $result = array();
  1351 + //清除选中
  1352 + $result['checkedConditions']['clearUrl'] = self::current();
  1353 + //频道
  1354 + $result['channel'] = self::gender(self::$filter);
  1355 + //品牌
  1356 + $result['brand'] = self::brand(self::$filter);
  1357 + //价格
  1358 + $result['price'] = self::price(self::$filter);
  1359 + $result['customPrice'] = self::customPrice(self::$filter);
  1360 + //颜色
  1361 + $result['color'] = self::color(self::$filter);
  1362 + //尺寸
  1363 + $result['size'] = self::size(self::$filter);
  1364 + //高级选项
  1365 + $result['seniorChose'] = self::seniorChose(self::$filter);
  1366 + return $result;
  1367 + }
  1368 + /**
  1369 + * 其他选项
  1370 + */
  1371 + public static function getOpts()
  1372 + {
  1373 + //排序方式
  1374 + $result['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount());
  1375 + //特殊:新品、特价、限量
  1376 + $result['checks'] = array(self::isnew(),self::specialoffer(),self::limited());
  1377 + //每行显示5个产品
  1378 + $result['fivePerLine'] = true;
  1379 + //每行显示6个产品
  1380 + $result['sixPerLineHref'] = true;
  1381 + //每页显示的数量
  1382 + $result['countPerPage'] = self::$options['viewNum'];
  1383 + //可选每页显示数量
  1384 + $result['pageCounts'] = self::viewNum();
  1385 + $result['curPage'] = self::$page;
  1386 + $result['pageCount'] = self::$pageTotal;
  1387 + $result['nextHref'] = ($next = self::next(self::$pageTotal, self::$filter)) ? $next['href'] : '';
  1388 + return $result;
  1389 + }
1373 } 1390 }
@@ -173,12 +173,6 @@ class SearchModel @@ -173,12 +173,6 @@ class SearchModel
173 // 组合搜索商品url 173 // 组合搜索商品url
174 $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']); 174 $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);
175 // 组合搜索分类url 175 // 组合搜索分类url
176 - if (isset($condition['msort'])) {  
177 - unset($condition['msort']);  
178 - }  
179 - if (isset($condition['misort'])) {  
180 - unset($condition['misort']);  
181 - }  
182 $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']); 176 $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']);
183 // 组合搜索店铺url 177 // 组合搜索店铺url
184 if (isset($param['keyword'])) { 178 if (isset($param['keyword'])) {