StarClass.php
13.4 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2016-4-12
* Time: 9:53
*/
namespace Guang;
use Plugin\Helpers;
use LibModels\Wap\Guang\StarClassData;
use Api\Yohobuy;
/**
* 星潮教室相关的模板数据模型
* Class StarClassModel
* @package Guang
*/
class StarClassModel
{
public static $_isApp = false;
/* 星潮教室首页楼层资源的位置码 */
const CODE_FLOOR_STARCLASS_INDEX = '8adc27fcf5676f356602889afcfd2a8e';
/* 星专题楼层资源的位置码 */
const CODE_FLOOR_STARCLASS_SPECIAL = '89cc20483ee2cbc8a716dcfe2b6c7603';
/**
* 星潮教室首页(全部)
* @param $uid
* @return array
*/
public static function getStarClass($uid, $isApp)
{
self::$_isApp = $isApp;
$result = array();
//头部导航
$result['headTab'] = self::getHeadTab('index');
//组装调资源位URL(获取星潮教室首页数据)
$res['starClassIndex'] = StarClassData::getResourceDataUrl(self::CODE_FLOOR_STARCLASS_INDEX);
//组装获得每日签到数据接口URL
$res['rankInfo'] = StarClassData::rankInfoDataUrl($uid);
//批量调接口
$data = Yohobuy::getMulti($res);
//调用成功封装数据
if (isset($data['starClassIndex']) && !empty($data['starClassIndex'])) {
$starClassIndex = $data['starClassIndex'];
//初始化$build参数
$build = array();
foreach ($starClassIndex as $value) {
if (empty($value)) {
continue;
}
$fun = $value['template_name'];
if (empty($value['data']) || !is_callable("self::$fun")) {
continue;
}
//调用各模块处理函数处理数据
$build = self::$fun($value['data']);
if (empty($build)) {
continue;
}
$result['resources'][] = $build;
}
//释放$build参数
$build = array();
}
//签到信息封装
if (isset($data['rankInfo'])) {
$rankInfo = array(
array(
'portraitUrl' => isset($data['rankInfo']['avatar']) ? Helpers::getOriginalImg($data['rankInfo']['avatar']) : '',
'username' => isset($data['rankInfo']['username']) ? $data['rankInfo']['username'] : '',
'rank' => isset($data['rankInfo']['userRank']) ? $data['rankInfo']['userRank'] : '0',
'intimacy' => isset($data['rankInfo']['userNum']) ? $data['rankInfo']['userNum'] : '0',
'week' => array(
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fn', 'Sat'
),
'homeSign' => true,
)
);
}
//将签到数据插入资源位第二位置(签到信息不属于资源位,并且位置不可配置)
if (isset($data['starClassIndex']) && !empty($data['starClassIndex'])) {
array_splice($result['resources'], 1, 0 ,$rankInfo);
}
//top100链接
$result['topUrl'] = Helpers::url('/guang/starclass/top');
return $result;
}
/**
* 星专题
* @return array
*/
public static function getspecial($isApp)
{
self::$_isApp = $isApp;
$result = array();
//头部导航
$result['headTab'] = self::getHeadTab('special');
//组装资源位获取星潮教室首页数据URL
$data = StarClassData::getResourceData(self::CODE_FLOOR_STARCLASS_SPECIAL);
//资源位数据处理
if (isset($data['code']) && $data['code'] == 200) {
//初始化$build参数
$build = array();
foreach ($data['data'] as $value) {
if (empty($value)) {
continue;
}
$fun = $value['template_name'];
if (empty($value['data']) || !is_callable("self::$fun")) {
continue;
}
//循环调用模块处理函数
$build = self::$fun($value['data']);
if (empty($build)) {
continue;
}
$result['resources'][] = $build;
}
//释放$build参数
$build = array();
}
return $result;
}
/**
* 星搭配页面
*/
public static function getCollocation()
{
$result = array();
//头部导航
$result['headTab'] = self::getHeadTab('collocation');
return $result;
}
/**
* 星搭配文章请求
*/
public static function ajaxCollocation($page, $uid, $isApp, $limit)
{
//调取接口获得星搭配文章数据
$data = StarClassData::collocationData($page, $uid, $limit);
$result = array();
$collocationList = array();
//处理星搭配文章数据
if (isset($data['code']) && $data['code'] == 200 && !empty($data['data'])) {
foreach ($data['data']['list']['artList'] as $key => $value) {
//获得原尺寸图片
$collocationList[$key]['img'] = Helpers::getOriginalImg($value['src']);
$collocationList[$key]['url'] = $isApp ? $value['url'] : Helpers::getFilterUrl($value['url']);
$collocationList[$key]['title'] = $value['title'];
$collocationList[$key]['content'] = $value['intro'];
$collocationList[$key]['time'] = $value['publish_time'];
$collocationList[$key]['seeNum'] = $value['views_num'];
$collocationList[$key]['articleId'] = $value['id'];
//string转bool值
$collocationList[$key]['isLiked'] = $value['isPraise'] == 'Y' ? true : false;
$collocationList[$key]['isCollected'] = $value['isFavor'] == 'Y' ? true : false;
//判断客户端是APP时给分享链接
$isApp ? $collocationList[$key]['share'] = $value['share']['url'] : '';
}
$result['collocationList'] = $collocationList;
}
return $result;
}
/**
* 签到Top100排行榜数据
* @param $uid
* @return array
*/
public static function getTop($uid)
{
//调取接口获得签到TOP100数据
$data = StarClassData::topData($uid);
$result = array();
//处理签到TOP100数据
if (isset($data['code']) && $data['code'] == 200) {
foreach ($data['data']['top'] as $key=>$value) {
$result['rankingList'][$key]['num'] = intval($key) + 1;
$result['rankingList'][$key]['img'] = Helpers::getImageUrl($value['avatar'], 640, 240);
$result['rankingList'][$key]['name'] = $value['username'];
$result['rankingList'][$key]['intimacyNum'] = $value['num'];
//前三名给一个高亮参数
if ($key <= 2) {
$result['rankingList'][$key]['highLigth'] = true;
}
}
//用户基本信息数据
$result['userImg'] = isset($data['data']['userStarInfo']['avatar']) && !empty($data['data']['userStarInfo']['avatar']) ? Helpers::getOriginalImg($data['data']['userStarInfo']['avatar']) : '';
$result['userName'] = $data['data']['userStarInfo']['username'];
$result['rankNum'] = $data['data']['userStarInfo']['userRank'];
$result['intimacy'] = $data['data']['userStarInfo']['userNum'];
}
return $result;
}
/**
* 签到
* @param $uid
* @return array|void
*/
public static function sign($uid)
{
//调用接口签到,并返回签到信息数据
$data = StarClassData::sign($uid);
$result = array();
//处理签到数据
if (isset($data['code']) && $data['code'] == 200) {
$result['signDay'] = '';
foreach ($data['data']['logs'] as $key => $value) {
$result['signDay'] .= !empty($value['createTime']) ? date('d', $value['createTime']) . ',' : '';
$result['todayIntimacy'] = $value['addNum'];
}
$result['intimacyNum'] = isset($data['data']['addNum']) ? $data['data']['addNum'] : '0';
foreach ($data['data']['rankList'] as $key => $value) {
//排名数据按数组顺序排列
$result['fanCharts'][$key]['num'] = intval($key) + 1;
$result['fanCharts'][$key]['img'] = Helpers::getOriginalImg($value['avatar']);
$result['fanCharts'][$key]['name'] = $value['username'];
$result['fanCharts'][$key]['intimacyNum'] = $value['num'];
}
}
if (!empty($result)) {
return array('code'=>200, 'data'=>$result);
}else{
return array('code'=>201, 'message'=>'签到失败');
}
}
/**
* 获取headTab
*/
public static function getHeadTab($tab)
{
$result = array(
array(
'name' => '全部',
'url' => Helpers::url('/guang/starclass/index'),
),
array(
'name' => '星专题',
'url' => Helpers::url('/guang/starclass/special')
),
array(
'name' => '星搭配',
'url' => Helpers::url('/guang/starclass/collocation')
),
// array(
// 'name' => '星鲜事',
// 'url' => Helpers::url('/guang/starclass/fresh')
// )
);
switch ($tab) {
case 'index':
$result[0]['cur'] = true;
break;
case 'special':
$result[1]['cur'] = true;
break;
case 'collocation':
$result[2]['cur'] = true;
break;
// case 'fresh':
// $result[3]['cur'] = true;
// break;
default:
break;
}
return $result;
}
/**
* single_name_image星专题 一个图片一个连接,一个title
* @param $data
* @return array
*/
public static function single_name_image($data)
{
$isApp = self::$_isApp;
$result = array();
$result['url'] = $isApp ? $data['url'] : Helpers::getFilterUrl($data['url']);
$result['img'] = Helpers::getOriginalImg($data['src']);
$result['title'] = $data['title'];
$result['subject'] = true;
return $result;
}
/**
* 星潮教室首页焦点图
* @param $data
* @return array
*/
public static function focus($data)
{
$isApp = self::$_isApp;
$result = array();
foreach ($data as $key=>$value) {
$result['banner'][$key]['url'] = $isApp ? $value['url'] : Helpers::getFilterUrl($value['url']);
$result['banner'][$key]['img'] = Helpers::getOriginalImg($value['src']);
$result['banner'][$key]['bgColor'] = $value['bgColor'];
$result['banner'][$key]['title'] = $value['title'];
}
$result['bannerList'] = true;
return $result;
}
/**
* 一个图片一个链接资源位
* @param $data
* @return array
*/
public static function title_image($data)
{
$isApp = self::$_isApp;
$result = array();
$result['title']['title'] = $data['title'];
$result['title']['more_url'] = $data['more_url'];
$result['title']['moreName'] = $data['more_name'];
$result['subjectBanner']['url'] = $isApp ? $data['image']['url'] : Helpers::getFilterUrl($data['image']['url']);
$result['subjectBanner']['img'] = Helpers::getOriginalImg($data['image']['src']);
$result['starSubject'] = true;
return $result;
}
/**
* 一个视频资源位
* @param $data
* @return array
*/
public static function single_image($data)
{
$isApp = self::$_isApp;
$result = array();
$result['videoImg'] = Helpers::getOriginalImg($data[0]['src']);
$result['videoUrl'] = $isApp ? $data[0]['url'] : Helpers::getFilterUrl($data[0]['url']);
$result['alt'] = $data[0]['alt'];
$result['title'] = $data[0]['title'];
$result['video'] = true;
return $result;
}
/**
* 星搭配资源位
* @param $data
* @return array
*/
public static function match_image($data)
{
$isApp = self::$_isApp;
$result = array();
//title
$result['title']['title'] = $data['title']['name'];
$result['title']['more_url'] = $data['title']['more_url'];
$result['title']['moreName'] = $data['title']['more_name'];
//两张大图
foreach ($data['top_image'] as $key=>$value) {
$result['collocationBigImg'][$key]['url'] = $isApp ? $value['url']: Helpers::getFilterUrl($value['url']);
$result['collocationBigImg'][$key]['img'] = Helpers::getOriginalImg($value['src']);
}
//n张小图
foreach ($data['list'] as $key=>$value) {
$result['collocationList'][$key]['url'] = $isApp ? $value['url'] : Helpers::getFilterUrl($value['url']);
$result['collocationList'][$key]['img'] = Helpers::getOriginalImg($value['src']);
}
$result['starCollocation'] = true;
return $result;
}
}