Authored by Rock Zhang

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

... ... @@ -82,6 +82,7 @@ class NewsaleData
*/
public static function selectNewSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit = null, $limit = 60, $page = 1, $order = 's_t_desc')
{
$selectItems = array(
'gender' => $gender,
'brand' => $brand,
... ...
... ... @@ -82,6 +82,9 @@ class ListProcess
$filters['classify'][] = $build;
}
// 按照指定字段进行排序筛选数据
self::sortArrByField($filters['classify'], 'sort_col');
return $filters;
}
... ... @@ -91,6 +94,7 @@ class ListProcess
$result = array(
'title' => '品牌',
'name' => '所有品牌',
'sort_col' => 1,
'dataType' => 'brand',
'subs' => array(
array(
... ... @@ -120,6 +124,7 @@ class ListProcess
$result = array(
'title' => '颜色',
'name' => '所有颜色',
'sort_col' => 3,
'dataType' => 'color',
'subs' => array(
array(
... ... @@ -146,6 +151,7 @@ class ListProcess
$result = array(
'title' => '折扣',
'name' => '所有商品',
'sort_col' => 6,
'dataType' => 'discount',
'subs' => array(
array(
... ... @@ -172,6 +178,7 @@ class ListProcess
$result = array(
'title' => '性别',
'name' => '所有性别',
'sort_col' => 0,
'dataType' => 'gender',
'subs' => array(
array(
... ... @@ -180,12 +187,12 @@ class ListProcess
'name' => '所有性别'
),
array(
'dataId' => 'boys',
'name' => '男'
'dataId' => '1,3',
'name' => 'BOYS'
),
array(
'dataId' => 'girls',
'name' => '女'
'dataId' => '2,3',
'name' => 'GIRLS'
),
)
);
... ... @@ -198,6 +205,7 @@ class ListProcess
$result = array(
'title' => '品类',
'name' => '所有品类',
'sort_col' => 2,
'dataType' => 'sort',
'subs' => array(
array(
... ... @@ -237,6 +245,7 @@ class ListProcess
$result = array(
'title' => '价格',
'name' => '所有价格',
'sort_col' => 5,
'dataType' => 'price',
'subs' => array(
array(
... ... @@ -263,6 +272,7 @@ class ListProcess
$result = array(
'title' => '尺码',
'name' => '所有尺码',
'sort_col' => 4,
'dataType' => 'size',
'subs' => array(
array(
... ...
... ... @@ -117,6 +117,32 @@ class Helpers
}
/**
* 根据排序类型和类型值获得正确的排序参数
* @param integer $order 类型值
* @param string $type 排序类型
* @return string 转换之后的排序参数
*/
public static function transOrder($order, $type)
{
$result = '';
switch ($type) {
case 'price':
$result = ($order == 0) ? 's_p_desc' : 's_p_asc';
break;
case 'discount':
$result = ($order == 0) ? 'p_d_desc' : 'p_d_asc';
break;
case 'newest':
default:
$result = ($order == 0) ? 's_t_desc' : 's_t_asc';
break;
}
return $result;
}
/**
* 格式化商品信息
*
* @param array $productData 需要格式化的商品数据
... ...
{{> filter}}
\ No newline at end of file
... ...
... ... @@ -5,6 +5,7 @@ namespace Product;
use Configs\CacheConfig;
use LibModels\Wap\Product\NewsaleData;
use Plugin\DataProcess\NewSaleProcess;
use Plugin\DataProcess\ListProcess;
use Plugin\Helpers;
use Plugin\Cache;
... ... @@ -219,4 +220,22 @@ class NewsaleModel
return $result;
}
/**
* 获取筛选数据
* @param array $data 接口返回的数据
* @return array 处理之后的数据
*/
public static function filterData($data)
{
$result = array();
/* 格式化筛选数据 */
if (isset($data['code']) && $data['code'] == 200 && isset($data['data']['filter'])) {
$result['filter'] = ListProcess::getFilterData($data['data']['filter']);
}
return $result;
}
}
... ...
... ... @@ -78,7 +78,7 @@ class NewsaleController extends AbstractAction
public function selectNewSaleAction()
{
if ($this->isAjax()) {
$gender = $this->get('gender', 'boys');
$gender = $this->get('gender', null);
$brand = $this->get('brand', null);
$sort = $this->get('sort', null);
$color = $this->get('color', null);
... ... @@ -89,30 +89,10 @@ class NewsaleController extends AbstractAction
$limit = $this->get('limit', 60);
$page = $this->get('page', 1);
// 转换性别
if ($gender === 'boys') {
$gender = '1,3';
} elseif ($gender === 'girls') {
$gender = '2,3';
} else {
$gender = '1,2,3';
}
// 转换排序方式
$order = $this->get('order', null);
$orderVal = $this->get('order', null);
$type = $this->get('type', '');
switch ($type) {
case 'price':
$order = ($order == 0) ? 's_p_desc' : 's_p_asc';
break;
case 'discount':
$order = ($order == 0) ? 'p_d_desc' : 'p_d_asc';
break;
case 'newest':
default:
$order = ($order == 0) ? 's_t_desc' : 's_t_asc';
break;
}
$order = Helpers::transOrder($orderVal, $type);
// 转换频道
$channel = Helpers::getChannelByCookie();
... ... @@ -132,4 +112,45 @@ class NewsaleController extends AbstractAction
}
}
/**
* Ajax方式查询筛选数据
*
* @return array 筛选数据
*/
public function filterAction()
{
if ($this->isAjax()) {
$gender = $this->get('gender', null);
$brand = $this->get('brand', null);
$sort = $this->get('sort', null);
$color = $this->get('color', null);
$size = $this->get('size', null);
$price = $this->get('price', null);
$p_d = $this->get('discount', null);
$dayLimit = $this->get('dayLimit', null);
$limit = $this->get('limit', 60);
$page = $this->get('page', 1);
// 转换排序方式
$orderVal = $this->get('order', null);
$type = $this->get('type', '');
$order = Helpers::transOrder($orderVal, $type);
$channel = Helpers::getChannelByCookie();
$data = NewsaleData::selectNewSaleProducts(
$gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page, $order
);
$result = \Product\NewsaleModel::filterData($data);
if (empty($result)) {
echo ' ';
} else {
$this->_view->display('filter', $result);
}
} else {
echo ' ';
}
}
}
... ...