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

/**
* 开关相关
*/
class Switches extends MY_Controller
{

    public $postData = array('frombg' => 1, 'mod' => '', 'act' => '', 'lid' => 1, 'sid' => 1);
    public $data = array('referer' =>'', 'refresh' => 'false', 'state' => 'error', 'message' => '');

    public function __construct()
    {
        parent::__construct();
        $this->load->helper('cookie');
        $this->load->library('curl');

        $this->env = get_cookie($this->_wenenv);
    }


    /**
     * 获取开关
     */
	public function getList(){
//        if(!$this->isAdmin()) {//如果不是管理员没有权限查看用户列表
//            redirect('permission/forbidpage');
//            exit;
//        }
        $data = array( 'list' => array());
        if( $this->env == 1 ){
            $url = $this->config->item('officialUrl');
        }else{
            $url = $this->config->item('localUrl');
            $this->postData['demo'] = 1;
        }
        $this->postData['mod'] = 'Switches';
        $this->postData['act'] = 'getList';
        $retData = $this->curl->req($url, $this->postData);
        $list = json_decode($retData, TRUE);
        $data['list'] = $list;
        $this->load->view('switches/list', $data);
    }

    /**
    *   更新开关
    */
    public function actionswi()
    {
        $data = $this->data;
        $switch_comment = $this->input->post('switch_comment') ?? 2;//评论开关
        $switch_comment_ios = $this->input->post('switch_comment_ios') ?? 2;//评论开关
        
        $switch_thirdPayment = $this->input->post('switch_thirdPayment') ?? 2;//第三方支付 安卓
        $switch_thirdPayment_ios = $this->input->post('switch_thirdPayment_ios') ?? 2;//第三方支付 苹果

        $switch_hide_level = $this->input->post('switch_hide_level') ?? 2;//场次开关 安卓
        $switch_hide_level_ios = $this->input->post('switch_hide_level_ios') ?? 2;//场次开关 苹果

        $switch_match = $this->input->post('switch_match') ?? 2;//比赛场开关 安卓
        $switch_match_ios = $this->input->post('switch_match_ios') ?? 2;//比赛场开关 苹果


        $switch_level_speed = $this->input->post('switch_level_speed') ?? 2;//普通快速场开关 安卓
        $switch_level_speed_ios = $this->input->post('switch_level_speed_ios') ?? 2;//普通快速场开关 苹果

        $switch_level_people = $this->input->post('switch_level_people') ?? 2;//场次人数开关 安卓
        $switch_level_people_ios = $this->input->post('switch_level_people_ios') ?? 2;//场次人数开关 苹果

        $switch_aomaha = $this->input->post('switch_aomaha') ?? 2;//奥马哈 安卓
        $switch_aomaha_ios = $this->input->post('switch_aomaha_ios') ?? 2;//奥马哈 苹果


        $switch_dabol = $this->input->post('switch_dabol') ?? 2;//大菠萝 安卓
        $switch_dabol_ios = $this->input->post('switch_dabol_ios') ?? 2;//大菠萝 苹果

        $switch_honghei = $this->input->post('switch_honghei') ?? 2;//红黑 安卓
        $switch_honghei_ios = $this->input->post('switch_honghei_ios') ?? 2;//红黑 苹果

        $postData = $this->postData;
        if($this->env == 1){
            $url = $this->config->item('officialUrl');
        }else{
            $url = $this->config->item('localUrl');
            $postData['demo'] = 1;
        }
        
        $postData['mod'] = 'Switches';
        $postData['act'] = 'actionswi';
        $postData['switch_comment'] = $switch_comment;
        $postData['switch_comment_ios'] = $switch_comment_ios;
        $postData['switch_thirdPayment'] = $switch_thirdPayment;
        $postData['switch_thirdPayment_ios'] = $switch_thirdPayment_ios;
        $postData['switch_hide_level'] = $switch_hide_level;
        $postData['switch_hide_level_ios'] = $switch_hide_level_ios;
        $postData['switch_match'] = $switch_match;
        $postData['switch_match_ios'] = $switch_match_ios;
        $postData['switch_level_speed'] = $switch_level_speed;
        $postData['switch_level_speed_ios'] = $switch_level_speed_ios;
        $postData['switch_level_people'] = $switch_level_people;
        $postData['switch_level_people_ios'] = $switch_level_people_ios;
        $postData['switch_aomaha'] = $switch_aomaha;
        $postData['switch_aomaha_ios'] = $switch_aomaha_ios;
        $postData['switch_dabol'] = $switch_dabol;
        $postData['switch_dabol_ios'] = $switch_dabol_ios;
        $postData['switch_honghei'] = $switch_honghei;
        $postData['switch_honghei_ios'] = $switch_honghei_ios;

        $res = $this->curl->req($url, $postData);
        $retData = json_decode($res);

        $data['state'] = 'success';
        $data['message'] = '成功';
        die(json_encode($data));
    }



    public function Bullet(){
        if( $this->env == 1 ){
            $url = $this->config->item('officialUrl');
        }else{
            $url = $this->config->item('localUrl');
            $this->postData['demo'] = 1;
        }
        $this->postData['mod'] = 'Switches';
        $this->postData['act'] = 'getBullet';
        $retData = $this->curl->req($url, $this->postData);
        $list = json_decode($retData, TRUE);
        $data['list'] = $list;
        $this->load->view('switches/bullet', $data);
    }

    public function actionBullet(){
        $id = $this->input->post('id');
        $status = $this->input->post('status');


        if( $this->env == 1 ){
            $url = $this->config->item('officialUrl');
        }else{
            $url = $this->config->item('localUrl');
            $this->postData['demo'] = 1;
        }
        $this->postData['mod'] = 'Switches';
        $this->postData['act'] = 'actionBullet';
        $this->postData['id'] = $id;
        $this->postData['status'] = $status;
        $this->curl->req($url, $this->postData);
    }

}