Authored by Rock Zhang

添加筛选数据接口,调整筛选数据顺序

@@ -82,6 +82,7 @@ class NewsaleData @@ -82,6 +82,7 @@ class NewsaleData
82 */ 82 */
83 public static function selectNewSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit = null, $limit = 60, $page = 1, $order = 's_t_desc') 83 public static function selectNewSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit = null, $limit = 60, $page = 1, $order = 's_t_desc')
84 { 84 {
  85 +
85 $selectItems = array( 86 $selectItems = array(
86 'gender' => $gender, 87 'gender' => $gender,
87 'brand' => $brand, 88 'brand' => $brand,
@@ -82,6 +82,9 @@ class ListProcess @@ -82,6 +82,9 @@ class ListProcess
82 $filters['classify'][] = $build; 82 $filters['classify'][] = $build;
83 } 83 }
84 84
  85 + // 按照指定字段进行排序筛选数据
  86 + self::sortArrByField($filters['classify'], 'sort_col');
  87 +
85 return $filters; 88 return $filters;
86 89
87 } 90 }
@@ -91,6 +94,7 @@ class ListProcess @@ -91,6 +94,7 @@ class ListProcess
91 $result = array( 94 $result = array(
92 'title' => '品牌', 95 'title' => '品牌',
93 'name' => '所有品牌', 96 'name' => '所有品牌',
  97 + 'sort_col' => 1,
94 'dataType' => 'brand', 98 'dataType' => 'brand',
95 'subs' => array( 99 'subs' => array(
96 array( 100 array(
@@ -120,6 +124,7 @@ class ListProcess @@ -120,6 +124,7 @@ class ListProcess
120 $result = array( 124 $result = array(
121 'title' => '颜色', 125 'title' => '颜色',
122 'name' => '所有颜色', 126 'name' => '所有颜色',
  127 + 'sort_col' => 3,
123 'dataType' => 'color', 128 'dataType' => 'color',
124 'subs' => array( 129 'subs' => array(
125 array( 130 array(
@@ -146,6 +151,7 @@ class ListProcess @@ -146,6 +151,7 @@ class ListProcess
146 $result = array( 151 $result = array(
147 'title' => '折扣', 152 'title' => '折扣',
148 'name' => '所有商品', 153 'name' => '所有商品',
  154 + 'sort_col' => 6,
149 'dataType' => 'discount', 155 'dataType' => 'discount',
150 'subs' => array( 156 'subs' => array(
151 array( 157 array(
@@ -172,6 +178,7 @@ class ListProcess @@ -172,6 +178,7 @@ class ListProcess
172 $result = array( 178 $result = array(
173 'title' => '性别', 179 'title' => '性别',
174 'name' => '所有性别', 180 'name' => '所有性别',
  181 + 'sort_col' => 0,
175 'dataType' => 'gender', 182 'dataType' => 'gender',
176 'subs' => array( 183 'subs' => array(
177 array( 184 array(
@@ -180,12 +187,12 @@ class ListProcess @@ -180,12 +187,12 @@ class ListProcess
180 'name' => '所有性别' 187 'name' => '所有性别'
181 ), 188 ),
182 array( 189 array(
183 - 'dataId' => 'boys',  
184 - 'name' => '男' 190 + 'dataId' => '1,3',
  191 + 'name' => 'BOYS'
185 ), 192 ),
186 array( 193 array(
187 - 'dataId' => 'girls',  
188 - 'name' => '女' 194 + 'dataId' => '2,3',
  195 + 'name' => 'GIRLS'
189 ), 196 ),
190 ) 197 )
191 ); 198 );
@@ -198,6 +205,7 @@ class ListProcess @@ -198,6 +205,7 @@ class ListProcess
198 $result = array( 205 $result = array(
199 'title' => '品类', 206 'title' => '品类',
200 'name' => '所有品类', 207 'name' => '所有品类',
  208 + 'sort_col' => 2,
201 'dataType' => 'sort', 209 'dataType' => 'sort',
202 'subs' => array( 210 'subs' => array(
203 array( 211 array(
@@ -237,6 +245,7 @@ class ListProcess @@ -237,6 +245,7 @@ class ListProcess
237 $result = array( 245 $result = array(
238 'title' => '价格', 246 'title' => '价格',
239 'name' => '所有价格', 247 'name' => '所有价格',
  248 + 'sort_col' => 5,
240 'dataType' => 'price', 249 'dataType' => 'price',
241 'subs' => array( 250 'subs' => array(
242 array( 251 array(
@@ -263,6 +272,7 @@ class ListProcess @@ -263,6 +272,7 @@ class ListProcess
263 $result = array( 272 $result = array(
264 'title' => '尺码', 273 'title' => '尺码',
265 'name' => '所有尺码', 274 'name' => '所有尺码',
  275 + 'sort_col' => 4,
266 'dataType' => 'size', 276 'dataType' => 'size',
267 'subs' => array( 277 'subs' => array(
268 array( 278 array(
@@ -117,6 +117,32 @@ class Helpers @@ -117,6 +117,32 @@ class Helpers
117 } 117 }
118 118
119 /** 119 /**
  120 + * 根据排序类型和类型值获得正确的排序参数
  121 + * @param integer $order 类型值
  122 + * @param string $type 排序类型
  123 + * @return string 转换之后的排序参数
  124 + */
  125 + public static function transOrder($order, $type)
  126 + {
  127 + $result = '';
  128 +
  129 + switch ($type) {
  130 + case 'price':
  131 + $result = ($order == 0) ? 's_p_desc' : 's_p_asc';
  132 + break;
  133 + case 'discount':
  134 + $result = ($order == 0) ? 'p_d_desc' : 'p_d_asc';
  135 + break;
  136 + case 'newest':
  137 + default:
  138 + $result = ($order == 0) ? 's_t_desc' : 's_t_asc';
  139 + break;
  140 + }
  141 +
  142 + return $result;
  143 + }
  144 +
  145 + /**
120 * 格式化商品信息 146 * 格式化商品信息
121 * 147 *
122 * @param array $productData 需要格式化的商品数据 148 * @param array $productData 需要格式化的商品数据
@@ -5,6 +5,7 @@ namespace Product; @@ -5,6 +5,7 @@ namespace Product;
5 use Configs\CacheConfig; 5 use Configs\CacheConfig;
6 use LibModels\Wap\Product\NewsaleData; 6 use LibModels\Wap\Product\NewsaleData;
7 use Plugin\DataProcess\NewSaleProcess; 7 use Plugin\DataProcess\NewSaleProcess;
  8 +use Plugin\DataProcess\ListProcess;
8 use Plugin\Helpers; 9 use Plugin\Helpers;
9 use Plugin\Cache; 10 use Plugin\Cache;
10 11
@@ -219,4 +220,22 @@ class NewsaleModel @@ -219,4 +220,22 @@ class NewsaleModel
219 220
220 return $result; 221 return $result;
221 } 222 }
  223 +
  224 +
  225 + /**
  226 + * 获取筛选数据
  227 + * @param array $data 接口返回的数据
  228 + * @return array 处理之后的数据
  229 + */
  230 + public static function filterData($data)
  231 + {
  232 + $result = array();
  233 +
  234 + /* 格式化筛选数据 */
  235 + if (isset($data['code']) && $data['code'] == 200 && isset($data['data']['filter'])) {
  236 + $result['filter'] = ListProcess::getFilterData($data['data']['filter']);
  237 + }
  238 +
  239 + return $result;
  240 + }
222 } 241 }
@@ -78,7 +78,7 @@ class NewsaleController extends AbstractAction @@ -78,7 +78,7 @@ class NewsaleController extends AbstractAction
78 public function selectNewSaleAction() 78 public function selectNewSaleAction()
79 { 79 {
80 if ($this->isAjax()) { 80 if ($this->isAjax()) {
81 - $gender = $this->get('gender', 'boys'); 81 + $gender = $this->get('gender', null);
82 $brand = $this->get('brand', null); 82 $brand = $this->get('brand', null);
83 $sort = $this->get('sort', null); 83 $sort = $this->get('sort', null);
84 $color = $this->get('color', null); 84 $color = $this->get('color', null);
@@ -89,30 +89,10 @@ class NewsaleController extends AbstractAction @@ -89,30 +89,10 @@ class NewsaleController extends AbstractAction
89 $limit = $this->get('limit', 60); 89 $limit = $this->get('limit', 60);
90 $page = $this->get('page', 1); 90 $page = $this->get('page', 1);
91 91
92 - // 转换性别  
93 - if ($gender === 'boys') {  
94 - $gender = '1,3';  
95 - } elseif ($gender === 'girls') {  
96 - $gender = '2,3';  
97 - } else {  
98 - $gender = '1,2,3';  
99 - }  
100 -  
101 // 转换排序方式 92 // 转换排序方式
102 - $order = $this->get('order', null); 93 + $orderVal = $this->get('order', null);
103 $type = $this->get('type', ''); 94 $type = $this->get('type', '');
104 - switch ($type) {  
105 - case 'price':  
106 - $order = ($order == 0) ? 's_p_desc' : 's_p_asc';  
107 - break;  
108 - case 'discount':  
109 - $order = ($order == 0) ? 'p_d_desc' : 'p_d_asc';  
110 - break;  
111 - case 'newest':  
112 - default:  
113 - $order = ($order == 0) ? 's_t_desc' : 's_t_asc';  
114 - break;  
115 - } 95 + $order = Helpers::transOrder($orderVal, $type);
116 96
117 // 转换频道 97 // 转换频道
118 $channel = Helpers::getChannelByCookie(); 98 $channel = Helpers::getChannelByCookie();
@@ -132,4 +112,45 @@ class NewsaleController extends AbstractAction @@ -132,4 +112,45 @@ class NewsaleController extends AbstractAction
132 } 112 }
133 } 113 }
134 114
  115 + /**
  116 + * Ajax方式查询筛选数据
  117 + *
  118 + * @return array 筛选数据
  119 + */
  120 + public function filterAction()
  121 + {
  122 + if ($this->isAjax()) {
  123 + $gender = $this->get('gender', null);
  124 + $brand = $this->get('brand', null);
  125 + $sort = $this->get('sort', null);
  126 + $color = $this->get('color', null);
  127 + $size = $this->get('size', null);
  128 + $price = $this->get('price', null);
  129 + $p_d = $this->get('discount', null);
  130 + $dayLimit = $this->get('dayLimit', null);
  131 + $limit = $this->get('limit', 60);
  132 + $page = $this->get('page', 1);
  133 +
  134 + // 转换排序方式
  135 + $orderVal = $this->get('order', null);
  136 + $type = $this->get('type', '');
  137 + $order = Helpers::transOrder($orderVal, $type);
  138 +
  139 + $channel = Helpers::getChannelByCookie();
  140 +
  141 + $data = NewsaleData::selectNewSaleProducts(
  142 + $gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page, $order
  143 + );
  144 + $result = \Product\NewsaleModel::filterData($data);
  145 +
  146 + if (empty($result)) {
  147 + echo ' ';
  148 + } else {
  149 + $this->_view->display('filter', $result);
  150 + }
  151 + } else {
  152 + echo ' ';
  153 + }
  154 + }
  155 +
135 } 156 }