<?php
/**
 *配置相关
 */

defined('IN_WEB') or die('Include Error!');

class Config
{
    public function __construct()
    {
        date_default_timezone_set("Asia/Shanghai");
    }

//    /**
//     * 桌子配置
//     */
//    public function table($param)
//    {
//        $levelBegin = oo::functions()->uint($param['levelBegin']);
//        $levelEnd = oo::functions()->uint($param['levelEnd']);
//        $table = otable::srv_tableconfig();
//        $where = ' WHERE 1 = 1 ';
//        if(!empty($levelBegin)) {
//            $where .= " AND level >= {$levelBegin} ";
//        }
//        if(!empty($levelEnd)) {
//            $where .= " AND level <= {$levelEnd} ";
//        }
//        $sql = " SELECT * FROM {$table} {$where} ORDER BY SmallBlind ASC , level ASC ";
//        $list = oo::commonOprDb('admin')->getAll($sql, MYSQLI_ASSOC);
//        return json_encode($list);
//    }

//    /**
//     * 编辑桌子表
//     */
//    public function edittable($param)
//    {
//        $table = otable::srv_tableconfig();
//        $level = $param['level'];
//        $SmallBlind = $param['SmallBlind'];
//        $one_card_time = $param['one_card_time'];
//        $BET_TIME = $param['BET_TIME'];
//        $show_pool_time = $param['show_pool_time'];
//        $delaystop_time = $param['delaystop_time'];
//        $MAX_SIT_USER = $param['MAX_SIT_USER'];
//        $FEE = $param['FEE'];
//        $MIN_ANTE = $param['MIN_ANTE'];
//        $MAX_ANTE = $param['MAX_ANTE'];
//        $MIN_IN = $param['MIN_IN'];
//        $MAX_IN = $param['MAX_IN'];
//        $ANIMATION_TIME = $param['ANIMATION_TIME'];
//        $NO_OPER_STAND_ROUND = $param['NO_OPER_STAND_ROUND'];
//        $table_name = $param['table_name'];
//        $robot_check_time = $param['robot_check_time'];
//        $robot_num = $param['robot_num'];
//        $robot_in_min_time = $param['robot_in_min_time'];
//        $robot_in_max_time = $param['robot_in_max_time'];
//        $robot_out_min_time = $param['robot_out_min_time'];
//        $robot_out_max_time = $param['robot_out_max_time'];
//        $newplayer_rounds = $param['newplayer_rounds'];
//        $newplayer_probability = $param['newplayer_probability'];
//
//        $sql = "UPDATE {$table} SET SmallBlind = {$SmallBlind}, one_card_time = {$one_card_time}, BET_TIME = {$BET_TIME}, show_pool_time = {$show_pool_time}, delaystop_time = {$delaystop_time},  MAX_SIT_USER = {$MAX_SIT_USER}, FEE = {$FEE}, MIN_ANTE = {$MIN_ANTE}, MAX_ANTE = {$MAX_ANTE}, MIN_IN = {$MIN_IN}, MAX_IN = {$MAX_IN}, ANIMATION_TIME = {$ANIMATION_TIME}, NO_OPER_STAND_ROUND = {$NO_OPER_STAND_ROUND}, table_name = '{$table_name}', robot_check_time = {$robot_check_time}, robot_num = '{$robot_num}', robot_in_min_time = {$robot_in_min_time}, robot_in_max_time = {$robot_in_max_time}, robot_out_min_time = {$robot_out_min_time}, robot_out_max_time = {$robot_out_max_time}, newplayer_rounds = {$newplayer_rounds}, newplayer_probability = {$newplayer_probability} WHERE level = {$level} LIMIT 1";
//        $rs = oo::commonOprDb('admin')->query($sql);
//        if( $rs ){//通知server
//            if ($level < 100) {//小于100的是比赛场
//                oo::cserver()->noticeServerMatchInfoUpdate($level);
//            }else{
//                shell_exec("sh /data/server/DzGameServer/GameServer/bin/cfg_reload/cfg_reload.sh");
//            }
//            //清除桌子缓存
//            $tableKey = okeys::tableconfig();
//            oo::commonOprRedis('common')->delete($tableKey);
//        }
//
//        return $rs ? 1 : 0;
//    }

//    /**
//     * 修改桌子配置  --通过ajax提交，只更新一个字段
//     * @param $param
//     * @return mixed
//     */
//    public  function  eidtTableOne($param) {
//        $postDataKey = array('frombg', 'lid' , 'sid', 'mod', 'act', 'demo');
//        $level = oo::functions()->uint($param['level']);
//        if(empty($level)) {
//            oo::logs()->debug3(['editTableOne'=>'查找不到要更新的记录'], 'Config.php');
//            return 0;
//        }
//
//        $table = otable::srv_tableconfig();
//
//        $setStr = '';
//        foreach ($param as $k => $v) {
//            if($k == 'level' || in_array($k, $postDataKey)) {
//                continue;
//            }
//            $setStr .= ' '.$k. '=' ."'{$v}'";
//        }
//        if(empty($setStr)) {
//            oo::logs()->debug3(['editTableOne'=>'没有需要更新的数据'], 'Config.php');
//            return 0;
//        }
//        $sql = " UPDATE {$table} SET {$setStr} WHERE level = {$level} LIMIT 1";
//        oo::logs()->debug3(['sql'=>$sql], 'Config.php');
//        $rs = oo::commonOprDb('admin')->query($sql);
//
//        if( $rs ){//通知server
//            if ($level < 100) {//小于100的是比赛场
//                oo::cserver()->noticeServerMatchInfoUpdate($level);
//            }else if($level < 501 ){//德州桌子
//                shell_exec("sh /data/server/DzGameServer/GameServer/bin/cfg_reload/cfg_reload.sh");
//            }else if($level < 506){//奥马哈桌子
//                shell_exec("sh /data/server/OmahaGameServer/GameServer/bin/cfg_reload/cfg_reload.sh");
//            }
//            //清除桌子缓存
//            $tableKey = okeys::tableconfig();
//            oo::commonOprRedis('common')->delete($tableKey);
//        }
//
//        return $rs;
//    }

    /**
     * 老虎机配置修改
     */
    public function optConfig($param){

        if(!$param['actStatus'] == 0){
            if(empty($param['levelId']) || empty($param['slotpro'])){
                return json_encode(['code' => -1, 'msg' => 'id或者配置为空']);
            }
        }


        $levelId = intval($param['levelId']); //关卡id
        $slotpro = json_decode($param['slotpro'],true);
        $update_desc = $param['update_desc'];
        $infoSlot = json_encode($slotpro,JSON_UNESCAPED_UNICODE);

        if($param['tb'] == 'slot'){
            $tb = otable::slotConfig();
        }else if($param['tb'] == 'turn'){
            $version = empty($param['conf_ver']) ? '' : '2';
            $tb = otable::slotTurntable($version);
        }else{
            return json_encode(['code' => -2, 'msg' => '数据库为空']);
        }

        if($param['actStatus'] == 0){
            //新增
            $sql = "INSERT INTO {$tb} VALUES(NULL, '{$infoSlot}', '{$update_desc}')";
            oo::commonOprDb('common')->query($sql);
            $rs = oo::commonOprDb('common')->insertID();
        }else if($param['actStatus'] == 1){
            //修改
            $sql = "UPDATE {$tb} SET `slotpro` = '{$infoSlot}' ,`update_desc`='{$update_desc}' WHERE `levelId` = {$levelId}";
            $rs = oo::commonOprDb('common')->query($sql);

        }

        return $rs ? $rs : 0;
    }

    /**
     * 获取建筑物价格配置
     * @param $param
     * @return false|string
     * Created by: Cassie Lee
     * Created on: 2019/6/4 17:16
     * Description:
     */
    public function getBuildConfig($param){
        $start = ($param['page'] -1)*10;
        $length = $param['page_size'];

        $tb = otable::coinConfig();
        $sql = "SELECT * from {$tb} LIMIT {$start},{$length}";
        $rs = oo::commonOprDb('common')->getAll($sql,1);
        $arr = [];
        foreach ($rs as $k=>$v){
            $arr[$v['levelId']] = json_decode($v['coinConfig']);
        }
        $sql = "SELECT COUNT(*) as num from {$tb}";
        $rs = oo::commonOprDb('common')->getOne($sql,1);
        $returnData = [
            'total'=>$rs['num'],
            'data'=>$arr,
        ];

        return json_encode($returnData);
    }

    /**
     * 保存建筑物价格配置
     * @param $param
     * @return int
     * Created by: Cassie Lee
     * Created on: 2019/6/4 20:02
     * Description:
     */
    public function saveBuildConfig($param){
        $data = json_decode($param['data'],true);
        $tb = otable::coinConfig();

        $sql = "SELECT * FROM {$tb} WHERE 1";
        $ret = oo::commonOprDb('common')->getAll($sql,MYSQLI_ASSOC);
        $id = [];
        foreach ($ret as $row){
            $id[] = $row['levelId'];
        }

        foreach ($data as $key=>$value){
            $temp = json_encode($value['coinConfig'],JSON_NUMERIC_CHECK);
            if(in_array($value['level'],$id)){
                $sql = "UPDATE {$tb} SET coinConfig='{$temp}' WHERE levelId={$value['level']}";
            }else{
                $sql = "INSERT INTO {$tb} (levelId,coinConfig,name,name_en,pictureId,reward_spin,reward_coin,reward) VALUES ({$value['level']},'{$temp}','导入未命名','Not Name','{$value['level']}',50,4000000,'')";
            }
            $rs = oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hDel(okeys::CoinConfig(),$value['level']);
            oo::commonOprModel('level')->getLevelConf($value['level'],true);
        }
        return $rs ? $rs : 0;
    }

