Side.php
6.75 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
193
194
195
196
197
198
199
200
201
<?php
namespace Index;
use LibModels\Wap\Home\SideData;
use Configs\CacheConfig;
use Plugin\Helpers;
use Plugin\Cache;
/**
*
* @name SideModel
* @package models/Index
* @copyright yoho.inc
* @version 1.0 (2015-10-21 21:21:09)
* @author fei.hong <fei.hong@yoho.cn>
*/
class SideModel
{
/**
* 获取左侧边栏数据
*
* @param string $guangChoosed 逛默认选中项 "all"表示全部,"boys":只看男生,"girls":只看女生
*/
public static function getLeftNav($guangChoosed = 'all')
{
$result = array();
if (USE_CACHE) {
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get(CacheConfig::KEY_COMMON_SIDE_NAV.'_'.$guangChoosed, 'master');
if (!empty($result)) {
// $result[] = self::genLeftNavGuang($guangChoosed);
return $result;
}
}
// 调用接口获取后台配置的侧边栏数据
$side = SideData::leftNav();
if (!empty($side['data']) && is_array($side['data'])) {
$group = array();
$num = 0;
$groupKey = 0;
$count = count($side['data']);
foreach ($side['data'] as $key => $value) {
if ($value['separative_sign'] === 'Y') {
$result[$num] = $group;
$num++;
$groupKey = 0;
$group = array();
}
// 逛的按照原来的做法,使用配置
/*if ($value['sort_name_en'] === 'TRENDFINDER') {
continue;
}*/
$group[$groupKey] = self::formatSideItem($value);
// 如果存在子菜单,就输出子菜单
if (isset($value['sub']) && !empty($value['sub'])) {
unset($group[$groupKey]['url']);
$subs = array(
array(
'textCn' => $group[$groupKey]['textCn'],
'textEn' => $group[$groupKey]['textEn'],
'back' => true,
'isSelect' => false,
'bgColor' => self::getSideTopColor($guangChoosed)
)
);
foreach ($value['sub'] as $oneSub) {
$subs[] = self::formatSideItem($oneSub);
}
$group[$groupKey]['styleClass'] = 'guang';
$group[$groupKey]['subNav']['list'] = $subs;
}
$groupKey++;
if ($count === $key + 1) {
$result[$num] = $group;
}
}
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get(CacheConfig::KEY_COMMON_SIDE_NAV.'_'.$guangChoosed, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set(CacheConfig::KEY_COMMON_SIDE_NAV.'_'.$guangChoosed, $result);
}
}
// 追加逛的子分类数据
// $result[] = self::genLeftNavGuang($guangChoosed);
return $result;
}
/**
* 获取并生成左侧边栏中逛的数据
*
* @param string $guangChoosed 逛默认选中项 "all"表示全部,"boys":只看男生,"girls":只看女生
* @return array
*/
private static function genLeftNavGuang($guangChoosed = 'all')
{
// 判断逛的背景色
$color = self::getSideTopColor($guangChoosed);
return
array(
array(
'textCn' => '逛',
'textEn' => 'TRENDFINDER',
'styleClass' => 'guang',
'subNav' => array(
'list' => array(
0 => array(
'textCn' => '逛',
'textEn' => 'TrendFinder',
'back' => true,
'isSelect' => false,
'bgColor' => $color,
),
1 => array(
'textCn' => '查看全部',
'textEn' => '',
'back' => false,
'isSelect' => ($guangChoosed === 'lifestyle' || $guangChoosed === 'kids') ? true : false,
'url' => Helpers::url('', array('gender' => '1,2,3'), 'guang')
),
2 => array(
'textCn' => '只看男生',
'textEn' => 'Boys',
'back' => false,
'isSelect' => ($guangChoosed === 'boys') ? true : false,
'url' => Helpers::url('', array('gender' => '1,3'), 'guang')
),
3 => array(
'textCn' => '只看女生',
'textEn' => 'Girls',
'back' => false,
'isSelect' => ($guangChoosed === 'girls') ? true : false,
'url' => Helpers::url('', array('gender' => '2,3'), 'guang')
),
)
)
)
);
}
/**
* 根据选择的频道获取逛的背景色
* @param string $guangChoosed 逛默认选中项 "all"表示全部,"boys":只看男生,"girls":只看女生
* @return string color值
*/
private static function getSideTopColor($guangChoosed)
{
// 判断逛的背景色
$color = false;
if ($guangChoosed === 'girls') {
$color = '#FF88AE';
} else if ($guangChoosed === 'kids') {
$color = '#7ad9f9';
} else if ($guangChoosed === 'lifestyle') {
$color = '#4f4138';
}
return $color;
}
/**
* 格式化侧边栏数据
*
* @param array $data 要格式化的侧边栏数据
* @return array
*/
private static function formatSideItem($data)
{
$result = array();
$result['textCn'] = $data['sort_name'];
$result['textEn'] = $data['sort_name_en'];
$result['styleClass'] = strtolower($data['sort_name_en']);
$result['url'] = Helpers::getFilterUrl($data['sort_url']);
$result['img'] = Helpers::getImageUrl($data['sort_ico'], 60, 60, 1);
if (isset($data['sort_name_color'])) {
$result['color'] = $data['sort_name_color'];
}
return $result;
}
}