Channel.php 1.78 KB
<?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;
    }
}