Showing
4 changed files
with
88 additions
and
69 deletions
@@ -15,34 +15,33 @@ use Api\Sign; | @@ -15,34 +15,33 @@ use Api\Sign; | ||
15 | */ | 15 | */ |
16 | class NewsaleData | 16 | class NewsaleData |
17 | { | 17 | { |
18 | + const URI_NEWSALE_TOPPOS = 'operations/api/v5/resource/get'; | ||
18 | 19 | ||
19 | /** | 20 | /** |
20 | - * 获取新品到着,折扣专区焦点图数据 | ||
21 | - * @param string $contentCode 内容位置码 | ||
22 | - * @return array 新品到着焦点图有关数据 | 21 | + * 封装新品到着、折扣专区页面的顶部焦点图和下部商品的数据 |
22 | + * | ||
23 | + * @param string $contentCode 获取广告资源需要的位置码 | ||
24 | + * @param string $gender 1,3表示男, 2,3表示女,1,2,3表示全部 | ||
25 | + * @param integer $channel 频道标识 1:男,2:女,3:潮童,4:创意生活 | ||
26 | + * @param integer $limit 查询返回的最大限制数, 默认为50 | ||
27 | + * @param integer $page 分页第几页, 默认第1页 | ||
28 | + * @return array( | ||
29 | + * "newsaleTop": "顶部的轮翻广告数据", | ||
30 | + * "newsaleList": "产品列表数据" | ||
31 | + * ) | ||
32 | + * @author gtskk <rocky.zhang@yoho.cn> | ||
23 | */ | 33 | */ |
24 | - public static function getNewsaleFocus($contentCode) | 34 | + public static function package($contentCode, $gender, $channel, $limit = 50, $page = 1) |
25 | { | 35 | { |
26 | - // 构建必传参数 | ||
27 | - $param = Yohobuy::param(); | 36 | + $urlList = array(); |
28 | 37 | ||
38 | + /* 顶部的轮翻广告数据 */ | ||
39 | + $param = Yohobuy::param(); | ||
29 | $param['content_code'] = $contentCode; | 40 | $param['content_code'] = $contentCode; |
30 | $param['client_secret'] = Sign::getSign($param); | 41 | $param['client_secret'] = Sign::getSign($param); |
42 | + $urlList['newsaleTop'] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_NEWSALE_TOPPOS, $param); | ||
31 | 43 | ||
32 | - return Yohobuy::get(Yohobuy::SERVICE_URL.'operations/api/v5/resource/get', $param); | ||
33 | - } | ||
34 | - | ||
35 | - /** | ||
36 | - * 获取新品到着商品数据 | ||
37 | - * | ||
38 | - * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部 | ||
39 | - * @param string $channel 1表示男, 2表示女 | ||
40 | - * @param integer $limit 查询返回的最大限制数, 默认为50 | ||
41 | - * @param integer $page 分页第几页, 默认第1页 | ||
42 | - * @return array 新品到着商品数据 | ||
43 | - */ | ||
44 | - public static function getNewProducts($gender, $channel, $limit = 50, $page = 1) | ||
45 | - { | 44 | + /* 产品列表数据 */ |
46 | $param = Yohobuy::param(); | 45 | $param = Yohobuy::param(); |
47 | $param['method'] = 'app.search.newProduct'; | 46 | $param['method'] = 'app.search.newProduct'; |
48 | $param['gender'] = $gender; | 47 | $param['gender'] = $gender; |
@@ -51,7 +50,6 @@ class NewsaleData | @@ -51,7 +50,6 @@ class NewsaleData | ||
51 | $param['yh_channel'] = $channel; | 50 | $param['yh_channel'] = $channel; |
52 | 51 | ||
53 | // 构建url地址列表 | 52 | // 构建url地址列表 |
54 | - $urlList = array(); | ||
55 | $param['dayLimit'] = 1; | 53 | $param['dayLimit'] = 1; |
56 | $param['client_secret'] = Sign::getSign($param); | 54 | $param['client_secret'] = Sign::getSign($param); |
57 | $urlList['new'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | 55 | $urlList['new'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); |
@@ -63,7 +61,6 @@ class NewsaleData | @@ -63,7 +61,6 @@ class NewsaleData | ||
63 | unset($param['client_secret']); | 61 | unset($param['client_secret']); |
64 | $param['client_secret'] = Sign::getSign($param); | 62 | $param['client_secret'] = Sign::getSign($param); |
65 | $urlList['sale'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | 63 | $urlList['sale'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); |
66 | - //var_dump($urlList);exit; | ||
67 | 64 | ||
68 | return Yohobuy::getMulti($urlList); | 65 | return Yohobuy::getMulti($urlList); |
69 | } | 66 | } |
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | -namespace Plugin\DataProcess; | 3 | +namespace Product; |
4 | + | ||
5 | +use LibModels\Wap\Product\NewsaleData; | ||
6 | +use Configs\CacheConfig; | ||
4 | use Plugin\Helpers; | 7 | use Plugin\Helpers; |
5 | 8 | ||
6 | /** | 9 | /** |
7 | - * 新品到着、折扣专区数据处理类 | 10 | + * 新品到着、折扣专区相关的模板数据模型 |
11 | + * | ||
12 | + * @name NewsaleModel | ||
13 | + * @package Models/Category | ||
14 | + * @copyright yoho.inc | ||
15 | + * @version 1.0 (2015-10-22 19:52:44) | ||
16 | + * @author gtskk <rocky.zhang@yoho.cn> | ||
8 | */ | 17 | */ |
9 | -class NewSaleProcess | 18 | +class NewsaleModel |
10 | { | 19 | { |
20 | + /* 男生频道取新品到着及折扣专区数据的位置码 */ | ||
21 | + const CODE_TOP_NEW_BOYS = 'a7989369aa86681c678bc40f171b8f1d'; | ||
22 | + const CODE_TOP_SALE_BOYS = 'e9c9be32d72e2906d404a72ee24cb523'; | ||
23 | + /* 女生频道取新品到着及折扣专区数据的位置码 */ | ||
24 | + const CODE_TOP_NEW_GIRLS = 'b0ba12104cfecacdcfd7ad74117a22b8'; | ||
25 | + const CODE_TOP_SALE_GIRLS = '785c0e6aab746949073c4ffb9d5106ac'; | ||
26 | + /* 潮童频道取新品到着及折扣专区数据的位置码 */ | ||
27 | + const CODE_TOP_NEW_KIDS = 'c39607aa21219117976848819cf81a69'; | ||
28 | + const CODE_TOP_SALE_KIDS = 'ad1bb67a6007819c86f737d74172fd2e'; | ||
29 | + /* 创意生活频道取新品到着及折扣专区数据的位置码 */ | ||
30 | + const CODE_TOP_NEW_LIFESTYLE = '7c9ae01071f7a75d3911782feb4caebd'; | ||
31 | + const CODE_TOP_SALE_LIFESTYLE = '8132c7db3adbeb7b0d0002de9691c753'; | ||
11 | 32 | ||
12 | /** | 33 | /** |
13 | - * 处理新品到着、折扣专区数据 | 34 | + * 根据频道获取新品到着数据 |
14 | * | 35 | * |
15 | - * @param array $data 接口传回的数据 | ||
16 | - * @return array 处理之后的数据 | 36 | + * @param int $channel boys表示男生频道, girls表示女生频道, kids表示潮童频道, lifestyle表示创意生活频道 |
37 | + * @return array | ||
17 | */ | 38 | */ |
18 | - public static function newSaleData($focus, $products) | 39 | + public static function getNewsaleByChannel($channel) |
19 | { | 40 | { |
20 | - $result = array( | ||
21 | - 'headerBanner' => self::bannerData($focus), | ||
22 | - 'goodsContainer' => array() | ||
23 | - ); | 41 | + $result = array(); |
42 | + $newsale = array(); | ||
43 | + | ||
44 | + /* 根据频道调用接口 */ | ||
45 | + switch (intval($channel)) { | ||
46 | + case 'boys': // 男生 | ||
47 | + $newsale = NewsaleData::package(self::CODE_TOP_NEW_BOYS, '1,3', 1); | ||
48 | + break; | ||
49 | + case 'girls': // 女生 | ||
50 | + $newsale = NewsaleData::package(self::CODE_TOP_NEW_GIRLS, '2,3', 2); | ||
51 | + break; | ||
52 | + case 'kids': // 潮童 | ||
53 | + $newsale = NewsaleData::package(self::CODE_TOP_NEW_KIDS, '1,2,3', 3); | ||
54 | + break; | ||
55 | + case 'lifestyle': // 创意生活 | ||
56 | + $newsale = NewsaleData::package(self::CODE_TOP_NEW_LIFESTYLE, '1,2,3', 4); | ||
57 | + break; | ||
58 | + } | ||
59 | + | ||
60 | + /* 顶部的轮翻广告列表 */ | ||
61 | + $result['headerBanner'] = self::bannerData($newsale['newsaleTop']); | ||
24 | 62 | ||
25 | - foreach($products as $single) | 63 | + /* 下部商品列表 */ |
64 | + unset($newsale['newsaleTop']); | ||
65 | + foreach($newsale as $single) | ||
26 | { | 66 | { |
27 | // 处理Tabs | 67 | // 处理Tabs |
28 | $noTab = true; | 68 | $noTab = true; |
@@ -53,7 +93,7 @@ class NewSaleProcess | @@ -53,7 +93,7 @@ class NewSaleProcess | ||
53 | } | 93 | } |
54 | 94 | ||
55 | // 对于第一个productsLi添加show字段 | 95 | // 对于第一个productsLi添加show字段 |
56 | - if(count($result['goodsContainer']) === 0) | 96 | + if(!isset($result['goodsContainer'])) |
57 | { | 97 | { |
58 | $productsLi['show'] = true; | 98 | $productsLi['show'] = true; |
59 | } | 99 | } |
@@ -64,24 +104,6 @@ class NewSaleProcess | @@ -64,24 +104,6 @@ class NewSaleProcess | ||
64 | return $result; | 104 | return $result; |
65 | } | 105 | } |
66 | 106 | ||
67 | - /** | ||
68 | - * 筛选出来的商品数据处理 | ||
69 | - * | ||
70 | - * @param array $data 筛选出来的原数据 | ||
71 | - * @return array 处理之后的数据 | ||
72 | - */ | ||
73 | - public static function selectData($data) | ||
74 | - { | ||
75 | - $result = array('goods'=>array()); | ||
76 | - if($data['code'] === 200) | ||
77 | - { | ||
78 | - foreach ($data['data']['product_list'] as $val) { | ||
79 | - $result['goods'][] = Helpers::formatProduct($val); | ||
80 | - } | ||
81 | - } | ||
82 | - | ||
83 | - return $result; | ||
84 | - } | ||
85 | 107 | ||
86 | /** | 108 | /** |
87 | * 处理页面顶部焦点图数据 | 109 | * 处理页面顶部焦点图数据 |
@@ -91,19 +113,28 @@ class NewSaleProcess | @@ -91,19 +113,28 @@ class NewSaleProcess | ||
91 | */ | 113 | */ |
92 | private static function bannerData($data) | 114 | private static function bannerData($data) |
93 | { | 115 | { |
94 | - $result = array('list'=>array()); | 116 | + $result = array(); |
95 | 117 | ||
96 | foreach ($data as $single) | 118 | foreach ($data as $single) |
97 | { | 119 | { |
98 | foreach ($single['data'] as $one) | 120 | foreach ($single['data'] as $one) |
99 | { | 121 | { |
100 | $banner = array(); | 122 | $banner = array(); |
101 | - $banner['img'] = Helpers::getImageUrl($one['src'], 750, 364, 1); | 123 | + $banner['img'] = Helpers::getImageUrl($one['src'], 640, 240, 1); |
102 | $banner['url'] = $one['url']; | 124 | $banner['url'] = $one['url']; |
125 | + | ||
126 | + if(count($single['data']) === 1) | ||
127 | + { | ||
128 | + $result = $banner; | ||
129 | + } | ||
130 | + else | ||
131 | + { | ||
103 | $result['list'][] = $banner; | 132 | $result['list'][] = $banner; |
104 | } | 133 | } |
105 | } | 134 | } |
135 | + } | ||
106 | 136 | ||
107 | return $result; | 137 | return $result; |
108 | } | 138 | } |
139 | + | ||
109 | } | 140 | } |
@@ -180,7 +180,7 @@ class ListController extends AbstractAction | @@ -180,7 +180,7 @@ class ListController extends AbstractAction | ||
180 | ), | 180 | ), |
181 | 'brand' => $brand, | 181 | 'brand' => $brand, |
182 | 'msort' => 0, | 182 | 'msort' => 0, |
183 | - 'gender' => $this->getCookie('_Channel', '1,2'), | 183 | + 'gender' => $this->getCookie('_Channel', '1,3'), |
184 | 'sort' => 0, | 184 | 'sort' => 0, |
185 | 'price' => 0, | 185 | 'price' => 0, |
186 | 'size' => 0, | 186 | 'size' => 0, |
@@ -241,7 +241,7 @@ class ListController extends AbstractAction | @@ -241,7 +241,7 @@ class ListController extends AbstractAction | ||
241 | 'goodList' => array( | 241 | 'goodList' => array( |
242 | 'brand' => 0, | 242 | 'brand' => 0, |
243 | 'msort' => 0, | 243 | 'msort' => 0, |
244 | - 'gender' => $this->getCookie('_Channel', '1,2'), | 244 | + 'gender' => $this->getCookie('_Channel', '1,3'), |
245 | 'sort' => $sort, | 245 | 'sort' => $sort, |
246 | 'price' => 0, | 246 | 'price' => 0, |
247 | 'size' => 0, | 247 | 'size' => 0, |
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | use Action\AbstractAction; | 3 | use Action\AbstractAction; |
4 | use LibModels\Wap\Product\NewsaleData; | 4 | use LibModels\Wap\Product\NewsaleData; |
5 | -use Plugin\DataProcess\NewSaleProcess; | 5 | +use Product\NewsaleModel; |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * 新品到着 | 8 | * 新品到着 |
@@ -23,18 +23,9 @@ class NewsaleController extends AbstractAction | @@ -23,18 +23,9 @@ class NewsaleController extends AbstractAction | ||
23 | ) | 23 | ) |
24 | ); | 24 | ); |
25 | 25 | ||
26 | - // 新品到着顶部焦点图 | ||
27 | - $focusData = NewsaleData::getNewsaleFocus('a7989369aa86681c678bc40f171b8f1d'); | ||
28 | - // 处理返回的数据 | ||
29 | - $focus = array(); | ||
30 | - if (isset($focusData['code']) && $focusData['code'] == 200) { | ||
31 | - $focus = $focusData['data']; | ||
32 | - } | ||
33 | - | ||
34 | - // 批量获取新品到着商品数据 | ||
35 | - $products = NewsaleData::getNewProducts('1,3', 1, 60); | 26 | + $channel = $this->getCookie('_Channel', 'boys'); |
36 | // 添加商品数据 | 27 | // 添加商品数据 |
37 | - $data += NewSaleProcess::newSaleData($focus, $products); | 28 | + $data += NewsaleModel::getNewsaleByChannel($channel); |
38 | 29 | ||
39 | $this->_view->display('new', $data); | 30 | $this->_view->display('new', $data); |
40 | } | 31 | } |
-
Please register or login to post a comment