    /**
     * 获取老虎机配置
     * @param $param
     * @return false|string
     * Created by: Cassie Lee
     * Created on: 2019/6/4 17:16
     * Description:
     */
    public function getSoltConfig($param){
        $start = ($param['page'] -1)*10;
        $length = $param['page_size'];

        $tb = otable::slotConfig();
        $sql = "SELECT * from {$tb} LIMIT {$start},{$length}";
        $rs = oo::commonOprDb('common')->getAll($sql,1);
        $arr = [];
        foreach ($rs as $k=>$v){
            $arr[$v['levelId']] = json_decode($v['slotpro']);
        }
        $sql = "SELECT COUNT(*) as num from {$tb}";
        $rs = oo::commonOprDb('common')->getOne($sql,1);
        $returnData = [
            'total'=>$rs['num'],
            'data'=>$arr,
        ];

        return json_encode($returnData);
    }

    /**
     * 保存老虎机配置
     * @param $param
     * @return int
     * Created by: Cassie Lee
     * Created on: 2019/6/4 20:02
     * Description:
     */
    public function saveSoltConfig($param){
        $data = json_decode($param['data']);
        $tb = otable::slotConfig();
        $sql = "SELECT levelId from {$tb}";
        $rs = oo::commonOprDb('common')->getAll($sql,1);
        $temp = [];
        foreach ($rs as $row){
            array_push($temp,(int)$row['levelId']);
        }

        foreach ($data as $row){
            $tempData = json_encode($row->slotpro,JSON_UNESCAPED_UNICODE);
            if(in_array($row->level,$temp)){
                $sql = "UPDATE {$tb} SET slotpro='{$tempData}' WHERE levelId={$row->level}";
            }else{
                $sql = "INSERT INTO {$tb} (levelId,slotpro) VALUES ({$row->level},'{$tempData}')";
            }
            $rs = oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hDel(okeys::SlotConfig(),$row->level);
        }

        $online = oo::commonOprModel('Workerman')->getAllUidList();
        foreach ($online as $row){
            oo::commonOprRedis('User')->delete(okeys::SlotSet($row));
        }

        return $rs ? $rs : 0;
    }

    /**
     * 获取老虎机活动配置
     * @param $param
     * @return false|string
     * Created by: Hss
     * Created on: 2020/11/18 11:58
     * Description:
     */
    public function getSlotActivityConfig($param){
        $start = ($param['page'] -1)*10;
        $length = $param['page_size'];

        $tb = otable::slotActivityConfig();
        $sql = "SELECT * from {$tb} LIMIT {$start},{$length}";
        $rs = oo::commonOprDb('common')->getAll($sql,1);
        $arr = [];
        foreach ($rs as $k=>$v){
            $arr[$v['levelId']] = json_decode($v['data']);
        }
        $sql = "SELECT COUNT(*) as num from {$tb}";
        $rs = oo::commonOprDb('common')->getOne($sql,1);
        $returnData = [
            'total'=>$rs['num'],
            'data'=>$arr,
        ];

        return json_encode($returnData);
    }

    /**
     * 保存老虎机活动配置
     * @param $param
     * @return int
     * Created by: Hss
     * Created on: 2020/11/18 21:05
     * Description:
     */
    public function saveSlotActivityConfig($param){
        $data = json_decode($param['data']);
        $tb = otable::slotActivityConfig();
        $sql = "SELECT levelId from {$tb}";
        $rs = oo::commonOprDb('common')->getAll($sql,1);
        $temp = [];
        foreach ($rs as $row){
            array_push($temp,(int)$row['levelId']);
        }

        foreach ($data as $row){
            $tempData = json_encode($row->data,JSON_UNESCAPED_UNICODE);
            if(in_array($row->level,$temp)){
                $sql = "UPDATE {$tb} SET data='{$tempData}' WHERE levelId={$row->level}";
            }else{
                $sql = "INSERT INTO {$tb} (levelId,data) VALUES ({$row->level},'{$tempData}')";
            }
            $rs = oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hDel(okeys::slotActivityConfig(),$row->level);
        }

        return $rs ? $rs : 0;
    }

    /**
     * 获取大转盘配置
     * @param $param
     * @return false|string
     * Created by: Cassie Lee
     * Created on: 2019/6/4 17:16
     * Description:
     */
    public function getTurnConfig($param){
        if($param['type'] == 'plus'){
            $tb = otable::TurntableConfigPlus();
            $sql = "SELECT * from {$tb}";
            $rs = oo::commonOprDb('common')->getAll($sql,1);
            $returnData = [];
            foreach ($rs as $k=>$v){
                $returnData[] = [
                    'levelId'=>$v['levelId'],
                    'slotpro'=>json_decode($v['slotpro'])
                ];
            }
        }else{
            $version = empty($param['conf_ver']) ? '' : '2';
            $tb = otable::slotTurntable($version);
            $sql = "SELECT * from {$tb}";
            $rs = oo::commonOprDb('common')->getAll($sql,1);
            $arr = [];
            foreach ($rs as $k=>$v){
                $arr[$v['levelId']] = json_decode($v['slotpro']);
            }
            $returnData = [
                'total'=>count($rs),
                'data'=>$arr,
            ];
        }
        return json_encode($returnData);
    }

    /**
     * 保存大转盘配置
     * @param $param
     * @return mixed
     * Created by: Cassie Lee
     * Created on: 2019/6/4 20:02
     * Description:
     */
    public function saveTurnConfig($param){
        if($param['type'] == 'plus'){
            $data = json_decode($param['data'],true);
            $tb = otable::TurntableConfigPlus();
            $sql = "SELECT levelId from {$tb}";
            $rs = oo::commonOprDb('common')->getAll($sql,1);
            $temp = array_column($rs,'levelId');
            foreach ($data as $row){
                if(in_array($row['levelId'],$temp)){
                    $sql = "UPDATE {$tb} SET slotpro='{$row['slotpro']}' WHERE levelId={$row['levelId']}";
                }else{
                    $sql = "INSERT INTO {$tb} (levelId,slotpro) VALUES ({$row['levelId']},'{$row['slotpro']}')";
                }
                oo::commonOprDb('common')->query($sql);
            }
            return $this->makeTurnTableJson();
        }else{
            $data = json_decode($param['data']);
            $version = empty($param['conf_ver']) ? '' : '2';
            $tb = otable::slotTurntable($version);
            $sql = "SELECT levelId from {$tb}";
            $rs = oo::commonOprDb('common')->getAll($sql,1);
            $temp = [];
            foreach ($rs as $row){
                array_push($temp,(int)$row['levelId']);
            }
            foreach ($data as $row){
                $tempData = json_encode($row->slotpro,JSON_UNESCAPED_UNICODE);
                if(in_array($row->level,$temp)){
                    $sql = "UPDATE {$tb} SET slotpro='{$tempData}' WHERE levelId={$row->level}";
                }else{
                    $sql = "INSERT INTO {$tb} (levelId,slotpro) VALUES ({$row->level},'{$tempData}')";
                }
                $rs = oo::commonOprDb('common')->query($sql);
            }
            oo::commonOprRedis('common')->delete(okeys::slotTurntable($version));
            return $rs ? $rs : 0;
        }
    }

    public function makeTurnTableJson(){
        $tb = otable::TurntableConfigPlus();
        $data = oo::commonOprDb('common')->getAll("SELECT * from {$tb}",MYSQLI_ASSOC);
        $out = [];
        foreach ($data as $row){
            $temp = json_decode($row['slotpro'],true);
            $tmp  = [];
            foreach ($temp as $x){
                $tmp[] = [
                    'type'=> $x['type'],
                    'num' => $x['num'],
                ];
            }
            $out[] = [
                'level' => $row['levelId'],
                'data' => $tmp,
            ];
        }
        $plus = $out;
        $tbs = otable::slotTurntable();
        $sqls = "select * from {$tbs} where 1";
        $confs = oo::commonOprDb('config')->getAll($sqls, MYSQLI_ASSOC);
        $out = [];
        foreach ($confs as $row){
            $temp = json_decode($row['slotpro'],true);
            $tmp  = [];
            foreach ($temp as $x){
                $tmp[] = [
                    'type' => 1,
                    'num' => $x['prize'],
                ];
            }
            $out[] = [
                'level' => $row['levelId'],
                'data' => $tmp,
            ];
        }
        $normal = $out;

        $tbs = otable::slotTurntable(2);
        $sqls = "select * from {$tbs} where 1";
        $confs = oo::commonOprDb('config')->getAll($sqls, MYSQLI_ASSOC);
        $out = [];
        foreach ($confs as $row){
            $temp = json_decode($row['slotpro'],true);
            $tmp  = [];
            foreach ($temp as $x){
                $tmp[] = [
                    'type' => 1,
                    'num' => $x['prize'],
                ];
            }
            $out[] = [
                'level' => $row['levelId'],
                'data' => $tmp,
            ];
        }
        $normal2 = $out;

        $filename = "TurnTableConfig".time().".json";
        oo::commonOprModel('config')->setStaticConfig("TurnTable",$filename);
        oo::commonOprRedis('common')->delete(okeys::TurntableConfigPlus());
        return json_encode([
            'filename' => $filename,
            'data' => [
                'normal'  => $normal,
                'plus'    => $plus,
                'normal2' => $normal2,
                'bet'     => oo::commonOprModel('readconfig')->getCon('basic','turntableBet'),
            ],
        ]);
    }

