From d9a85d3c0b54021ee1866ca5029f31a449a9753c Mon Sep 17 00:00:00 2001 From: Rock Zhang <iamgtskk@gmail.com> Date: Thu, 22 Oct 2015 13:48:59 +0800 Subject: [PATCH] 增加列表页的处理逻辑 --- framework | 2 +- library/LibModels/Wap/Category/ClassData.php | 9 +++++---- library/Plugin/DataProcess/ListProcess.php | 7 +++++++ template/m.yohobuy.com/actions/product/list/list.phtml | 3 +++ yohobuy/m.yohobuy.com/application/modules/Product/controllers/List.php | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 141 insertions(+), 12 deletions(-) create mode 100644 template/m.yohobuy.com/actions/product/list/list.phtml diff --git a/framework b/framework index 119c247..75bbc3b 160000 --- a/framework +++ b/framework @@ -1 +1 @@ -Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05 +Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2 diff --git a/library/LibModels/Wap/Category/ClassData.php b/library/LibModels/Wap/Category/ClassData.php index 0d431e3..5da9ccb 100644 --- a/library/LibModels/Wap/Category/ClassData.php +++ b/library/LibModels/Wap/Category/ClassData.php @@ -47,8 +47,11 @@ class ClassData * @param integer $channel 表示频道号,1位男生,2为女生 * @return array 品类商品数据 */ - public static function selectBrandDetail($gender, $brand, $sort, $color, $size, $price, $p_d, $channel = 1, $order = 's_t_desc', $limit = 60, $page = 1) + public static function selectClassDetail($gender, $brand, $sort, $color, $size, $price, $p_d, $channel = 1, $order = 's_t_desc', $limit = 60, $page = 1) { + // 构建必传参数 + $param = Yohobuy::param(); + $selectItems = array( 'gender' => $gender, 'brand' => $brand, @@ -60,9 +63,7 @@ class ClassData ); // 拉取筛选参数 $queriedParams = array_filter($selectItems, function($v) {return $v !== null;}); - - // 构建必传参数 - $param = Yohobuy::param(); + $param += $queriedParams; $param['method'] = 'app.search.category'; $param['page'] = $page; diff --git a/library/Plugin/DataProcess/ListProcess.php b/library/Plugin/DataProcess/ListProcess.php index 7e75356..1148e54 100644 --- a/library/Plugin/DataProcess/ListProcess.php +++ b/library/Plugin/DataProcess/ListProcess.php @@ -63,6 +63,7 @@ class ListProcess // 过滤条件数据 $filters = array('classify'=>array()); + $num = 1; foreach ($data as $key => $val) { if(empty($val)) { @@ -72,6 +73,12 @@ class ListProcess continue; } $build = self::$key($val); + if($num === 1) + { + $build['active'] = true; + } + + $num++; $filters['classify'][] = $build; } diff --git a/template/m.yohobuy.com/actions/product/list/list.phtml b/template/m.yohobuy.com/actions/product/list/list.phtml new file mode 100644 index 0000000..78c71c3 --- /dev/null +++ b/template/m.yohobuy.com/actions/product/list/list.phtml @@ -0,0 +1,3 @@ +{{# new}} + {{> good}} +{{/ new}} \ No newline at end of file diff --git a/yohobuy/m.yohobuy.com/application/modules/Product/controllers/List.php b/yohobuy/m.yohobuy.com/application/modules/Product/controllers/List.php index e7a1c05..213b8ea 100644 --- a/yohobuy/m.yohobuy.com/application/modules/Product/controllers/List.php +++ b/yohobuy/m.yohobuy.com/application/modules/Product/controllers/List.php @@ -3,6 +3,7 @@ use Action\AbstractAction; use LibModels\Wap\Product\SearchData; use LibModels\Wap\Category\BrandData; +use LibModels\Wap\Category\ClassData; use Plugin\DataProcess\ListProcess; use Plugin\Helpers; @@ -11,33 +12,115 @@ use Plugin\Helpers; */ class ListController extends AbstractAction { + /** + * 搜索列表页 + */ public function indexAction() { - $data = array( - 'goodListPage' => true, - 'goodList' => array( - ) - ); - + $query = $this->get('query', null); $brand = $this->get('brand', null); $gender = $this->get('gender', null); $p_d = $this->get('p_d', null); $misort = $this->get('misort', null); $msort = $this->get('msort', null); + $data = array( + 'pageHeader' => array( + 'navBack' => true, + 'navTitle' => '搜索', + 'navHome' => '/' + ), + 'goodListPage' => true, + 'goodList' => array() + ); + + // 如果存在搜索字符串就显示搜索栏 + if(!is_null($query)) + { + $data['search'] = array( + 'default' => $query + ); + } + // 查询数据 - $listData = SearchData::searchLiDatas(null, $brand, $gender, $p_d, $misort, $msort); + $listData = SearchData::searchLiDatas($query, $brand, $gender, $p_d, $misort, $msort); // 处理返回的数据 if (isset($listData['code']) && $listData['code'] === 200) { $tmpData = $listData['data']; + // 如果存在品牌信息就显示品牌字段 + if(isset($tmpData['brand']) && !empty($tmpData['brand'])) + { + $brandData = $tmpData['brand']; + $data['brandWay'] = array( + 'url' => '/product/list/brand?brand='.$brandData['id'], + 'thumb' => Helpers::getImageUrl($brandData['brand_ico'], 75, 40), + 'name' => $brandData['brand_name'] + ); + } + $data['goodList'] = ListProcess::getListData($tmpData); } $this->_view->display('index', $data); } + + /** + * Ajax异步筛选请求 + */ + public function searchAction() + { + if($this->isAjax()) + { + $query = $this->get('query', null); + $brand = $this->get('brand', null); + $gender = $this->get('gender', null); + $p_d = $this->get('p_d', null); + $misort = $this->get('misort', null); + $msort = $this->get('msort', null); + + $order = $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; + } + + $data = array(); + // 查询数据 + $listData = SearchData::searchLiDatas($query, $brand, $gender, $p_d, $misort, $msort, $order); + // 处理返回的数据 + if (isset($listData['code']) && $listData['code'] === 200) { + $tmpData = $listData['data']; + + unset($tmpData['filter']);// 不要筛选条件的数据 + $data = ListProcess::getListData($tmpData); + } + + if(empty($data)) + { + echo ' '; + } + else + { + $this->_view->display('list', $data); + } + } + } + + /** + * 品牌商品列表页 + */ public function brandAction() { $brand = $this->get('brand', null); @@ -50,6 +133,7 @@ class ListController extends AbstractAction $data = array( 'pageHeader' => array( + 'navBack' => true, 'navHome' => '/' ), 'goodListPage' => true, @@ -88,5 +172,39 @@ class ListController extends AbstractAction $this->_view->display('index', $data); } + + /** + * 品类商品列表页 + */ + public function classAction() + { + $brand = $this->get('brand', null); + $gender = $this->get('gender', 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('p_d', null); + + $data = array( + 'pageHeader' => array( + 'navBack' => true, + 'navHome' => '/' + ), + 'goodListPage' => true, + 'goodList' => array() + ); + + // 查询数据 + $listData = ClassData::selectClassDetail($gender, $brand, $sort, $color, $size, $price, $p_d); + // 处理返回的数据 + if (isset($listData['code']) && $listData['code'] === 200) { + $tmpData = $listData['data']; + + $data['goodList'] = ListProcess::getListData($tmpData); + } + + $this->_view->display('index', $data); + } } -- libgit2 0.24.0