Channel.php
1.78 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2016-5-3
* Time: 10:34
*/
namespace Index;
use LibModels\Wap\Home\ChannelData;
use LibModels\Wap\Home\IndexData;
use Plugin\Helpers;
use Plugin\Cache;
use Plugin\DataProcess\FloorProcess;
use Configs\CacheConfig;
class ChannelModel
{
const CHANNEl_CODE = 'cdcc581da92a13c74e3bf1826f1806d1';
/**
* 获取男生首页的楼层数据
*
* @return array | false
*/
public static function getChannelFloor($contentCode)
{
$result = array();
$contentCode = !empty($contentCode) ? $contentCode : self::CHANNEl_CODE;
if (USE_CACHE) {
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get(CacheConfig::KEY_ACTION_CHANNEL_INDEX, 'master');
if (!empty($result)) {
return $result;
}
}
// 调用接口获取楼层数据, 并封装成模板渲染需要的数据格式
$channelData = ChannelData::getChannelData($contentCode);
if (isset($channelData['code']) && $channelData['code'] == 200) {
$channelData = array(
'list'=>$channelData['data']
);
$result = FloorProcess::getContent($channelData);
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get(CacheConfig::KEY_ACTION_CHANNEL_INDEX, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set(CacheConfig::KEY_ACTION_CHANNEL_INDEX, $result);
}
}
return $result;
}
}