Showing
4 changed files
with
114 additions
and
95 deletions
@@ -15,57 +15,54 @@ use Api\Sign; | @@ -15,57 +15,54 @@ 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 新品到着焦点图有关数据 | ||
23 | - */ | ||
24 | - public static function getNewsaleFocus($contentCode) | ||
25 | - { | ||
26 | - // 构建必传参数 | ||
27 | - $param = Yohobuy::param(); | ||
28 | - | ||
29 | - $param['content_code'] = $contentCode; | ||
30 | - $param['client_secret'] = Sign::getSign($param); | ||
31 | - | ||
32 | - return Yohobuy::get(Yohobuy::SERVICE_URL.'operations/api/v5/resource/get', $param); | ||
33 | - } | ||
34 | - | ||
35 | - /** | ||
36 | - * 获取新品到着商品数据 | 21 | + * 封装新品到着、折扣专区页面的顶部焦点图和下部商品的数据 |
37 | * | 22 | * |
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 新品到着商品数据 | 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> | ||
43 | */ | 33 | */ |
44 | - public static function getNewProducts($gender, $channel, $limit = 50, $page = 1) | 34 | + public static function package($contentCode, $gender, $channel, $limit = 50, $page = 1) |
45 | { | 35 | { |
46 | - $param = Yohobuy::param(); | ||
47 | - $param['method'] = 'app.search.newProduct'; | ||
48 | - $param['gender'] = $gender; | ||
49 | - $param['page'] = $page; | ||
50 | - $param['limit'] = $limit; | ||
51 | - $param['yh_channel'] = $channel; | ||
52 | - | ||
53 | - // 构建url地址列表 | ||
54 | - $urlList = array(); | ||
55 | - $param['dayLimit'] = 1; | ||
56 | - $param['client_secret'] = Sign::getSign($param); | ||
57 | - $urlList['new'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | ||
58 | - $param['dayLimit'] = 2; | ||
59 | - unset($param['client_secret']); | ||
60 | - $param['client_secret'] = Sign::getSign($param); | ||
61 | - $urlList['week'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | ||
62 | - $param['dayLimit'] = 3; | ||
63 | - unset($param['client_secret']); | ||
64 | - $param['client_secret'] = Sign::getSign($param); | ||
65 | - $urlList['sale'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | ||
66 | - //var_dump($urlList);exit; | ||
67 | - | ||
68 | - return Yohobuy::getMulti($urlList); | 36 | + $urlList = array(); |
37 | + | ||
38 | + /* 顶部的轮翻广告数据 */ | ||
39 | + $param = Yohobuy::param(); | ||
40 | + $param['content_code'] = $contentCode; | ||
41 | + $param['client_secret'] = Sign::getSign($param); | ||
42 | + $urlList['newsaleTop'] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_NEWSALE_TOPPOS, $param); | ||
43 | + | ||
44 | + /* 产品列表数据 */ | ||
45 | + $param = Yohobuy::param(); | ||
46 | + $param['method'] = 'app.search.newProduct'; | ||
47 | + $param['gender'] = $gender; | ||
48 | + $param['page'] = $page; | ||
49 | + $param['limit'] = $limit; | ||
50 | + $param['yh_channel'] = $channel; | ||
51 | + | ||
52 | + // 构建url地址列表 | ||
53 | + $param['dayLimit'] = 1; | ||
54 | + $param['client_secret'] = Sign::getSign($param); | ||
55 | + $urlList['new'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | ||
56 | + $param['dayLimit'] = 2; | ||
57 | + unset($param['client_secret']); | ||
58 | + $param['client_secret'] = Sign::getSign($param); | ||
59 | + $urlList['week'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | ||
60 | + $param['dayLimit'] = 3; | ||
61 | + unset($param['client_secret']); | ||
62 | + $param['client_secret'] = Sign::getSign($param); | ||
63 | + $urlList['sale'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param); | ||
64 | + | ||
65 | + return Yohobuy::getMulti($urlList); | ||
69 | } | 66 | } |
70 | 67 | ||
71 | /** | 68 | /** |
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 | { |
11 | - | 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'; | ||
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 | + } | ||
24 | 59 | ||
25 | - foreach($products as $single) | 60 | + /* 顶部的轮翻广告列表 */ |
61 | + $result['headerBanner'] = self::bannerData($newsale['newsaleTop']); | ||
62 | + | ||
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']; |
103 | - $result['list'][] = $banner; | 125 | + |
126 | + if(count($single['data']) === 1) | ||
127 | + { | ||
128 | + $result = $banner; | ||
129 | + } | ||
130 | + else | ||
131 | + { | ||
132 | + $result['list'][] = $banner; | ||
133 | + } | ||
104 | } | 134 | } |
105 | } | 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