<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 配置相关
 */
class Chest extends MY_Controller
{

    public function __construct()
    {
//        date_default_timezone_set("Asia/Shanghai");
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('cookie');
        $this->load->library('curl');
        $this->load->library('pagination');
        $this->env = get_cookie($this->_wenenv);
        $this->_url = $this->config->item('officialUrl');
        //判断model是否存在
        if (file_exists(APPPATH.'models/Common.php'))
        {
            $this->load->model('common');
        }
        $levelTiele = oo::cfg('lang')['lang_level'];
    }

    public function normalCardNum(){

        $typeKey = okeys::chestConfig('NORMAL_CARD_NUM');
        $config = oo::commonOprModel('config')->getCommonConf($typeKey);
        foreach (CHEST_TYPE_NORMALS as  $item){
            list($text, $chestType) = $item;
            $columns[$chestType] = $this->inputField($chestType,$text, MY_Controller::$inputFieldTypeText,  $config[$chestType] ?? '');
        }
        $data = [
            'title' => '普通宝箱开卡数配置',
            'type' => $typeKey,
            'config' => $config,
            'columns' => $columns,
            'saveUrl' => 'chest/saveNormalCardNum',
        ];

        $this->load->view('commonConfig', $data);
    }
    public function saveNormalCardNum(){
        $input = $this->input->post();
        $config = $input;
        $configName = '普通宝箱开卡数配置';
        $typeKey = okeys::chestConfig('NORMAL_CARD_NUM');
        $res = oo::commonOprModel('config')->saveCommonConf($typeKey, $config, $configName);
        if(!$res)$this->response(__LINE__ * -1, '保存失败');
        oo::commonOprRedis('games')->delete($typeKey);
        $this->response(1, '保存成功');
    }

}
