NewSaleProcess.php
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
* 新品到着、折扣专区数据处理类
*/
class NewSaleProcess
{
/**
* 处理新品到着、折扣专区数据
*
* @param array $data 接口传回的数据
* @return array 处理之后的数据
*/
public static function newSaleData($focus, $products)
{
$result = array(
'headerBanner' => self::bannerData($focus),
'goodsContainer' => array()
);
foreach($products as $single)
{
// 处理Tabs
$noTab = true;
if(isset($single['tabs']) && $noTab)
{
$result['tabs'] = array();
foreach ($single['tabs'] as $key => $one)
{
$tabItem = array();
$tabItem['title'] = $one;
if($key === 1)
{
$tabItem['focus'] = true;
}
$result['tabs'][] = $tabItem;
}
$noTab = false;
}
// 处理商品
$productsLi = array('goods'=>array());
if(isset($single['product_list']))
{
foreach ($single['product_list'] as $value)
{
$productsLi['goods'][] = Helpers::formatProduct($value);
}
}
// 对于第一个productsLi添加show字段
if(count($result['goodsContainer']) === 0)
{
$productsLi['show'] = true;
}
$result['goodsContainer'][] = $productsLi;
}
return $result;
}
/**
* 筛选出来的商品数据处理
*
* @param array $data 筛选出来的原数据
* @return array 处理之后的数据
*/
public static function selectData($data)
{
$result = array('goods'=>array());
if($data['code'] === 200)
{
foreach ($data['data']['product_list'] as $val) {
$result['goods'][] = Helpers::formatProduct($val);
}
}
return $result;
}
/**
* 处理页面顶部焦点图数据
*
* @param array $data 接口传回的焦点图数据
* @return array 处理之后的数据
*/
private static function bannerData($data)
{
$result = array('list'=>array());
foreach ($data as $single)
{
foreach ($single['data'] as $one)
{
$banner = array();
$banner['img'] = Helpers::getImageUrl($one['src'], 750, 364, 1);
$banner['url'] = $one['url'];
$result['list'][] = $banner;
}
}
return $result;
}
}