Index.php
7.56 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<?php
namespace Guang;
use LibModels\Web\Home\IndexData;
use WebPlugin\Cache;
use WebPlugin\Images;
use LibModels\Web\Guang\ListData;
use WebPlugin\Helpers;
use LibModels\Web\Guang\InfoData;
use Configs\WebCacheConfig;
class IndexModel
{
//boys的逛的banner
const CODE_BOYS_GUANG = '15a288635c2ed9f6c807417be90f5d2d';
//girls的逛的banner
const CODE_GIRLS_GUANG = 'e14e12e35af8626650979f7af8a0de2b';
//lifestyle
const CODE_LIFESTYLE_GUANG = '1d398e899f759c6d88971be680521a6f';
//kids
const CODE_KIDS_GUANG = 'ad14ee01ad048ce308aa3ca416133d2a';
//boys的逛的ads
const CODE_BOYS_GUANG_ADS = '41777aa7ac86347692c5aa0d394b2f59';
const CODE_GIRLS_GUANG_ADS = '722253573823ebb994e313e71b0a4fb9';
const CODE_LIFESTYLE_GUANG_ADS = '02568b6042510e4be739cc688dc7d6ae';
const CODE_KIDS_GUANG_ADS = '1ffdd6ea22c58af52ee6408cd353c2d5';
/**
* 获取各频道的banner
*
* @param string $channel
* @return array
*/
public static function getBanner($channel)
{
$contentCode = self::CODE_BOYS_GUANG;
$channels = array(
'boys' => self::CODE_BOYS_GUANG,
'girls'=> self::CODE_GIRLS_GUANG,
'lifestyle'=> self::CODE_LIFESTYLE_GUANG,
'kids'=> self::CODE_KIDS_GUANG
);
if(isset($channels[$channel])) {
$contentCode = $channels[$channel];
}
$key = WebCacheConfig::KEY_WEB_GUANG_BANNER_DATA.'_'.$contentCode;
$data = Cache::get($key);
if(empty($data)) {
$resource = IndexData::getResourceData($contentCode);
if (isset($resource['data']) && !empty($resource['data']) && $resource['code'] == 200) {
$list = current($resource['data']);
foreach($list['data'] as $val) {
$data [] = array( 'img' => Images::getImageUrl($val['src'], 830, 327, 1),
'url' => Helpers::getUrlSafe($val['url']));
}
//格式化数据
Cache::set($key, $data, 3600);
}
}
//master没有数据,资源位没有数据, 取二层缓存
if(empty($data)) {
$data = Cache::get($key, 'slave');
}
return $data;
}
/**
* 获取所有分类
*
* @param string $currentSortId
* @return array
*/
public static function getCategory($currentSortId = 0)
{
$ret = array();
$data = ListData::category();
foreach($data['data'] as $category)
{
// if ($category['name'] == '专题') {
// continue;
// }
$ret[] = array('typeId' => $category['id'],'type' => $category['name'],
'isActive' => $currentSortId == $category['id'] ? true :false,
'navUrl' => Helpers::url('/index/index', array('type'=> $category['id']),'guang'));
}
return $ret;
}
/**
* 获取分类列表
*
* @param int $sortId
* @param string $gender
* @param string $page
* @param int $limit
* @param string $udid
*/
public static function article($gender, $sortId, $uid = 0, $udid = '', $page = 1, $tag = null, $authorId = null, $limit = null)
{
$total = 0;
$article = ListData::article($gender, $sortId, $uid, $udid, $page, $tag, $authorId, $limit);
$articleList = array();
if (!empty($article['data']['list']['artList'])) {
foreach ($article['data']['list']['artList'] as $articleItem) {
$articleList[] = Helpers::formatArticle($articleItem, true, false, false, $uid);
}
}
$adlist = array();
if (!empty($article['data']['list']['adlist'])) {
foreach ($article['data']['list']['adlist'] as $ad) {
$adlist[] = Helpers::formatAd($ad, true, false, false, $uid);
}
}
if(!empty($article['data']['total'])) {
$total = intval($article['data']['total']);
}
return array('msgs' => $articleList, 'ads' => $adlist, 'total' => $total);
}
/**
* 获取热门标签
*
* @return array
*/
public static function getHotTags($page, $limit)
{
$tags = array();
$data = InfoData::tagTop($page, $limit);
if(!empty($data['data'])) {
foreach($data['data'] as $tag) {
$tags[] = array('tagName' => $tag['tag_name'],
'url'=> Helpers::url('/tags/index',array('query' => $tag['tag_name']),'guang'),
);
}
}
return $tags;
}
/**
* 获取精彩推荐
*
* @param string $gender
* @param int $page
* @param int $limit
* @return array
*/
public static function getExcellectRecos($gender, $page, $limit)
{
$list = array();
$data = InfoData::recommend($gender, $page, $limit);
if(!empty($data['data'])) {
foreach($data['data'] as $key => $article) {
$list[] = array(
'url' => Helpers::getArticleUrl($article['url'], $article['id']), //Helpers::url('/'.$article['id'].'.html', '', 'guang'),
'title' => $article['title']
);
if (isset($article['src']) && !empty($article['src'])) {
$list[$key]['img'] = Images::getImageUrl($article['src'], 90, 60, 1);
}
}
}
return $list;
}
/**
* 获取广告
*
* @param string $channel
* @return array
*/
public static function getAds($channel)
{
$contentCode = self::CODE_BOYS_GUANG_ADS;
$channels = array(
'boys' => self::CODE_BOYS_GUANG_ADS,
'girls'=> self::CODE_GIRLS_GUANG_ADS,
'lifestyle'=> self::CODE_LIFESTYLE_GUANG_ADS,
'kids'=> self::CODE_KIDS_GUANG_ADS
);
if(isset($channels[$channel])) {
$contentCode = $channels[$channel];
}
$key = WebCacheConfig::KEY_WEB_GUANG_ADS_DATA.'_'.$contentCode;
$data = Cache::get($key);
if(empty($data)) {
$resource = IndexData::getResourceData($contentCode);
if (isset($resource['data']) && !empty($resource['data']) && $resource['code'] == 200) {
$list = current($resource['data']);
foreach($list['data'] as $val) {
$data [] = array( 'img' => Images::getImageUrl($val['src'], 640,640, 1),
'url' => Helpers::getUrlSafe($val['url']));
}
//最多取5个
$data = array_slice($data, 0, 5);
//格式化数据
Cache::set($key, $data, 1800);
}
}
//master没有数据,资源位没有数据, 取二层缓存
if(empty($data)) {
$data = Cache::get($key, 'slave');
}
return $data;
}
/**
* 获取path导航
*
* @param string $tag
* @return array
*/
public static function getPathNav($tag = '')
{
$paths[] = array('href' => Helpers::url('/index/index',array(),'guang'), 'name' => '逛','pathTitle' => '逛');
if(!empty($tag)) {
$paths[] = array('name' => $tag,'pathTitle' => $tag);
}
return $paths;
}
}