<?php
/**
 * 企业管理Controller
 * Created by PhpStorm.
 * User: 小威
 * Date: 2020/03/19
 * Time: 18:21
 */

namespace JinDouYun\Controller\Manage;

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

use JinDouYun\Cache\EnterpriseCache;

use JinDouYun\Controller\BaseController;

use JinDouYun\Model\Manage\MEnterprise;

class Enterprise extends BaseController
{
    private $objMEnterprise;

    public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = false)
    {
        parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
        $this->objMEnterprise = new MEnterprise();
    }

    /**
     * 获取所有企业列表
     * @throws \Exception
     */
    public function getAllEnterprise()
    {
        $result = $this->objMEnterprise->getAllEnterprise();
        if ($result->isSuccess()) {
            parent::sendOutput($result->getData()['enterpriseData']);
        } else {
            parent::sendOutput($result->getData(), ErrorCode::$dberror);
        }
    }

    /**
     * 企业编辑
     */
    public function updateEnterprise()
    {
        $id = $this->request->param('request_id');
        $params = $this->request->getRawJson();
        $data = [
            'id' => $id,
            'expireTime' => isset($params['expireTime']) ? $params['expireTime'] : '',
        ];
        foreach($data as $key => $value){
            if(empty($value)){
                parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
            }
        }
        $modelResult = $this->objMEnterprise->updateEnterprise($data);
        if(!$modelResult->isSuccess()){
            parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
        }
        parent::sendOutput($modelResult->getData());
    }


}