CouponFloorProcess.php
3.74 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
<?php
/**
* Created by PhpStorm.
* User: Targaryen
* Date: 2016/4/15
* Time: 13:17
*/
namespace Plugin\DataProcess;
use Plugin\Images;
class CouponFloorProcess
{
/**
* 获取楼层数据
*
* @param $data
* @return array
*/
public static function getContent($data)
{
$result = array();
if (empty($data)) {
return array();
}
$build = array();
foreach ($data as $k => &$v) {
$fun = '';
if (empty($v) || !is_array($v) || !array_key_exists('template_name', $v)) {
if (array_key_exists('templateName', $v)) {
$fun = $v['templateName'];
} else {
continue;
}
}
if ($fun !== 'single_image') {
$fun = $v['template_name'];
}
if (empty($v['data']) || !is_callable("self::$fun")) {
continue;
}
// tar note 处理楼层标题
if ($fun === 'getCoupon' && array_key_exists('template_name', $data[$k - 1]) && $data[$k - 1]['template_name'] === 'text') {
$v['data']['floorTitle'] = $data[$k - 1]['data'];
}
$build = self::$fun($v['data']);
if (empty($build)) {
continue;
}
$result[] = $build;
}
$build = array();
return $result;
}
/**
* 焦点图处理
*
* @param $data
* @return mixed
*/
private static function carousel_banner($data)
{
if (empty($data['list'])) {
return array();
}
foreach ($data['list'] as &$item) {
$item['img'] = Images::getImageUrl($item['src'], 0, 0);
if (!is_string($item['url'])) {
$item['url'] = '';
}
}
$data['isCarouselBanner'] = true;
return $data;
}
/**
*
* 领券楼层数据处理
*
* @param $data
* @return array
* @internal param $type
*/
private static function getCoupon($data)
{
$result = array();
if (empty($data)) {
return array();
}
$floorTitle = '';
foreach ($data as $key => &$item) {
if ($key === 'floorTitle') {
$floorTitle = (key_exists('text', $item) && ($item['text'] !== '')) ? $item['text'] : '';
continue;
}
$imageSrc = Images::getImageUrl($item['image']['src'], 0, 0);
$item['image']['src'] = $imageSrc;
switch ($item['status']) {
case 1:
$item['isGet'] = true;
break;
case 2:
$item['isZero'] = true;
break;
case 3:
$item['isGeted'] = true;
break;
default:
break;
}
}
if ($floorTitle !== '') {
$data[0]['floorTitle'] = $floorTitle;
$data[0]['showFloorTitle'] = true;
}
$result = $data[0];
$result['isCoupon'] = true;
return $result;
}
/**
* 处理标题数据
*
* @param $data
* @return bool
*/
private static function text($data)
{
$data['isTitle'] = true;
if ($data['text']) {
$data['isShow'] = true;
}
return $data;
}
/**
*
* 单张图片的处理方法
*
* @param $data
* @return mixed
*/
private static function single_image($data)
{
$data[0]['src'] = Images::getImageUrl($data[0]['src'], 0, 0);
$data[0]['isSingleImage'] = true;
return $data[0];
}
}