<?php
namespace App\Http\Controllers\Admin;

use App\AdminConfig;
use App\Http\Controllers\Controller;
use App\Http\helper\NumConfig;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

class ConfigController extends Controller
{
    /**
     * @Desc: 配置列表
     * @Author: woann <304550409@qq.com>
     * @param Request $request
     * @return \Illuminate\View\View
     */
    public function configList(Request $request)
    {
        $wd   = $request->input('wd');
        $list = AdminConfig::searchCondition($wd)->paginate(10);
        return view('admin.config', ['list' => $list, 'wd' => $wd]);
    }

    /**
     * @Desc: 添加配置
     * @Author: woann <304550409@qq.com>
     * @param Request $request
     * @return \Illuminate\View\View
     */
    public function configAddView(Request $request)
    {
        return view('admin.config_add');
    }

    public function configAdd(Request $request)
    {
        $data   = $request->post();
        $config = new AdminConfig();
        $config->fill($data)->save();
        return $this->json(200, '添加成功');
    }

    /**
     * @Desc: 修改配置信息
     * @Author: woann <304550409@qq.com>
     * @param Request $request
     * @param $id
     * @return \Illuminate\View\View
     */
    public function configUpdateView(Request $request, $id)
    {
        return view('admin.config_update', ['config' => AdminConfig::findOrFail($id)]);
    }

    public function configUpdate(Request $request, $id)
    {
        $config = AdminConfig::findOrFail($id);
        $data   = $request->post();
        $config->fill($data);
        $config->save();
        return $this->json(200, '修改成功');
    }

    /**
     * @Desc: 删除配置
     * @Author: woann <304550409@qq.com>
     * @param $id
     * @return mixed
     */
    public function configDel($id)
    {
        AdminConfig::findOrFail($id)->delete();
        return $this->json(200, '删除成功');
    }


    /**
     * 宝藏拉霸配置
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function treasureSlot()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 3018;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场'
        ];
        $config = [];
        foreach (range(1, 3) as $v) {
            foreach (range(0, 4) as $v1) {
                $key = "jackpot_{$kindID}_{$v}_{$v1}";
                $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
                $descriptions[$key] = "{$rooms[$v]} jackpot彩金池 {$v1}池";
                $key = "jackpotBase_{$kindID}_{$v}_{$v1}";
                $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
                $descriptions[$key] = "{$rooms[$v]} jackpot爆出线 {$v1}池";
                $key = "jackpotRate_{$kindID}_{$v}_{$v1}";
                $config[$key] = $redis->get($key).'%';
                $descriptions[$key] = "{$rooms[$v]} jackpot占税收比例 {$v1}池";
            }
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => '宝藏',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }

    /**
     * 宝藏拉霸配置
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function newolympusSlot(Request $request)
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 6001;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场'
        ];
        $config = [];
        foreach (range(1, 3) as $v) {
            $key = "jackpot_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $descriptions[$key] = "{$rooms[$v]} jackpot彩金池";
            $key = "jackpotBase_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $descriptions[$key] = "{$rooms[$v]} jackpot爆出线";
            $key = "jackpotRate_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) . '%';
            $descriptions[$key] = "{$rooms[$v]} jackpot占税收比例";
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => '新宙斯',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }

    public function LightSlot()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 3019;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场'
        ];
        $config = [];
        foreach (range(1, 3) as $v) {
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => '闪电',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }


    public function Joker5x1()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 5002;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场',

            4 => '超级场'
        ];
        $config = [];
        foreach (range(1, 4) as $v) {
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => 'MasterJoker 水果单线',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }
    public function FortuneTiger()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 5006;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场',

        ];
        $config = [];
        foreach (range(1, 3) as $v) {
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => 'FortuneTiger 金老虎',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }
    public function FortuneOX()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 5007;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场',

        ];
        $config = [];
        foreach (range(1, 3) as $v) {
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => 'FortuneOX 金牛',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }
    public function FortuneRabbit()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 5007;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场',

        ];
        $config = [];
        foreach (range(1, 3) as $v) {
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => 'FortuneRabbit 金兔',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }
    public function FishingPlus()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 5005;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场',

        ];
        $config = [];
        foreach (range(1, 3) as $v) {
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => 'BigBass钓鱼',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }

    public function gameConfigUpdate($key, Request $request)
    {
        if ($request->isMethod('post')) {
            $Value = (int)$request->Value;

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

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


    public function Halloween()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 3020;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场'
        ];
        $config = [];
        foreach (range(1, 3) as $v) {
            foreach (range(0, 3) as $v1) {
                $key = "jackpot_{$kindID}_{$v}_{$v1}";
                $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
                $descriptions[$key] = "{$rooms[$v]} jackpot彩金池 {$v1}池";
                $key = "jackpotBase_{$kindID}_{$v}_{$v1}";
                $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
                $descriptions[$key] = "{$rooms[$v]} jackpot爆出线 {$v1}池";
                $key = "jackpotRate_{$kindID}_{$v}_{$v1}";
                $config[$key] = $redis->get($key).'%';
                $descriptions[$key] = "{$rooms[$v]} jackpot占税收比例 {$v1}池";
            }
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => '万圣节',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }

    public function Fruit9x()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 3014;
        $descriptions = [];
        $rooms = [
            1 => '体验场',
            2 => '初级场',
            3 => '中级场',
            4 => '高级场'
        ];
        $config = [];
        foreach (range(1, 4) as $v) {
            $key = "jackpot_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $descriptions[$key] = "{$rooms[$v]} jackpot彩金池";
            $key = "jackpotBase_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $descriptions[$key] = "{$rooms[$v]} jackpot爆出线";
            $key = "jackpotRate_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) . '%';
            $descriptions[$key] = "{$rooms[$v]} jackpot占税收比例";
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => '水果9线',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }

    public function Hive()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 3021;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场'
        ];
        $config = [];
        foreach (range(1, 3) as $v) {
            $key = "jackpot_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $descriptions[$key] = "{$rooms[$v]} jackpot彩金池";
            $key = "jackpotBase_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) / NumConfig::NUM_VALUE;
            $descriptions[$key] = "{$rooms[$v]} jackpot爆出线";
            $key = "jackpotRate_{$kindID}_{$v}";
            $config[$key] = $redis->get($key) . '%';
            $descriptions[$key] = "{$rooms[$v]} jackpot占税收比例";
            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => '蜜蜂',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }
    public function Aztec()
    {
        $redis = Redis::connection('ServerGameRedis');
        $kindID = 5004;
        $descriptions = [];
        $rooms = [
            1 => '初级场',
            2 => '中级场',
            3 => '高级场'
        ];
        $config = [];
        foreach (range(1, 3) as $v) {

            $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]} 控制线以上玩家 充值上限比例";
        }

        return view('admin.config.treasure_slot', [
            'game_name' => 'Aztec Spell',
            'config' => $config,
            'descriptions' => $descriptions
        ]);
    }

}
