<?php
/**
 * 分销商管理Controller
 * Created by PhpStorm.
 * User: haoren
 * Date: 2020/07/22
 * Time: 15:00
 */

namespace JinDouYun\Controller\Commission;

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

use JinDouYun\Controller\BaseController;

use JinDouYun\Model\Commission\MCommissionSetting;

class CommissionSetting extends BaseController
{
    private $objMCommissionSetting;

    public function __construct($isCheckAcl = true, $isMustLogin = true)
    {
        parent::__construct($isCheckAcl, $isMustLogin);
        $this->objMCommissionSetting = new MCommissionSetting($this->onlineEnterpriseId, $this->onlineUserId);
    }

    /**
     * 获取参数
     */
    public function commonFieldFilter()
    {
        $params = $this->request->getRawJson();
        if (empty($params)) {
            parent::sendOutput('参数为空', ErrorCode::$paramError);
        }
        $data = [
            'level' => isset($params['level']) ? $params['level'] : '',
            'self' => isset($params['self']) ? $params['self'] : '',
            'audit' => isset($params['audit']) ? $params['audit'] : '',
            'businessmanCondition' => isset($params['businessmanCondition']) ? $params['businessmanCondition'] : '',
            'buyNum' => isset($params['buyNum']) ? $params['buyNum'] : '',
            'buyAmount' => isset($params['buyAmount']) ? $params['buyAmount'] : '',
            'buyGoods' => isset($params['buyGoods']) ? $params['buyGoods'] : '',
            'buyCondition' => isset($params['buyCondition']) ? $params['buyCondition'] : '',
            'image' => isset($params['image']) ? $params['image'] : '',
            'infoStatus' => isset($params['infoStatus']) ? $params['infoStatus'] : '',
            'info' => isset($params['info']) ? $params['info'] : '',
            'descStatus' => isset($params['descStatus']) ? $params['descStatus'] : '',
            'title' => isset($params['title']) ? $params['title'] : '',
            'desc' => isset($params['desc']) ? $params['desc'] : '',
            'subConditions' => isset($params['subConditions']) ? $params['subConditions'] : '',
            'goods' => isset($params['goods']) ? $params['goods'] : '',
            'mode' => isset($params['mode']) ? $params['mode'] : '',
            'quota' => isset($params['quota']) ? $params['quota'] : '',
            'fee' => isset($params['fee']) ? $params['fee'] : '',
            'freeStart' => isset($params['freeStart']) ? $params['freeStart'] : '',
            'freeEnd' => isset($params['freeEnd']) ? $params['freeEnd'] : '',
            'day' => isset($params['day']) ? $params['day'] : '',
            'withdrawAudit' => isset($params['withdrawAudit']) ? $params['withdrawAudit'] : '',
            'withdrawGrade' => isset($params['withdrawGrade']) ? $params['withdrawGrade'] : '',
            'withdrawAmount' => isset($params['withdrawAmount']) ? $params['withdrawAmount'] : '',
            'autoPay' => isset($params['autoPay']) ? $params['autoPay'] : '',
            'payType' => isset($params['payType']) ? $params['payType'] : '',
            'withdrawType' => isset($params['withdrawType']) ? $params['withdrawType'] : '',
            'withdrawInfo' => isset($params['withdrawInfo']) ? $params['withdrawInfo'] : '',
            'leaderboard' => isset($params['leaderboard']) ? $params['leaderboard'] : '',
        ];
        foreach($data as $key => $value){
            if($value === ''){
                unset($data[$key]);
            }
        }
        return $data;
    }

    /**
     * 保存设置
     */
    public function saveSetting()
    {
        $data = self::commonFieldFilter();
        $modelResult = $this->objMCommissionSetting->saveSetting($data);
        if(!$modelResult->isSuccess()){
            parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
        }
        parent::sendOutput($modelResult->getData());
    }

    /**
     * 查询设置
     */
    public function getSetting()
    {
        $modelResult = $this->objMCommissionSetting->getSetting();
        if(!$modelResult->isSuccess()){
            parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
        }
        parent::sendOutput($modelResult->getData());
    }

    /**
     * 保存文字设置
     */
    public function saveTxtSetting()
    {
        $params = $this->request->getRawJson();
        if(empty($params)){
            parent::sendOutput('参数为空', ErrorCode::$paramError);
        }
        $data['desc'] = $params;
        $modelResult = $this->objMCommissionSetting->saveTxtSetting($data);
        if(!$modelResult->isSuccess()){
            parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
        }
        parent::sendOutput($modelResult->getData());
    }

    /**
     * 查询文字设置
     */
    public function getTxtSetting()
    {
        $modelResult = $this->objMCommissionSetting->getTxtSetting();
        if(!$modelResult->isSuccess()){
            parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
        }
        parent::sendOutput($modelResult->getData());
    }


}
