DetailController.class.php 1.75 KB
<?php
/**
 * DetailController.class.php
 * 同事圈详情
 * User: 代军
 * Date: 2017-04-24
 */

namespace Apicp\Controller\Topic;

use Common\Common\Config;
use Common\Service\CircleService;
use Common\Service\SceneService;
use Common\Service\SettingService;

class DetailController extends AbstractController
{
    /**
     * @var  CircleService 帖子信息表
     */
    protected $_circle_serv;

    /**
     * @var SettingService 同事圈配置表
     */
    protected $settingServ;


    public function before_action($action = '')
    {

        if (!parent::before_action($action)) {
            return false;
        }
        // 实例化帖子信息表
        $this->_circle_serv = new CircleService();

        // 实例化同事圈配置表
        $this->settingServ = new SettingService();


        return true;
    }

    public function Index_post()
    {
        // 接收参数
        $id = I('post.id');

        // 参数验证
        if (empty($id)) {
            $this->_set_error('_EMPTY_ID');

            return false;
        }

        // 获取帖子基本信息
        $data = $this->_circle_serv->get($id);
        if (empty($data)) {
            $this->_set_error('_ERR_DATA_EXIST');

            return false;
        }

        // 格式化详情数据
        $this->_circle_serv->format_detail($data);
        $data['cover_url'] = imgUrlReal($data['cover_id']);

        // 实例化场景表
        $SceneSer = new SceneService();
        $info = $SceneSer->get($data['sc_id']);
        $data['sc_title'] = strval($info['title']);

        $setting = Config::instance()->getCacheData();
        $data['is_open_check'] = rintval($setting['is_need_check']);

        // 返回数据
        $this->_result = $data;

        return true;
    }

}