  	/**
     * 获取体力大转盘配置
     * @param $param
     * @return false|string
     * Created by: Cassie Lee
     * Created on: 2019/6/4 17:16
     * Description:
     */
    public function getTurnSpinsConfig($param){
        $type = $param['type'];
        $tb = otable::spinsTurntable();
        $sql = "SELECT * from {$tb} WHERE type={$type}";
        $rs = oo::commonOprDb('common')->getAll($sql,1);
        $arr = [];
        foreach ($rs as $k=>$v){
            $arr[$v['levelId']] = json_decode($v['slotpro']);
        }
        $sql = "SELECT COUNT(*) as num from {$tb} WHERE type={$type}";
        $rs = oo::commonOprDb('common')->getOne($sql,1);
        $returnData = [
            'total'=>$rs['num'],
            'data'=>$arr,
        ];

        return json_encode($returnData);
    }

    /**
     * 获取体力大转盘配置
     * @param $param
     * @return int
     * Created by: Cassie Lee
     * Created on: 2019/6/4 20:02
     * Description:
     */
    public function saveTurnSpinsConfig($param){
        $type = $param['type'];
        $data = json_decode($param['data']);
        $tb = otable::spinsTurntable();
        $sql = "SELECT levelId from {$tb} WHERE type={$type}";
        $rs = oo::commonOprDb('common')->getAll($sql,1);
        $temp = [];
        foreach ($rs as $row){
            array_push($temp,(int)$row['levelId']);
        }

        foreach ($data as $row){
            $tempData = json_encode($row->slotpro,JSON_UNESCAPED_UNICODE);
            if(in_array($row->level,$temp)){
                $sql = "UPDATE {$tb} SET slotpro='{$tempData}' WHERE levelId={$row->level} AND type={$type}";
            }else{
                $sql = "INSERT INTO {$tb} (levelId,type,slotpro) VALUES ({$row->level},{$type},'{$tempData}')";
            }
            $rs = oo::commonOprDb('common')->query($sql);
        }

        return $rs ? $rs : 0;
    }
  	
    /**
     * 获取建筑物价格配置
     * @param $param
     * @return false|string
     * Created by: Cassie Lee
     * Created on: 2019/6/4 17:16
     * Description:
     */
    public function getLevelConfig($param){
        $start = ($param['page'] -1)*10;
        $length = $param['page_size'];

        $tb = otable::coinConfig();
        $sql = "SELECT * from {$tb} LIMIT {$start},{$length}";
        $arr = oo::commonOprDb('common')->getAll($sql,1);
        $sql = "SELECT COUNT(*) as num from {$tb}";
        $rs = oo::commonOprDb('common')->getOne($sql,1);
        $returnData = [
            'total'=>$rs['num'],
            'data'=>$arr,
        ];

        return json_encode($returnData);
    }

    public function saveLevelConfig($param){
        $param['data'] = empty($param['data']) ? oo::commonOprRedis('statistics')->hGet($param['uniqidKey'],'data') : $param['data'];
        oo::commonOprRedis('statistics')->delete($param['uniqidKey']);
        $data = json_decode($param['data']);
        $tb = otable::coinConfig();
        foreach ($data as $row){
            $sql = "UPDATE {$tb} SET ";
            if(!empty($row->data->name)){
                $sql .= "name='{$row->data->name}',name_tw='{$row->data->name_tw}',";
            }
            if(!empty($row->data->name_en)){
                $row->data->name_en = str_replace("'","\'",$row->data->name_en);
                $sql .= "name_en='{$row->data->name_en}',";
                $row->data->name_fr = str_replace("'","\'",$row->data->name_fr);
                $sql .= "name_fr='{$row->data->name_fr}',";

                $row->data->name_de = str_replace("'","\'",$row->data->name_de);
                $sql .= "name_de='{$row->data->name_de}',";

                $row->data->name_es = str_replace("'","\'",$row->data->name_es);
                $sql .= "name_es='{$row->data->name_es}',";

                $row->data->name_pt = str_replace("'","\'",$row->data->name_pt);
                $sql .= "name_pt='{$row->data->name_pt}',";

                $row->data->name_th = str_replace("'","\'",$row->data->name_th);
                $sql .= "name_th='{$row->data->name_th}',";

                $row->data->name_vn = str_replace("'","\'",$row->data->name_vn);
                $sql .= "name_vn='{$row->data->name_vn}',";

                $row->data->name_no = str_replace("'","\'",$row->data->name_no);
                $sql .= "name_no='{$row->data->name_no}',";

                $row->data->name_id = str_replace("'","\'",$row->data->name_id);
                $sql .= "name_id='{$row->data->name_id}',";

                $row->data->name_rou = str_replace("'","\'",$row->data->name_rou);
                $sql .= "name_rou='{$row->data->name_rou}',";

                $row->data->name_my = str_replace("'","\'",$row->data->name_my);
                $sql .= "name_my='{$row->data->name_my}',";
                $row->data->name_it = str_replace("'","\'",$row->data->name_it);
                $sql .= "name_it='{$row->data->name_it}',";
                $row->data->name_pl = str_replace("'","\'",$row->data->name_pl);
                $sql .= "name_pl='{$row->data->name_pl}',";

            }
            $sql .= "pictureId='{$row->data->pictureId}',reward='{$row->data->reward}' WHERE levelId={$row->levelId}";
            $rs = oo::commonOprDb('common')->query($sql);
            oo::commonOprModel('level')->getLevelConf($row->levelId,true);
        }

        return $rs ? $rs : 0;
    }

    /**
     * 上传岛图片
     * @param $param
     * @return int
     * Created by: Owen
     * Created on: 2019/8/23 15:03
     * Description:
     */
    public function saveLevelPic($param){
        $pictureId = $param['pictureId'];
        $levelId = intval($param['levelId']);
        $tb = otable::coinConfig();
        $sql = "UPDATE {$tb} SET  pictureId='{$pictureId}' WHERE levelId={$levelId}";
        $rs = oo::commonOprDb('common')->query($sql);
        return $rs ? $rs : 0;
    }


    /**
     * 获取矿工价格配置
     * @param $param
     * @return false|string
     * Created by: Cassie Lee
     * Created on: 2019/6/4 17:16
     * Description:
     */
    public function getMiningConfig($param){
        $start = ($param['page'] -1)*10;
        $length = $param['page_size'];

        $tb = otable::upgradeMiners_Config();
        $sql = "SELECT * from {$tb} LIMIT {$start},{$length}";
        $arr = oo::commonOprDb('common')->getAll($sql,1);
        $sql = "SELECT COUNT(*) as num from {$tb}";
        $rs = oo::commonOprDb('common')->getOne($sql,1);
        $returnData = [
            'total'=>$rs['num'],
            'data'=>$arr,
        ];

        return json_encode($returnData);
    }

    public function saveMiningConfig($param){
        $data = json_decode($param['data']);
        $tb = otable::upgradeMiners_Config();

        $sql = "SELECT * FROM {$tb} WHERE 1";
        $ret = oo::commonOprDb('common')->getAll($sql,MYSQLI_ASSOC);
        $id = [];
        foreach ($ret as $row){
            $id[] = $row['id'];
        }

        foreach ($data as $row){
            $config = json_encode($row->config);
            if(in_array($row->id,$id)){
                $sql = "UPDATE {$tb} SET initIncome='{$row->initIncome}',growIncome='{$row->growIncome}',config='{$config}' WHERE id={$row->id}";
            }else{
                $sql = "INSERT INTO {$tb} (id,initIncome,growIncome,config) VALUES ({$row->id},{$row->initIncome},{$row->growIncome},'{$config}')";
            }
            $rs = oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hDel(okeys::MiningConfig(),$row->id);
        }
        return $rs ? $rs : 0;
    }

    public function GetTaskConfig(){
        $tb = otable::taskConfig();
        $sql = "SELECT * from {$tb} WHERE 1";
        $arr = oo::commonOprDb('common')->getAll($sql,1);
        $returnData = [
            'code'=>1,
            'data'=>$arr,
        ];
        return json_encode($returnData);
    }

    public function saveTaskConfig($param){
        $data = json_decode($param['data']);
        $tb = otable::taskConfig();
        foreach ($data as $row){
            $row->task_title_en = str_replace("'","\'",$row->task_title_en);
            $sql = "UPDATE {$tb} SET task_title='{$row->task_title}',task_title_en='{$row->task_title_en}',task_title_tw='{$row->task_title_tw}',task_title_fr='{$row->task_title_fr}',task_title_de='{$row->task_title_de}',task_title_es='{$row->task_title_es}',task_title_pt='{$row->task_title_pt}',task_title_th='{$row->task_title_th}',task_type='{$row->task_type}',reward_type='{$row->reward_type}',reward_num='{$row->reward_num}',target_times='{$row->target_times}' WHERE id={$row->id}";
            $rs = oo::commonOprDb('common')->query($sql);
        }
        oo::commonOprRedis('common')->delete(okeys::taskConfig());
        return $rs ? $rs : 0;
    }

    public function getAchiConfig(){
        $tb = otable::achievementConfig();
        $sql = "SELECT * from {$tb} WHERE 1";
        $arr = oo::commonOprDb('common')->getAll($sql,1);
        $returnData = [
            'code'=>1,
            'data'=>$arr,
        ];
        return json_encode($returnData);
    }

    public function saveAchiConfig($param){
        $data = json_decode($param['data']);
        $tb = otable::achievementConfig();
        foreach ($data as $row){
            $reward = json_encode($row->reward);
            $row->designation_en = str_replace("'","\'",$row->designation_en);
            $sql = "UPDATE {$tb} SET designation='{$row->designation}',designation_tw='{$row->designation_tw}',designation_en='{$row->designation_en}',designation_fr='{$row->designation_fr}',designation_de='{$row->designation_de}',designation_es='{$row->designation_es}',designation_pt='{$row->designation_pt}',designation_th='{$row->designation_th}',content='{$row->content}',content_tw='{$row->content_tw}',content_en='{$row->content_en}',content_fr='{$row->content_fr}',content_de='{$row->content_de}',content_es='{$row->content_es}',content_pt='{$row->content_pt}',content_th='{$row->content_th}',stage='{$row->stage}',reward='{$reward}' WHERE aid={$row->aid}";
            $rs = oo::commonOprDb('common')->query($sql);
        }
        return $rs ? $rs : 0;
    }

