Authored by 周少峰

代码整理,控制器公共条件放控制器,并行调用接口

@@ -4,7 +4,7 @@ namespace LibModels\Web\Product; @@ -4,7 +4,7 @@ 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 $shops_url = 'http://101.200.31.165/yohosearch/shops.json'; 7 + public static $shopsUrl = 'http://101.200.31.165/yohosearch/shops.json';
8 /** 8 /**
9 * 获取搜索的服务地址 9 * 获取搜索的服务地址
10 * 10 *
@@ -136,7 +136,7 @@ class SearchData extends \LibModels\Wap\Product\SearchData @@ -136,7 +136,7 @@ class SearchData extends \LibModels\Wap\Product\SearchData
136 */ 136 */
137 public static function getShop(array $params) 137 public static function getShop(array $params)
138 { 138 {
139 - return Yohobuy::get(self::$shops_url,$params); 139 + return Yohobuy::get(self::$shopsUrl,$params);
140 } 140 }
141 141
142 /** 142 /**
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 /**
  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_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;
  87 + }
  88 + if (!$price[1]) {
  89 + $price[1] = 99999;
  90 + }
  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;
  114 + }
  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 + /**
20 * 根据条件获取搜索数据 126 * 根据条件获取搜索数据
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 127 + * @param array $customCondition
  128 + * @param array $customOptions
26 * @return array 129 * @return array
27 */ 130 */
28 - public static function getSearchData($condition, $options) 131 + public static function getSearchData($customCondition = array(), $customOptions = array())
29 { 132 {
30 $data = array(); 133 $data = array();
  134 + $searchCondition = self::searchCondition($customCondition, $customOptions);
31 // 调用接口查询商品数据 135 // 调用接口查询商品数据
32 - $result = SearchData::searchElasticByCondition($condition);  
33 - if (isset($result['code']) && $result['code'] === 200) { 136 + $urlList['productUrl'] = HelperSearch::getProductUrl($searchCondition['condition']);
34 // 调用分类信息 137 // 调用分类信息
35 - $category = SearchData::getClassesData($condition);  
36 - if (isset($category['code']) && $category['code'] === 200) {  
37 - $result['data']['filter']['group_sort'] = $category['data']['sort'];  
38 - } 138 + $urlList['sortUrl'] = HelperSearch::getSortUrl($searchCondition['condition']);
  139 +// $result['data']['filter']['group_sort'] = $category['data']['sort'];
  140 +
39 // 调用折扣区间 141 // 调用折扣区间
40 - $discount = SearchData::getDiscount();  
41 - if (isset($discount['code']) && $discount['code'] === 200) {  
42 - $result['data']['filter']['discount'] = $discount['data']['discount'];  
43 - } 142 + $urlList['discountUrl'] = HelperSearch::getDiscountUrl($searchCondition['condition']);
  143 +// $result['data']['filter']['discount'] = $discount['data']['discount'];
44 // 调用最新上架 144 // 调用最新上架
45 - $recent = SearchData::recentShelve();  
46 - if (isset($discount['code']) && $discount['code'] === 200) {  
47 - $result['data']['filter']['recent'] = $recent['data']['recent'];  
48 - } 145 + $urlList['recentUrl'] = HelperSearch::getRecentUrl($searchCondition['condition']);
  146 +// $result['data']['filter']['recent'] = $recent['data']['recent'];
  147 +
49 //用户浏览记录 148 //用户浏览记录
50 - $result['data']['filter']['review'] = SearchData::getRecentReview(); 149 + //$urlList['reviewUrl'] = HelperSearch::getReviewUrl($searchCondition['condition']);
  150 +
  151 + $result = Yohobuy::getMulti($urlList, array(), true);
  152 +
  153 +
  154 +
51 // 组织模板数据 155 // 组织模板数据
52 - $data = HelperSearch::getList($result, $options);  
53 - } 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'])) {
@@ -5,93 +5,9 @@ class SearchController extends WebAction @@ -5,93 +5,9 @@ class SearchController extends WebAction
5 { 5 {
6 public function indexAction() 6 public function indexAction()
7 { 7 {
8 - /* 过滤请求参数 */  
9 - $condition = filter_input_array(INPUT_GET, array(  
10 - 'query' => FILTER_SANITIZE_STRING,  
11 - 'brand' => FILTER_VALIDATE_INT,  
12 - 'sort' => FILTER_VALIDATE_INT,  
13 - 'msort' => FILTER_VALIDATE_INT,  
14 - 'misort' => FILTER_VALIDATE_INT,  
15 - 'color' => FILTER_VALIDATE_INT,  
16 - 'size' => FILTER_DEFAULT,  
17 - 'style' => FILTER_DEFAULT,  
18 - 'price' => FILTER_DEFAULT,  
19 - 'gender' => FILTER_DEFAULT,  
20 - 'p_d' => FILTER_DEFAULT,  
21 - 'shelve_time' => FILTER_DEFAULT,  
22 - 'isNew' => FILTER_DEFAULT,  
23 - 'specialoffer' => FILTER_DEFAULT,  
24 - 'limited' => FILTER_DEFAULT,  
25 - 'order' => FILTER_DEFAULT,  
26 - 'viewNum' => FILTER_VALIDATE_INT,  
27 - 'rowNum' => FILTER_VALIDATE_INT,  
28 - 'page' => FILTER_VALIDATE_INT), false);  
29 - //字符转码  
30 - foreach($condition as $key => $val){  
31 - $condition[$key] = rawurldecode($val);  
32 - }  
33 - //性別(频道)  
34 - $gender_cookie = !isset($_COOKIE['_Gender']) ? '3' : ($_COOKIE['_Gender']=='2,3' ? 2 : 1);  
35 - $gender = $this->get('gender') ? ($this->get('gender') == '2,3' ? 2 : 1) : $gender_cookie ;  
36 - $condition['gender'] = $gender;  
37 - //每页显示商品数  
38 - if(!isset($condition['viewNum']) || empty($condition['viewNum'])){  
39 - $condition['viewNum'] =60;  
40 - }  
41 - $view_num_arr = array(60, 100, 200);  
42 - if (!in_array($condition['viewNum'], $view_num_arr)) {  
43 - $condition['viewNum'] = 60;  
44 - }  
45 - //每行显示的商品数量  
46 - if(!isset($condition['rowNum']) || empty($condition['rowNum'])){  
47 - $condition['rowNum'] =5;  
48 - }  
49 - if ($condition['rowNum'] == 6) {  
50 - $imgSize = array(195, 260);  
51 - $minImgSize = array(50, 67);  
52 - } else {  
53 - $condition['rowNum'] = 5;  
54 - $imgSize = array(235, 314);  
55 - $minImgSize = array(60, 80);  
56 - }  
57 - //自定义搜索价格  
58 - if (isset($condition['price']) && !empty($condition['price'])) {  
59 - $price = explode(',', $condition['price']);  
60 - if (!$price[0]) {  
61 - $price[0] = 0;  
62 - }  
63 - if ($price[1]) {  
64 - $price[1] = 99999;  
65 - }  
66 - $condition['price'] = implode(',', $price);  
67 - }  
68 -  
69 - //返回搜索条件  
70 - $condition['needFilter'] = 1;  
71 - //过滤赠品  
72 - $condition['attribute_not'] = 2;  
73 - /*sale*/  
74 - //默认排序  
75 - if (!isset($condition['order']) || empty($condition['order'])) {  
76 - $condition['order'] = 's_n_desc';  
77 - }  
78 - if (!isset($condition['p_d']) || empty($condition['p_d'])) {  
79 - $condition['p_d'] = '0,0.9';  
80 - }  
81 - $options = array(  
82 - 'imgSize' => $imgSize,  
83 - 'minImgSize' => $minImgSize,  
84 - 'rowNum' =>$condition['rowNum'],  
85 - 'viewNum' =>$condition['viewNum'],  
86 - );  
87 - $params = $condition + $_GET;  
88 - $params = array_filter($params);  
89 - //每页记录数减1,下一页占位  
90 - $params['viewNum'] = $params['viewNum'] - 1;  
91 $options['controller'] = $this->_request->controller; 8 $options['controller'] = $this->_request->controller;
92 - $searchData = SearchModel::searchData($params,$options);  
93 - $cate = array('boys','girls','kids','lifestyle');  
94 - $this->setWebNavHeader($cate[$gender-1]); 9 + $searchData = SearchModel::searchData('',$options);
  10 + $this->setWebNavHeader();
95 $data = array( 11 $data = array(
96 //初始化js 12 //初始化js
97 'searchListPage' => true, 13 'searchListPage' => true,