<?php
/**
 * 常用应用控制器
 * Created by PhpStorm.
 * User: 小威
 * Date: 2020/01/11
 * Time: 10:10
 */

namespace JinDouYun\Controller\SystemSettings;

use Exception;
use Mall\Framework\Core\ErrorCode;
use Mall\Framework\Core\StatusCode;

use JinDouYun\Controller\BaseController;
use JinDouYun\Model\SystemSettings\MCommonApp;

class CommonApp extends BaseController
{
    private $objMCommonApp;

    public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true)
    {
        parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
        $this->objMCommonApp = new MCommonApp($this->onlineEnterpriseId,$this->onlineUserId);
    }

    /**
     * 修改常用应用
     */
    public function updateCommonApp()
    {
        $id = $this->request->param('request_id');
        $params = $this->request->getRawJson();
        if (empty($params)) {
            parent::sendOutput('参数为空', ErrorCode::$paramError);
        }
        $where = [
            'userCenterId' => $id ? $id : $this->onlineUserId,
            'enterpriseId' => $this->onlineEnterpriseId,
        ];

        $modelResult = $this->objMCommonApp->updateCommonApp($params, $where);
        if (!$modelResult->isSuccess()) {
            parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
        }
        parent::sendOutput($modelResult->getData());
    }

    /**
     * 查询常用应用
     */
    public function getCommonAppInfo()
    {
        $id = $this->request->param('request_id');
        $where = [
            'userCenterId' => $id ? $id : $this->onlineUserId,
            'enterpriseId' => $this->onlineEnterpriseId,
        ];

        $modelResult = $this->objMCommonApp->getCommonAppInfo($where);
        if (!$modelResult->isSuccess()) {
            parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
        }
        parent::sendOutput($modelResult->getData());
    }

}