<?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 ClearBombController
{
    /**
     * ClearBomb控制参数配置
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
     */
    public function operate()
    {

//        $redis = Redis::connection();
        $redis = Redis::connection('ServerGameRedis');
        $config=[];
        $descriptions=[];
        $kindID = 4021;
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场',

        ];
        foreach (range(1, 3) as $v) {
            $config['ClearBomb_InitStock_'.$v] = $redis->get("ClearBomb_InitStock_".$v) / NumConfig::NUM_VALUE;
            $config['ClearBomb_SystemKillRate_'.$v] = $redis->get("ClearBomb_SystemKillRate_".$v) / NumConfig::NUM_VALUE;
            $config['ClearBomb_BaseStock_'.$v] = $redis->get("ClearBomb_BaseStock_".$v);
            $config['ClearBomb_MinMulti_'.$v] = $redis->get("ClearBomb_MinMulti_".$v).'%';
            $config['ClearBomb_KillStock_'.$v] = $redis->get("ClearBomb_KillStock_".$v) / NumConfig::NUM_VALUE;





            $descriptions =array_merge($descriptions, ['ClearBomb_InitStock_'.$v => $rooms[$v].'库存比较基线', 'ClearBomb_SystemKillRate_'.$v => $rooms[$v].'达到控杀区后的控杀率', 'ClearBomb_BaseStock_'.$v => $rooms[$v].'保底库存值', 'ClearBomb_KillStock_'.$v => $rooms[$v].'库存控杀线','ClearBomb_MinMulti_'.$v=>$rooms[$v].'随机上限倍数保底（最高500%，用户倍率可超越）']);


            $key = "ClearBomb_RandomRange_{$v}";
            $config[$key] = $redis->get($key) ;
            $descriptions[$key] = "{$rooms[$v]} 当局随机范围参数左侧(正数,eg:-5-5)";


            $key = "ClearBomb_RandomRange2_{$v}";
            $config[$key] = $redis->get($key) ;
            $descriptions[$key] = "{$rooms[$v]} 当局随机范围参数右侧(正数,eg:-5-5)";

            $key = "ClearBomb_ExplodeProtectRate_{$v}";
            $config[$key] = $redis->get($key) ;
            $descriptions[$key] = "{$rooms[$v]} 个控10-20爆炸保护概率25:3Z%-25%的概率判断为不爆炸,最多保护2";

            $key = "ClearBomb_ExplodeRateBonus_{$v}";
            $config[$key] = $redis->get($key) ;
            $descriptions[$key] = "{$rooms[$v]} 个控0-7区间，出雷概率为原基础提升30%-2Z";

            $key = "ClearBomb_RandMin_{$v}";
            $config[$key] = $redis->get($key) ;
            $descriptions[$key] = "{$rooms[$v]} 最低随机保底比例(0-90)";

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


        }


        $data = compact('config', 'descriptions');
        return view('admin.clearBomb.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, 'ClearBomb_RandomRange_') !== false
                || strpos($key, 'ClearBomb_RandomRange2_') !== false
                || strpos($key, 'ClearBomb_ExplodeProtectRate_') !== false
                || strpos($key, 'ClearBomb_ExplodeRateBonus_') !== false
            ) {

            }else if (strstr($key,'ClearBomb_BaseStock_')||strstr($key,'ClearBomb_MinMulti_')||strstr($key,'ClearBomb_RandMin_')) {

            }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.clearBomb.update', compact('key'));
        }


    }
}
