Index.php
9.43 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
namespace Guang;
use LibModels\Wap\Guang\ListData;
use LibModels\Wap\Guang\DetailData;
use Configs\CacheConfig;
use Plugin\Helpers;
use Plugin\Cache;
/**
*
* @name IndexModel
* @package models/Guang
* @copyright yoho.inc
* @version 1.0 (2015-10-27 11:31:49)
* @author fei.hong <fei.hong@yoho.cn>
*/
class IndexModel
{
/**
* 获取逛首页分类内容列表
*
* @param string $gender "1,3"表示男, "2,3"表示女
* @param int channel APP客户端标识 1表示男,2:表示女,3:潮童,4:创意生活
* @param int type 分类ID 0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士
* @param int $uid 用户ID
* @param string $udid 客户端唯一标识
* @param int $page 分页第几页, 默认第1页
* @return array
*/
public static function getArticleGroup($gender, $type, $uid, $udid, $page = 1)
{
// 逛首页的分类名称列表
$category = ListData::category();
$articleGroup = array();
switch ($gender) {
case '1,3': // 男
$articleGroup = ListData::articleGroup($category['data'], '1,3', $uid, $udid, $page);
break;
case '2,3': // 女
$articleGroup = ListData::articleGroup($category['data'], '2,3', $uid, $udid, $page);
break;
default: // 其它所有
$articleGroup = ListData::articleGroup($category['data'], '1,2,3', $uid, $udid, $page);
break;
}
$data = array();
$build = array();
// 模板中使用JS的标识
$data['guangHome'] = true;
// 顶部的分类列表
foreach ($category['data'] as $value) {
$build = array();
$build['typeId'] = $value['id'];
$build['type'] = $value['name'];
$build['focus'] = ($value['id'] == $type);
$data['navs'][] = $build;
}
$data['guang']['swiper'] = array();
$data['guang']['infos'] = array();
foreach ($articleGroup as $id => $value) {
// 判断是否有内容
if (empty($value['list'])) {
continue;
}
// 轮番广告
if ($id == 0) {
$build = array();
foreach ($value['list']['adlist'] as $banner) {
$build['url'] = Helpers::getFilterUrl($banner['url']);
$build['img'] = Helpers::getImageUrl($banner['src'], 830, 327);
$data['guang']['swiper'][] = $build;
}
}
// 内容列表
$build = array();
$build['show'] = ($id == $type);
foreach ($value['list']['artList'] as $article) {
$build['info'][] = Helpers::formatArticle($article, true, false);
}
$data['guang']['infos'][] = $build;
}
// 分页需要参数
$data['guang']['gender'] = $gender;
$category = array();
return $data;
}
/**
* 获取逛首页分类内容列表
*
* @param string $gender "1,3"表示男, "2,3"表示女
* @param int channel APP客户端标识 1表示男,2:表示女,3:潮童,4:创意生活
* @param int type 分类ID 0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士
* @param int $uid 用户ID
* @param string $udid 客户端唯一标识
* @param int $page 分页第几页, 默认第1页
* @return array
*/
public static function getArticle($gender, $type, $uid, $udid, $page = 1)
{
// 逛首页的分类名称列表
$category = ListData::category();
$article = array();
switch ($gender) {
case '1,3': // 男
$article = ListData::article('1,3', $type, $uid, $udid, $page);
break;
case '2,3': // 女
$article = ListData::article('2,3', $type, $uid, $udid, $page);
break;
default: // 其它所有
$article = ListData::article('1,2,3', $type, $uid, $udid, $page);
break;
}
$data = array();
$build = array();
// 模板中使用JS的标识
$data['guangHome'] = true;
// 顶部的分类列表
if (!empty($category['data'])) {
foreach ($category['data'] as $value) {
$build = array();
$build['typeId'] = $value['id'];
$build['type'] = $value['name'];
$build['focus'] = ($value['id'] == $type);
$data['navs'][] = $build;
$data['guang']['infos'][] = array(
'show' => $build['focus'],
'info' => array(),
);
}
}
// 广告列表
if (!empty($article['data']['list']['adlist'])) {
foreach ($article['data']['list']['adlist'] as $value) {
$build = array();
$build['url'] = Helpers::getFilterUrl($value['url']);
$build['img'] = Helpers::getImageUrl($value['src'], 830, 327);
$data['guang']['swiper'][] = $build;
}
}
// 只有当$type=0时才有广告参数返回, 所以需要再调一次!!
else {
$temp = ListData::article('1,3', 0, 0, '', $page);
if (!empty($temp['data']['list']['adlist'])) {
foreach ($temp['data']['list']['adlist'] as $value) {
$build = array();
$build['url'] = Helpers::getFilterUrl($value['url']);
$build['img'] = Helpers::getImageUrl($value['src'], 830, 327);
$data['guang']['swiper'][] = $build;
}
}
$temp = array();
}
// 内容列表
if (!empty($article['data']['list']['artList'])) {
$type = intval($type);
foreach ($article['data']['list']['artList'] as $value) {
$data['guang']['infos'][$type]['info'][] = Helpers::formatArticle($value, true, false, true);
}
}
// 分页需要参数
$data['guang']['gender'] = $gender;
// 显示底部
$data['pageFooter'] = true;
$category = array();
$article = array();
return $data;
}
/**
* 获取订阅的资讯文章列表
*
* @param string $gender 性别参数(1,3表示男, 2,3表示女, 默认为所有)
* @return array
*/
public static function getRssArticle($gender)
{
$result = array();
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_GUANG_RSS_DATA;
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
$article = array();
switch ($gender) {
case '1,3':
$article = ListData::article('1,3', 0, 0, '', 1, null, null, 100, false);
break;
case '2,3':
$article = ListData::article('2,3', 0, 0, '', 1, null, null, 100, false);
break;
default:
$article = ListData::article('1,2,3', 0, 0, '', 1, null, null, 100, false);
break;
}
// 内容列表
if (!empty($article['data']['list']['artList'])) {
$build = array();
foreach ($article['data']['list']['artList'] as $value) {
if (isset($value['id'])) {
$build = Helpers::formatArticle($value, false, false, true);
if (!isset($build['author']['name'])) {
$build['author']['name'] = '';
}
$build['intro'] = self::genIntro($value['id']);
$result[] = $build;
}
}
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result);
}
}
return $result;
}
/**
* 构建信息内容
*
* @param array $data
* @return array
*/
private static function genIntro($id)
{
$result = '';
$data = DetailData::intro($id);
if (!empty($data)) {
foreach ($data as $value) {
// 文字
if (isset($value['text'])) {
$result .= trim( strip_tags( htmlspecialchars_decode($value['text']['data']['text']) ) ) . '<br/>';
}
// 单张图
elseif (isset($value['singleImage'])) {
$result .= '<img src="' . Helpers::getImageUrl($value['singleImage']['data'][0]['src'], 640, 640) . '"/><br/>';
}
// 多张小图
elseif (isset($value['smallPic']['data'])) {
foreach ($value['smallPic']['data'] as $small) {
$result .= '<img src="' . Helpers::getImageUrl($small['src'], 315, 420) . '"/>';
}
$result .= '<br/>';
}
}
}
$data = array();
return $result;
}
}