Showing
4 changed files
with
271 additions
and
28 deletions
@@ -18,7 +18,7 @@ class NewsaleData | @@ -18,7 +18,7 @@ class NewsaleData | ||
18 | const URI_NEWSALE_TOPPOS = 'operations/api/v5/resource/get'; | 18 | const URI_NEWSALE_TOPPOS = 'operations/api/v5/resource/get'; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | - * 封装新品到着、折扣专区页面的顶部焦点图和下部商品的数据 | 21 | + * 封装新品到着页面的顶部焦点图和下部商品的数据 |
22 | * | 22 | * |
23 | * @param string $contentCode 获取广告资源需要的位置码 | 23 | * @param string $contentCode 获取广告资源需要的位置码 |
24 | * @param string $gender 1,3表示男, 2,3表示女,1,2,3表示全部 | 24 | * @param string $gender 1,3表示男, 2,3表示女,1,2,3表示全部 |
@@ -31,7 +31,7 @@ class NewsaleData | @@ -31,7 +31,7 @@ class NewsaleData | ||
31 | * ) | 31 | * ) |
32 | * @author gtskk <rocky.zhang@yoho.cn> | 32 | * @author gtskk <rocky.zhang@yoho.cn> |
33 | */ | 33 | */ |
34 | - public static function package($contentCode, $gender, $channel, $limit = 50, $page = 1) | 34 | + public static function newPackage($contentCode, $gender, $channel, $limit = 50, $page = 1) |
35 | { | 35 | { |
36 | $urlList = array(); | 36 | $urlList = array(); |
37 | 37 | ||
@@ -65,6 +65,59 @@ class NewsaleData | @@ -65,6 +65,59 @@ class NewsaleData | ||
65 | return Yohobuy::getMulti($urlList); | 65 | return Yohobuy::getMulti($urlList); |
66 | } | 66 | } |
67 | 67 | ||
68 | + | ||
69 | + /** | ||
70 | + * 封装折扣专区页面的顶部焦点图和下部商品的数据 | ||
71 | + * | ||
72 | + * @param string $contentCode 获取广告资源需要的位置码 | ||
73 | + * @param string $gender 1,3表示男, 2,3表示女,1,2,3表示全部 | ||
74 | + * @param integer $channel 频道标识 1:男,2:女,3:潮童,4:创意生活 | ||
75 | + * @param integer $limit 查询返回的最大限制数, 默认为50 | ||
76 | + * @param integer $page 分页第几页, 默认第1页 | ||
77 | + * @return array( | ||
78 | + * "newsaleTop": "顶部的轮翻广告数据", | ||
79 | + * "newsaleList": "产品列表数据" | ||
80 | + * ) | ||
81 | + * @author gtskk <rocky.zhang@yoho.cn> | ||
82 | + */ | ||
83 | + public static function salePackage($contentCode, $gender, $channel, $limit = 50, $page = 1) | ||
84 | + { | ||
85 | + $urlList = array(); | ||
86 | + | ||
87 | + /* 顶部的轮翻广告数据 */ | ||
88 | + $param = Yohobuy::param(); | ||
89 | + $param['content_code'] = $contentCode; | ||
90 | + $param['client_secret'] = Sign::getSign($param); | ||
91 | + $urlList['newsaleTop'] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_NEWSALE_TOPPOS, $param); | ||
92 | + | ||
93 | + /* 产品列表数据 */ | ||
94 | + $param = Yohobuy::param(); | ||
95 | + $param['method'] = 'app.search.sales'; | ||
96 | + $param['gender'] = $gender; | ||
97 | + $param['page'] = $page; | ||
98 | + $param['limit'] = $limit; | ||
99 | + $param['yh_channel'] = $channel; | ||
100 | + | ||
101 | + // 构建url地址列表 | ||
102 | + $param['p_d'] = '0.1,0.3'; | ||
103 | + $param['client_secret'] = Sign::getSign($param); | ||
104 | + $urlList['1-3折'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | ||
105 | + $param['p_d'] = '0.4,0.6'; | ||
106 | + unset($param['client_secret']); | ||
107 | + $param['client_secret'] = Sign::getSign($param); | ||
108 | + $urlList['4-6折'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | ||
109 | + $param['p_d'] = '0.7,0.9'; | ||
110 | + unset($param['client_secret']); | ||
111 | + $param['client_secret'] = Sign::getSign($param); | ||
112 | + $urlList['7-9折'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | ||
113 | + $param['p_d'] = '0.1,0.9'; | ||
114 | + unset($param['client_secret']); | ||
115 | + $param['client_secret'] = Sign::getSign($param); | ||
116 | + $urlList['ALL'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | ||
117 | + | ||
118 | + return Yohobuy::getMulti($urlList); | ||
119 | + } | ||
120 | + | ||
68 | /** | 121 | /** |
69 | * 筛选新品到着、折扣专区商品 | 122 | * 筛选新品到着、折扣专区商品 |
70 | * | 123 | * |
@@ -159,11 +212,12 @@ class NewsaleData | @@ -159,11 +212,12 @@ class NewsaleData | ||
159 | * @param string price 价格 | 212 | * @param string price 价格 |
160 | * @param string $channel 1表示男, 2表示女 | 213 | * @param string $channel 1表示男, 2表示女 |
161 | * @param integer $p_d 折扣 | 214 | * @param integer $p_d 折扣 |
215 | + * @param integer $dayLimit查询天数的限制区间,默认为1 | ||
162 | * @param integer $limit 查询返回的最大限制数, 默认为50 | 216 | * @param integer $limit 查询返回的最大限制数, 默认为50 |
163 | * @param integer $page 分页第几页, 默认第1页 | 217 | * @param integer $page 分页第几页, 默认第1页 |
164 | * @return array 筛选出来的折扣专区商品 | 218 | * @return array 筛选出来的折扣专区商品 |
165 | */ | 219 | */ |
166 | - public static function selectSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $limit = 50, $page = 1) | 220 | + public static function selectSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit = 1, $limit = 50, $page = 1) |
167 | { | 221 | { |
168 | $selectItems = array( | 222 | $selectItems = array( |
169 | 'gender' => $gender, | 223 | 'gender' => $gender, |
@@ -181,6 +235,7 @@ class NewsaleData | @@ -181,6 +235,7 @@ class NewsaleData | ||
181 | $param['yh_channel'] = $channel; | 235 | $param['yh_channel'] = $channel; |
182 | $param['p_d'] = $p_d; | 236 | $param['p_d'] = $p_d; |
183 | $param['page'] = $page; | 237 | $param['page'] = $page; |
238 | + $param['dayLimit'] = $dayLimit; | ||
184 | $param['limit'] = $limit; | 239 | $param['limit'] = $limit; |
185 | $param = array_merge($param, $queriedParams); | 240 | $param = array_merge($param, $queriedParams); |
186 | 241 |
1 | +<?php | ||
2 | + | ||
3 | +namespace Plugin\DataProcess; | ||
4 | +use Plugin\Helpers; | ||
5 | + | ||
6 | +/** | ||
7 | + * 新品到着、折扣专区数据处理类 | ||
8 | + */ | ||
9 | +class NewSaleProcess | ||
10 | +{ | ||
11 | + | ||
12 | + /** | ||
13 | + * 处理新品到着、折扣专区数据 | ||
14 | + * | ||
15 | + * @param array $data 接口传回的数据 | ||
16 | + * @return array 处理之后的数据 | ||
17 | + */ | ||
18 | + public static function newSaleData($focus, $products) | ||
19 | + { | ||
20 | + $result = array( | ||
21 | + 'headerBanner' => self::bannerData($focus), | ||
22 | + 'goodsContainer' => array() | ||
23 | + ); | ||
24 | + | ||
25 | + foreach($products as $single) | ||
26 | + { | ||
27 | + // 处理Tabs | ||
28 | + $noTab = true; | ||
29 | + if(isset($single['tabs']) && $noTab) | ||
30 | + { | ||
31 | + $result['tabs'] = array(); | ||
32 | + foreach ($single['tabs'] as $key => $one) | ||
33 | + { | ||
34 | + $tabItem = array(); | ||
35 | + $tabItem['title'] = $one; | ||
36 | + if($key === 1) | ||
37 | + { | ||
38 | + $tabItem['focus'] = true; | ||
39 | + } | ||
40 | + $result['tabs'][] = $tabItem; | ||
41 | + } | ||
42 | + $noTab = false; | ||
43 | + } | ||
44 | + | ||
45 | + // 处理商品 | ||
46 | + $productsLi = array('goods'=>array()); | ||
47 | + if(isset($single['product_list'])) | ||
48 | + { | ||
49 | + foreach ($single['product_list'] as $value) | ||
50 | + { | ||
51 | + $productsLi['goods'][] = Helpers::formatProduct($value); | ||
52 | + } | ||
53 | + } | ||
54 | + | ||
55 | + // 对于第一个productsLi添加show字段 | ||
56 | + if(count($result['goodsContainer']) === 0) | ||
57 | + { | ||
58 | + $productsLi['show'] = true; | ||
59 | + } | ||
60 | + | ||
61 | + $result['goodsContainer'][] = $productsLi; | ||
62 | + } | ||
63 | + | ||
64 | + return $result; | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * 处理页面顶部焦点图数据 | ||
69 | + * | ||
70 | + * @param array $data 接口传回的焦点图数据 | ||
71 | + * @return array 处理之后的数据 | ||
72 | + */ | ||
73 | + private static function bannerData($data) | ||
74 | + { | ||
75 | + $result = array('list'=>array()); | ||
76 | + | ||
77 | + foreach ($data as $single) | ||
78 | + { | ||
79 | + foreach ($single['data'] as $one) | ||
80 | + { | ||
81 | + $banner = array(); | ||
82 | + $banner['img'] = Helpers::getImageUrl($one['src'], 750, 364, 1); | ||
83 | + $banner['url'] = $one['url']; | ||
84 | + $result['list'][] = $banner; | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + return $result; | ||
89 | + } | ||
90 | +} |
@@ -36,33 +36,108 @@ class NewsaleModel | @@ -36,33 +36,108 @@ class NewsaleModel | ||
36 | * @param int $channel boys表示男生频道, girls表示女生频道, kids表示潮童频道, lifestyle表示创意生活频道 | 36 | * @param int $channel boys表示男生频道, girls表示女生频道, kids表示潮童频道, lifestyle表示创意生活频道 |
37 | * @return array | 37 | * @return array |
38 | */ | 38 | */ |
39 | - public static function getNewsaleByChannel($channel) | 39 | + public static function getNewByChannel($channel) |
40 | { | 40 | { |
41 | $result = array(); | 41 | $result = array(); |
42 | - $newsale = array(); | 42 | + $new = array(); |
43 | 43 | ||
44 | /* 根据频道调用接口 */ | 44 | /* 根据频道调用接口 */ |
45 | - switch (intval($channel)) { | 45 | + switch ($channel) { |
46 | case 'boys': // 男生 | 46 | case 'boys': // 男生 |
47 | - $newsale = NewsaleData::package(self::CODE_TOP_NEW_BOYS, '1,3', 1); | 47 | + $new = NewsaleData::newPackage(self::CODE_TOP_NEW_BOYS, '1,3', 1); |
48 | break; | 48 | break; |
49 | case 'girls': // 女生 | 49 | case 'girls': // 女生 |
50 | - $newsale = NewsaleData::package(self::CODE_TOP_NEW_GIRLS, '2,3', 2); | 50 | + $new = NewsaleData::newPackage(self::CODE_TOP_NEW_GIRLS, '2,3', 2); |
51 | break; | 51 | break; |
52 | case 'kids': // 潮童 | 52 | case 'kids': // 潮童 |
53 | - $newsale = NewsaleData::package(self::CODE_TOP_NEW_KIDS, '1,2,3', 3); | 53 | + $new = NewsaleData::newPackage(self::CODE_TOP_NEW_KIDS, '1,2,3', 3); |
54 | break; | 54 | break; |
55 | case 'lifestyle': // 创意生活 | 55 | case 'lifestyle': // 创意生活 |
56 | - $newsale = NewsaleData::package(self::CODE_TOP_NEW_LIFESTYLE, '1,2,3', 4); | 56 | + $new = NewsaleData::newPackage(self::CODE_TOP_NEW_LIFESTYLE, '1,2,3', 4); |
57 | break; | 57 | break; |
58 | } | 58 | } |
59 | 59 | ||
60 | /* 顶部的轮翻广告列表 */ | 60 | /* 顶部的轮翻广告列表 */ |
61 | - $result['headerBanner'] = self::bannerData($newsale['newsaleTop']); | 61 | + $result['headerBanner'] = self::bannerData($new['newsaleTop']); |
62 | 62 | ||
63 | /* 下部商品列表 */ | 63 | /* 下部商品列表 */ |
64 | - unset($newsale['newsaleTop']); | ||
65 | - foreach($newsale as $single) | 64 | + unset($new['newsaleTop']); |
65 | + foreach($new as $single) | ||
66 | + { | ||
67 | + // 处理Tabs | ||
68 | + $noTab = true; | ||
69 | + if(isset($single['tabs']) && $noTab) | ||
70 | + { | ||
71 | + $result['tabs'] = array(); | ||
72 | + foreach ($single['tabs'] as $key => $one) | ||
73 | + { | ||
74 | + $tabItem = array(); | ||
75 | + $tabItem['title'] = $one; | ||
76 | + if($key === 1) | ||
77 | + { | ||
78 | + $tabItem['focus'] = true; | ||
79 | + } | ||
80 | + $result['tabs'][] = $tabItem; | ||
81 | + } | ||
82 | + $noTab = false; | ||
83 | + } | ||
84 | + | ||
85 | + // 处理商品 | ||
86 | + $productsLi = array('goods'=>array()); | ||
87 | + if(isset($single['product_list'])) | ||
88 | + { | ||
89 | + foreach ($single['product_list'] as $value) | ||
90 | + { | ||
91 | + $productsLi['goods'][] = Helpers::formatProduct($value); | ||
92 | + } | ||
93 | + } | ||
94 | + | ||
95 | + // 对于第一个productsLi添加show字段 | ||
96 | + if(!isset($result['goodsContainer'])) | ||
97 | + { | ||
98 | + $productsLi['show'] = true; | ||
99 | + } | ||
100 | + | ||
101 | + $result['goodsContainer'][] = $productsLi; | ||
102 | + } | ||
103 | + | ||
104 | + return $result; | ||
105 | + } | ||
106 | + | ||
107 | + | ||
108 | + /** | ||
109 | + * 根据频道获取折扣专区数据 | ||
110 | + * | ||
111 | + * @param int $channel boys表示男生频道, girls表示女生频道, kids表示潮童频道, lifestyle表示创意生活频道 | ||
112 | + * @return array | ||
113 | + */ | ||
114 | + public static function getSaleByChannel($channel) | ||
115 | + { | ||
116 | + $result = array(); | ||
117 | + $sale = array(); | ||
118 | + | ||
119 | + /* 根据频道调用接口 */ | ||
120 | + switch ($channel) { | ||
121 | + case 'boys': // 男生 | ||
122 | + $sale = NewsaleData::salePackage(self::CODE_TOP_SALE_BOYS, '1,3', 1); | ||
123 | + break; | ||
124 | + case 'girls': // 女生 | ||
125 | + $sale = NewsaleData::salePackage(self::CODE_TOP_SALE_GIRLS, '2,3', 2); | ||
126 | + break; | ||
127 | + case 'kids': // 潮童 | ||
128 | + $sale = NewsaleData::salePackage(self::CODE_TOP_SALE_KIDS, '1,2,3', 3); | ||
129 | + break; | ||
130 | + case 'lifestyle': // 创意生活 | ||
131 | + $sale = NewsaleData::salePackage(self::CODE_TOP_SALE_LIFESTYLE, '1,2,3', 4); | ||
132 | + break; | ||
133 | + } | ||
134 | + | ||
135 | + /* 顶部的轮翻广告列表 */ | ||
136 | + $result['headerBanner'] = self::bannerData($sale['newsaleTop']); | ||
137 | + | ||
138 | + /* 下部商品列表 */ | ||
139 | + unset($sale['newsaleTop']); | ||
140 | + foreach($sale as $single) | ||
66 | { | 141 | { |
67 | // 处理Tabs | 142 | // 处理Tabs |
68 | $noTab = true; | 143 | $noTab = true; |
@@ -137,4 +212,37 @@ class NewsaleModel | @@ -137,4 +212,37 @@ class NewsaleModel | ||
137 | return $result; | 212 | return $result; |
138 | } | 213 | } |
139 | 214 | ||
215 | + | ||
216 | + /** | ||
217 | + * 筛选出来的商品数据处理 | ||
218 | + * | ||
219 | + * @param string gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 | ||
220 | + * @param integer brand 品牌Id | ||
221 | + * @param integer sort 品类Id | ||
222 | + * @param integer color 颜色Id | ||
223 | + * @param integer size 尺码Id | ||
224 | + * @param string price 价格 | ||
225 | + * @param string $channel 1表示男, 2表示女 | ||
226 | + * @param integer $p_d 折扣 | ||
227 | + * @param integer $dayLimit查询天数的限制区间,默认为1 | ||
228 | + * @param integer $limit 查询返回的最大限制数, 默认为50 | ||
229 | + * @param integer $page 分页第几页, 默认第1页 | ||
230 | + * @return array 处理之后的筛选数据 | ||
231 | + */ | ||
232 | + public static function selectData($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit = 1, $limit = 50, $page = 1) | ||
233 | + { | ||
234 | + $data = NewsaleData::selectNewSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page); | ||
235 | + | ||
236 | + $result = array(); | ||
237 | + | ||
238 | + if($data['code'] === 200) | ||
239 | + { | ||
240 | + foreach ($data['data']['product_list'] as $val) { | ||
241 | + $result['goods'][] = Helpers::formatProduct($val); | ||
242 | + } | ||
243 | + } | ||
244 | + | ||
245 | + return $result; | ||
246 | + } | ||
247 | + | ||
140 | } | 248 | } |
@@ -25,7 +25,7 @@ class NewsaleController extends AbstractAction | @@ -25,7 +25,7 @@ class NewsaleController extends AbstractAction | ||
25 | 25 | ||
26 | $channel = $this->getCookie('_Channel', 'boys'); | 26 | $channel = $this->getCookie('_Channel', 'boys'); |
27 | // 添加商品数据 | 27 | // 添加商品数据 |
28 | - $data += NewsaleModel::getNewsaleByChannel($channel); | 28 | + $data += NewsaleModel::getNewByChannel($channel); |
29 | 29 | ||
30 | $this->_view->display('new', $data); | 30 | $this->_view->display('new', $data); |
31 | } | 31 | } |
@@ -50,9 +50,7 @@ class NewsaleController extends AbstractAction | @@ -50,9 +50,7 @@ class NewsaleController extends AbstractAction | ||
50 | $limit = $this->get('limit', 50); | 50 | $limit = $this->get('limit', 50); |
51 | $page = $this->get('page', 1); | 51 | $page = $this->get('page', 1); |
52 | 52 | ||
53 | - $data = NewsaleData::selectNewSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page); | ||
54 | - | ||
55 | - $result = NewSaleProcess::selectData($data); | 53 | + $result = NewsaleModel::selectData($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page); |
56 | 54 | ||
57 | $this->_view->display('product', $result); | 55 | $this->_view->display('product', $result); |
58 | } | 56 | } |
@@ -74,16 +72,10 @@ class NewsaleController extends AbstractAction | @@ -74,16 +72,10 @@ class NewsaleController extends AbstractAction | ||
74 | ) | 72 | ) |
75 | ); | 73 | ); |
76 | 74 | ||
77 | - // 折扣专区顶部焦点图 | ||
78 | - $focusData = NewsaleData::getNewsaleFocus('e9c9be32d72e2906d404a72ee24cb523'); | ||
79 | - // 处理返回的数据 | ||
80 | - $focus = array(); | ||
81 | - if (isset($focusData['code']) && $focusData['code'] == 200) { | ||
82 | - $focus = $focusData['data']; | ||
83 | - } | 75 | + $channel = $this->getCookie('_Channel', 'boys'); |
76 | + // 添加商品数据 | ||
77 | + $data += NewsaleModel::getSaleByChannel($channel); | ||
84 | 78 | ||
85 | - // 折扣专区商品数据 | ||
86 | - $products = NewsaleData::getSaleProducts('1,3', 1); | ||
87 | // 更新tabs | 79 | // 更新tabs |
88 | $tabs = array(); | 80 | $tabs = array(); |
89 | foreach (array_keys($products) as $key => $value) { | 81 | foreach (array_keys($products) as $key => $value) { |
@@ -95,8 +87,6 @@ class NewsaleController extends AbstractAction | @@ -95,8 +87,6 @@ class NewsaleController extends AbstractAction | ||
95 | $tabs[] = $tabItem; | 87 | $tabs[] = $tabItem; |
96 | } | 88 | } |
97 | $data['tabs'] = $tabs; | 89 | $data['tabs'] = $tabs; |
98 | - // 添加商品数据 | ||
99 | - $data += NewSaleProcess::newSaleData($focus, $products); | ||
100 | 90 | ||
101 | /* echo '<pre>'; | 91 | /* echo '<pre>'; |
102 | print_r($data);exit; */ | 92 | print_r($data);exit; */ |
-
Please register or login to post a comment