|
@@ -20,6 +20,7 @@ use Configs\CacheConfig; |
|
@@ -20,6 +20,7 @@ use Configs\CacheConfig; |
20
|
class HomeModel
|
20
|
class HomeModel
|
21
|
{
|
21
|
{
|
22
|
/* 频道选择页取背景图片的位置码 */
|
22
|
/* 频道选择页取背景图片的位置码 */
|
|
|
23
|
+
|
23
|
const CODE_BG = '7ba9118028f9b22090b57341487567eb';
|
24
|
const CODE_BG = '7ba9118028f9b22090b57341487567eb';
|
24
|
|
25
|
|
25
|
/* 男生楼层资源的位置码 */
|
26
|
/* 男生楼层资源的位置码 */
|
|
@@ -70,6 +71,7 @@ class HomeModel |
|
@@ -70,6 +71,7 @@ class HomeModel |
70
|
|
71
|
|
71
|
/**
|
72
|
/**
|
72
|
* 设置选择的频道保存到浏览器COOKIE
|
73
|
* 设置选择的频道保存到浏览器COOKIE
|
|
|
74
|
+ * (已废弃,改成JS设置)
|
73
|
*
|
75
|
*
|
74
|
* @param string $cookie
|
76
|
* @param string $cookie
|
75
|
* @return void
|
77
|
* @return void
|
|
@@ -128,7 +130,7 @@ class HomeModel |
|
@@ -128,7 +130,7 @@ class HomeModel |
128
|
public static function getBottomBanner($channel)
|
130
|
public static function getBottomBanner($channel)
|
129
|
{
|
131
|
{
|
130
|
$result = false;
|
132
|
$result = false;
|
131
|
- if($channel == 2) {
|
133
|
+ if ($channel == 2) {
|
132
|
$resource = self::CODE_NAME_GIRLS_BOTTOM_BANNER;
|
134
|
$resource = self::CODE_NAME_GIRLS_BOTTOM_BANNER;
|
133
|
$cache = CacheConfig::KEY_ACTION_GRILS_BOTTOM_BANNER;
|
135
|
$cache = CacheConfig::KEY_ACTION_GRILS_BOTTOM_BANNER;
|
134
|
} else {
|
136
|
} else {
|
|
@@ -324,45 +326,65 @@ class HomeModel |
|
@@ -324,45 +326,65 @@ class HomeModel |
324
|
*
|
326
|
*
|
325
|
* @return array
|
327
|
* @return array
|
326
|
*/
|
328
|
*/
|
327
|
- public static function getChannel(){
|
329
|
+ public static function getChannel()
|
|
|
330
|
+ {
|
328
|
$result = array();
|
331
|
$result = array();
|
329
|
- $result['showYohood'] = false;
|
|
|
330
|
|
332
|
|
331
|
- $data = IndexData::channelData();
|
333
|
+ if (USE_CACHE) {
|
|
|
334
|
+ $key = CacheConfig::KEY_ACTION_INDEX_CONFIG;
|
|
|
335
|
+ // 先尝试获取一级缓存(master), 有数据则直接返回.
|
|
|
336
|
+ $result = Cache::get($key, 'master');
|
|
|
337
|
+ if (!empty($result)) {
|
|
|
338
|
+ return $result;
|
|
|
339
|
+ }
|
|
|
340
|
+ }
|
332
|
|
341
|
|
333
|
- $channelList = array();
|
|
|
334
|
- if(isset($data['data']['list'])){
|
|
|
335
|
- foreach($data['data']['list'] as $key => $value){
|
|
|
336
|
- switch ($value['channel_id']) {
|
|
|
337
|
- case 5:
|
|
|
338
|
- $result['showYohood'] = true;
|
|
|
339
|
- $result['yohoodHref'] = '/yohood';
|
|
|
340
|
- break;
|
342
|
+ $data = IndexData::channelData();
|
|
|
343
|
+ if (!empty($data['data']['list'])) {
|
|
|
344
|
+ $build = array();
|
|
|
345
|
+ foreach ($data['data']['list'] as $value) {
|
|
|
346
|
+ $build = array();
|
|
|
347
|
+ switch (intval($value['channel_id'])) {
|
341
|
case 1:
|
348
|
case 1:
|
342
|
- $channelList[$key]['href'] = '/boys';
|
|
|
343
|
- $channelList[$key]['title'] = '男生';
|
|
|
344
|
- $channelList[$key]['entitle'] = 'BOYS';
|
349
|
+ $build['href'] = '/boys';
|
|
|
350
|
+ $build['title'] = '男生';
|
|
|
351
|
+ $build['entitle'] = 'BOYS';
|
345
|
break;
|
352
|
break;
|
346
|
case 2:
|
353
|
case 2:
|
347
|
- $channelList[$key]['href'] = '/girls';
|
|
|
348
|
- $channelList[$key]['title'] = '女生';
|
|
|
349
|
- $channelList[$key]['entitle'] = 'GIRLS';
|
354
|
+ $build['href'] = '/girls';
|
|
|
355
|
+ $build['title'] = '女生';
|
|
|
356
|
+ $build['entitle'] = 'GIRLS';
|
350
|
break;
|
357
|
break;
|
351
|
case 3:
|
358
|
case 3:
|
352
|
- $channelList[$key]['href'] = '/kids';
|
|
|
353
|
- $channelList[$key]['title'] = '潮童';
|
|
|
354
|
- $channelList[$key]['entitle'] = 'KIDS';
|
359
|
+ $build['href'] = '/kids';
|
|
|
360
|
+ $build['title'] = '潮童';
|
|
|
361
|
+ $build['entitle'] = 'KIDS';
|
355
|
break;
|
362
|
break;
|
356
|
case 4:
|
363
|
case 4:
|
357
|
- $channelList[$key]['href'] = '/lifestyle';
|
|
|
358
|
- $channelList[$key]['title'] = '创意生活';
|
|
|
359
|
- $channelList[$key]['entitle'] = 'LIFESTYLE';
|
364
|
+ $build['href'] = '/lifestyle';
|
|
|
365
|
+ $build['title'] = '创意生活';
|
|
|
366
|
+ $build['entitle'] = 'LIFESTYLE';
|
360
|
break;
|
367
|
break;
|
361
|
- default:
|
368
|
+ case 5:
|
|
|
369
|
+ $result['showYohood'] = true;
|
|
|
370
|
+ $result['yohoodHref'] = 'http://yohood.cn';
|
362
|
break;
|
371
|
break;
|
|
|
372
|
+ default:
|
|
|
373
|
+ continue;
|
363
|
}
|
374
|
}
|
|
|
375
|
+ $result['channelList'][] = $build;
|
|
|
376
|
+ }
|
|
|
377
|
+ }
|
|
|
378
|
+
|
|
|
379
|
+ if (USE_CACHE) {
|
|
|
380
|
+ // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
|
|
|
381
|
+ if (empty($result)) {
|
|
|
382
|
+ $result = Cache::get($key, 'slave');
|
|
|
383
|
+ }
|
|
|
384
|
+ // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
|
|
|
385
|
+ else {
|
|
|
386
|
+ Cache::set($key, $result);
|
364
|
}
|
387
|
}
|
365
|
- $result['channelList'] = $channelList;
|
|
|
366
|
}
|
388
|
}
|
367
|
|
389
|
|
368
|
return $result;
|
390
|
return $result;
|