Showing
5 changed files
with
211 additions
and
1 deletions
1 | +<?php | ||
2 | +namespace Plugin\DataProcess\WebChannel; | ||
3 | +class Channel | ||
4 | +{ | ||
5 | + public static $formatChannel = array( | ||
6 | + 'boys' => '\Plugin\DataProcess\WebChannel\Channel\Kids', | ||
7 | + 'girls' => '\Plugin\DataProcess\WebChannel\Channel\Girls', | ||
8 | + 'kids' => '\Plugin\DataProcess\WebChannel\Channel\Kids' | ||
9 | + ); | ||
10 | + public static function getFormat($channel, $data) | ||
11 | + { | ||
12 | + //通用处理器 | ||
13 | + $result = Process::getContent($data, $channel); | ||
14 | + $channelResult = array(); | ||
15 | + if(isset(self::$formatChannel[$channel])) | ||
16 | + { | ||
17 | + $class = self::$formatChannel[$channel]; | ||
18 | + $channelResult = $class::format($data); | ||
19 | + } | ||
20 | + //组合数据 | ||
21 | + $result = $result + $channelResult; | ||
22 | + ksort($result); | ||
23 | + return array_values($result); | ||
24 | + } | ||
25 | +} |
1 | +<?php | ||
2 | +namespace Plugin\DataProcess\WebChannel\Channel; | ||
3 | +class Kids extends AbstractChannel | ||
4 | +{ | ||
5 | + /** | ||
6 | + * {@inheritDoc} | ||
7 | + * @see \Plugin\DataProcess\WebChannel\Channel\AbstractChannel::format() | ||
8 | + */ | ||
9 | + public static function format($resource) | ||
10 | + { | ||
11 | + $data = array(); | ||
12 | + foreach($resource as $key => $val) | ||
13 | + { | ||
14 | + | ||
15 | + } | ||
16 | + return $data; | ||
17 | + } | ||
18 | + | ||
19 | + | ||
20 | +} |
1 | +<?php | ||
2 | +namespace Plugin\DataProcess\WebChannel; | ||
3 | +/** | ||
4 | + * web版通用处理器 | ||
5 | + */ | ||
6 | +class Process | ||
7 | +{ | ||
8 | + public static function getContent(array &$data, $type = 1) | ||
9 | + { | ||
10 | + //组合处理数据 | ||
11 | + $result = self::mergeProcess($data, $type); | ||
12 | + foreach($data as $key => $val) | ||
13 | + { | ||
14 | + $fun = $val['template_name']; | ||
15 | + if (empty($val['data']) || !is_callable("self::$fun")) { | ||
16 | + continue; | ||
17 | + } | ||
18 | + //单个处理数据 | ||
19 | + $build = self::$fun($val, $type); | ||
20 | + if(!empty($build)) | ||
21 | + { | ||
22 | + $result[$key] = $build; | ||
23 | + } | ||
24 | + unset($data[$key]); | ||
25 | + } | ||
26 | + return $result; | ||
27 | + } | ||
28 | + | ||
29 | + /** | ||
30 | + * 热门分类处理 | ||
31 | + * | ||
32 | + * @param array $data | ||
33 | + * @param string $type | ||
34 | + * @return array | ||
35 | + */ | ||
36 | + public static function hotCategory(array $data, $type) | ||
37 | + { | ||
38 | + $data = $data['data']; | ||
39 | + $result = $temp = array(); | ||
40 | + $temp = array('name' => $data['name'], | ||
41 | + 'navs' => array(),'tplrecommend'=> array()); | ||
42 | + foreach($data['navs']['list'] as $val) { | ||
43 | + $temp['navs'][] = array( | ||
44 | + 'id'=>'', 'href'=> $val['url'], | ||
45 | + 'name' => $val['name'] | ||
46 | + ); | ||
47 | + } | ||
48 | + foreach($data['menuNav']['blocks'] as $val) { | ||
49 | + $temp['tplrecommend']['keyword'][] = array('href'=> $val['url'],'name'=> $val['title'],'img'=>['src']); | ||
50 | + } | ||
51 | + foreach($data['menuNav']['list'] as $val) { | ||
52 | + $temp['tplrecommend']['category'][] = array('name'=> $val['name'],'url'=> $val['url']); | ||
53 | + } | ||
54 | + foreach($data['imgs'] as $val) { | ||
55 | + $temp['tplrecommend']['types'][] = array('href'=> $val['url'],'name'=> $val['title'],'img'=>['src']); | ||
56 | + } | ||
57 | + $result['recommend'] = $temp; | ||
58 | + return $result; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * banner处理 | ||
63 | + * | ||
64 | + * @param array $data | ||
65 | + * @param string $type | ||
66 | + * @return array | ||
67 | + */ | ||
68 | + public static function focus(array $data, $type) | ||
69 | + { | ||
70 | + $result = array(); | ||
71 | + $temp = array(); | ||
72 | + if($data['focus_type'] == 1) { | ||
73 | + foreach($data['data'] as $val) { | ||
74 | + $temp[] = array('href'=> $val['url'],'img' => $val['src']); | ||
75 | + } | ||
76 | + $result['slide']['list'] = $temp; | ||
77 | + } | ||
78 | + return $result; | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * 组合数据处理 | ||
83 | + * | ||
84 | + * @param array $data | ||
85 | + * @param string $type | ||
86 | + * @return array | ||
87 | + */ | ||
88 | + public static function mergeProcess(array &$data, $type) | ||
89 | + { | ||
90 | + $result = array(); | ||
91 | + foreach($data as $key => $val) | ||
92 | + { | ||
93 | + if(isset($data[$key]) && isset($data[$key+3])) //人气单品[template: text & textNav & goods & floor] | ||
94 | + { | ||
95 | + $temp = array('singlehot' => array('name'=>'','imgHot'=> array(),'brands'=> array())); | ||
96 | + if($data[$key]['template_name'] == 'text' && $data[$key+1]['template_name'] == 'textNav' | ||
97 | + && $data[$key+2]['template_name'] == 'goods' && $data[$key+3]['template_name'] == 'floor') | ||
98 | + { | ||
99 | + $temp['singlehot']['name']= $val['data']['text']; | ||
100 | + foreach($data[$key+2]['data'] as $val)//TODO | ||
101 | + { | ||
102 | + $temp['singlehot']['imgHot'][] = array('href'=> '',//$val['url'], | ||
103 | + 'name' => '','price'=> ''); | ||
104 | + } | ||
105 | + foreach($data[$key+3]['data'] as $val) | ||
106 | + { | ||
107 | + $temp['singlehot']['brands'][] = array('href' => $val['url'], | ||
108 | + 'img' => $val['src'],'name'=>$val['title']); | ||
109 | + } | ||
110 | + $result[$key] = $temp; | ||
111 | + unset($data[$key], $data[$key+1], $data[$key+2], $data[$key+3]); | ||
112 | + } | ||
113 | + } | ||
114 | + if(isset($data[$key]) && isset($data[$key+1])) //优选品牌 [ template: text & focus] | ||
115 | + { | ||
116 | + $temp = array('preferenceBrands'=> array('name'=>'', 'slider'=> array())); | ||
117 | + if($data[$key]['template_name'] =='text' && $data[$key+1]['template_name'] =='focus') | ||
118 | + { | ||
119 | + $temp['preferenceBrands']['name'] = $val['data']['text']; | ||
120 | + foreach($data[$key+1]['data'] as $val) | ||
121 | + { | ||
122 | + $temp['preferenceBrands']['slider'][] = array('href'=> $val['url'],'img'=> $val['src']); | ||
123 | + } | ||
124 | + $result[$key] = $temp; | ||
125 | + unset($data[$key], $data[$key+1]); | ||
126 | + } | ||
127 | + } | ||
128 | + if(isset($data[$key]) && isset($data[$key+2])) //girlkids[ template: text & textNav & goods] | ||
129 | + { | ||
130 | + $temp = array('girlkids'=> array('name'=>'', 'imgHot'=> array())); | ||
131 | + if($data[$key]['template_name'] =='text' && $data[$key+2]['template_name'] =='goods') | ||
132 | + { | ||
133 | + $temp['girlkids']['name'] = $val['data']['text']; | ||
134 | + foreach($data[$key+2]['data'] as $val)//TODO | ||
135 | + { | ||
136 | + $temp['girlkids']['imgHot'][] = array('href'=> '',//$val['url'], | ||
137 | + 'name' => '','price'=>''); | ||
138 | + } | ||
139 | + $result[$key] = $temp; | ||
140 | + unset($data[$key], $data[$key+1], $data[$key+2]); | ||
141 | + } | ||
142 | + } | ||
143 | + } | ||
144 | + return $result; | ||
145 | + } | ||
146 | + | ||
147 | +} |
@@ -6,6 +6,7 @@ use Plugin\Helpers; | @@ -6,6 +6,7 @@ use Plugin\Helpers; | ||
6 | use Plugin\Cache; | 6 | use Plugin\Cache; |
7 | use LibModels\Web\Home\IndexData; | 7 | use LibModels\Web\Home\IndexData; |
8 | use LibModels\Web\Product\SearchData; | 8 | use LibModels\Web\Product\SearchData; |
9 | +use Plugin\DataProcess\WebChannel\Channel as ChannelProcess; | ||
9 | /** | 10 | /** |
10 | * web首页模板数据模型 | 11 | * web首页模板数据模型 |
11 | * | 12 | * |
@@ -131,13 +132,19 @@ class HomeModel | @@ -131,13 +132,19 @@ class HomeModel | ||
131 | /** | 132 | /** |
132 | * 获取频道资源 | 133 | * 获取频道资源 |
133 | * | 134 | * |
135 | + * @param string $channel | ||
134 | * @param string $content_code | 136 | * @param string $content_code |
135 | * @return array | 137 | * @return array |
136 | */ | 138 | */ |
137 | public static function getChannelResource($content_code) | 139 | public static function getChannelResource($content_code) |
138 | { | 140 | { |
139 | - $data = IndexData::getResourceData($content_code); | 141 | + $resource = IndexData::getResourceData($content_code); |
142 | + header( 'Content-Type:text/html;charset=utf-8 '); | ||
140 | //格式化数据 | 143 | //格式化数据 |
144 | + $data = ChannelProcess::getFormat('kids', $resource['data']); | ||
145 | + print_r($data); | ||
146 | + exit(); | ||
147 | + return $data; | ||
141 | } | 148 | } |
142 | 149 | ||
143 | /** | 150 | /** |
-
Please register or login to post a comment