Authored by hf

code review by fei.hong: do format new arrival codes

1 <?php 1 <?php
  2 +
2 namespace WebPlugin\DataProcess; 3 namespace WebPlugin\DataProcess;
3 4
4 class Channel 5 class Channel
@@ -13,7 +14,7 @@ class Channel @@ -13,7 +14,7 @@ class Channel
13 14
14 public static function getFormat($channel, $data) 15 public static function getFormat($channel, $data)
15 { 16 {
16 - if(empty($data)) { 17 + if (empty($data)) {
17 return array(); 18 return array();
18 } 19 }
19 // 通用处理器 20 // 通用处理器
@@ -28,4 +29,5 @@ class Channel @@ -28,4 +29,5 @@ class Channel
28 ksort($result); 29 ksort($result);
29 return array_values($result); 30 return array_values($result);
30 } 31 }
  32 +
31 } 33 }
1 <?php 1 <?php
  2 +
2 namespace WebPlugin\DataProcess\Channel; 3 namespace WebPlugin\DataProcess\Channel;
  4 +
3 abstract class AbstractChannel 5 abstract class AbstractChannel
4 { 6 {
5 - /*** 7 + /* * *
6 * 处理数据 8 * 处理数据
7 * @param array $resource 9 * @param array $resource
8 * @return array[以key方式存储数据] 10 * @return array[以key方式存储数据]
9 */ 11 */
10 - public static function format($resource){}  
11 - 12 +
  13 + public static function format($resource)
  14 + {
  15 +
  16 + }
  17 +
12 /** 18 /**
13 * 获取格式化最新上架数据 19 * 获取格式化最新上架数据
14 * 20 *
@@ -18,20 +24,16 @@ abstract class AbstractChannel @@ -18,20 +24,16 @@ abstract class AbstractChannel
18 public static function getFormatNewArrivals(&$resource) 24 public static function getFormatNewArrivals(&$resource)
19 { 25 {
20 $result = array(); 26 $result = array();
21 - foreach($resource as $key => $val)  
22 - {  
23 - if(isset($resource[$key]) && isset($resource[$key + 2]))  
24 - { 27 + foreach ($resource as $key => $val) {
  28 + if (isset($resource[$key]) && isset($resource[$key + 2])) {
25 $temp = array('newArrivls' => array('name' => '', 'navs' => array()), 'href' => ''); 29 $temp = array('newArrivls' => array('name' => '', 'navs' => array()), 'href' => '');
26 //newArrivals 30 //newArrivals
27 - if($resource[$key]['template_name'] == 'text' && $resource[$key + 1]['template_name'] == 'textNav')  
28 - { 31 + if ($resource[$key]['template_name'] == 'text' && $resource[$key + 1]['template_name'] == 'textNav') {
29 //text模版 32 //text模版
30 $temp['newArrivls']['name'] = $resource[$key]['data']['text']; 33 $temp['newArrivls']['name'] = $resource[$key]['data']['text'];
31 //textNav模版 34 //textNav模版
32 - foreach($resource[$key + 1]['data'] as $val)  
33 - {  
34 - $temp['newArrivls']['navs'][] = array('href' => $val['url'],'name' => $val['name']); 35 + foreach ($resource[$key + 1]['data'] as $val) {
  36 + $temp['newArrivls']['navs'][] = array('href' => $val['url'], 'name' => $val['name']);
35 } 37 }
36 //link模版 38 //link模版
37 $temp['href'] = $resource[$key + 2]['data'][0]['url']; 39 $temp['href'] = $resource[$key + 2]['data'][0]['url'];
@@ -42,4 +44,5 @@ abstract class AbstractChannel @@ -42,4 +44,5 @@ abstract class AbstractChannel
42 } 44 }
43 return $result; 45 return $result;
44 } 46 }
45 -}  
  47 +
  48 +}
1 <?php 1 <?php
  2 +
2 namespace WebPlugin\DataProcess\Channel; 3 namespace WebPlugin\DataProcess\Channel;
  4 +
3 class Boys extends AbstractChannel 5 class Boys extends AbstractChannel
4 { 6 {
  7 +
5 /** 8 /**
6 * 格式化数据 9 * 格式化数据
7 * 10 *
@@ -13,4 +16,5 @@ class Boys extends AbstractChannel @@ -13,4 +16,5 @@ class Boys extends AbstractChannel
13 $result = self::getFormatNewArrivals($resource); 16 $result = self::getFormatNewArrivals($resource);
14 return $result; 17 return $result;
15 } 18 }
16 -}  
  19 +
  20 +}
1 <?php 1 <?php
  2 +
2 namespace WebPlugin\DataProcess\Channel; 3 namespace WebPlugin\DataProcess\Channel;
  4 +
3 class Girls extends AbstractChannel 5 class Girls extends AbstractChannel
4 { 6 {
  7 +
5 public static function format($resource) 8 public static function format($resource)
6 { 9 {
7 $result = array(); 10 $result = array();
8 $result += self::getFormatNewArrivals($resource); 11 $result += self::getFormatNewArrivals($resource);
9 - foreach($resource as $key => $val)//老版是title模版  
10 - {  
11 - if(isset($resource[$key]) && isset($resource[$key + 2]))  
12 - { 12 + foreach ($resource as $key => $val) {//老版是title模版
  13 + if (isset($resource[$key]) && isset($resource[$key + 2])) {
13 $temp = array('newArrivls' => array('name' => '', 'navs' => array(), 'href' => '')); 14 $temp = array('newArrivls' => array('name' => '', 'navs' => array(), 'href' => ''));
14 - if($resource[$key]['template_name'] == 'text' &&  
15 - $resource[$key + 1]['template_name'] == 'title' && //老版是title模版  
16 - $resource[$key + 2]['template_name'] == 'link'  
17 - )  
18 - { 15 + if ($resource[$key]['template_name'] == 'text' &&
  16 + $resource[$key + 1]['template_name'] == 'title' && //老版是title模版
  17 + $resource[$key + 2]['template_name'] == 'link'
  18 + ) {
19 //text模版 19 //text模版
20 $temp['newArrivls']['name'] = $resource[$key]['data']['text']; 20 $temp['newArrivls']['name'] = $resource[$key]['data']['text'];
21 //title模版 21 //title模版
22 - foreach($resource[$key + 1]['data']['nav'] as $val)  
23 - {  
24 - $temp['newArrivls']['navs'][] = array('href' => $val['url'],'name' => $val['name']); 22 + foreach ($resource[$key + 1]['data']['nav'] as $val) {
  23 + $temp['newArrivls']['navs'][] = array('href' => $val['url'], 'name' => $val['name']);
25 } 24 }
26 $link = $resource[$key + 2]['data'][0]; 25 $link = $resource[$key + 2]['data'][0];
27 - $temp['newArrivls']['href'] = $link['url']; 26 + $temp['newArrivls']['href'] = $link['url'];
28 unset($resource[$key], $resource[$key + 1]); 27 unset($resource[$key], $resource[$key + 1]);
29 $result[$key] = $temp; 28 $result[$key] = $temp;
30 } 29 }
@@ -32,4 +31,5 @@ class Girls extends AbstractChannel @@ -32,4 +31,5 @@ class Girls extends AbstractChannel
32 } 31 }
33 return $result; 32 return $result;
34 } 33 }
  34 +
35 } 35 }
1 <?php 1 <?php
  2 +
2 namespace WebPlugin\DataProcess\Channel; 3 namespace WebPlugin\DataProcess\Channel;
  4 +
3 class Kids extends AbstractChannel 5 class Kids extends AbstractChannel
4 { 6 {
  7 +
5 /** 8 /**
6 * 格式化数据 9 * 格式化数据
7 * 10 *
@@ -12,20 +15,16 @@ class Kids extends AbstractChannel @@ -12,20 +15,16 @@ class Kids extends AbstractChannel
12 { 15 {
13 $result = array(); 16 $result = array();
14 $result += self::getFormatNewArrivals($resource); 17 $result += self::getFormatNewArrivals($resource);
15 - foreach($resource as $key => $val)//老版处理  
16 - {  
17 - if(isset($resource[$key]) && isset($resource[$key + 1]))  
18 - { 18 + foreach ($resource as $key => $val) {//老版处理
  19 + if (isset($resource[$key]) && isset($resource[$key + 1])) {
19 $temp = array('newArrivls' => array('name' => '', 'navs' => array())); 20 $temp = array('newArrivls' => array('name' => '', 'navs' => array()));
20 //newArrivals 21 //newArrivals
21 - if($resource[$key]['template_name'] == 'text' && $resource[$key + 1]['template_name'] == 'textNav')  
22 - { 22 + if ($resource[$key]['template_name'] == 'text' && $resource[$key + 1]['template_name'] == 'textNav') {
23 //text模版 23 //text模版
24 $temp['newArrivls']['name'] = $resource[$key]['data']['text']; 24 $temp['newArrivls']['name'] = $resource[$key]['data']['text'];
25 //textNav模版 25 //textNav模版
26 - foreach($resource[$key + 1]['data'] as $val)  
27 - {  
28 - $temp['newArrivls']['navs'][] = array('href' => $val['url'],'name' => $val['name']); 26 + foreach ($resource[$key + 1]['data'] as $val) {
  27 + $temp['newArrivls']['navs'][] = array('href' => $val['url'], 'name' => $val['name']);
29 } 28 }
30 unset($resource[$key], $resource[$key + 1]); 29 unset($resource[$key], $resource[$key + 1]);
31 $result[$key] = $temp; 30 $result[$key] = $temp;
@@ -35,5 +34,4 @@ class Kids extends AbstractChannel @@ -35,5 +34,4 @@ class Kids extends AbstractChannel
35 return $result; 34 return $result;
36 } 35 }
37 36
38 -  
39 -}  
  37 +}
1 <?php 1 <?php
  2 +
2 namespace WebPlugin\DataProcess\Channel; 3 namespace WebPlugin\DataProcess\Channel;
  4 +
3 class Lifestyle extends AbstractChannel 5 class Lifestyle extends AbstractChannel
4 { 6 {
  7 +
5 /** 8 /**
6 * 格式化数据 9 * 格式化数据
7 * 10 *
@@ -12,20 +15,16 @@ class Lifestyle extends AbstractChannel @@ -12,20 +15,16 @@ class Lifestyle extends AbstractChannel
12 { 15 {
13 $result = array(); 16 $result = array();
14 $result += self::getFormatNewArrivals($resource); 17 $result += self::getFormatNewArrivals($resource);
15 - foreach($resource as $key => $val)//老版处理  
16 - {  
17 - if(isset($resource[$key]) && isset($resource[$key + 1]))  
18 - { 18 + foreach ($resource as $key => $val) {//老版处理
  19 + if (isset($resource[$key]) && isset($resource[$key + 1])) {
19 $temp = array('newArrivls' => array('name' => '', 'navs' => array())); 20 $temp = array('newArrivls' => array('name' => '', 'navs' => array()));
20 //newArrivals 21 //newArrivals
21 - if($resource[$key]['template_name'] == 'textNav' && $resource[$key + 1]['template_name'] == 'link')  
22 - { 22 + if ($resource[$key]['template_name'] == 'textNav' && $resource[$key + 1]['template_name'] == 'link') {
23 //text模版 23 //text模版
24 $temp['newArrivls']['name'] = '最新上架 NEW ARRIVALS'; 24 $temp['newArrivls']['name'] = '最新上架 NEW ARRIVALS';
25 //textNav模版 25 //textNav模版
26 - foreach($resource[$key]['data'] as $val)  
27 - {  
28 - $temp['newArrivls']['navs'][] = array('href' => $val['url'],'name' => $val['name']); 26 + foreach ($resource[$key]['data'] as $val) {
  27 + $temp['newArrivls']['navs'][] = array('href' => $val['url'], 'name' => $val['name']);
29 } 28 }
30 unset($resource[$key], $resource[$key + 1]); 29 unset($resource[$key], $resource[$key + 1]);
31 $result[$key] = $temp; 30 $result[$key] = $temp;
@@ -34,4 +33,5 @@ class Lifestyle extends AbstractChannel @@ -34,4 +33,5 @@ class Lifestyle extends AbstractChannel
34 } 33 }
35 return $result; 34 return $result;
36 } 35 }
37 -}  
  36 +
  37 +}
1 <?php 1 <?php
  2 +
2 namespace WebPlugin\DataProcess; 3 namespace WebPlugin\DataProcess;
3 4
4 use WebPlugin\Images; 5 use WebPlugin\Images;
@@ -12,6 +13,7 @@ use LibModels\Web\Product\SearchData; @@ -12,6 +13,7 @@ use LibModels\Web\Product\SearchData;
12 */ 13 */
13 class Process 14 class Process
14 { 15 {
  16 +
15 /** 17 /**
16 * 18 *
17 * @param array $data 19 * @param array $data
@@ -21,15 +23,16 @@ class Process @@ -21,15 +23,16 @@ class Process
21 { 23 {
22 // 组合处理数据 24 // 组合处理数据
23 $result = self::mergeProcess($data, $type); 25 $result = self::mergeProcess($data, $type);
  26 + $build = array();
24 foreach ($data as $key => $val) { 27 foreach ($data as $key => $val) {
25 $fun = $val['template_name']; 28 $fun = $val['template_name'];
26 - if (empty($val['data']) || ! is_callable("self::$fun")) { 29 + if (empty($val['data']) || !is_callable("self::$fun")) {
27 continue; 30 continue;
28 } 31 }
29 - 32 +
30 // 单个处理数据 33 // 单个处理数据
31 $build = self::$fun($val, $type); 34 $build = self::$fun($val, $type);
32 - if (! empty($build)) { 35 + if (!empty($build)) {
33 $result[$key] = $build; 36 $result[$key] = $build;
34 unset($data[$key]); 37 unset($data[$key]);
35 } 38 }
@@ -62,7 +65,7 @@ class Process @@ -62,7 +65,7 @@ class Process
62 } 65 }
63 $len = count($data['menuNav']['blocks']); 66 $len = count($data['menuNav']['blocks']);
64 foreach ($data['menuNav']['blocks'] as $key => $val) { 67 foreach ($data['menuNav']['blocks'] as $key => $val) {
65 - if($len <= 2 && $key == 0) { 68 + if ($len <= 2 && $key == 0) {
66 $val['img'] = Images::getImageUrl($val['img'], 185, 152, 1); 69 $val['img'] = Images::getImageUrl($val['img'], 185, 152, 1);
67 } 70 }
68 $val['img'] = Images::getImageUrl($val['img'], 185, 76, 1); 71 $val['img'] = Images::getImageUrl($val['img'], 185, 76, 1);
@@ -73,7 +76,7 @@ class Process @@ -73,7 +76,7 @@ class Process
73 'img' => $val['img'] 76 'img' => $val['img']
74 ); 77 );
75 } 78 }
76 - 79 +
77 foreach ($data['menuNav']['list'] as $val) { 80 foreach ($data['menuNav']['list'] as $val) {
78 if (empty($val['name']) && empty($val['url'])) { 81 if (empty($val['name']) && empty($val['url'])) {
79 continue; 82 continue;
@@ -84,7 +87,7 @@ class Process @@ -84,7 +87,7 @@ class Process
84 'href' => $val['url'] 87 'href' => $val['url']
85 ); 88 );
86 } 89 }
87 - 90 +
88 foreach ($data['imgs'] as $key => $val) { 91 foreach ($data['imgs'] as $key => $val) {
89 $val['url'] = Helpers::transUrl($val['url'], $type); 92 $val['url'] = Helpers::transUrl($val['url'], $type);
90 if ($key == 0) { 93 if ($key == 0) {
@@ -118,19 +121,16 @@ class Process @@ -118,19 +121,16 @@ class Process
118 { 121 {
119 $result = array(); 122 $result = array();
120 $temp = array(); 123 $temp = array();
121 - $width = 1150;  
122 - $height = 450;  
123 if ($data['focus_type'] == 1) { 124 if ($data['focus_type'] == 1) {
124 foreach ($data['data'] as $val) { 125 foreach ($data['data'] as $val) {
125 - $ret = array();  
126 - $val['src'] = Images::getImageUrl($val['src'], $width, $height, 1); 126 + $val['src'] = Images::getImageUrl($val['src'], 1150, 450, 1);
127 $val['url'] = Helpers::transUrl($val['url'], $type); 127 $val['url'] = Helpers::transUrl($val['url'], $type);
128 - $ret = array ( 128 + $ret = array(
129 'href' => $val['url'], 129 'href' => $val['url'],
130 'img' => $val['src'], 130 'img' => $val['src'],
131 ); 131 );
132 - if(!empty($val['bgColor'])) {  
133 - $ret['bgColor'] = $val['bgColor']; 132 + if (!empty($val['bgColor'])) {
  133 + $ret['bgColor'] = $val['bgColor'];
134 } 134 }
135 $temp[] = $ret; 135 $temp[] = $ret;
136 } 136 }
@@ -152,21 +152,17 @@ class Process @@ -152,21 +152,17 @@ class Process
152 $temp = array(); 152 $temp = array();
153 if ($data['template_name'] == 'recommend_content_three') { 153 if ($data['template_name'] == 'recommend_content_three') {
154 foreach ($data['data']['big_image'] as $val) { 154 foreach ($data['data']['big_image'] as $val) {
155 - $width = 1150;  
156 - $height = 450;  
157 - $val['src'] = Images::getImageUrl($val['src'], $width, $height, 1); 155 + $val['src'] = Images::getImageUrl($val['src'], 1150, 450, 1);
158 $val['url'] = Helpers::transUrl($val['url'], $type); 156 $val['url'] = Helpers::transUrl($val['url'], $type);
159 $temp['list'][] = array( 157 $temp['list'][] = array(
160 'href' => $val['url'], 158 'href' => $val['url'],
161 'img' => $val['src'], 159 'img' => $val['src'],
162 - // 'bgColor'=> $val[] 160 + // 'bgColor'=> $val[]
163 ); 161 );
164 } 162 }
165 - 163 +
166 foreach ($data['data']['list'] as $val) { 164 foreach ($data['data']['list'] as $val) {
167 - $width = 138;  
168 - $height = 54;  
169 - $val['src'] = Images::getImageUrl($val['src'], $width, $height, 1); 165 + $val['src'] = Images::getImageUrl($val['src'], 138, 54, 1);
170 $val['url'] = Helpers::transUrl($val['url'], $type); 166 $val['url'] = Helpers::transUrl($val['url'], $type);
171 $temp['pagination'][] = array( 167 $temp['pagination'][] = array(
172 'href' => $val['url'], 168 'href' => $val['url'],
@@ -270,11 +266,12 @@ class Process @@ -270,11 +266,12 @@ class Process
270 'mergeGirlkidsData', 266 'mergeGirlkidsData',
271 'mergeHotBrandsData' 267 'mergeHotBrandsData'
272 ); 268 );
  269 + $temp = array();
273 foreach ($data as $key => $val) { 270 foreach ($data as $key => $val) {
274 foreach ($mergeProcessList as $merge) { 271 foreach ($mergeProcessList as $merge) {
275 if (isset($data[$key])) { 272 if (isset($data[$key])) {
276 $temp = self::$merge($key, $data, $type); 273 $temp = self::$merge($key, $data, $type);
277 - if (! empty($temp)) { 274 + if (!empty($temp)) {
278 $result[$key] = $temp; 275 $result[$key] = $temp;
279 } 276 }
280 } 277 }
@@ -298,43 +295,35 @@ class Process @@ -298,43 +295,35 @@ class Process
298 public static function mergeSinglehotData($key, array &$data, $type) 295 public static function mergeSinglehotData($key, array &$data, $type)
299 { 296 {
300 $result = array(); 297 $result = array();
301 - if ((isset($data[$key]) && isset($data[$key + 2])) || (isset($data[$key]) && isset($data[$key + 3])))  
302 - { 298 + if ((isset($data[$key]) && isset($data[$key + 2])) || (isset($data[$key]) && isset($data[$key + 3]))) {
303 $title = ''; 299 $title = '';
304 $source = $goods = $floor = array(); 300 $source = $goods = $floor = array();
305 - if ($data[$key]['template_name'] == 'textNav' && $data[$key + 1]['template_name'] == 'goods'  
306 - && $data[$key + 2]['template_name'] == 'floor')  
307 - { 301 + if ($data[$key]['template_name'] == 'textNav' && $data[$key + 1]['template_name'] == 'goods' && $data[$key + 2]['template_name'] == 'floor') {
308 $title = '人气单品 TOP100'; 302 $title = '人气单品 TOP100';
309 $source = $data[$key]; 303 $source = $data[$key];
310 $goods = $data[$key + 1]; 304 $goods = $data[$key + 1];
311 $floor = $data[$key + 2]; 305 $floor = $data[$key + 2];
312 unset($data[$key], $data[$key + 1], $data[$key + 2]); 306 unset($data[$key], $data[$key + 1], $data[$key + 2]);
313 - } else if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'  
314 - && $data[$key + 2]['template_name'] == 'goods' && $data[$key + 3]['template_name'] == 'floor')  
315 - { 307 + } else if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav' && $data[$key + 2]['template_name'] == 'goods' && $data[$key + 3]['template_name'] == 'floor') {
316 $title = $data[$key]['data']['text']; 308 $title = $data[$key]['data']['text'];
317 $source = $data[$key + 1]; 309 $source = $data[$key + 1];
318 $goods = $data[$key + 2]; 310 $goods = $data[$key + 2];
319 $floor = $data[$key + 3]; 311 $floor = $data[$key + 3];
320 unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]); 312 unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
321 - } else if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'  
322 - && $data[$key + 2]['template_name'] == 'goods' && $data[$key + 3]['template_name'] == 'app_icon_list')  
323 - { 313 + } else if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav' && $data[$key + 2]['template_name'] == 'goods' && $data[$key + 3]['template_name'] == 'app_icon_list') {
324 $title = $data[$key]['data']['text']; 314 $title = $data[$key]['data']['text'];
325 $source = $data[$key + 1]; 315 $source = $data[$key + 1];
326 $goods = $data[$key + 2]; 316 $goods = $data[$key + 2];
327 $floor = $data[$key + 3]; 317 $floor = $data[$key + 3];
328 unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]); 318 unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
329 } 319 }
330 - if (! empty($source) && ! empty($floor))  
331 - { 320 + if (!empty($source) && !empty($floor)) {
332 $result = array( 321 $result = array(
333 'singlehot' => array( 322 'singlehot' => array(
334 'name' => '', 323 'name' => '',
335 'imgHot' => array(), 324 'imgHot' => array(),
336 'brands' => array(), 325 'brands' => array(),
337 - 'navs'=> array(), 326 + 'navs' => array(),
338 ) 327 )
339 ); 328 );
340 // text模版 329 // text模版
@@ -367,9 +356,7 @@ class Process @@ -367,9 +356,7 @@ class Process
367 { 356 {
368 $result = array(); 357 $result = array();
369 if (isset($data[$key]) && isset($data[$key + 2])) { 358 if (isset($data[$key]) && isset($data[$key + 2])) {
370 - if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'small_pic'  
371 - && $data[$key + 2]['template_name'] == 'floor')  
372 - { 359 + if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'small_pic' && $data[$key + 2]['template_name'] == 'floor') {
373 $result = array( 360 $result = array(
374 'singlehot' => array( 361 'singlehot' => array(
375 'name' => '', 362 'name' => '',
@@ -379,40 +366,27 @@ class Process @@ -379,40 +366,27 @@ class Process
379 // text 366 // text
380 $result['singlehot']['name'] = $data[$key]['data']['text']; 367 $result['singlehot']['name'] = $data[$key]['data']['text'];
381 $len = 10; 368 $len = 10;
382 - $list = array();  
383 // small_pic 369 // small_pic
384 foreach ($data[$key + 1]['data'] as &$val) { 370 foreach ($data[$key + 1]['data'] as &$val) {
385 - $w = 378;  
386 - $h = 248;  
387 - $val['src'] = Images::getImageUrl($val['src'], $w, $h, 1); 371 + $val['src'] = Images::getImageUrl($val['src'], 378, 248, 1);
388 } 372 }
389 //floor 373 //floor
390 - foreach ($data[$key + 2]['data'] as &$val)  
391 - {  
392 - $w = 185;  
393 - $h = 248;  
394 - $val['src'] = Images::getImageUrl($val['src'], $w, $h, 1); 374 + foreach ($data[$key + 2]['data'] as &$val) {
  375 + $val['src'] = Images::getImageUrl($val['src'], 185, 248, 1);
395 } 376 }
396 - for ($i = 0; $i < $len; $i ++)  
397 - { 377 + for ($i = 0; $i < $len; $i ++) {
398 $pos = $i; 378 $pos = $i;
399 - if ($i == 1)  
400 - { 379 + if ($i == 1) {
401 $val = $data[$key + 1]['data'][0]; // 第二个是大图 380 $val = $data[$key + 1]['data'][0]; // 第二个是大图
402 - }  
403 - else if ($i == $len - 1)  
404 - { 381 + } else if ($i == $len - 1) {
405 $val = $data[$key + 1]['data'][1]; // 最后一个是大图 382 $val = $data[$key + 1]['data'][1]; // 最后一个是大图
406 - }  
407 - else  
408 - {  
409 - if ($pos > 1) // 小图  
410 - { 383 + } else {
  384 + if ($pos > 1) { // 小图
411 $pos = $pos - 1; 385 $pos = $pos - 1;
412 } 386 }
413 $val = $data[$key + 2]['data'][$pos]; 387 $val = $data[$key + 2]['data'][$pos];
414 } 388 }
415 - 389 +
416 $result['singlehot']['imgHot'][] = array( 390 $result['singlehot']['imgHot'][] = array(
417 'href' => $val['url'], 391 'href' => $val['url'],
418 'img' => $val['src'], 392 'img' => $val['src'],
@@ -437,16 +411,14 @@ class Process @@ -437,16 +411,14 @@ class Process
437 { 411 {
438 $result = array(); 412 $result = array();
439 if (isset($data[$key]) && isset($data[$key + 2])) { 413 if (isset($data[$key]) && isset($data[$key + 2])) {
440 - if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'focus'  
441 - && ($data[$key + 2]['template_name'] == 'floor' ||  
442 - $data[$key + 2]['template_name'] == 'app_icon_list'))  
443 - { 414 + if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'focus' && ($data[$key + 2]['template_name'] == 'floor' ||
  415 + $data[$key + 2]['template_name'] == 'app_icon_list')) {
444 //slider颜色 416 //slider颜色
445 - $sliderColor = array('girls' => '#8ae6e0','kids'=>'#7AD3F8','lifestyle'=>'#4e433d', 'boys'=>''); 417 + $sliderColor = array('girls' => '#8ae6e0', 'kids' => '#7AD3F8', 'lifestyle' => '#4e433d', 'boys' => '');
446 $result = array( 418 $result = array(
447 'preferenceBrands' => array( 419 'preferenceBrands' => array(
448 'name' => '', 420 'name' => '',
449 - 'sliderColor'=> $sliderColor[$type], 421 + 'sliderColor' => $sliderColor[$type],
450 'imgBrand' => array(), 422 'imgBrand' => array(),
451 'brandUrl' => '' 423 'brandUrl' => ''
452 ) 424 )
@@ -454,11 +426,15 @@ class Process @@ -454,11 +426,15 @@ class Process
454 // text模版 426 // text模版
455 $result['preferenceBrands']['name'] = $data[$key]['data']['text']; 427 $result['preferenceBrands']['name'] = $data[$key]['data']['text'];
456 // focus模版 428 // focus模版
  429 + $width = 0;
  430 + $height = 0;
457 foreach ($data[$key + 1]['data'] as $val) { 431 foreach ($data[$key + 1]['data'] as $val) {
458 - if($type == 'boys') {  
459 - $width = 378; $height = 175;  
460 - } else{  
461 - $width = 320;$height = 430; 432 + if ($type == 'boys') {
  433 + $width = 378;
  434 + $height = 175;
  435 + } else {
  436 + $width = 320;
  437 + $height = 430;
462 } 438 }
463 $val['src'] = Images::getImageUrl($val['src'], $width, $height, 1); 439 $val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
464 $val['url'] = Helpers::transUrl($val['url'], $type); 440 $val['url'] = Helpers::transUrl($val['url'], $type);
@@ -487,10 +463,10 @@ class Process @@ -487,10 +463,10 @@ class Process
487 $floor['moreBrand'] = $data[$key + 3]['data'][0]['url']; 463 $floor['moreBrand'] = $data[$key + 3]['data'][0]['url'];
488 unset($data[$key + 3]); 464 unset($data[$key + 3]);
489 } 465 }
490 - $type_key = sprintf("%s_%s", $type, $key + 2);  
491 - $cacheKey = sprintf("%s_%s", WebCacheConfig::KEY_WEB_INDEX_BRANDS_LIST_DATA, $type_key); 466 + $typeKey = sprintf("%s_%s", $type, $key + 2);
  467 + $cacheKey = sprintf("%s_%s", WebCacheConfig::KEY_WEB_INDEX_BRANDS_LIST_DATA, $typeKey);
492 Cache::set($cacheKey, $floor, 86400); 468 Cache::set($cacheKey, $floor, 86400);
493 - $result['preferenceBrands']['brandUrl'] = '/common/getIndexResourceBrand?type=' . $type_key; 469 + $result['preferenceBrands']['brandUrl'] = Helpers::url('/common/getIndexResourceBrand', array('type' => $typeKey));
494 unset($data[$key], $data[$key + 1], $data[$key + 2]); 470 unset($data[$key], $data[$key + 1], $data[$key + 2]);
495 } 471 }
496 } 472 }
@@ -508,10 +484,8 @@ class Process @@ -508,10 +484,8 @@ class Process
508 public static function mergeGirlkidsData($key, array &$data, $type) 484 public static function mergeGirlkidsData($key, array &$data, $type)
509 { 485 {
510 $result = array(); 486 $result = array();
511 - if (isset($data[$key]) && isset($data[$key + 2]))  
512 - {  
513 - if ($data[$key]['template_name'] == 'text' && $data[$key + 2]['template_name'] == 'goods')  
514 - { 487 + if (isset($data[$key]) && isset($data[$key + 2])) {
  488 + if ($data[$key]['template_name'] == 'text' && $data[$key + 2]['template_name'] == 'goods') {
515 $result = array( 489 $result = array(
516 'girlkids' => array( 490 'girlkids' => array(
517 'name' => '', 491 'name' => '',
@@ -520,13 +494,13 @@ class Process @@ -520,13 +494,13 @@ class Process
520 ); 494 );
521 // text 495 // text
522 $result['girlkids']['name'] = $data[$key]['data']['text']; 496 $result['girlkids']['name'] = $data[$key]['data']['text'];
523 - 497 +
524 // goods 498 // goods
525 $result['girlkids']['imgHot'] = self::mergeGoodsProcess($data[$key + 2], $type); 499 $result['girlkids']['imgHot'] = self::mergeGoodsProcess($data[$key + 2], $type);
526 unset($data[$key], $data[$key + 1], $data[$key + 2]); 500 unset($data[$key], $data[$key + 1], $data[$key + 2]);
527 } 501 }
528 } 502 }
529 - 503 +
530 return $result; 504 return $result;
531 } 505 }
532 506
@@ -541,11 +515,8 @@ class Process @@ -541,11 +515,8 @@ class Process
541 public static function mergeAccordionData($key, array &$data, $type) 515 public static function mergeAccordionData($key, array &$data, $type)
542 { 516 {
543 $result = array(); 517 $result = array();
544 - if (isset($data[$key]) && isset($data[$key + 2]))  
545 - {  
546 - if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'  
547 - && $data[$key + 2]['template_name'] == 'focus')  
548 - { 518 + if (isset($data[$key]) && isset($data[$key + 2])) {
  519 + if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav' && $data[$key + 2]['template_name'] == 'focus') {
549 $result = array( 520 $result = array(
550 'accordion' => array( 521 'accordion' => array(
551 'name' => '', 522 'name' => '',
@@ -554,12 +525,12 @@ class Process @@ -554,12 +525,12 @@ class Process
554 ) 525 )
555 ); 526 );
556 $result['accordion']['name'] = $data[$key]['data']['text']; 527 $result['accordion']['name'] = $data[$key]['data']['text'];
557 - 528 +
558 // textNav模版 529 // textNav模版
559 - if (! empty($data[$key + 1]['data'])) { 530 + if (!empty($data[$key + 1]['data'])) {
560 $result['accordion']['navs'] = self::mergeNavProcess($data[$key + 1], $type); 531 $result['accordion']['navs'] = self::mergeNavProcess($data[$key + 1], $type);
561 } 532 }
562 - 533 +
563 // focus模版 534 // focus模版
564 foreach ($data[$key + 2]['data'] as $val) { 535 foreach ($data[$key + 2]['data'] as $val) {
565 $val['src'] = Images::getImageUrl($val['src'], 650, 400, 1); 536 $val['src'] = Images::getImageUrl($val['src'], 650, 400, 1);
@@ -572,7 +543,7 @@ class Process @@ -572,7 +543,7 @@ class Process
572 unset($data[$key], $data[$key + 1], $data[$key + 2]); 543 unset($data[$key], $data[$key + 1], $data[$key + 2]);
573 } 544 }
574 } 545 }
575 - 546 +
576 return $result; 547 return $result;
577 } 548 }
578 549
@@ -587,12 +558,9 @@ class Process @@ -587,12 +558,9 @@ class Process
587 public static function mergeNewReportData($key, array &$data, $type) 558 public static function mergeNewReportData($key, array &$data, $type)
588 { 559 {
589 $result = array(); 560 $result = array();
590 - if (isset($data[$key]) && isset($data[$key + 3]))  
591 - {  
592 - if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'single_image'  
593 - && $data[$key + 2]['template_name'] == 'floor' &&  
594 - $data[$key + 3]['template_name'] == 'single_image')  
595 - { 561 + if (isset($data[$key]) && isset($data[$key + 3])) {
  562 + if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'single_image' && $data[$key + 2]['template_name'] == 'floor' &&
  563 + $data[$key + 3]['template_name'] == 'single_image') {
596 $result = array( 564 $result = array(
597 'newReport' => array( 565 'newReport' => array(
598 'name' => '', 566 'name' => '',
@@ -635,8 +603,7 @@ class Process @@ -635,8 +603,7 @@ class Process
635 { 603 {
636 $result = array(); 604 $result = array();
637 if (isset($data[$key]) && isset($data[$key + 2])) { 605 if (isset($data[$key]) && isset($data[$key + 2])) {
638 - if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'  
639 - && $data[$key + 2]['template_name'] == 'floor') { 606 + if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav' && $data[$key + 2]['template_name'] == 'floor') {
640 $result = array( 607 $result = array(
641 'category' => array( 608 'category' => array(
642 'name' => '', 609 'name' => '',
@@ -646,18 +613,20 @@ class Process @@ -646,18 +613,20 @@ class Process
646 ); 613 );
647 // text模版 614 // text模版
648 $result['category']['name'] = $data[$key]['data']['text']; 615 $result['category']['name'] = $data[$key]['data']['text'];
649 - 616 +
650 // textNav模版 617 // textNav模版
651 - if (! empty($data[$key + 1]['data'])) { 618 + if (!empty($data[$key + 1]['data'])) {
652 $result['category']['navs'] = self::mergeNavProcess($data[$key + 1], $type); 619 $result['category']['navs'] = self::mergeNavProcess($data[$key + 1], $type);
653 } 620 }
654 // floor模版 621 // floor模版
655 - $width = 0; 622 + $width = 0;
656 $height = 0; 623 $height = 0;
657 foreach ($data[$key + 2]['data'] as $pos => $val) { 624 foreach ($data[$key + 2]['data'] as $pos => $val) {
658 - $width = 185; $height = 510;  
659 - if($pos == 1) {  
660 - $width = 377; $height = 504; 625 + $width = 185;
  626 + $height = 510;
  627 + if ($pos == 1) {
  628 + $width = 377;
  629 + $height = 504;
661 } 630 }
662 $val['src'] = Images::getImageUrl($val['src'], $width, $height, 2); 631 $val['src'] = Images::getImageUrl($val['src'], $width, $height, 2);
663 $val['url'] = Helpers::transUrl($val['url'], $type); 632 $val['url'] = Helpers::transUrl($val['url'], $type);
@@ -670,7 +639,7 @@ class Process @@ -670,7 +639,7 @@ class Process
670 unset($data[$key], $data[$key + 1], $data[$key + 2]); 639 unset($data[$key], $data[$key + 1], $data[$key + 2]);
671 } 640 }
672 } 641 }
673 - 642 +
674 return $result; 643 return $result;
675 } 644 }
676 645
@@ -685,10 +654,8 @@ class Process @@ -685,10 +654,8 @@ class Process
685 public static function mergeHotCategoryData($key, &$data, $type) 654 public static function mergeHotCategoryData($key, &$data, $type)
686 { 655 {
687 $result = array(); 656 $result = array();
688 - if (isset($data[$key]) && isset($data[$key + 1]))  
689 - {  
690 - if ($data[$key]['template_name'] == 'hotCategory' && $data[$key + 1]['template_name'] == 'floor')  
691 - { 657 + if (isset($data[$key]) && isset($data[$key + 1])) {
  658 + if ($data[$key]['template_name'] == 'hotCategory' && $data[$key + 1]['template_name'] == 'floor') {
692 $result = array( 659 $result = array(
693 'name' => '', 660 'name' => '',
694 'navs' => array(), 661 'navs' => array(),
@@ -707,11 +674,9 @@ class Process @@ -707,11 +674,9 @@ class Process
707 $result['navs'] = $temp['navs']; 674 $result['navs'] = $temp['navs'];
708 $result['tplrecommend']['keyword'] = $temp['tplrecommend']['keyword']; 675 $result['tplrecommend']['keyword'] = $temp['tplrecommend']['keyword'];
709 $result['tplrecommend']['category'] = $temp['tplrecommend']['category']; 676 $result['tplrecommend']['category'] = $temp['tplrecommend']['category'];
710 - foreach ($data[$key]['data']['imgs'] as $key2 => $val)  
711 - { 677 + foreach ($data[$key]['data']['imgs'] as $key2 => $val) {
712 $val['url'] = Helpers::transUrl($val['url'], $type); 678 $val['url'] = Helpers::transUrl($val['url'], $type);
713 - if ($key2 == 0 || $key2 == 4) // 两个大图  
714 - { 679 + if ($key2 == 0 || $key2 == 4) { // 两个大图
715 $val['img'] = Images::getImageUrl($val['img'], 378, 248, 1); // 大图 680 $val['img'] = Images::getImageUrl($val['img'], 378, 248, 1); // 大图
716 $result['tplrecommend']['brands'][] = array( 681 $result['tplrecommend']['brands'][] = array(
717 'href' => $val['url'], 682 'href' => $val['url'],
@@ -727,10 +692,9 @@ class Process @@ -727,10 +692,9 @@ class Process
727 ); 692 );
728 } 693 }
729 } 694 }
730 - 695 +
731 // floor模版 696 // floor模版
732 - foreach ($data[$key + 1]['data'] as $val)  
733 - { 697 + foreach ($data[$key + 1]['data'] as $val) {
734 $val['src'] = Images::getImageUrl($val['src'], 222, 298, 1); // 小图 698 $val['src'] = Images::getImageUrl($val['src'], 222, 298, 1); // 小图
735 $result['tplrecommend']['products'][] = array( 699 $result['tplrecommend']['products'][] = array(
736 'href' => $val['url'], 700 'href' => $val['url'],
@@ -744,7 +708,7 @@ class Process @@ -744,7 +708,7 @@ class Process
744 ); 708 );
745 } 709 }
746 } 710 }
747 - 711 +
748 return $result; 712 return $result;
749 } 713 }
750 714
@@ -783,7 +747,7 @@ class Process @@ -783,7 +747,7 @@ class Process
783 $skns = ''; 747 $skns = '';
784 foreach ($data['data'] as $val) { 748 foreach ($data['data'] as $val) {
785 $skns .= $val['id'] . ' '; 749 $skns .= $val['id'] . ' ';
786 - } 750 + }
787 $params = array( 751 $params = array(
788 'query' => rtrim($skns), 752 'query' => rtrim($skns),
789 'client_type' => 'web' 753 'client_type' => 'web'
@@ -793,8 +757,7 @@ class Process @@ -793,8 +757,7 @@ class Process
793 $pos = 0; 757 $pos = 0;
794 $url = ''; 758 $url = '';
795 $oneGoods = array(); 759 $oneGoods = array();
796 - foreach ($goodsList as $goods)  
797 - { 760 + foreach ($goodsList as $goods) {
798 $oneGoods = array(); 761 $oneGoods = array();
799 $pos ++; 762 $pos ++;
800 if ($pos > 12) { 763 if ($pos > 12) {
@@ -810,7 +773,7 @@ class Process @@ -810,7 +773,7 @@ class Process
810 $oneGoods['href'] = Helpers::transUrl($url, $type); 773 $oneGoods['href'] = Helpers::transUrl($url, $type);
811 $result[$goods['product_skn']] = $oneGoods; 774 $result[$goods['product_skn']] = $oneGoods;
812 } 775 }
813 - 776 +
814 // 排序 777 // 排序
815 uksort($result, function ($a, $b) use($skns) { 778 uksort($result, function ($a, $b) use($skns) {
816 $skn_arr = explode(' ', $skns); 779 $skn_arr = explode(' ', $skns);
@@ -818,29 +781,27 @@ class Process @@ -818,29 +781,27 @@ class Process
818 }); 781 });
819 $pos = 1; 782 $pos = 1;
820 //添加TOP标示 783 //添加TOP标示
821 - foreach($result as &$val) {  
822 - if($pos < 4) {  
823 - $val['tip'] = 'TOP'.$pos;  
824 - }  
825 - else {  
826 - break;  
827 - }  
828 - $pos ++; 784 + foreach ($result as &$val) {
  785 + if ($pos < 4) {
  786 + $val['tip'] = 'TOP' . $pos;
  787 + } else {
  788 + break;
  789 + }
  790 + $pos ++;
829 } 791 }
830 return $result; 792 return $result;
831 } 793 }
832 - 794 +
833 /** 795 /**
834 * 热门品牌数据处理 796 * 热门品牌数据处理
835 * 797 *
836 * @param array $data 798 * @param array $data
837 * @param string $type 799 * @param string $type
838 */ 800 */
839 - public static function mergeHotBrandsData($key,array &$data,$type) 801 + public static function mergeHotBrandsData($key, array &$data, $type)
840 { 802 {
841 $result = array(); 803 $result = array();
842 - if ($data[$key]['template_name'] == 'custom_brands')  
843 - { 804 + if ($data[$key]['template_name'] == 'custom_brands') {
844 $result = array( 805 $result = array(
845 'hotBrands' => array( 806 'hotBrands' => array(
846 'name' => '', 807 'name' => '',
@@ -854,24 +815,23 @@ class Process @@ -854,24 +815,23 @@ class Process
854 'logoBrand' => '', 815 'logoBrand' => '',
855 'moreBrand' => '' 816 'moreBrand' => ''
856 ); 817 );
857 - 818 +
858 $brands = $data[$key]['data']['list']; 819 $brands = $data[$key]['data']['list'];
859 - foreach ($brands as $val)  
860 - {  
861 - $val['src'] = Images::getImageUrl($val['src'], 185, 86, 2);  
862 - $val['url'] = Helpers::transUrl($val['url'], $type);  
863 - $floor['logoBrand'][] = array(  
864 - 'href' => $val['url'],  
865 - 'img' => $val['src']  
866 - );  
867 - } 820 + foreach ($brands as $val) {
  821 + $val['src'] = Images::getImageUrl($val['src'], 185, 86, 2);
  822 + $val['url'] = Helpers::transUrl($val['url'], $type);
  823 + $floor['logoBrand'][] = array(
  824 + 'href' => $val['url'],
  825 + 'img' => $val['src']
  826 + );
  827 + }
868 $floor['moreBrand'] = Helpers::url('/brands'); 828 $floor['moreBrand'] = Helpers::url('/brands');
869 - $typeKey = sprintf("%s_%s", $type, $key); 829 + $typeKey = sprintf("%s_%s", $type, $key);
870 $cacheKey = sprintf("%s_%s", WebCacheConfig::KEY_WEB_INDEX_BRANDS_LIST_DATA, $typeKey); 830 $cacheKey = sprintf("%s_%s", WebCacheConfig::KEY_WEB_INDEX_BRANDS_LIST_DATA, $typeKey);
871 Cache::set($cacheKey, $floor, 86400); 831 Cache::set($cacheKey, $floor, 86400);
872 $result['hotBrands']['brandUrl'] = Helpers::url('/common/getIndexResourceBrand', array('type' => $typeKey)); 832 $result['hotBrands']['brandUrl'] = Helpers::url('/common/getIndexResourceBrand', array('type' => $typeKey));
873 } 833 }
874 return $result; 834 return $result;
875 } 835 }
876 -  
877 -}  
  836 +
  837 +}
@@ -26,15 +26,14 @@ class CommonController extends WebAction @@ -26,15 +26,14 @@ class CommonController extends WebAction
26 if (empty($type)) { 26 if (empty($type)) {
27 break; 27 break;
28 } 28 }
29 - }  
30 - while (false);  
31 - // 首页资源品牌,采用内存存储  
32 - $type = $this->get('type');  
33 - if (! empty($type)) { 29 +
  30 + // 首页资源品牌,采用内存存储
34 $key = WebCacheConfig::KEY_WEB_INDEX_BRANDS_LIST_DATA . '_' . $type; 31 $key = WebCacheConfig::KEY_WEB_INDEX_BRANDS_LIST_DATA . '_' . $type;
35 // array('logoBrand'=>'','moreBrand'=>'') 32 // array('logoBrand'=>'','moreBrand'=>'')
36 $data = Cache::get($key); 33 $data = Cache::get($key);
37 - } 34 + }
  35 + while (false);
  36 +
38 $this->echoJson($data); 37 $this->echoJson($data);
39 } 38 }
40 39