Side.php
4.02 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
<?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, 'master');
if (!empty($result)) {
$result[] = self::genLeftNavGuang($guangChoosed);
return $result;
}
}
// 调用接口获取后台配置的侧边栏数据
$side = SideData::leftNav();
if (!empty($side['data'])) {
foreach ($side['data'] as $key => $value) {
// 逛的按照原来的做法,使用配置
if ($value['sort_name_en'] === 'TRENDFINDER') {
continue;
}
$result[$key]['textCn'] = $value['sort_name'];
$result[$key]['textEn'] = $value['sort_name_en'];
$result[$key]['styleClass'] = strtolower($value['sort_name_en']);
$result[$key]['url'] = $value['sort_url'];
$result[$key]['img'] = Helpers::getImageUrl($value['sort_ico'], 60, 60);
}
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get(CacheConfig::KEY_COMMON_SIDE_NAV, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set(CacheConfig::KEY_COMMON_SIDE_NAV, $result);
}
}
// 追加逛的子分类数据
$result[] = self::genLeftNavGuang($guangChoosed);
return $result;
}
/**
* 获取并生成左侧边栏中逛的数据
*
* @param string $guangChoosed 逛默认选中项 "all"表示全部,"boys":只看男生,"girls":只看女生
* @return array
*/
private static function genLeftNavGuang($guangChoosed = 'all')
{
return array(
'textCn' => '逛',
'textEn' => 'TRENDFINDER',
'styleClass' => 'guang',
'subNav' => array(
'list' => array(
0 => array(
'textCn' => '逛',
'textEn' => 'TrendFinder',
'back' => true,
'isSelect' => false,
'bgColor' => ($guangChoosed === 'girls') ? '#FF88AE' : false,
),
1 => array(
'textCn' => '查看全部',
'textEn' => '',
'back' => false,
'isSelect' => ($guangChoosed === 'all') ? true : false,
'url' => '/guang/list/index?gender=1,2,3'
),
2 => array(
'textCn' => '只看男生',
'textEn' => 'Boys',
'back' => false,
'isSelect' => ($guangChoosed === 'boys') ? true : false,
'url' => '/guang/list/index?gender=1,3'
),
3 => array(
'textCn' => '只看女生',
'textEn' => 'Girls',
'back' => false,
'isSelect' => ($guangChoosed === 'girls') ? true : false,
'url' => '/guang/list/index?gender=2,3',
),
)
)
);
}
}