Process.php
7.18 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
namespace Plugin\DataProcess\WebChannel;
use Plugin\Images;
use Plugin\Helpers;
/**
* web版通用处理器
*/
class Process
{
public static function getContent(array &$data, $type = 1)
{
//组合处理数据
$result = self::mergeProcess($data, $type);
foreach($data as $key => $val)
{
$fun = $val['template_name'];
if (empty($val['data']) || !is_callable("self::$fun")) {
continue;
}
//单个处理数据
$build = self::$fun($val, $type);
if(!empty($build))
{
$result[$key] = $build;
}
unset($data[$key]);
}
return $result;
}
/**
* 热门分类处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function hotCategory(array $data, $type)
{
$data = $data['data'];
$result = $temp = array();
$temp = array('name' => $data['name'],
'navs' => array(),'tplrecommend'=> array());
foreach($data['navs']['list'] as $val) {
$temp['navs'][] = array(
'id'=>'', 'href'=> $val['url'],
'name' => $val['name']
);
}
foreach($data['menuNav']['blocks'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 185, 76, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['tplrecommend']['keyword'][] = array('href'=> $val['url'],'name'=> $val['title'], 'img'=>$val['img']);
}
foreach($data['menuNav']['list'] as $val) {
if(empty($val['name']) && empty($val['url']))
{
continue;
}
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['tplrecommend']['category'][] = array('name'=> $val['name'],'url'=> $val['url']);
}
foreach($data['imgs'] as $key => $val) {
$w = 185; $h = 248;
if($key == 0)
{
$w = 377;
$h = 504;
}
$val['img'] = Images::getImageUrl($val['img'], $w, $h, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
if($key == 0)
{
$temp['tplrecommend']['brands'][] = array('href'=> $val['url'],'name'=> $val['title'],'img'=> $val['img']);
}
else
{
$temp['tplrecommend']['types'][] = array('href'=> $val['url'],'name'=> $val['title'],'img'=> $val['img']);
}
}
$result['recommend'] = $temp;
return $result;
}
/**
* banner处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function focus(array $data, $type)
{
$result = array();
$temp = array();
$width = 1150;
$height = 450;
if($data['focus_type'] == 1) {
foreach($data['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp[] = array('href'=> $val['url'],'img' => $val['src']);
}
$result['slide']['list'] = $temp;
}
return $result;
}
/**
* 组合数据处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeProcess(array &$data, $type)
{
$result = array();
foreach($data as $key => $val)
{
if(isset($data[$key]) && isset($data[$key+3])) //人气单品[template: text & textNav & goods & floor]
{
$temp = array('singlehot' => array('name'=>'','imgHot'=> array(),'brands'=> array()));
if($data[$key]['template_name'] == 'text' && $data[$key+1]['template_name'] == 'textNav'
&& $data[$key+2]['template_name'] == 'goods' && $data[$key+3]['template_name'] == 'floor')
{
//text模版
$temp['singlehot']['name']= $val['data']['text'];
//goods模版
foreach($data[$key+2]['data'] as $val)//TODO
{
$temp['singlehot']['imgHot'][] = array('href'=> '',//$val['url'],
'name' => '','price'=> '');
}
//floor模版
foreach($data[$key+3]['data'] as $val)
{
$val['src'] = Images::getImageUrl($val['src'], 185, 86, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['singlehot']['brands'][] = array('href' => $val['url'],
'img' => $val['src'],'name'=>$val['title']);
}
$result[$key] = $temp;
unset($data[$key], $data[$key+1], $data[$key+2], $data[$key+3]);
}
}
if(isset($data[$key]) && isset($data[$key+1])) //优选品牌 [ template: text & focus ]
{
$temp = array('preferenceBrands'=> array('name'=>'', 'slider'=> array()));
if($data[$key]['template_name'] =='text' && $data[$key+1]['template_name'] =='focus')
{
$temp['preferenceBrands']['name'] = $val['data']['text'];
//focus 分类
foreach($data[$key+1]['data'] as $val)
{
$width = 320;
$height = 430;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['preferenceBrands']['slider'][] = array('href'=> $val['url'],'img'=> $val['src']);
}
$result[$key] = $temp;
unset($data[$key], $data[$key+1]);
}
}
if(isset($data[$key]) && isset($data[$key+2])) //girlkids[ template: text & textNav & goods]
{
$temp = array('girlkids'=> array('name'=>'', 'imgHot'=> array()));
if($data[$key]['template_name'] =='text' && $data[$key+2]['template_name'] =='goods')
{
$temp['girlkids']['name'] = $val['data']['text'];
foreach($data[$key+2]['data'] as $val)//TODO
{
$temp['girlkids']['imgHot'][] = array('href'=> '',//$val['url'],
'name' => '','price'=>'');
}
$result[$key] = $temp;
unset($data[$key], $data[$key+1], $data[$key+2]);
}
}
}
return $result;
}
}