Authored by Rock Zhang

初步调试列表页功能

@@ -135,6 +135,9 @@ class BrandData @@ -135,6 +135,9 @@ class BrandData
135 */ 135 */
136 public static function selectBrandDetail($gender, $brand, $sort, $color, $size, $price, $p_d, $channel = 1, $order = 's_t_desc', $limit = 60, $page = 1) 136 public static function selectBrandDetail($gender, $brand, $sort, $color, $size, $price, $p_d, $channel = 1, $order = 's_t_desc', $limit = 60, $page = 1)
137 { 137 {
  138 + // 构建必传参数
  139 + $param = Yohobuy::param();
  140 +
138 $selectItems = array( 141 $selectItems = array(
139 'gender' => $gender, 142 'gender' => $gender,
140 'brand' => $brand, 143 'brand' => $brand,
@@ -148,9 +151,7 @@ class BrandData @@ -148,9 +151,7 @@ class BrandData
148 $queriedParams = array_filter($selectItems, function($v) { 151 $queriedParams = array_filter($selectItems, function($v) {
149 return $v !== null; 152 return $v !== null;
150 }); 153 });
151 -  
152 - // 构建必传参数  
153 - $param = Yohobuy::param(); 154 + $param += $queriedParams;
154 155
155 $param['method'] = 'app.search.brand'; 156 $param['method'] = 'app.search.brand';
156 $param['page'] = $page; 157 $param['page'] = $page;
  1 +<?php
  2 +
  3 +namespace Plugin\DataProcess;
  4 +use Plugin\Helpers;
  5 +
  6 +/**
  7 + * 列表数据处理类
  8 + */
  9 +class ListProcess
  10 +{
  11 +
  12 + /**
  13 + * 返回商品和过滤数据
  14 + *
  15 + * @param $data
  16 + * @return array 处理之后的商品数据
  17 + */
  18 + public static function getListData($data)
  19 + {
  20 + $result = array('new'=>array(), 'filter'=>array());
  21 +
  22 + if(isset($data['product_list']))
  23 + {
  24 + $result['new'] = self::getProductData($data['product_list']);
  25 + }
  26 + if(isset($data['filter']))
  27 + {
  28 + $result['filter'] = self::getFilterData($data['filter']);
  29 + }
  30 +
  31 + return $result;
  32 +
  33 + }
  34 +
  35 + /**
  36 + * 处理列表商品数据
  37 + *
  38 + * @param $data
  39 + * @return array 处理之后的商品数据
  40 + */
  41 + public static function getProductData($data)
  42 + {
  43 + // 处理商品
  44 + $products = array();
  45 +
  46 + foreach ($data as $value)
  47 + {
  48 + $products[] = Helpers::formatProduct($value);
  49 + }
  50 +
  51 + return $products;
  52 +
  53 + }
  54 +
  55 + /**
  56 + * 处理筛选数据
  57 + *
  58 + * @param $data
  59 + * @return array 处理之后的筛选数据
  60 + */
  61 + public static function getFilterData($data)
  62 + {
  63 + // 过滤条件数据
  64 + $filters = array('classify'=>array());
  65 +
  66 + foreach ($data as $key => $val) {
  67 + if(empty($val))
  68 + {
  69 + continue;
  70 + }
  71 + if (!is_callable("self::$key")) {
  72 + continue;
  73 + }
  74 + $build = self::$key($val);
  75 + $filters['classify'][] = $build;
  76 + }
  77 +
  78 + return $filters;
  79 +
  80 + }
  81 +
  82 + private static function brand($data)
  83 + {
  84 + $result = array(
  85 + 'title' => '品牌',
  86 + 'name' => '所有品牌',
  87 + 'subs' => array(
  88 + array(
  89 + 'chosed' => true,
  90 + 'dataId' => 0,
  91 + 'name' => '所有品牌'
  92 + )
  93 + )
  94 + );
  95 +
  96 + // 对品牌数据按照品牌字母进行排序
  97 + self::sortArrByField($data, 'brand_alif');
  98 +
  99 + foreach ($data as $one) {
  100 + $brand = array();
  101 + $brand['dataId'] = $one['id'];
  102 + $brand['name'] = $one['brand_name'];
  103 +
  104 + $result['subs'][] = $brand;
  105 + }
  106 +
  107 + return $result;
  108 + }
  109 +
  110 + private static function color($data)
  111 + {
  112 + $result = array(
  113 + 'title' => '颜色',
  114 + 'name' => '所有颜色',
  115 + 'subs' => array(
  116 + array(
  117 + 'chosed' => true,
  118 + 'dataId' => 0,
  119 + 'name' => '所有颜色'
  120 + )
  121 + )
  122 + );
  123 +
  124 + foreach ($data as $one) {
  125 + $color = array();
  126 + $color['dataId'] = $one['color_id'];
  127 + $color['name'] = $one['color_name'];
  128 +
  129 + $result['subs'][] = $color;
  130 + }
  131 +
  132 + return $result;
  133 + }
  134 +
  135 + private static function discount($data)
  136 + {
  137 + $result = array(
  138 + 'title' => '折扣',
  139 + 'name' => '所有商品',
  140 + 'subs' => array(
  141 + array(
  142 + 'chosed' => true,
  143 + 'dataId' => 0,
  144 + 'name' => '所有商品'
  145 + )
  146 + )
  147 + );
  148 +
  149 + foreach ($data as $one) {
  150 + $discount = array();
  151 + $discount['dataId'] = $one['count'];
  152 + $discount['name'] = $one['name'] .'折商品';
  153 +
  154 + $result['subs'][] = $discount;
  155 + }
  156 +
  157 + return $result;
  158 + }
  159 +
  160 + private static function gender($data)
  161 + {
  162 + $result = array(
  163 + 'title' => '性别',
  164 + 'name' => '所有性别',
  165 + 'subs' => array(
  166 + array(
  167 + 'chosed' => true,
  168 + 'dataId' => 0,
  169 + 'name' => '所有性别'
  170 + ),
  171 + array(
  172 + 'dataId' => 1,
  173 + 'name' => '男'
  174 + ),
  175 + array(
  176 + 'dataId' => 2,
  177 + 'name' => '女'
  178 + ),
  179 + )
  180 + );
  181 +
  182 + return $result;
  183 + }
  184 +
  185 + private static function group_sort($data)
  186 + {
  187 + $result = array(
  188 + 'title' => '品类',
  189 + 'name' => '所有品类',
  190 + 'subs' => array(
  191 + array(
  192 + 'chosed' => true,
  193 + 'dataId' => 0,
  194 + 'name' => '所有品类'
  195 + )
  196 + )
  197 + );
  198 +
  199 + foreach ($data as $one) {
  200 + $category = array();
  201 + $category['dataId'] = $one['category_id'];
  202 + $category['name'] = $one['category_name'];
  203 +
  204 + // 子品类
  205 + if(isset($one['sub']))
  206 + {
  207 + $category['subs'] = array();
  208 + foreach ($one['sub'] as $single) {
  209 + $subitem = array();
  210 + $subitem['dataId'] = $single['category_id'];
  211 + $subitem['name'] = $single['category_name'];
  212 +
  213 + $category['subs'][] = $subitem;
  214 + }
  215 + }
  216 +
  217 + $result['subs'][] = $category;
  218 + }
  219 +
  220 + return $result;
  221 + }
  222 +
  223 + private static function priceRange($data)
  224 + {
  225 + $result = array(
  226 + 'title' => '价格',
  227 + 'name' => '所有价格',
  228 + 'subs' => array(
  229 + array(
  230 + 'chosed' => true,
  231 + 'dataId' => 0,
  232 + 'name' => '所有价格'
  233 + )
  234 + )
  235 + );
  236 +
  237 + foreach ($data as $one) {
  238 + $price = array();
  239 + $price['name'] = $one;
  240 +
  241 + $result[] = $price;
  242 + }
  243 +
  244 + return $result;
  245 + }
  246 +
  247 + private static function size($data)
  248 + {
  249 + $result = array(
  250 + 'title' => '尺码',
  251 + 'name' => '所有尺码',
  252 + 'subs' => array(
  253 + array(
  254 + 'chosed' => true,
  255 + 'dataId' => 0,
  256 + 'name' => '所有尺码'
  257 + )
  258 + )
  259 + );
  260 +
  261 + foreach ($data as $one) {
  262 + $size = array();
  263 + $size['dataId'] = $one['size_id'];
  264 + $size['name'] = $one['size_name'];
  265 +
  266 + $result['subs'][] = $size;
  267 + }
  268 +
  269 + return $result;
  270 + }
  271 +
  272 + /**
  273 + * 按照数组中指定字段排序二维数组
  274 + *
  275 + * @param array &$array 需要排序的数组
  276 + * @param string $field 字段名称
  277 + * @param boolean $desc 时候降序排列,默认为false
  278 + */
  279 + private static function sortArrByField(&$array, $field, $desc = false){
  280 + $fieldArr = array();
  281 + foreach ($array as $k => $v) {
  282 + $fieldArr[$k] = $v[$field];
  283 + }
  284 + $sort = $desc == false ? SORT_ASC : SORT_DESC;
  285 + array_multisort($fieldArr, $sort, $array);
  286 + }
  287 +}
@@ -4,6 +4,7 @@ use Action\AbstractAction; @@ -4,6 +4,7 @@ use Action\AbstractAction;
4 use LibModels\Wap\Product\SearchData; 4 use LibModels\Wap\Product\SearchData;
5 use LibModels\Wap\Category\BrandData; 5 use LibModels\Wap\Category\BrandData;
6 use Plugin\DataProcess\ListProcess; 6 use Plugin\DataProcess\ListProcess;
  7 +use Plugin\Helpers;
7 8
8 /** 9 /**
9 * 商品列表页 10 * 商品列表页
@@ -15,7 +16,6 @@ class ListController extends AbstractAction @@ -15,7 +16,6 @@ class ListController extends AbstractAction
15 $data = array( 16 $data = array(
16 'goodListPage' => true, 17 'goodListPage' => true,
17 'goodList' => array( 18 'goodList' => array(
18 -<<<<<<< HEAD  
19 ) 19 )
20 ); 20 );
21 21
@@ -28,7 +28,7 @@ class ListController extends AbstractAction @@ -28,7 +28,7 @@ class ListController extends AbstractAction
28 // 查询数据 28 // 查询数据
29 $listData = SearchData::searchLiDatas(null, $brand, $gender, $p_d, $misort, $msort); 29 $listData = SearchData::searchLiDatas(null, $brand, $gender, $p_d, $misort, $msort);
30 // 处理返回的数据 30 // 处理返回的数据
31 - if (isset($listData['code']) && $listData['code'] == 200) { 31 + if (isset($listData['code']) && $listData['code'] === 200) {
32 $tmpData = $listData['data']; 32 $tmpData = $listData['data'];
33 33
34 $data['goodList'] = ListProcess::getListData($tmpData); 34 $data['goodList'] = ListProcess::getListData($tmpData);
@@ -49,128 +49,40 @@ class ListController extends AbstractAction @@ -49,128 +49,40 @@ class ListController extends AbstractAction
49 $p_d = $this->get('p_d', null); 49 $p_d = $this->get('p_d', null);
50 50
51 $data = array( 51 $data = array(
  52 + 'pageHeader' => array(
  53 + 'navHome' => '/'
  54 + ),
52 'goodListPage' => true, 55 'goodListPage' => true,
53 'goodList' => array( 56 'goodList' => array(
54 'brand' => array( 57 'brand' => array(
55 'id' => $brand 58 'id' => $brand
56 -=======  
57 - 'search' => 'Aape',  
58 - 'brandWay' => array(  
59 - 'url' => 'http://aape.m.yohobuy.com/',  
60 - 'name' => 'Aape',  
61 - 'thumb' => 'http://img13.static.yhbimg.com/brandLogo/2015/08/26/15/02261f64c198cb4b181c5ef9e61f38f4b9.jpg?imageMogr2/thumbnail/150x70/extent/150x70/background/d2hpdGU=/position/center/quality/90'  
62 - ),  
63 - 'brand' => array(  
64 - 'id' => 1,  
65 - 'banner' => 'http://img10.static.yhbimg.com/brandBanner/2015/08/26/07/015af5d6ee626cb132cd9c436e896fae26.jpg?imageMogr2/crop/640x'  
66 - ),  
67 - 'new' => array(  
68 - array(  
69 - 'id' => 1,  
70 - 'thumb' => 'http://img13.static.yhbimg.com/goodsimg/2015/09/15/03/02e50b1037b45b90aa8f33ee328b18facf.jpg?imageMogr2/thumbnail/290x388/extent/290x388/background/d2hpdGU=/position/center/quality/90',  
71 - 'url' => '',  
72 - 'name' => 'Aape X YO’HOOD moon face YOH',  
73 - 'salePrice' => 599,  
74 - 'tags' => array(  
75 - 'is_new' => true,  
76 - 'is_discount' => true  
77 - ),  
78 - 'is_soon_sold_out' => true  
79 - ),  
80 - array(  
81 - 'id' => 2,  
82 - 'thumb' => 'http://img10.static.yhbimg.com/goodsimg/2015/09/15/03/0101b0c3998752d02724a5512c6efcb241.jpg?imageMogr2/thumbnail/290x388/extent/290x388/background/d2hpdGU=/position/center/quality/90',  
83 - 'url' => '',  
84 - 'name' => 'Aape X YO’HOOD moon face YOH',  
85 - 'salePrice' => 99,  
86 - 'tags' => array(  
87 - 'is_yohoood' => true  
88 - ),  
89 - 'is_soon_sold_out' => true  
90 - )  
91 - ),  
92 - 'filter' => array(  
93 - array(  
94 - 'classify' => array(  
95 - array(  
96 - 'title' => '性别',  
97 - 'name' => '全部性别',  
98 - 'default' => true,  
99 - 'subs' => array(  
100 - array(  
101 - 'chosed' => true,  
102 - 'dataId' => 0,  
103 - 'name' => '全部性别'  
104 - ),  
105 - array(  
106 - 'dataId' => 1,  
107 - 'name' => '男'  
108 - ),  
109 - array(  
110 - 'dataId' => 3,  
111 - 'name' => '女'  
112 - )  
113 - )  
114 - ),  
115 - array(  
116 - 'title' => '尺寸',  
117 - 'name' => 'XL',  
118 - 'subs' => array(  
119 - array(  
120 - 'dataId' => 0,  
121 - 'name' => '全部尺寸'  
122 - ),  
123 - array(  
124 - 'dataId' => 1,  
125 - 'name' => 'S'  
126 - ),  
127 - array(  
128 - 'dataId' => 2,  
129 - 'name' => 'M'  
130 - ),  
131 - array(  
132 - 'dataId' => 3,  
133 - 'name' => 'L'  
134 - ),  
135 - array(  
136 - 'chosed' => true,  
137 - 'dataId' => 4,  
138 - 'name' => 'XL'  
139 - ),  
140 - array(  
141 - 'dataId' => 5,  
142 - 'name' => 'XXL'  
143 - )  
144 - )  
145 - )  
146 - )  
147 - )  
148 ->>>>>>> 4b0a4270663f76e6b242af42f29607e22ffa75e7  
149 ) 59 )
150 ) 60 )
151 ); 61 );
152 62
153 // 获取品牌介绍信息 63 // 获取品牌介绍信息
154 $introData = BrandData::getBrandIntro($brand); 64 $introData = BrandData::getBrandIntro($brand);
155 - if(isset($introData['code']) && $introData['code'] == 200) 65 + if(isset($introData['code']) && $introData['code'] === 200)
156 { 66 {
157 - $data['goodList']['intro'] = isset($introData['data']['brand_intro']) ? $introData['data']['brand_intro'] : ''; 67 + $data['goodList']['brand']['intro'] = isset($introData['data']['brand_intro']) ? $introData['data']['brand_intro'] : '';
158 } 68 }
159 69
160 // 获取品牌banner的数据 70 // 获取品牌banner的数据
161 $bannerData = BrandData::getBrandBanner($brand, 0); 71 $bannerData = BrandData::getBrandBanner($brand, 0);
162 - if(isset($bannerData['code']) && $bannerData['code'] == 200) 72 + if(isset($bannerData['code']) && $bannerData['code'] === 200)
163 { 73 {
164 - $data['goodList']['banner'] = isset($bannerData['data']['banner']) ? $bannerData['data']['banner'] : ''; 74 + $data['goodList']['brand']['banner'] = isset($bannerData['data']['banner']) ? Helpers::getImageUrl($bannerData['data']['banner'], 640, 75) : '';
165 } 75 }
166 76
167 // 查询数据 77 // 查询数据
168 $listData = BrandData::selectBrandDetail($gender, $brand, $sort, $color, $size, $price, $p_d); 78 $listData = BrandData::selectBrandDetail($gender, $brand, $sort, $color, $size, $price, $p_d);
169 // 处理返回的数据 79 // 处理返回的数据
170 - if (isset($listData['code']) && $listData['code'] == 200) { 80 + if (isset($listData['code']) && $listData['code'] === 200) {
171 $tmpData = $listData['data']; 81 $tmpData = $listData['data'];
  82 + // 设置品牌名称
  83 + $data['pageHeader']['navTitle'] = isset($tmpData['brand_name']) ? $tmpData['brand_name'] : '';
172 84
173 - $data['goodList'] = ListProcess::getListData($tmpData); 85 + $data['goodList'] += ListProcess::getListData($tmpData);
174 } 86 }
175 87
176 $this->_view->display('index', $data); 88 $this->_view->display('index', $data);