AbstractChannel.php
1.5 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
<?php
namespace WebPlugin\DataProcess\Channel;
abstract class AbstractChannel
{
/***
* 处理数据
* @param array $resource
* @return array[以key方式存储数据]
*/
public static function format($resource){}
/**
* 获取格式化最新上架数据
*
* @param array &$resource
* @return array
*/
public static function getFormatNewArrivals(&$resource)
{
$result = array();
foreach($resource as $key => $val)
{
if(isset($resource[$key]) && isset($resource[$key + 2]))
{
$temp = array('newArrivls' => array('name' => '', 'navs' => array()), 'href' => '');
//newArrivals
if($resource[$key]['template_name'] == 'text' && $resource[$key + 1]['template_name'] == 'textNav')
{
//text模版
$temp['newArrivls']['name'] = $resource[$key]['data']['text'];
//textNav模版
foreach($resource[$key + 1]['data'] as $val)
{
$temp['newArrivls']['navs'][] = array('href' => $val['url'],'name' => $val['name']);
}
//link模版
$temp['href'] = $resource[$key + 2]['data'][0]['url'];
unset($resource[$key], $resource[$key + 1], $resource[$key + 2]);
$result[$key] = $temp;
}
}
}
return $result;
}
}