Authored by 周少峰

特价、打折、新品;ajax搜索提示;ajax获取分类尺码信息

@@ -4,7 +4,6 @@ namespace LibModels\Web\Product; @@ -4,7 +4,6 @@ namespace LibModels\Web\Product;
4 use Api\Yohobuy; 4 use Api\Yohobuy;
5 class SearchData extends \LibModels\Wap\Product\SearchData 5 class SearchData extends \LibModels\Wap\Product\SearchData
6 { 6 {
7 - public static $shopsUrl = 'http://101.200.31.165/yohosearch/shops.json';  
8 /** 7 /**
9 * 获取搜索的服务地址 8 * 获取搜索的服务地址
10 * 9 *
@@ -402,7 +402,7 @@ class HelperSearch @@ -402,7 +402,7 @@ class HelperSearch
402 $existName .= $brandAll[$val].'、'; 402 $existName .= $brandAll[$val].'、';
403 } 403 }
404 if ($existBrandNum === 1){ 404 if ($existBrandNum === 1){
405 - $existName .= $brandAll[$val].'...'; 405 + $existName .= substr($brandAll[$val], 0, 3).'...';
406 } 406 }
407 $existBrandNum++; 407 $existBrandNum++;
408 } 408 }
@@ -410,10 +410,13 @@ class HelperSearch @@ -410,10 +410,13 @@ class HelperSearch
410 break; 410 break;
411 } 411 }
412 } 412 }
413 - self::$selected['brand'] = array(  
414 - 'name' => $existName,  
415 - 'href' => self::buildUrl($params)  
416 - ); 413 + //设置选中
  414 + if (isset(self::$params['brand']) && !empty(self::$params['brand'])) {
  415 + self::$selected['brand'] = array(
  416 + 'name' => rtrim($existName, '、'),
  417 + 'href' => self::buildUrl($params)
  418 + );
  419 + }
417 ksort($brandList); 420 ksort($brandList);
418 //品牌列表排序, 添加品牌索引 421 //品牌列表排序, 添加品牌索引
419 $index_key = array(); 422 $index_key = array();
@@ -443,9 +446,13 @@ class HelperSearch @@ -443,9 +446,13 @@ class HelperSearch
443 * @param array $filter 446 * @param array $filter
444 * @return array 447 * @return array
445 */ 448 */
446 - public static function size($filter) 449 + public static function size($filter, $isAjax = false)
447 { 450 {
448 $params = self::$params; 451 $params = self::$params;
  452 + $paramsValue = array_filter($params);
  453 + if (!$isAjax && empty($paramsValue)) {
  454 + return array();
  455 + }
449 $sizeId = isset($params['size']) && !empty($params['size']) ? $params['size'] : ''; 456 $sizeId = isset($params['size']) && !empty($params['size']) ? $params['size'] : '';
450 if (isset($params['size'])) { 457 if (isset($params['size'])) {
451 unset($params['size']); 458 unset($params['size']);
@@ -705,7 +712,7 @@ class HelperSearch @@ -705,7 +712,7 @@ class HelperSearch
705 $selected = true; 712 $selected = true;
706 } 713 }
707 else { 714 else {
708 - $params['specialoffer'] = 1; 715 + $params['specialoffer'] = 'Y';
709 } 716 }
710 return array( 717 return array(
711 'name' => '打折', 718 'name' => '打折',
@@ -742,12 +749,12 @@ class HelperSearch @@ -742,12 +749,12 @@ class HelperSearch
742 { 749 {
743 $params = self::$params; 750 $params = self::$params;
744 $selected = ''; 751 $selected = '';
745 - if (isset($params['isNew']) && !empty($params['isNew'])) {  
746 - unset($params['isNew']); 752 + if (isset($params['new']) && !empty($params['new'])) {
  753 + unset($params['new']);
747 $selected = true; 754 $selected = true;
748 } 755 }
749 else { 756 else {
750 - $params['isNew'] = 'Y'; 757 + $params['new'] = 'Y';
751 } 758 }
752 return array( 759 return array(
753 'name' => '新品', 760 'name' => '新品',
@@ -854,7 +861,6 @@ class HelperSearch @@ -854,7 +861,6 @@ class HelperSearch
854 ))); 861 )));
855 $active = ''; 862 $active = '';
856 $desc = true; 863 $desc = true;
857 -  
858 } 864 }
859 else if (self::$params['order'] == 'p_d_asc') { 865 else if (self::$params['order'] == 'p_d_asc') {
860 $url = self::buildUrl(array_merge($params, array( 866 $url = self::buildUrl(array_merge($params, array(
@@ -920,6 +926,7 @@ class HelperSearch @@ -920,6 +926,7 @@ class HelperSearch
920 if ($data) { 926 if ($data) {
921 $result['conditions'] = $data; 927 $result['conditions'] = $data;
922 } 928 }
  929 +// print_r($result); exit;
923 return $result; 930 return $result;
924 } 931 }
925 932
@@ -1305,7 +1312,8 @@ class HelperSearch @@ -1305,7 +1312,8 @@ class HelperSearch
1305 elseif ($type == 'shop') { 1312 elseif ($type == 'shop') {
1306 return 'http://101.200.31.165/yohosearch/shops.json'; 1313 return 'http://101.200.31.165/yohosearch/shops.json';
1307 } 1314 }
1308 - return 'http://192.168.10.64:8080/yohosearch/search-once.json'; 1315 + return 'http://101.200.31.165/yohosearch/search.json';
  1316 +// return 'http://192.168.10.64:8080/yohosearch/search-once.json';
1309 } 1317 }
1310 } 1318 }
1311 1319
@@ -40,7 +40,7 @@ class SearchModel @@ -40,7 +40,7 @@ class SearchModel
40 'gender' => FILTER_SANITIZE_STRING, 40 'gender' => FILTER_SANITIZE_STRING,
41 'p_d' => FILTER_DEFAULT, 41 'p_d' => FILTER_DEFAULT,
42 'shelve_time' => FILTER_DEFAULT, 42 'shelve_time' => FILTER_DEFAULT,
43 - 'isNew' => FILTER_DEFAULT, 43 + 'new' => FILTER_DEFAULT,
44 'specialoffer' => FILTER_DEFAULT, 44 'specialoffer' => FILTER_DEFAULT,
45 'limited' => FILTER_DEFAULT, 45 'limited' => FILTER_DEFAULT,
46 'order' => FILTER_DEFAULT, 46 'order' => FILTER_DEFAULT,
@@ -175,7 +175,7 @@ class SearchModel @@ -175,7 +175,7 @@ class SearchModel
175 // 组合搜索分类url 175 // 组合搜索分类url
176 $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']); 176 $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']);
177 // 组合搜索店铺url 177 // 组合搜索店铺url
178 - if (isset($param['keyword'])) { 178 + if (isset($searchCondition['condition']['query'])) {
179 $param['keyword'] = $searchCondition['condition']['query']; 179 $param['keyword'] = $searchCondition['condition']['query'];
180 $urlList['shop'] = HelperSearch::getShopUrl($param); 180 $urlList['shop'] = HelperSearch::getShopUrl($param);
181 } 181 }
@@ -210,11 +210,32 @@ class SearchModel @@ -210,11 +210,32 @@ class SearchModel
210 /** 210 /**
211 * 查询搜索提示 211 * 查询搜索提示
212 * @param $query 212 * @param $query
  213 + * @return array
213 */ 214 */
214 public static function getSuggest($query) 215 public static function getSuggest($query)
215 { 216 {
216 - $param = array();  
217 - $result = SearchData::getSuggest($param);  
218 - return $result; 217 + $data = '';
  218 + $result = SearchData::getSuggest($query);
  219 + if (isset($result['code']) && $result['code'] == 200 && isset($result['suggest']['items']) && !empty($result['suggest']['items'])) {
  220 + foreach ($result['suggest']['items'] as $v) {
  221 + $data .= '<li><a style="display: block;" href="http://search.yohobuy.com/?query='.$v['item'].'" class="clearfix clear search-item" title="'.$v['item'].'" act="http://search.yohobuy.com/?query='.$v['item'].'"><span class="searchvalue" >'.$v['item'].'</span><span class="valuenum">约'.$v['frequency'].'个商品</span></a></li>';
  222 + }
  223 + }
  224 + echo $data;
  225 + }
  226 +
  227 + /**
  228 + * 获取分类的尺码
  229 + */
  230 + public static function getSortSize($condition)
  231 + {
  232 + $size = array();
  233 + //返回搜索条件
  234 + $condition['needFilter'] = 1;
  235 + $condition['viewNum'] = 1;
  236 + $result = SearchData::searchElasticByCondition($condition);
  237 + if (isset($result['code']) && $result['code'] == 200 && isset($result['data']['filter']) && !empty($result['data']['filter'])) {
  238 + return HelperSearch::size($result['data']['filter'], true);
  239 + }
219 } 240 }
220 } 241 }
@@ -16,12 +16,26 @@ class SearchController extends WebAction @@ -16,12 +16,26 @@ class SearchController extends WebAction
16 $this->_view->display('search', $data); 16 $this->_view->display('search', $data);
17 } 17 }
18 18
19 - public function suggest() 19 + /**
  20 + * 搜索提示
  21 + */
  22 + public function suggestAction()
20 { 23 {
21 $query = rawurldecode($this->get('query')); 24 $query = rawurldecode($this->get('query'));
22 if ($query) { 25 if ($query) {
23 $param['query'] = $query; 26 $param['query'] = $query;
24 - $result = SearchModel::getSuggest($param); 27 + SearchModel::getSuggest($param);
25 } 28 }
26 } 29 }
  30 +
  31 + /**
  32 + * 根据分类id,获取分类尺码
  33 + */
  34 + public function sortSizeAction()
  35 + {
  36 + $condition['msort'] = $this->get('msort');
  37 + $size = SearchModel::getSortSize($condition);
  38 + print_r($size); exit;
  39 + $this->echoJson($size);
  40 + }
27 } 41 }