<?php


namespace App\Http\Controllers\Admin;


use App\Facade\TableName;
use App\Http\helper\NumConfig;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class CrashController
{
    /**
     * crash控制参数配置
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
     */
    public function operate()
    {

//        $redis = Redis::connection();
        $redis = Redis::connection('ServerGameRedis');
//        $config['crash_SystemOpenRate_1'] = $redis->get("crash_SystemOpenRate_1");
//        $config['crash_BetParam_1'] = $redis->get("crash_BetParam_1");
//        $config['crash_InitStock_1'] = $redis->get("crash_InitStock_1") / NumConfig::NUM_VALUE;
//        $config['crash_BaseStock_1'] = $redis->get("crash_BaseStock_1") / NumConfig::NUM_VALUE;
//        $config['crash_MinBetPeople_1'] = $redis->get("crash_MinBetPeople_1");
//
//        $config_name = ['crash_InitStock_1' => '初始库存参数', 'crash_SystemOpenRate_1' => '放水概率参数', 'crash_BaseStock_1' => '库存基数参数', 'crash_BetParam_1' => '下注参数', 'crash_MinBetPeople_1' => '最低下注人数'];$config['crash_SystemOpenRate_1'] = $redis->get("crash_SystemOpenRate_1");
//        $config['crash_ControlParam_1'] = $redis->get("crash_ControlParam_1");
//        $config['crash_InitStock_1'] = $redis->get("crash_InitStock_1") / NumConfig::NUM_VALUE;
//        $config['crash_BaseStock_1'] = $redis->get("crash_BaseStock_1") / NumConfig::NUM_VALUE;
//        $config['crash_MinBetPeople_1'] = $redis->get("crash_MinBetPeople_1");




        $kindID = 4020;
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场',

        ];

        foreach (range(1, 3) as $v) {
            $key = 'crash_ControlParam_'.$v ;
            $config_name[$key]=$rooms[$v].'提前爆炸条件个控值，默认7';
            $config[$key] = $redis->get($key);


            $key = 'crash_ControlRand_'.$v ;
            $config_name[$key]=$rooms[$v].'提前爆炸随机值上限，默认35';
            $config[$key] = $redis->get($key);

            $key = 'crash_ControlTopThree_'.$v ;
            $config_name[$key]=$rooms[$v].'前三项随机基础乘数，默认15';
            $config[$key] = $redis->get($key);


            $key = "FreeWinMax_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $config_name[$key] = "{$rooms[$v]} 充值控制线以下玩家最多赢多少";
            $key = "RechargeControl_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $config_name[$key] = "{$rooms[$v]} 充值控制线";
            $key = "RechargeMaxPercent_{$kindID}_{$v}";
            $config[$key] = $redis->get($key).'%';
            $config_name[$key] = "{$rooms[$v]} 控制线以上玩家 充值上限比例";


        }




        $data = compact('config', 'config_name');
        return view('admin.crash.operate', $data);
    }

    /**
     * 彩金池修改值
     * @param Request $request
     * @param $GameID
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
     */
    public function config_update(Request $request, $key)
    {


        if ($request->isMethod('post')) {
            $Value = (int)$request->Value;

            $redis = Redis::connection('ServerGameRedis');
//            $redis = Redis::connection();
            if (strpos($key , 'RechargeMaxPercent_') !== false
                || strpos($key, 'jackpotRate_') !== false|| strpos($key, 'crash_ControlParam_') !== false||strpos($key, 'crash_ControlTopThree_') !== false|| strpos($key, 'crash_ControlRand_') !== false) {


//            }else if ($key != 'crash_ControlParam_1' &&$key != 'crash_SystemOpenRate_1' && $key != 'crash_BetParam_1' && $key != 'crash_MinBetPeople_1') {

            }else{
                $Value = $Value * NumConfig::NUM_VALUE;
            }

            if ($Value < 0) {

                $redis->decrBy($key, abs($Value));

            } else {

                $redis->incrBy($key, $Value);
            }

            return apiReturnSuc();
        } else {
            return view('admin.crash.update', compact('key'));
        }


    }
    public function aviator_operate()
    {

//        $redis = Redis::connection();
        $redis = Redis::connection('ServerGameRedis');
//        $config['crash_SystemOpenRate_1'] = $redis->get("crash_SystemOpenRate_1");
//        $config['crash_BetParam_1'] = $redis->get("crash_BetParam_1");
//        $config['crash_InitStock_1'] = $redis->get("crash_InitStock_1") / NumConfig::NUM_VALUE;
//        $config['crash_BaseStock_1'] = $redis->get("crash_BaseStock_1") / NumConfig::NUM_VALUE;
//        $config['crash_MinBetPeople_1'] = $redis->get("crash_MinBetPeople_1");
//
//        $config_name = ['crash_InitStock_1' => '初始库存参数', 'crash_SystemOpenRate_1' => '放水概率参数', 'crash_BaseStock_1' => '库存基数参数', 'crash_BetParam_1' => '下注参数', 'crash_MinBetPeople_1' => '最低下注人数'];$config['crash_SystemOpenRate_1'] = $redis->get("crash_SystemOpenRate_1");
//        $config['crash_ControlParam_1'] = $redis->get("crash_ControlParam_1");
//        $config['crash_InitStock_1'] = $redis->get("crash_InitStock_1") / NumConfig::NUM_VALUE;
//        $config['crash_BaseStock_1'] = $redis->get("crash_BaseStock_1") / NumConfig::NUM_VALUE;
//        $config['crash_MinBetPeople_1'] = $redis->get("crash_MinBetPeople_1");




        $kindID = 4028;
        $rooms = [
            1 => '初级场',
//            2 => '中级场',
//            3 => '高级场',

        ];

        foreach (range(1, count($rooms)) as $v) {
            $key = 'aviator_ControlParam_'.$v ;
            $config_name[$key]=$rooms[$v].'随机控制参数（10-40之间)';
            $config[$key] = $redis->get($key);


            $key = 'aviator_ControlRand_'.$v ;
            $config_name[$key]=$rooms[$v].'随机值提高比例（0-90之间，0就是不变，90则随机都接近最大值)';
            $config[$key] = $redis->get($key);

            $key = "FreeWinMax_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $config_name[$key] = "{$rooms[$v]} 充值控制线以下玩家最多赢多少";
            $key = "RechargeControl_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $config_name[$key] = "{$rooms[$v]} 充值控制线";
            $key = "RechargeMaxPercent_{$kindID}_{$v}";
            $config[$key] = $redis->get($key).'%';
            $config_name[$key] = "{$rooms[$v]} 控制线以上玩家 充值上限比例";


        }



        $address='/admin/aviator/config_update/';
        $data = compact('config', 'config_name','address');
        return view('admin.crash.aviator_operate', $data);
    }

    /**
     * 彩金池修改值
     * @param Request $request
     * @param $GameID
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
     */
    public function aviator_config_update(Request $request, $key)
    {


        if ($request->isMethod('post')) {
            $Value = (int)$request->Value;

            $redis = Redis::connection('ServerGameRedis');
//            $redis = Redis::connection();
            if (strpos($key , 'RechargeMaxPercent_') !== false
                || strpos($key, 'jackpotRate_') !== false|| strpos($key, 'aviator_ControlParam_') !== false|| strpos($key, 'aviator_ControlRand_') !== false) {

            }else{// if ($key != 'crash_ControlParam_1' &&$key != 'crash_SystemOpenRate_1' && $key != 'crash_BetParam_1' && $key != 'crash_MinBetPeople_1') {

                $Value = $Value * NumConfig::NUM_VALUE;
            }

            if ($Value < 0) {

                $redis->decrBy($key, abs($Value));

            } else {

                $redis->incrBy($key, $Value);
            }

            return apiReturnSuc();
        } else {
            $address='/admin/aviator/config_update/';
            return view('admin.crash.aviator_update', compact('key','address'));
        }


    }
    public function aviator2_operate()
    {

//        $redis = Redis::connection();
        $redis = Redis::connection('ServerGameRedis');

        $kindID = 4029;
        $rooms = [
            1 => '初级场',
//            2 => '中级场',
//            3 => '高级场',

        ];

        foreach (range(1, count($rooms)) as $v) {
            $key = 'aviator2_ControlParam_'.$v ;
            $config_name[$key]=$rooms[$v].'提前爆炸条件个控值，默认7';
            $config[$key] = $redis->get($key);


            $key = 'aviator2_ControlRand_'.$v ;
            $config_name[$key]=$rooms[$v].'提前爆炸随机值上限，默认35';
            $config[$key] = $redis->get($key);

            $key = 'aviator2_ControlTopThree_'.$v ;
            $config_name[$key]=$rooms[$v].'前三项随机基础乘数，默认15';
            $config[$key] = $redis->get($key);

            $key = "FreeWinMax_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $config_name[$key] = "{$rooms[$v]} 充值控制线以下玩家最多赢多少";
            $key = "RechargeControl_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $config_name[$key] = "{$rooms[$v]} 充值控制线";
            $key = "RechargeMaxPercent_{$kindID}_{$v}";
            $config[$key] = $redis->get($key).'%';
            $config_name[$key] = "{$rooms[$v]} 控制线以上玩家 充值上限比例";


        }



        $address='/admin/aviator2/config_update/';
        $data = compact('config', 'config_name','address');
        return view('admin.crash.aviator_operate', $data);
    }

    /**
     * 彩金池修改值
     * @param Request $request
     * @param $GameID
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
     */
    public function aviator2_config_update(Request $request, $key)
    {


        if ($request->isMethod('post')) {
            $Value = (int)$request->Value;

            $redis = Redis::connection('ServerGameRedis');
//            $redis = Redis::connection();
            if (strpos($key , 'RechargeMaxPercent_') !== false
                || strpos($key, 'jackpotRate_') !== false|| strpos($key, 'aviator2_ControlParam_') !== false||strpos($key, 'aviator2_ControlTopThree_') !== false|| strpos($key, 'aviator2_ControlRand_') !== false) {

            }else{// if ($key != 'crash_ControlParam_1' &&$key != 'crash_SystemOpenRate_1' && $key != 'crash_BetParam_1' && $key != 'crash_MinBetPeople_1') {

                $Value = $Value * NumConfig::NUM_VALUE;
            }

            if ($Value < 0) {

                $redis->decrBy($key, abs($Value));

            } else {

                $redis->incrBy($key, $Value);
            }

            return apiReturnSuc();
        } else {
            $address='/admin/aviator2/config_update/';
            return view('admin.crash.aviator_update', compact('key','address'));
        }


    }
}
