<?php
/**
 * 页面
 * Created by PhpStorm.
 * User: XiaoMing
 * Date: 2020/3/19
 * Time: 15:51
 */

namespace JinDouYun\Controller\System;

use JinDouYun\Controller\BaseController;
use JinDouYun\Model\System\MPage;

class ApiPage extends BaseController
{
    private $objMPage;

    /**
     * ApiPage constructor.
     * @param bool $isCheckAcl
     * @param bool $isMustLogin
     * @param bool $checkToken
     * @param bool $getAreaCode
     * @throws \Exception
     */
    public function __construct($isCheckAcl = false, $isMustLogin = false,$checkToken=true,$getAreaCode=true)
    {
        parent::__construct($isCheckAcl, $isMustLogin, $checkToken,$getAreaCode);
        $authorization = $this->request->getServerParam('HTTP_AUTHORIZATION');
        if (!empty($authorization)) {
            self::getUserIdByAuthorization();
        }
        $this->objMPage = new MPage($this->onlineUserId,$this->onlineEnterpriseId,$this->areaCode);
    }


    /**
     * 获取app首页(现在没有用了,统一用的homePage)
     *
     * @throws \Exception
     * @deprecated
     */
    public function home()
    {
        $result = $this->objMPage->home();
        if ($result->isSuccess()) {
            parent::sendOutput($result->getData());
        }
        parent::sendOutput($result->getData(), $result->getErrorCode());
    }

    /**
     * 根据id获取页面详情(主要用来获取专题详情页)
     * @throws \Exception
     */
    public function getDetailById()
    {
        $id = $this->request->param('request_id');
        $result = $this->objMPage->getDetailById($id);
        if ($result->isSuccess()) {
            parent::sendOutput($result->getData());
        }
        parent::sendOutput($result->getData(), $result->getErrorCode());
    }
}