<?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 Joker5x1Controller
{
    private $kindID = 5002;
    /**
     * crash控制参数配置
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
     */
    public function operate()
    {

//        $redis = Redis::connection();
        $redis = Redis::connection('ServerGameRedis');
        $config["jackpotBase_{$this->kindID}_1"] =
            $redis->get("jackpotBase_{$this->kindID}_1")/NumConfig::NUM_VALUE;
        $config["jackpotBase_{$this->kindID}_2"] =
            $redis->get("jackpotBase_{$this->kindID}_2")/NumConfig::NUM_VALUE;
        $config["jackpotBase_{$this->kindID}_3"] =
            $redis->get("jackpotBase_{$this->kindID}_3")/NumConfig::NUM_VALUE;

        $config["jackpotRate_{$this->kindID}_1"] = $redis->get("jackpotRate_{$this->kindID}_1").'%';
        $config["jackpotRate_{$this->kindID}_2"] = $redis->get("jackpotRate_{$this->kindID}_2").'%';
        $config["jackpotRate_{$this->kindID}_3"] = $redis->get("jackpotRate_{$this->kindID}_3").'%';

        $config["FreeWinMax_{$this->kindID}_1"] = $redis->get("FreeWinMax_{$this->kindID}_1") / NumConfig::NUM_VALUE;
        $config["FreeWinMax_{$this->kindID}_2"] = $redis->get("FreeWinMax_{$this->kindID}_2") / NumConfig::NUM_VALUE;
        $config["FreeWinMax_{$this->kindID}_3"] = $redis->get("FreeWinMax_{$this->kindID}_3") / NumConfig::NUM_VALUE;

        $config["RechargeControl_{$this->kindID}_1"] =
            $redis->get("RechargeControl_{$this->kindID}_1") / NumConfig::NUM_VALUE;
        $config["RechargeControl_{$this->kindID}_2"] =
            $redis->get("RechargeControl_{$this->kindID}_2") / NumConfig::NUM_VALUE;
        $config["RechargeControl_{$this->kindID}_3"] =
            $redis->get("RechargeControl_{$this->kindID}_3") / NumConfig::NUM_VALUE;

        $config["RechargeMaxPercent_{$this->kindID}_1"] =
            $redis->get("RechargeMaxPercent_{$this->kindID}_1").'%';
        $config["RechargeMaxPercent_{$this->kindID}_2"] =
            $redis->get("RechargeMaxPercent_{$this->kindID}_2").'%';
        $config["RechargeMaxPercent_{$this->kindID}_3"] =
            $redis->get("RechargeMaxPercent_{$this->kindID}_3").'%';

        $config_name = [
            "jackpotBase_{$this->kindID}_1" => '初级场 jackpot爆出线',
            "jackpotBase_{$this->kindID}_2" => '中级场 jackpot爆出线',
            "jackpotBase_{$this->kindID}_3" => '高级场 jackpot爆出线',

            "jackpotRate_{$this->kindID}_1" => '初级场 jackpot占税收比例',
            "jackpotRate_{$this->kindID}_2" => '中级场 jackpot占税收比例',
            "jackpotRate_{$this->kindID}_3" => '高级场 jackpot占税收比例',

            "FreeWinMax_{$this->kindID}_1" => '初级场 充值控制线以下玩家最多赢多少',
            "FreeWinMax_{$this->kindID}_2" => '中级场 充值控制线以下玩家最多赢多少',
            "FreeWinMax_{$this->kindID}_3" => '高级场 充值控制线以下玩家最多赢多少',

            "RechargeControl_{$this->kindID}_1" => '初级场 充值控制线',
            "RechargeControl_{$this->kindID}_2" => '中级场 充值控制线',
            "RechargeControl_{$this->kindID}_3" => '高级场 充值控制线',

            "RechargeMaxPercent_{$this->kindID}_1" => '初级场 控制线以上玩家 充值上限比例',
            "RechargeMaxPercent_{$this->kindID}_2" => '中级场 控制线以上玩家 充值上限比例',
            "RechargeMaxPercent_{$this->kindID}_3" => '高级场 控制线以上玩家 充值上限比例',
        ];
        $data = compact('config', 'config_name');
        return view('admin.slots_world_cup.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');
            if (strpos($key , 'RechargeMaxPercent_') !== false
                || strpos($key, 'jackpotRate_') !== false) {
                $Value = $Value;
            } 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.slots_world_cup.update', compact('key'));
        }


    }
}
