<?php

namespace JInDouYun\Controller\Cashier;

use JinDouYun\Controller\BaseController;
use JinDouYun\Model\Cashier\MCashierSettings;
use Mall\Framework\Core\ErrorCode;

/**
 * Description:
 * Class Settings
 * @package JInDouYun\Controller\Cashier
 */
class Settings extends BaseController
{
    /**
     * @var MCashierSettings
     */
    private $objMCashierSettings;

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

    /**
     * Doc: (des="配置")
     * User: XMing
     * Date: 2020/8/31
     * Time: 2:00 下午
     */
    public function set()
    {
        $params = $this->request->getRawJson();
        if (empty($params)){
            parent::sendOutput('参数为空',ErrorCode::$paramError);
        }
        $data = [
            'content' => json_encode($params),
            'enterpriseId' => $this->onlineEnterpriseId
        ];
        $result = $this->objMCashierSettings->set($data);
        if (!$result->isSuccess()){
            parent::sendOutput($result->getData(),$result->getErrorCode());
        }
        parent::sendOutput($result->getData());
    }

    /**
     * Doc: (des="获取配置")
     * User: XMing
     * Date: 2020/8/31
     * Time: 2:02 下午
     */
    public function get()
    {
        $result = $this->objMCashierSettings->get();
        if (!$result->isSuccess()){
            parent::sendOutput($result->getData(),$result->getErrorCode());
        }
        parent::sendOutput($result->getData());
    }
}