    public function makeMiningJson($param){
//        $tb = otable::upgradeMiners_Config();
//        $sql = "SELECT * from {$tb} WHERE 1";
//        $arr = oo::commonOprDb('common')->getAll($sql,1);
//        $initIncome = 0;
//        $growIncome = 0;
        $output = json_decode('{}');
        $temp = [];
        $tb = otable::coinConfig();
        $sql = "SELECT * from {$tb}";
        $coincConfig = oo::commonOprDb('common')->getAll($sql,1);
        $coinTemp = [];
        foreach ($coincConfig as $row){
            $coinTemp[$row['levelId']] = [
                'name'=>$row['name'],
                'name_en'=>$row['name_en'],
                'name_tw'=>$row['name_tw'],
                'name_fr'=>$row['name_fr'],
                'name_de'=>$row['name_de'],
                'name_es'=>$row['name_es'],
                'name_pt'=>$row['name_pt'],
                'name_th'=>$row['name_th'],
                'name_vn'=>$row['name_vn'],
                'name_no'=>$row['name_no'],
                'name_id'=>$row['name_id'],
                'name_rou'=>$row['name_rou'],
                'name_my'=>$row['name_my'],
                'name_it'=>$row['name_it'],
                'name_pl'=>$row['name_pl'],
                'pictureId'=>$row['pictureId'],
            ];
            $row['id'] = $row['levelId'];
            $temp[] = [
                intval($row['id']),
                [
                    $coinTemp[$row['id']]['name'],
                    $coinTemp[$row['id']]['name_en'],
                    $coinTemp[$row['id']]['name_tw'],
                    $coinTemp[$row['id']]['name_fr'],
                    $coinTemp[$row['id']]['name_de'],
                    $coinTemp[$row['id']]['name_es'],
                    $coinTemp[$row['id']]['name_pt'],
                    $coinTemp[$row['id']]['name_th'],
                    $coinTemp[$row['id']]['name_id'],
                    $coinTemp[$row['id']]['name_vn'],
                    $coinTemp[$row['id']]['name_no'],
                    $coinTemp[$row['id']]['name_rou']
                    ,$coinTemp[$row['id']]['name_my']
                    ,$coinTemp[$row['id']]['name_it']
                    ,$coinTemp[$row['id']]['name_pl']
                ]
            ];
        }

        $output->island = $temp;

        if(!empty($param['filename'])){
            $filename = $param['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='Mining'";
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'Mining',$filename);
        }

        return json_encode([
            'code'=>1,
            'data'=>$output,
        ]);
    }

    public function GetBaseConfig(){
        $table = otable::basicConfig();
        $sql = "SELECT * FROM {$table} WHERE id NOT IN (9,11)";
        $arr = oo::commonOprDb('common')->getAll($sql,1);
        $returnData = [
            'code'=>1,
            'data'=>$arr,
        ];
        return json_encode($returnData);
    }

    public function saveBaseConfig($param){
        $data = json_decode($param['data']);
        $tb = otable::basicConfig();

        $sql = "SELECT * FROM {$tb} WHERE 1";
        $ret = oo::commonOprDb('common')->getAll($sql,MYSQLI_ASSOC);
        $id = [];
        foreach ($ret as $row){
            $id[] = $row['id'];
        }

        foreach ($data as $row){
            if($row->item == "basic" && $row->title == "curMaxLevel"){
                $curLevel = oo::commonOprRedis('common')->hGet(otable::basicConfig(),$row->item.'-'.$row->title);
                if($row->content != $curLevel){
//                    oo::commonOprModel('Workerman')->pushAll(ocmd::$send['updateCurMaxLevel'],['curMaxLevel'=>intval($row->content)]);
                }
                if($curLevel < $row->content ){
                    oo::commonOprRedis('common')->setnx(okeys::UpdateCurMaxLevelPush(),1);
                }
            }
            if(in_array($row->id,$id)){
                $sql = "UPDATE {$tb} SET memo='{$row->memo}',item='{$row->item}',title='{$row->title}',content='{$row->content}' WHERE id={$row->id}";
            }else{
                $sql = "INSERT INTO {$tb} (id,item,title,content,memo) VALUES (NULL,'{$row->item}','{$row->title}','{$row->content}','{$row->memo}')";
            }
            $rs = oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hDel($tb,$row->item.'-'.$row->title);
            oo::commonOprRedis('common')->hDel(strtolower($tb),$row->item.'-'.$row->title);
        }

        if(!empty($param['filename'])){
            $filename = $param['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='Game'";
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'Game',$filename);
        }

        return $rs ? $rs : 0;
    }

    public function getSymbolConfig($param){
        $type = intval($param['type']);
        switch ($type){
            case 4:
                $table = otable::ThanksgivingConfig();
                break;
            default:
                $table = otable::SymbolConfig(2);
            break;
        }
        $sql = "SELECT * FROM {$table} WHERE 1";
        $arr = oo::commonOprDb('common')->getAll($sql,1);
        $returnData = [
            'code'=>1,
            'data'=>$arr,
        ];
        return json_encode($returnData);
    }

    public function saveSymbolConfig($param){
        $type = intval($param['type']);
        switch ($type){
            case 4:
                $tb = otable::ThanksgivingConfig();
                break;
            default:
                $tb = otable::SymbolConfig(2);
                break;
        }
        $data = json_decode($param['data']);
        foreach ($data as $row){
            $sql = "SELECT * FROM {$tb} WHERE stage={$row->stage}";
            oo::commonOprRedis('common')->hSet(okeys::SymbolConfig($type,2),$row->stage,$row->num);
            oo::commonOprRedis('common')->hSet(okeys::SymbolConfig($type,2),$row->stage."#type",$row->type);
            oo::commonOprRedis('common')->hSet(okeys::SymbolConfig($type,2),$row->stage."#reward",$row->reward);
            $rs = oo::commonOprDb('common')->getOne($sql,1);
            if(empty($rs)){
                $sql = "INSERT INTO {$tb} (stage,num,type,reward) VALUES ({$row->stage},{$row->num},{$row->type},{$row->reward})";
            }else{
                $sql = "UPDATE {$tb} SET stage={$row->stage},num={$row->num},type={$row->type},reward={$row->reward} WHERE stage={$row->stage}";
            }
            $rs = oo::commonOprDb('common')->query($sql);
        }
        return $rs ? $rs : 0;
    }

    public function getEventConfig($param){
        $table = otable::EventTitle();
        if(isset($param['event_id'])){
            $sql = "SELECT * FROM {$table} WHERE event_id={$param['event_id']}";
            $arr = oo::commonOprDb('common')->getOne($sql,1);
        }else{
            $sql = "SELECT * FROM {$table} WHERE 1";
            $arr = oo::commonOprDb('common')->getAll($sql,1);
        }
        $returnData = [
            'code'=>1,
            'data'=>$arr,
        ];
        return json_encode($returnData);
    }

    public function saveEventConfig($param){
        $tb = otable::EventTitle();
        if($param['action'] == "add"){
            $sql = "INSERT INTO {$tb} (name,event_id,mean,ids) VALUES('{$param['name']}','{$param['event_id']}','{$param['mean']}','{$param['ids']}')";
            $ret = oo::commonOprDb('common')->query($sql);
        }else{
            $set = "`name` = '{$param['name']}',`event_id` = '{$param['event_id']}',`mean` = '{$param['mean']}',`ids` = '{$param['ids']}'";
            $sql = "UPDATE {$tb} SET {$set} WHERE id = {$param['id']} LIMIT 1";
            $ret = oo::commonOprDb('common')->query($sql);
        }
        return $ret?$ret:0;
    }

    public function delEventConfig($param){
        $tb = otable::EventTitle();
        $sql = "DELETE FROM {$tb} WHERE id={$param['id']}";
        $ret = oo::commonOprDb('common')->query($sql);
        return $ret?$ret:0;
    }

    public function chatProhibit(){
        $tb = otable::chatProhibit();
        $sql = "SELECT content FROM {$tb} WHERE id=1 LIMIT 1";
        $ret = oo::commonOprDb('common')->getOne($sql,MYSQLI_ASSOC);
        return $ret['content'];
    }

    public function saveChatProhibit($param){
        $tb = otable::chatProhibit();
        $content = oo::functions()->escape($param['content']);
        $set = "`content`='{$content}'";
        $sql = "UPDATE {$tb} SET {$set} WHERE id=1 LIMIT 1";
        oo::commonOprDb('common')->getOne($sql,MYSQLI_ASSOC);
        if(!empty($param['filename'])){
            $filename = $param['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='chatProhibit'";
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'chatProhibit',$filename);
        }
        return 1;
    }
  
//  	public function getAnnouncement($param){
//        $tb = otable::announcement();
//        if(isset($param['id'])){
//            $sql = "SELECT * FROM {$tb} WHERE id={$param['id']}";
//            $ret = oo::commonOprDb('common')->getOne($sql,MYSQLI_ASSOC);
//        }else{
//            $sql = "SELECT * FROM {$tb}";
//            $ret = oo::commonOprDb('common')->getAll($sql,MYSQLI_ASSOC);
//        }
//        return json_encode($ret);
//    }
//
//    public function setAnnouncement($param){
//        $tb = otable::announcement();
//        if(isset($param['id'])){
//            $sql = "UPDATE {$tb} SET title='{$param['title']}',content='{$param['content']}',stime='{$param['stime']}',etime='{$param['etime']}', device='{$param['device']}',usertype='{$param['usertype']}' WHERE id={$param['id']}";
//            oo::commonOprDb('common')->query($sql);
//            $id = $param['id'];
//        }else{
//            $sql = "INSERT INTO {$tb} (title, content, stime, etime, device, usertype) VALUES('{$param['title']}','{$param['content']}','{$param['stime']}','{$param['etime']}','{$param['device']}','{$param['usertype']}')";
//            oo::commonOprDb('common')->query($sql);
//            $id = oo::commonOprDb('common')->insertID();
//        }
//        $temp = [
//            'stime'   =>$param['stime'],
//            'etime'   =>$param['etime'],
//            'usertype'=>$param['usertype'],
//            'device'  =>$param['device'],
//            'title'   =>$param['title'],
//            'content' =>$param['content'],
//        ];
//        oo::commonOprRedis('common')->hSet(okeys::announcement(),$id,json_encode($temp));
//        return $id;
//    }
//
//    public function delAnnouncement($param){
//        oo::commonOprRedis('common')->hDel(okeys::announcement(),$param['id']);
//        $tb = otable::announcement();
//        $sql = "DELETE FROM {$tb} WHERE id={$param['id']}";
//        $ret = oo::commonOprDb('common')->query($sql);
//        return $ret?$ret:0;
//    }
  
  	public function actionAnnouncement($param){
        $data = json_decode($param['data'],true);
        //新版本1.6.1后用
        if(isset($data['filename'])){
            $res2=oo::commonOprModel('notice')->setNotice($data);
        }

        //老版本1.6.1之前兼容
        if(!isset($data['filename'])){
            $tb = otable::StaticConfig();
            $sql = "SELECT * FROM {$tb} WHERE config='Announcement'";
            $ret = oo::commonOprDb('common')->getOne($sql,MYSQLI_ASSOC);
            return $ret['path'];
        }else{
            $filename = $data['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='Announcement'";
            $ret = oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'Announcement',$filename);
            return 1;
        }
    }

    public function sendAnnouncementCmd($param){
        oo::commonOprModel('Workerman')->pushAll(ocmd::$send['Announcement'],json_decode($param['data'],true));
        return 1;
    }

    private function getMaxVersionInfo(array $arr = []) {
        $version = '0.0.0';
        $info = [];
        foreach($arr as $v){
            if(!oo::compareVersion($version,$v['gu_version'])){
                $version = $v['gu_version'];
                $info = $v;
            }
        }
        return $info;
    }

  	/**
     * 生成版本配置
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2019/11/25 18:34
     */
    public function makeVersionJson($param){
        $sid    = intval($param['actionSid']);
        $lang   = json_decode($param['lang']);
        $data = [];
        $device = oo::commonOprModel('config')->getDeviceArr()[$sid];
        $table = otable::gameupdate();
        $sql = "SELECT * FROM {$table} WHERE gu_device='{$device}' ORDER BY id DESC";
        $tmp = oo::commonOprDb('common')->getAll($sql, 1);
        $ret = $this->getMaxVersionInfo($tmp);
        if(empty($ret)){
            return '[]';
        }
        $gu_version = $ret['gu_version'];
        $langTitleTmp = [];
        $langContentTmp = [];
        $isForce = $ret['gu_force'];
        //开始处理多语言,兼容之前发布的版本,没有多语言,只有泰语
        if ($ret['gu_langtitle']) {
            $langTitle = array_change_key_case(json_decode(unserialize($ret['gu_langtitle']), 1),CASE_UPPER);
            $langContent = array_change_key_case(json_decode(unserialize($ret['gu_langcontent']), 1),CASE_UPPER);
            foreach ($lang as $row){
                $key = strtoupper($row);
                $langTitleTmp[$key] = $langTitle[$key]??[];
                $langContentTmp[$key] = $langContent[$key]??[];
            }
            $langTitleTmp = array_filter($langTitleTmp);
            $langContentTmp = array_filter($langContentTmp);
        }
        $data['id'] = $sid;
        $data['curVersion'] = $gu_version??'1.0.0';
        $data['newVersion'] = $gu_version??'1.0.0';
        $data['verTitle'] = $langTitleTmp ?? '';
        $data['verMessage'] = $langContentTmp ?? '';
        $data['isForce'] = $isForce ?? 0;
        $data['reward'] = [
            'spins' => 0,
            'coins' => 0,
        ];

        $gu_reward = json_decode($ret['gu_reward'],true);
        if(!empty($gu_reward)){
            $data['reward']['spins'] = $gu_reward['spins'];
            $data['reward']['coins'] = $gu_reward['money'];
        }

        if($sid == 2){
            $data['updateUrl'] =  oo::commonOprModel('readconfig')->getCon('ios',"updateUrl");
            $data['commentUrl'] = oo::commonOprModel('readconfig')->getCon('ios',"assessUrl");
        }else {
            $data['updateUrl'] =  oo::commonOprModel('readconfig')->getCon('android',"updateUrl");
            $data['commentUrl'] = oo::commonOprModel('readconfig')->getCon('android',"assessUrl");
        }
        if(!empty($param['filename'])){
            $sidName = ucfirst($device)."Version";
            $filename = $param['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='{$sidName}'";
            oo::commonOprDb('common')->query($sql,false);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),$sidName,$filename);
        }

        if($data['isForce'] != 0){
            $cacheKey = okeys::CurForeVersion($sid);
            $curForeVersion = oo::commonOprRedis('common')->get($cacheKey);
            if(oo::compareVersion($data['curVersion'],$curForeVersion,false)){
                oo::commonOprRedis('common')->set($cacheKey,funs::changeVersionLength($data['curVersion']));
            }
        }else{
            $tmp = oo::commonOprDb('common')->getAll("SELECT * FROM {$table} WHERE gu_device='{$device}' AND gu_force=1 ORDER BY id DESC", MYSQLI_ASSOC);
            $forceVersion = $this->getMaxVersionInfo($tmp);
            if(empty($forceVersion)){
                return '[]';
            }
            oo::commonOprRedis('common')->set(okeys::CurForeVersion($sid),funs::changeVersionLength($forceVersion['gu_version']));
        }

        $data['iconUrl'] = "https://god.superant.cc/img/icon120.png?".$data['newVersion'];
        oo::commonOprRedis('common')->set(okeys::updateVersionCfg($sid),json_encode($data,256));
        return json_encode($data);
    }
  
  	public function getSignIn(){
        $tb  = otable::SignInConfig();
        $sql = "SELECT * FROM {$tb} WHERE 1";
        $ret = oo::commonOprDb('config')->getAll($sql,MYSQLI_ASSOC);
        return json_encode($ret);
    }

    public function saveSignInConfig($param){
        $data = json_decode($param['data'],true);
        $tb  = otable::SignInConfig();
        $key = okeys::SignInConfig('old');
        foreach ($data as $row){
            $sql = "UPDATE {$tb} SET type='{$row['type']}',num='{$row['num']}' WHERE id={$row['id']}";
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('Config')->hSet($key,$row['id'],json_encode($row));
        }
        if(!empty($param['filename'])){
            $filename = $param['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='Signin'";
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'Signin',$filename);
        }
        return 1;
    }
  
  	public function getShare($param){
        $version = $param['version'];
        $version = empty($version)?false:true;
        $tb  = otable::ShareConfig($version);
        $sql = "SELECT * FROM {$tb} WHERE 1";
        $ret = oo::commonOprDb('config')->getAll($sql,MYSQLI_ASSOC);
        return json_encode($ret);
    }

    public function saveShareConfig($param){
        $version = empty($param['type'])?false:true;
        $data = json_decode($param['data'],true);
        $tb  = otable::ShareConfig($version);
        $key = okeys::ShareConfig($version);
        foreach ($data as $row){
            if($version){
                $row['reward'] = json_encode($row['reward']);
                $show= intval($row['show']);
                $sql = "UPDATE {$tb} SET maxTimes='{$row['maxTimes']}',reward='{$row['reward']}',intervalTime='{$row['intervalTime']}',`show`='{$show}' WHERE type='{$row['type']}'";
            }else{
                $sql = "UPDATE {$tb} SET maxTimes='{$row['maxTimes']}',selfType='{$row['selfType']}',selfReward='{$row['selfReward']}',otherType='{$row['otherType']}',otherReward='{$row['otherReward']}' WHERE type='{$row['type']}'";
            }
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('Config')->hSet($key,$row['type'],json_encode($row));
        }
        if(!empty($param['filename'])){
            $filename = $param['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='Share'";
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'Share',$filename);
        }
        return 1;
    }
  
  	public function getSysCompen($param){
        $tb  = otable::SysCompenConfig();
        if(isset($param['id'])){
            $id = $param['id'];
            $sql = "SELECT * FROM {$tb} WHERE id={$id}";
            $ret = oo::commonOprDb('config')->getOne($sql,MYSQLI_ASSOC);
        }else{
            $sql = "SELECT * FROM {$tb} WHERE 1";
            $ret = oo::commonOprDb('config')->getAll($sql,MYSQLI_ASSOC);
        }
        return json_encode($ret);
    }

    public function saveSysCompen($param){
        $tb   = otable::SysCompenConfig();
        $filename = $param['filename'];
        $param= json_decode($param['data'],true);
        $param['endTime'] = strtotime($param['endTime'].' 00:00:00');
        $param['content'] = addslashes(json_encode($param['content'],320));
        $param['reward'] = json_encode($param['reward'],JSON_NUMERIC_CHECK);
        $param['levelId'] = isset($param['levelId']) ? (int)abs($param['levelId']) : 0;
        $param['levelIdEnd'] = isset($param['levelIdEnd']) ? (int)abs($param['levelIdEnd']) : 0;
        $flag = false;
        if(isset($param['id'])){
            $id = $param['id'];
            $sql = "SELECT max(id) as max FROM {$tb} WHERE 1";
            $ret = oo::commonOprDb('config')->getOne($sql,MYSQLI_ASSOC);
            if($ret['max'] == $id){
                $flag = true;
            }
            $sql = "UPDATE {$tb} SET endTime='{$param['endTime']}',content='{$param['content']}',reward='{$param['reward']}',remark='{$param['remark']}',levelId={$param['levelId']},levelIdEnd={$param['levelIdEnd']} WHERE id={$id}";
        }else{
            $flag = true;
            $time = time();
            $sql = "INSERT INTO {$tb} (id, endTime, content, reward, remark, addTime, levelId, levelIdEnd) VALUES(NULL,'{$param['endTime']}','{$param['content']}','{$param['reward']}','{$param['remark']}','{$time}',{$param['levelId']},{$param['levelIdEnd']})";
        }
        if(!empty($filename) && $flag){
            oo::commonOprRedis('common')->delete(okeys::sysCompensateConfig());
			
			//系统补偿领取率 重置
            oo::commonOprRedis('statistics')->delete(okeys::sysCompensateSta());
			
            $tb = otable::StaticConfig();
            oo::commonOprDb('common')->query("UPDATE {$tb} SET path='{$filename}' WHERE config='SystemCompensation'");
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'SystemCompensation',$filename);
        }
        oo::commonOprDb('common')->query($sql);
        return $flag?2:1;
    }


    public function getLuckyDrawConfig($param){
        $newVersion       = $param['newVersion'];
        $data = [
            'config'        => oo::commonOprModel('luckydraw')->getConfig('',false,$newVersion),
            'proconfig'     => oo::commonOprModel('luckydraw')->getProConfig(),
            'progressconfig'=> oo::commonOprModel('luckydraw')->getProgressConfig($newVersion),
        ];
        return json_encode($data,true);
    }

    public function saveLuckyDrawConfig($param){
        $actionType = $param['actionType'];
        $flag       = $param['flag'];
        $newVersion       = $param['newVersion'];
        if($actionType == 'pro'){
            $data = json_decode($param['data'],true);
            $tb   = otable::LuckyProConfig();
            foreach ($data as $row){
                $sql = "UPDATE {$tb} SET lucky='{$row['newLucky']}',{$flag}pro='{$row['pro']}' WHERE lucky='{$row['origLucky']}'";
                oo::commonOprDb('config')->query($sql);
            }
            return 1;
        }else if($actionType == 'progress'){
            $tb   = otable::LuckyProgressConfig($newVersion);
            $data = json_decode($param['data'],true);
            foreach ($data as $row){
                $sql = "UPDATE {$tb} SET progress='{$row['newProgress']}',reward='{$row['reward']}' WHERE progress='{$row['origProgress']}'";
                oo::commonOprDb('config')->query($sql);
            }
        }else if($actionType == 'reward'){
            $data = json_decode($param['data'],true);
            $tb   = otable::LuckyConfig($newVersion);
            foreach ($data as $row){
                $sql = "UPDATE {$tb} SET {$flag}reward='{$row['reward']}',sort='{$row['sort']}' WHERE id='{$row['id']}'";
                oo::commonOprDb('config')->query($sql);
            }
        }

        $configData= oo::commonOprModel('luckydraw')->getConfig('',false,$newVersion);
        array_multisort(array_column($configData,'sort'),SORT_ASC,$configData);
        $reward = array_column($configData,'reward');
        $config = [
            'reward'    => $reward,
            'vipreward' => array_column($configData,'vipreward'),
        ];


        $progress = oo::commonOprModel('luckydraw')->getProgressConfig($newVersion);
        $proconfig = [];
        foreach ($progress as $key=>$row){
            $proconfig[] = [
                'progress'=>$key,
                'reward'  =>$row,
            ];
        }
        $filename = 'LuckyDraw'.time().'.json';
        $tb = otable::StaticConfig();
        $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='LuckyDraw'";
        oo::commonOprDb('common')->query($sql);
        oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'LuckyDraw',$filename);
        return json_encode([
            'name'=>$filename,
            'data'=>[
                'config'        => $config,
                'proconfig'     => $proconfig,
                'diamond'        =>[
                    'one'  => 59,
                    'five' => 200,
                ],
            ],
        ],JSON_NUMERIC_CHECK);
    }

    public function getMiningGameConfig(){
        return json_encode([
            'miningGameConfig' => oo::commonOprModel('config')->getMiningGameConfig(0,2),
            'miningGameReward' => json_decode(oo::commonOprModel('readconfig')->getSysCon('MiningGame','Reward'),true),
            'mineralType'      => [
                ['id'=>1,'name'=>"金币"],['id'=>2,'name'=>"金袋"],['id'=>3,'name'=>"体力"],['id'=>4,'name'=>"小石头"],['id'=>5,'name'=>"中石头"],['id'=>6,'name'=>"大石头"],['id'=>7,'name'=>"老鼠"],['id'=>8,'name'=>"金老鼠"],['id'=>9,'name'=>"钱袋鼠"],['id'=>10,'name'=>"体力鼠"],['id'=>11,'name'=>"钻石"],['id'=>12,'name'=>"钻石鼠"],
            ],
        ]);
    }

    public function saveMiningGameConfig($param){
        $data = json_decode($param['data'],true);
        return oo::commonOprModel('config')->setMiningGameConfig($data,2);
    }

    public function saveMiningGameReward($param){
        return oo::commonOprModel('readconfig')->setSysCon('MiningGame',"Reward",$param['data']);
    }

    public function makeMiningGameJson(){
        $json = json_decode(oo::commonOprModel('readconfig')->getSysCon('MiningGame','Reward'),true);
        $tb = otable::MiningGameConfig(2);
        $ret= oo::commonOprDb('common')->getAll("SELECT * FROM {$tb}",MYSQLI_ASSOC);
        foreach ($ret as $key=>$row){
            $ret[$key]['mineralData'] = json_decode($row['mineralData']);
            $ret[$key]['hookUpSpeed'] = json_decode($row['hookUpSpeed']);
        }
        $json['lvData'] = $ret;
        $fileName = "MiningGameConfig".time().".json";
        oo::commonOprModel('config')->setStaticConfig("MiningGameConfig",$fileName);
        return json_encode([
           'filename' => $fileName,
           'data'     => $json,
        ]);
    }

    public function savePetConfig($param){
        $data = json_decode($param['data'],true);
        foreach ($data as $row){
            oo::commonOprModel('pet')->savePetConfig($row);
        }
        if(!empty($param['filename'])){
            $filename = $param['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='PetConfig'";
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'PetConfig',$filename);
        }
        return 1;
    }

    public function getVipConfig($param){
        $version = $param['vipVersion'] ?? "";
        return json_encode(oo::commonOprModel('newvip')->getVipLvConfig(0,$version));
    }

    public function saveVipConfig($param){
        $version = $param['vipVersion'];
        $data = json_decode($param['data'],true);
        $tb  = otable::VipLvConfig($version);
        foreach ($data as $row){
            $turnTable = addslashes($row['turnTable']);
            $weekRewardChest = addslashes($row['weekRewardChest']);
            $weekRewardBless = addslashes($row['weekRewardBless']);
            $weekRewardLuckydraw = addslashes($row['weekRewardLuckydraw']);
            $signInBet = empty($row['signInBet']) ? 1 : $row['signInBet'];
            $sql = "UPDATE {$tb} SET 
                        signInBet={$signInBet},
                        weekRewardLuckydraw='{$weekRewardLuckydraw}',
                        weekRewardBless='{$weekRewardBless}',
                        weekRewardChest='{$weekRewardChest}',
                        weekRewardShield='{$row['weekRewardShield']}',
                        weekRewardSpins='{$row['weekRewardSpins']}',
                        taskRewardBet='{$row['taskRewardBet']}',
                        spinsRestore='{$row['spinsRestore']}',
                        avatarBox='{$row['avatarBox']}',
                        shieldGroove='{$row['shieldGroove']}',
                        turnTable='{$turnTable}',
                        dayVipPoint='{$row['dayVipPoint']}',
                        attackCoinsPro='{$row['attackCoinsPro']}',
                        stealCoinsPro='{$row['stealCoinsPro']}',
                        attackCss='{$row['attackCss']}',
                        miningGame='{$row['miningGame']}',
                        mock='{$row['mock']}',
                        oneClick='{$row['oneClick']}',
                        richkingStyle='{$row['richkingStyle']}'
                    WHERE lv='{$row['lv']}'";
            oo::commonOprDb('config')->query($sql);
        }
        oo::commonOprModel('config')->setStaticConfig("VipConfig",$param['filename']);
        oo::commonOprRedis('config')->delete(okeys::VipLvConfig($version));
        return 1;
    }

    public function getCrazyBetConfig(){
        $data = [
            'config'        => oo::commonOprModel('config')->getCrazyBet(),
            'actSpinsLimit' => oo::commonOprModel('readconfig')->getSysCon('activtity14',"actSpinsLimit"),
            'actLevelLimit' => oo::commonOprModel('readconfig')->getCon('basic',"actLevelLimit"),
        ];
        return json_encode($data);
    }

    public function setCrazyBetConfig($param){
        $data = json_decode($param['data'],true);
        oo::commonOprModel('config')->setCrazyBet($data);
        if(!empty($param['filename'])){
            $filename = $param['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='CrazyBetConfig'";
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'CrazyBetConfig',$filename);
        }
        return 1;
    }

    public function getRewardCenterConfig(){
        $tb  = otable::RewardCenterConfig();
        $sql = "SELECT * FROM {$tb} WHERE 1";
        $ret = oo::commonOprDb('config')->getAll($sql,MYSQLI_ASSOC);
        $data= [
            'config' => $ret
        ];
        return json_encode($data);
    }

    public function setRewardCenterConfig($param){
        $tb  = otable::RewardCenterConfig();
        $data= json_decode($param['data'],true);
        $cacheKey = okeys::RewardCenterShow();
        foreach ($data as $row){
            if(isset($row['isShow'])){
                $up = " isShow={$row['isShow']} ";
                oo::commonOprRedis('common')->hSet($cacheKey,$row['id'],$row['isShow']);
                oo::commonOprRedis('common')->hSet(okeys::actCenterShowType(1),$row['id'],$row['isShow']);
            }
            if(isset($row['isShowBtn'])){
                $up .= ",isShowBtn={$row['isShowBtn']} ";
                oo::commonOprRedis('common')->hSet(okeys::actCenterShowType(2),$row['id'],$row['isShowBtn']);
            }
            if(isset($row['isShowCountdown'])){
                $up .= ",isShowCountdown={$row['isShowCountdown']} ";
                oo::commonOprRedis('common')->hSet(okeys::actCenterShowType(3),$row['id'],$row['isShowCountdown']);
            }
            if($up){
                $sql = "UPDATE {$tb} SET {$up} WHERE id='{$row['id']}'";
                $ret = oo::commonOprDb('common')->query($sql);
            }
            if(!$ret){
                return 0;
            }
        }
        return 1;
    }

    public function getMainBgConfig($param){
        $tb = otable::MainBgConfig();
        $sql = "SELECT * FROM {$tb} WHERE 1";
        $ret = oo::commonOprDb('config')->getAll($sql,MYSQLI_ASSOC);
        $data= [
            'config' => $ret
        ];
        return json_encode($data);
    }

    public function setMainBgConfig($param){
        $tb = otable::MainBgConfig();
        $data= json_decode($param['data'],true);
        foreach ($data as $row){
            $result = oo::commonOprDb('common')->getOne("select * from  {$tb}  WHERE levelId='{$row['levelId']}'", 1);
            if(!$result){
                oo::commonOprDb('common')->query("insert into  {$tb}  (levelId) values ('{$row['levelId']}' )");
            }
            oo::commonOprDb('common')->query("UPDATE {$tb} SET bg1='{$row['bg1']}',color1='{$row['color1']}',bg2='{$row['bg2']}',color2='{$row['color2']}',animation='{$row['animation']}',animation2='{$row['animation2']}' WHERE levelId='{$row['levelId']}'");
        }
        oo::commonOprModel('config')->setStaticConfig("MainBgConfig",$param['filename']);
        return 1;
    }

    public function getMaxLevelRewardConfig($param){
        $props  = oo::commonOprModel('props')->getPropsConfig();
        $config = oo::commonOprModel('readconfig')->getSysCon('Reward',"maxLevel");
        return json_encode([
            'props'  => $props,
            'config' => json_decode($config,true),
        ]);
    }

    public function setMaxLevelRewardConfig($param){
        return oo::commonOprModel('readconfig')->setSysCon('Reward',"maxLevel",$param['data']);
    }

    public function getSignInConfig($param){
        $props  = oo::commonOprModel('props')->getPropsConfig();
        $progress = oo::commonOprModel('config')->getSignInProgressConfig(0,0,2);
        $daily    = oo::commonOprModel('config')->getSignInConfig2();
        return json_encode([
            'props'    => $props,
            'progress' => $progress,
            'daily'    => $daily
        ]);
    }

    public function setSignInConfig($param){
        $data = json_decode($param['data'],true);
        $tb   = otable::SignInConfig(true);
        $section_id = $param['section_id'];
        if(empty($section_id)){
        	$where = " AND section_id = 0";
        }else{
        	$where = " AND section_id = {$section_id}";
			//修改签到等级区间
        	$start_level = $param['start_level'];
        	$end_level = $param['end_level'];
        	if(!empty($start_level) && !empty($start_level)){
        		$signinSection = otable::signinSection();
        		$ret = oo::commonOprDb('common')->query("UPDATE {$signinSection} SET `start_level`={$start_level},`end_level`={$end_level} WHERE section_id={$section_id}");
        	}
        }
		
        foreach ($data as $key=>$row){
            $coins = addslashes($row['coins']);
            $spins = $row['spins'];
            $props = addslashes($row['props']);
            $ret = oo::commonOprDb('common')->query("UPDATE {$tb} SET `coins`='{$coins}',`spins`='{$spins}',`props`='{$props}' WHERE id={$key} {$where}");
        }
        oo::commonOprRedis('config')->delete(okeys::SignInConfig($section_id));
        oo::commonOprRedis('config')->delete(okeys::signinSection());
        return $ret;
    }

    public function setSignInProgressConfig($param){
        $data = json_decode($param['data'],true);
        $tb   = otable::SignInProgressConfig(2);
		$section_id = $param['section_id'];
        if(empty($section_id)){
        	$where = " AND section_id = 0";
        }else{
        	$where = " AND section_id = {$section_id}";
        }
        foreach ($data as $key=>$row){
            $coins = addslashes($row['coins']);
            $spins = $row['spins'];
            $props = addslashes($row['props']);
            $ret = oo::commonOprDb('common')->query("UPDATE {$tb} SET `coins`='{$coins}',`spins`='{$spins}',`props`='{$props}' WHERE progress={$key} {$where}");
        }
        oo::commonOprRedis('config')->delete(okeys::SignInProgressConfig($section_id,2));
        return $ret;
    }

    public function getSignInJson($param){
    	
    	$filename = "Signin".time().'.json';
        oo::commonOprModel('config')->setStaticConfig("Signin",$filename);
        
    	$coins  = [
            'coins01' => 201,
            'coins02' => 202,
            'coins03' => 203,
            'coins04' => 204,
            'coins05' => 205,
            'coins06' => 206,
        ];
    	if(!empty($param['new'])){
    		$config = json_decode(self::getSigninSection(),true);
    		$daily  = $config['daily'];
    		$progress  = $config['progress'];
    		$section  = $config['section'];
    		$out = [];
    		foreach($daily as $k => $v){
    			$temp = $v;
    			foreach ($temp as $key=>$row){
		            $temp[$key]['coins']['gid'] = $coins[$row['coins']['coins']];
		            unset($temp[$key]['id']);
		            unset($temp[$key]['coins']['coins']);
		        }
    			$out['section_'.$k]['daily'] = $temp;
    		}
    		foreach($progress as $k => $v){
    			$temp = $v;
    			foreach ($temp as $key=>$row){
		            $temp[$key]['coins']['gid'] = $coins[$row['coins']['coins']];
		            unset($temp[$key]['id']);
		            unset($temp[$key]['coins']['coins']);
		            foreach ($row['props'] as $pIndex=>$p){
                        $pConf = oo::commonOprModel('props')->getChestData(0,$p['propsId']);
                        if($pConf){
                            $temp[$key]['props'][$pIndex]['value'] = $pConf;
                        }
                    }
		        }
    			$out['section_'.$k]['progress'] = $temp;
    		}

    		return json_encode([
	            'filename' => $filename,
	            'data'     => [
	                'section'   =>array_values($section),
	                'config'=>$out,
	            ],
	        ]);
    	}else{
    		$config = json_decode(self::getSignInConfig([]),true);
	        $daily  = $config['daily'];

	        foreach ($daily as $key=>$row){
	            $daily[$key]['coins']['gid'] = $coins[$row['coins']['coins']];
	            unset($daily[$key]['id']);
	            unset($daily[$key]['coins']['coins']);
	        }
	        $progress  = $config['progress'];
	        foreach ($progress as $key=>$row){
	            $progress[$key]['coins']['gid'] = $coins[$row['coins']['coins']];
	            unset($progress[$key]['coins']['coins']);
	            unset($progress[$key]['count']);
	        }

	        return json_encode([
	            'filename' => $filename,
	            'data'     => [
	                'daily'   =>$daily,
	                'progress'=>$progress,
	            ],
	        ]);
    	}
    }

    /**
     * 设置任务中心json
     * @return false|string
     * Created by: Owen
     * Created on: 2020/5/9 15:42
     */
    public function makeTaskCenterJson(){
        $achieveConfig = oo::commonOprModel('achievement')->getAchieveConfig();
        $achieve = [];
        foreach ($achieveConfig as $row){
            $stage  = explode(',',$row['stage']);
            $reward = json_decode($row['reward'],true);
            $rewardTemp = [];
            foreach ($reward as $r){
                $rewardTemp[] = [
                    'spins' => $r['spin'],
                    'coins' => $r['coin']
                ];
            }
            $achieve[] = [
                'id'          => $row['aid'],
                'name'        => [$row['designation'],$row['designation_en'],$row['designation_tw'],$row['designation_fr'],$row['designation_de'],$row['designation_es'],$row['designation_pt'],$row['designation_th']],
                'desc'        => [$row['content'],$row['content_en'],$row['content_tw'],$row['content_fr'],$row['content_de'],$row['content_es'],$row['content_pt'],$row['content_th']],
                'target'      => $stage,
                'reward'      => $rewardTemp
            ];
        }
        $out['achieve'] = $achieve;
        $taskProgressConfig = oo::commonOprModel('config')->getTaskProgressConfig();
        $taskProgress = [];
        foreach ($taskProgressConfig as $row){
            $taskProgress[] = [
                'progress' => $row['progress'],
                'spins'    => $row['spins']
            ];
        }
        $out['taskProgress'] = $taskProgress;
        $tb  = otable::taskConfig();
        $sql = "SELECT * FROM {$tb} where is_open = 1 ";
        $list = oo::commonOprDb('config')->getAll($sql, MYSQLI_ASSOC);
        $task = [];
        foreach ($list as $row){
            $reward = [
                'coins'=>[
                    'gid' => 201,
                    'bet' => $row['reward_type'] == 1? $row['reward_num'] : 0,
                ],
                'spins'   => $row['reward_type'] == 1? 0 :$row['reward_num']
            ];

            $task[] = [
                'id'          => $row['id'],
                'task_type'   => $row['task_type'],
                'name'        => [$row['task_title'],$row['task_title_en'],$row['task_title_tw'],$row['task_title_fr'],$row['task_title_de'],$row['task_title_es'],$row['task_title_pt'],$row['task_title_th']],
                'target'      => $row['target_times'],
                'reward'      => $reward,
                'reward_type' => $row['reward_type']
            ];
        }
        $out['task'] = $task;
        $filename = "TaskCenter".time().'.json';
        oo::commonOprModel('config')->setStaticConfig("TaskCenter",$filename);
        return json_encode([
            'filename' => $filename,
            'data'     => $out,
        ]);
    }

    /**
     * 获取弹框配置
     * @return false|string
     * Created by: Owen
     * Created on: 2020/5/19 20:20
     */
    public function loginBulletBox(){
        return json_encode(oo::commonOprModel('config')->loginBulletBox());
    }

    /**
     * 设置弹框
     * @return int
     * Created by: Owen
     * Created on: 2020/5/19 20:20
     */
    public function setLoginBulletBox($param){
        $data = json_decode($param['data'],true);
        oo::commonOprRedis('config')->delete(okeys::LoginBulletBox());
        $tb  = otable::LoginBulletBox();
        foreach ($data as $row){
            $sql = "UPDATE {$tb} SET `name`='{$row['name']}',`desc`='{$row['desc']}',`sort`='{$row['sort']}',`status`='{$row['status']}',`thematic`='{$row['thematic']}' WHERE `id`='{$row['id']}'";
            $ret = oo::commonOprDb('config')->query($sql);
        }
        return $ret?1:0;
    }

    /**
     * 拉取登陸弹框配置JSON
     * @return false|string
     * Created by: Owen
     * Created on: 2020/5/20 14:45
     */
    public function makeLoginBulletBoxJson(){
        $config = oo::commonOprModel('config')->loginBulletBox();
        $temp   = [];
        foreach ($config as $row){
            $temp[] = [
                'id'     => $row['id'],
                'desc'   => $row['name'].":".$row['desc'],
                'sort'   => $row['sort'],
                'status' => $row['status'],
                'thematic'=>$row['thematic']
            ];
        }
        $filename = "LoginDialog".time().'.json';
        oo::commonOprModel('config')->setStaticConfig("LoginDialog",$filename);
        return json_encode([
            'filename' => $filename,
            'data'     => $temp,
        ]);
    }

	/**
     * 获取签到配置等级区间
     * @return
     * Created by: Hss
     * Created on: 2020/5/23 12:18
     */
    public function getSigninSection(){
        $section = oo::commonOprModel('config')->signinSection();
        $out = ['daily'=>[],'progress'=>[],'section'=>[]];
        foreach($section as $sv){
        	$section_id = $sv['section_id'];
        	$out['daily'][$section_id] = oo::commonOprModel('config')->getSignInConfig2('',$section_id);
        	$out['section'][$section_id] = $sv;
        	$out['progress'][$section_id] = oo::commonOprModel('config')->getSignInProgressConfig(0,$section_id,2);
        }
        $out['props']  = oo::commonOprModel('props')->getPropsConfig();
        return json_encode($out);
    }

    /**
     * 回归配置
     * @return false|string
     * Created by: Owen
     * Created on: 2020/5/26 18:05
     */
    public function recallConfig(){
        return json_encode(oo::commonOprModel('config')->recallConfig());
    }

    /**
     * 设置回归配置
     * @param $param
     * @return int
     * Created by: Owen
     * Created on: 2020/5/26 19:40
     */
    public function setRecallConfig($param){
        $data      = json_decode($param['data'],true);
        $curConfig = oo::commonOprModel('config')->recallConfig();
        $curDay    = array_column($curConfig,'day');
        $newDay    = array_column($data,'day');
        $tb        = otable::recallConfig();
        foreach ($curDay as $row){
            if(!in_array($row,$newDay)){
                oo::commonOprRedis('common')->delete(okeys::RecallPush($row));
                oo::commonOprDb('config')->query("DELETE FROM {$tb} WHERE day='{$row}' LIMIT 1");
            }
        }
//        oo::commonOprCache('memcache')->delete(okeys::recallConfig());
        oo::commonOprRedis('config')->delete(okeys::recallConfig());
        foreach ($data as $row){
            $reward = addslashes(json_encode($row['reward'],JSON_NUMERIC_CHECK));
            if(in_array($row['day'],$curDay)){
                oo::commonOprDb('config')->query("UPDATE {$tb} SET `reward`='{$reward}' WHERE `day`='{$row['day']}'");
            }else{
                oo::commonOprDb('config')->query("INSERT INTO {$tb} (day,reward) VALUES ('{$row['day']}','{$reward}')");
            }
        }
        return 1;
    }

    public function makeBeginGuideJson(){
        $reward   = oo::commonOprModel('config')->getBeginGuideConfig();
        $fileName = "NoviceGuideConfig".time().".json";
        oo::commonOprModel('config')->setStaticConfig("NoviceGuide",$fileName);
        return json_encode([
            'filename' => $fileName,
            'data'     => [
                'list' => $reward
            ],
        ]);
    }

	/**
     * 获取打金币配置
     * @param $param
     * @return array
     * Created by: Hss
     * Created on: 2020/5/29 10:47
     * Description:
     */
    public function getAttackCoinConfig($param){
    	$page = $param['page'];
    	if(empty($page)){
    		$page = 1;
    	}
		$start = ($page - 1) * 10;
        $length = $param['page_size'];
        if(empty($length)){
        	$length = 10;
        }

        $tb = otable::attackCoinConfig();
        $sql = "SELECT * from {$tb} LIMIT {$start},{$length}";
        $ret = oo::commonOprDb('common')->getAll($sql,1);

        $sql = "SELECT COUNT(*) as num from {$tb}";
        $rs = oo::commonOprDb('common')->getOne($sql,1);
        $returnData = [
            'total'=>$rs['num'],
            'data'=>$ret,
        ];

        return json_encode($returnData);
    }

    /**
     * 保存打金币配置
     * @param $param
     * @return array
     * Created by: Hss
     * Created on: 2020/5/29 10:47
     * Description:
     */
    public function saveAttackCoinConfig($param){
        $data = json_decode($param['data']);
        $tb = otable::attackCoinConfig();
        $sql = "SELECT levelId from {$tb}";
        $rs = oo::commonOprDb('common')->getAll($sql,1);
        $temp = [];
        foreach ($rs as $row){
            array_push($temp,(int)$row['levelId']);
        }

        foreach ($data as $row){
			$shield = $row->shield;
			$no_shield = $row->no_shield;
            if(in_array($row->level,$temp)){
                $sql = "UPDATE {$tb} SET shield='{$shield}',no_shield='{$no_shield}' WHERE levelId={$row->level}";
            }else{
                $sql = "INSERT INTO {$tb} (levelId,shield,no_shield) VALUES ({$row->level},'{$shield}','{$no_shield}')";
            }
            $rs = oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hDel(okeys::attackCoinConfig(),$row->level);
        }

        return $rs ? $rs : 0;
    }

    /**
     * 获取道具配置
     * @return false|string
     * Created by: Owen
     * Created on: 2020/6/16 9:41
     */
    public function getPropsConfig(){
        $props  = oo::commonOprModel('props')->getPropsConfig();
        return json_encode([
            'props' => $props
        ]);
    }

    public function getNoticeList(){
        $list = oo::commonOprModel('notice')->getNotice();
        return json_encode($list);
    }

    public function setNotice($param){
        $data = $param['data'];
        $res = oo::commonOprModel('notice')->setNotice($data);
        return $res;
    }

    /**
     * 获取支付加倍配置
     * @return string
     * Created by: Hss
     * Created on: 2020/7/17 17:03
     */
    public function getTurnPaybetConfig(){
        $data = [
            'priceConfig'     => oo::commonOprModel('config')->getTurnPaybetConfig('price'),
            'betConfig'=> oo::commonOprModel('config')->getTurnPaybetConfig('bet'),
        ];
        return json_encode($data,true);
    }

    /**
     * 设置支付加倍配置
     * @return string
     * Created by: Hss
     * Created on: 2020/7/20 11:27
     */
    public function setTurnPaybetConfig($param){
        $data = json_decode($param['data'],1);
        $res = oo::commonOprModel('config')->setTurnPaybetConfig($param['type'],$data);
        return $res;
    }

    /**
     * 获取升级礼包配置
     * @return string
     * Created by: Hss
     * Created on: 2020/8/4 10:21
     */
    public function getGiftUpLevelConfig(){
        $data = oo::commonOprModel('config')->getGiftUpLevelConfig();
        return json_encode($data,true);
    }

    /**
     * 设置升级礼包配置
     * @return string
     * Created by: Hss
     * Created on: 2020/8/4 10:21
     */
    public function setGiftUpLevelConfig($param){
        $data = json_decode($param['data'],1);
        $res = oo::commonOprModel('config')->setGiftUpLevelConfig($data);

        if(!empty($param['filename'])){
            $filename = $param['filename'];
            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='GiftUpLevelConfig'";
            oo::commonOprDb('common')->query($sql);
            oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),'GiftUpLevelConfig',$filename);
        }

        return $res;
    }

    /**
     * Notes:获取道具配置
     * User: wsc
     * Time: 2020/9/16 10:09
     * @return false|string
     */
    public function getAllProps(){
        return json_encode(oo::cfg('props'));
    }

    /**
     * 国家代号
     * @return false|string
     * Created by: Owen
     * Created on: 2020/10/28 17:47
     */
    public function getAllCountry(){
        return json_encode(oo::cfg("country"));
    }
}

