<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once __DIR__ . '/Jackpot.php';

/**
 * 配置相关
 */
class Import extends MY_Controller
{
    public $postData = array('frombg' => 1, 'lid' => 1, 'sid' => 1);
    public function __construct()
    {
        parent::__construct();
        $config = array(
            'savePath' => 'Excel/uploads',             //存储文件夹
            'maxSize'  => 1024*5,                   //允许的文件最大尺寸，单位KB
            'allowFiles' => array('.xls','.xlsx','.csv')  //允许的文件格式
        );
        $this->load->library('uploader', $config);
        $this->load->library('PHPExcel');
        $this->load->library('PHPExcel/PHPExcel/IOFactory');
        $this->load->library('curl');
    }
    public function getExcelSheetsArray(){
        $file = $this->uploader->getFileInfo();
        $extensionType = $this->getExtensionType($file['originalName']);

        $xlsReader = IOFactory::createReader($extensionType);
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $sheetsCnt = $Sheets->getSheetCount();
        $dataArray = [];
        for($i=0 ; $i< $sheetsCnt; $i++){
            $tmpData = $Sheets->getSheet($i)->toArray() ?? [];
            foreach ($tmpData as $k => $item){
                foreach ($item as $k1 => $value){
                    $item[$k1] = trim($value);
                }
                $line = array_filter($item);
                if(empty($line))unset($tmpData[$k]);
            }
            $dataArray[$i] = $tmpData;
        }
        return $dataArray;
    }
    public function getExtensionType($fileName){
        $pathinfo = pathinfo($fileName);
        $extensionType = NULL;
        switch (strtolower($pathinfo['extension'])) {
            case 'xlsx':			//	Excel (OfficeOpenXML) Spreadsheet
            case 'xlsm':			//	Excel (OfficeOpenXML) Macro Spreadsheet (macros will be discarded)
            case 'xltx':			//	Excel (OfficeOpenXML) Template
            case 'xltm':			//	Excel (OfficeOpenXML) Macro Template (macros will be discarded)
                $extensionType = 'Excel2007';
                break;
            case 'xls':				//	Excel (BIFF) Spreadsheet
            case 'xlt':				//	Excel (BIFF) Template
                $extensionType = 'Excel5';
                break;
            case 'ods':				//	Open/Libre Offic Calc
            case 'ots':				//	Open/Libre Offic Calc Template
                $extensionType = 'OOCalc';
                break;
            case 'slk':
                $extensionType = 'SYLK';
                break;
            case 'xml':				//	Excel 2003 SpreadSheetML
                $extensionType = 'Excel2003XML';
                break;
            case 'gnumeric':
                $extensionType = 'Gnumeric';
                break;
            case 'htm':
            case 'html':
                $extensionType = 'HTML';
                break;
            case 'csv':
                $extensionType = 'CSV';
                break;
            default:
                $this->response(-1, '文件格式异常');
                break;
        }
        return $extensionType;
    }


    //===============================
    public function build()
    {
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();

        $levelId = 0;

        $conf = [];
        $reward = [];
        for ($i = 1; $i < count($dataArray); $i++) {
            $row = $dataArray[$i];

            if (!empty($row[0])) {
                $levelId = intval($row[0]);
            }
            $conf[$levelId][] = [$row[2], $row[6], $row[10], $row[14], $row[18]];

            $reward[$levelId][] = [
                funs::ParseRewards(array_slice($row, 3, 3), $i + 1),
                funs::ParseRewards(array_slice($row, 7, 3), $i + 1),
                funs::ParseRewards(array_slice($row, 11, 3), $i + 1),
                funs::ParseRewards(array_slice($row, 15, 3), $i + 1),
                funs::ParseRewards(array_slice($row, 19, 3), $i + 1),
            ];
        }

        $buildConf = [];
        foreach ($conf as $lv => $item) {
            $buildConf[] = [
                'level' => $lv,
                'coinConfig' => $item,
                'stage_reward' => $reward[$lv],
            ];
        }

        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'saveBuildConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['data'] = json_encode($buildConf, JSON_NUMERIC_CHECK);
        $retData = $this->httpPost($posts);
        if ($retData == 0) {
            return $this->response(1, '操作失败');
        } else {
            oo::commonOprModel('Json')->levelCoinConfig();
            return $this->response(0, '操作成功');
        }
    }


    public function symbol(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $temp = [];
        foreach ($dataArray as $key=>$row){
            $temp[] = [
                'stage'=>$row[0],
                'num'=>$row[1],
                'type'=>$row[2],
                'reward'=>$row[3],
            ];
        }
        $filename = 'SymbolConfig'.time().'.json';;
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'saveSymbolConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['data'] = json_encode($temp);
        $posts['filename'] = $filename;
        $this->SaveJson($temp,true,$filename);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }

    public function turn($version = ''){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $levelId = 0;
        $temp = [];
        foreach ($dataArray as $key=>$row){
            foreach ($row as $x=>$y){
                if($x == 0 && !empty($y)){
                    $levelId = intval($y);
                }
                if($x != 0){
                    if(empty($temp[$levelId][$x-1])){
                        $temp[$levelId][$x-1] = [
                            'id'=>$x-1,
                            'v'=>round($y,2),
                        ];
                    }else if($temp[$levelId][$x-1]['pv'] === null){
                        $temp[$levelId][$x-1]['pv'] = $y;
                    }else if($temp[$levelId][$x-1]['av'] === null){
                        $temp[$levelId][$x-1]['av'] = $y;
                    }else{
                        $temp[$levelId][$x-1]['prize'] = $y;
                    }
                }
            }
        }
        $upload = [];
        foreach ($temp as $key=>$row){
            $upload[] = [
                'level'=>$key,
                'slotpro' =>$row,
            ];
        }
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'saveTurnConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['data'] = json_encode($upload,JSON_UNESCAPED_UNICODE);
        $posts['conf_ver'] = $version;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            $ret = json_decode(oo::commonOprModel('common')->CurlApi([
                'mod'=>'Config',
                'act'=>'makeTurnTableJson',
            ]),true);
            self::SaveJson($ret['data'],$ret['filename']);
            return $this->response(0, '操作成功');
        }
    }

    public function mining(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $levelId = 0;
        $temp = [];

        foreach ($dataArray as $key=>$row){
            if(!empty($row[0])){
                $levelId = intval($row[0]);
            }
            if(empty($temp[$levelId-1])){
                $temp[$levelId-1] = [
                    'id'=>$levelId,
                    'config'=>[],
                    'initIncome'=>$row[4],
                    'growIncome'=>$row[5],
                ];
                $temp[$levelId-1]['config'][$row[1]-1] = [$row[2],$row[3]];
            }else{
                $temp[$levelId-1]['config'][$row[1]-1] = [$row[2],$row[3]];
            }
        }

        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'saveMiningConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['data'] = json_encode($temp);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            $this->actionSyncMinigJson("Mining".time().".json");
            return $this->response(0, '操作成功');
        }
    }

    public function actionSyncMinigJson($filename){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'makeMiningJson';
        $posts['filename'] = $filename;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        if($retData['code'] == 1){
            $data = $retData['data'];
            $this->SaveJson($data,$filename);
        }
    }

    public function SaveJson($data,$filename, $t=0){
        $dir = $this->staticPath;
        if (!is_dir($dir))
        {
            $old = umask(0);
            //mkdir($dir, PRODUCTION_SERVER ? 0775 : 0777, true);
            mkdir($dir,0775 , true);
            umask($old);
        }
        $filepath = "{$dir}{$filename}";
        file_put_contents($filepath, json_encode($data,JSON_NUMERIC_CHECK));

        if(method_exists($this->common,'upToOss')){
            $dir = str_replace("./","",$dir);
            $file_path = str_replace("\\","/",FCPATH . $dir.$filename);

            $this->common->upToOss($dir.$filename,$file_path);
        }
    }

    public function slotcoin(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getSoltConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 200;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $retData = $retData['data'];
        $length  = count($retData);
        $macData = $retData[max(count($retData) - 1,0)];
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);

        foreach ($dataArray as $key=>$row){
            if($key >= $length){
                $retData[$key] = $macData;
            }
            $retData[$row[0]][4]['prize'] = $row[1];
            $retData[$row[0]][5]['prize'] = $row[2];
            $retData[$row[0]][6]['prize'] = $row[3];
            $retData[$row[0]][7]['prize'] = $row[4];
            $retData[$row[0]][8]['prize'] = $row[5];
            $retData[$row[0]][9]['prize'] = $row[6];
        }

        foreach ($retData as $key=>$row){
            $upload[] = [
                'level'   =>$key,
                'slotpro' =>$row,
            ];
        }

        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'saveSoltConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['data'] = json_encode($upload,JSON_UNESCAPED_UNICODE);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            self::makeBeginGuideJson();
            return $this->response(0, '操作成功');
        }
    }
    public function slotcoin2(){

        $tb = otable::slotWeightCfg();
        $sql = "SELECT * from {$tb}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $arr = [];
        foreach ($rs as $k=>$v){
            $arr[$v['levelId']] = json_decode($v['slotpro'],1);
        }
        $retData = $arr;

        $length  = count($retData);
        $macData = $retData[max(count($retData) - 1,0)];
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        foreach ($dataArray as $key=>$row){
            if($key >= $length){
                $retData[$key] = $macData;
            }
            $retData[$row[0]][4]['prize'] = $row[1];
            $retData[$row[0]][5]['prize'] = $row[2];
            $retData[$row[0]][6]['prize'] = $row[3];
            $retData[$row[0]][7]['prize'] = $row[4];
            $retData[$row[0]][8]['prize'] = $row[5];
            $retData[$row[0]][9]['prize'] = $row[6];
        }
        foreach ($retData as $key=>$row){
            $upload[] = [
                'level'   =>$key,
                'slotpro' =>$row,
            ];
        }

        $tb = otable::slotWeightCfg();
        $sql = "SELECT levelId from {$tb}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $temp = [];
        foreach ($rs as $row){
            array_push($temp,(int)$row['levelId']);
        }
        $upload = json_decode(json_encode($upload));
        foreach ($upload 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}')";
            }
            $rs2 = oo::commonOprDb('games')->query($sql);
            oo::commonOprRedis('games')->hDel(okeys::slotWeightCfg(),$row->level);
        }

        $res = $rs2?$rs2:0;
        if($res == 0){
            return $this->response(1, '操作失败');
        }else{
//            self::makeBeginGuideJson();
            return $this->response(0, '操作成功');
        }
    }
    public function slotpro(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getSoltConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 100;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $retData = $retData['data'];
        $length  = count($retData);
        $macData = $retData[max(count($retData) - 1,0)];
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);

        foreach ($dataArray as $key=>$row){
            if($key >= $length){
                $retData[$key] = $macData;
            }
            for($j=0;$j<12;$j++){
                $t = $j + 1;
                $retData[$row[0]][$j]['v'] = $row[$t];
            }
        }

        foreach ($retData as $key=>$row){
            $upload[] = [
                'level'=>$key,
                'slotpro' =>$row,
            ];
        }


        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'saveSoltConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['data'] = json_encode($upload,JSON_UNESCAPED_UNICODE);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }
    public function slotWeight(){
        $tb = otable::slotWeightCfg();
        $sql = "SELECT * from {$tb}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $arr = [];
        foreach ($rs as $k=>$v){
            $arr[$v['levelId']] = json_decode($v['slotpro'],true);
        }
        $retData = $arr;
        $length  = count($retData);
        $macData = $retData[max(count($retData) - 1,0)];
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        foreach ($dataArray as $key=>$row){
            if($key >= $length){
                $retData[$key] = $macData;
            }
            for($j=0;$j<23;$j++){
                $t = $j + 1;
                $retData[$row[0]][$j]['v'] = $row[$t];
            }
        }
        foreach ($retData as $key=>$row){
            $upload[] = [
                'level'=>$key,
                'slotpro' =>$row,
            ];
        }
        $tb = otable::slotWeightCfg();
        $sql = "SELECT levelId from {$tb}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $temp = [];
        foreach ($rs as $row){
            array_push($temp,(int)$row['levelId']);
        }
        $upload = json_decode(json_encode($upload));
        foreach ($upload 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}')";
            }
            $rs2 = oo::commonOprDb('games')->query($sql);
            oo::commonOprRedis('games')->hDel(okeys::slotWeightCfg(),$row->level);
        }
        $res = $rs2?$rs2:0;
        if($res == 0){
            return $this->response(1, '操作失败',$dataArray);
        }else{
            return $this->response(0, '操作成功');
        }
    }

    public function getSlotItemByIdx($idx, $oldData){
        $idx = intval($idx);
        $id = $idx+1;
        $v = 0;
        switch ($idx){
            case  0:$type = 4;$prize = '攻击';break;
            case  1:$type = 3;$prize = '偷袭';break;
            case  2:$type = 2;$prize = '体力';break;
            case  3:$type = 5;$prize = '护盾';break;
            case  4:$type = 1;$prize = $oldData['prize'] ?? '0';$rewardId = 1;break;
            case  5:$type = 1;$prize = $oldData['prize'] ?? '0';$rewardId = 2;break;
            case  6:$type = 1;$prize = $oldData['prize'] ?? '0';$rewardId = 3;break;
            case  7:$type = 1;$prize = $oldData['prize'] ?? '0';$rewardId = 4;break;
            case  8:$type = 1;$prize = $oldData['prize'] ?? '0';$rewardId = 5;break;
            case  9:$type = 1;$prize = $oldData['prize'] ?? '0';$rewardId = 6;break;
            case 10:$type = 0;$prize = '没有奖励';break;
            case 11:$type = 6;$prize = '活动物品1';break;
            case 12:$type = 6;$prize = '活动物品2';break;
            case 13:$type = 6;$prize = '活动物品3';break;
            case 14:$type = 7;$prize = '小玩法物品1';break;
            case 15:$type = 7;$prize = '小玩法物品2';break;
            case 16:$type = 7;$prize = '小玩法物品3';break;
            case 17:$type = 8;$prize = '一个偷';break;
            case 18:$type = 8;$prize = '两个偷';break;
            case 19:$type = 9;$prize = '一个打';break;
            case 20:$type = 9;$prize = '两个打';break;
            case 21:$type = 10;$prize = '1个体力瓶';break;
            case 22:$type = 10;$prize = '2个体力瓶';break;
        }
        $reward = [];
        if(isset($id))$reward['id'] = $id;
        if(isset($type))$reward['type'] = $type;
        if(isset($prize))$reward['prize'] = $prize;
        if(isset($rewardId))$reward['rewardId'] = $rewardId;
        if(isset($v))$reward['v'] = $oldData['prize'] ?? $v;
        return $reward;
    }
    public function slotGroupWeights($gid){
        $tb = otable::slotWeightGroupsCfg();
        $sql = "SELECT * from {$tb} where gid={$gid}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $arr = [];
        $temp = [];
        foreach ($rs as $k=>$v){
            $arr[$v['levelId']] = json_decode($v['slotpro'],true);
            array_push($temp,(int)$v['levelId']);
        }

        $retData = $arr;
        $length  = count($retData);
        $macData = $retData[max(count($retData) - 1,0)];
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        foreach ($dataArray as $key=>$row){
            if($key >= $length){
                $retData[$key] = $macData;
            }
            for($j=0;$j<23;$j++){
                $t = $j + 1;
                $tempItem = $this->getSlotItemByIdx($j, $retData[$row[0]][$j] ?? []);
                $tempItem['v'] = $row[$t];
                $retData[$row[0]][$j] = $tempItem;
            }
        }
        foreach ($retData as $key=>$row){
            $upload[] = [
                'level'=>$key,
                'slotpro' =>$row,
            ];
        }
        $upload = json_decode(json_encode($upload));
        foreach ($upload 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 gid={$gid}";
            }else{
                $sql = "INSERT INTO {$tb} (gid,levelId,slotpro) VALUES ({$gid},{$row->level},'{$tempData}')";
            }
            $rs2 = oo::commonOprDb('games')->query($sql);

            oo::commonOprRedis('games')->hset(okeys::slotWeightGroupsCfg(),$gid . '_'.$row->level, $tempData);
        }
        $res = $rs2?$rs2:0;
        if($res == 0){
            return $this->response(1, '操作失败',$dataArray);
        }else{
            return $this->response(0, '操作成功');
        }
    }
    public function slotGroupCoins($gid){

        $tb = otable::slotWeightGroupsCfg();
        $sql = "SELECT * from {$tb} where gid={$gid}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $arr = [];
        $temp = [];
        foreach ($rs as $k=>$v){
            $arr[$v['levelId']] = json_decode($v['slotpro'],1);
            array_push($temp,(int)$v['levelId']);
        }
        $retData = $arr;

        $length  = count($retData);
        $macData = $retData[max(count($retData) - 1,0)];
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        foreach ($dataArray as $key=>$row){
            if($key >= $length){
                $retData[$key] = $macData;
            }
            $retData[$row[0]][4]['prize'] = $row[1];
            $retData[$row[0]][5]['prize'] = $row[2];
            $retData[$row[0]][6]['prize'] = $row[3];
            $retData[$row[0]][7]['prize'] = $row[4];
            $retData[$row[0]][8]['prize'] = $row[5];
            $retData[$row[0]][9]['prize'] = $row[6];
        }
        foreach ($retData as $key=>$row){
            $upload[] = [
                'level'   =>$key,
                'slotpro' =>$row,
            ];
        }

        $upload = json_decode(json_encode($upload));
        foreach ($upload 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 gid={$gid}";
            }else{
                $sql = "INSERT INTO {$tb} (gid, levelId,slotpro) VALUES ({$gid}, {$row->level},'{$tempData}')";
            }
            $rs2 = oo::commonOprDb('games')->query($sql);
            oo::commonOprRedis('games')->hset(okeys::slotWeightGroupsCfg(),$gid . '_'.$row->level, $tempData);
        }

        $res = $rs2?$rs2:0;
        if($res == 0){
            return $this->response(1, '操作失败');
        }else{
//            self::makeBeginGuideJson();
            return $this->response(0, '操作成功');
        }
    }

    public function slotActivity(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getSlotActivityConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 100;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $retData = $retData['data'];
        $length  = count($retData);
        $macData = $retData[max(count($retData) - 1,0)];
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);

        foreach ($dataArray as $key=>$row){
            if($key >= $length){
                $retData[$key] = $macData;
            }
            for($j=0;$j<4;$j++){
                $t = $j + 1;
                $retData[$row[0]][$j]['v'] = $row[$t];
            }
        }

        foreach ($retData as $key=>$row){
            $upload[] = [
                'level'=>$key,
                'data' =>$row,
            ];
        }


        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'saveSlotActivityConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['data'] = json_encode($upload,JSON_UNESCAPED_UNICODE);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }

    public function slotWeightChange($ctype){
        $retData =false;
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $datas =[];
        foreach ($dataArray as $key=>$row){
            $k=(string)$row[0];
            for($j=1;$j<22;$j++){
                $datas[$k][$j] = $row[$j];
            }
        }
        $conf_json = json_encode($datas);
        $tb = otable::slotWeightChangeCfg();
        $w = " type='".$ctype."'";
        $data['config'] =$conf_json;
        $sql = funs::db_updateSQL($tb,$data,$w);
        $retData = oo::commonOprDb('games')->query($sql);
        if($retData){
            $key = okeys::slotCoefficientCfg($ctype);
            oo::commonOprRedis('games')->delete($key);
            foreach ($datas as $k=>$v){
                $cache[$k] = json_encode($v);
            }
            $retData = oo::commonOprRedis('games')->hMset($key,$cache);
        }
        if($retData){
            return $this->response(0, '操作成功');
        }else{
            return $this->response(1, '操作失败');
        }
    }


    public function slotSpinsReturnRateCfg($ctype){
        $retData =false;
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $datas =[];
        foreach ($dataArray as $key=>$row){
            $k=(string)$row[0];
            for($j=1;$j<=11;$j++){
                $datas[$k][$j] = $row[$j];
            }
        }
        $conf_json = json_encode($datas);
        $tb = otable::slotSpinsReturnRateCfg();
        $sql = "SELECT * FROM {$tb} where type='" .$ctype . "'";
        $arr = oo::commonOprDb('slavedb')->getOne($sql,1);
        if($arr){
            $w = " type='".$ctype."'";
            $newData['config'] =$conf_json;
            $sql = funs::db_updateSQL($tb,$newData,$w);
        }else{
            $newData = [
                'type' => $ctype,
                'config' => $conf_json,
            ];
            $sql = funs::db_insertSQL($tb,$newData);
        }
        $retData = oo::commonOprDb('games')->query($sql);
        if($retData){
            $key = okeys::slotSpinsReturnRateCfg($ctype);
            $cache = [];
            foreach ($newData as $k=>$v){
                $cache[$k] = ($v);
            }
            oo::commonOprRedis('games')->hMset($key,$cache);
        }
        if($retData){
            return $this->response(0, '操作成功');
        }else{
            return $this->response(1, '操作失败');
        }
    }

    public function slotFreezePointCfg($ctype){
        $retData =false;
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $datas =[];
        foreach ($dataArray as $key=>$row){
            $k=(string)$row[0];
            for($j=1;$j<=16;$j++){
                $datas[$k][$j] = $row[$j];
            }
        }
        $conf_json = json_encode($datas);
        $tb = otable::slotFreezePointCfg();
        $sql = "SELECT * FROM {$tb} where type='" .$ctype . "'";
        $arr = oo::commonOprDb('slavedb')->getOne($sql,1);
        if($arr){
            $w = " type='".$ctype."'";
            $newData['config'] =$conf_json;
            $sql = funs::db_updateSQL($tb,$newData,$w);
        }else{
            $newData = [
                'type' => $ctype,
                'config' => $conf_json,
            ];
            $sql = funs::db_insertSQL($tb,$newData);
        }
        $retData = oo::commonOprDb('games')->query($sql);
        if($retData){
            $key = okeys::slotFreezePointCfg($ctype);
            $cache = [];
            foreach ($newData as $k=>$v){
                $cache[$k] = ($v);
            }
            oo::commonOprRedis('games')->hMset($key,$cache);
        }
        if($retData){
            return $this->response(0, '操作成功');
        }else{
            return $this->response(1, '操作失败');
        }
    }


    public function skucoin(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $base = "com.sa.crazygod.";
        $base = "com.unioncity.crazycoin.";
        foreach ($dataArray as $key=>$row){
            $retData[$row[0]] = [
                $base.'coins01'=>$row[1],
                $base.'coins02'=>$row[2],
                $base.'coins03'=>$row[3],
                $base.'coins04'=>$row[4],
                $base.'coins05'=>$row[5],
                $base.'coins06'=>$row[6],
            ];
        }

        foreach ($retData as $key=>$row){
            $postData[] = [
                'levelId'=>$key,
                'data' =>$row,
            ];
        }

        $posts = $this->postData;
        $posts['mod'] = 'Shop';
        $posts['act'] = 'saveLevel';
        $posts['data'] = json_encode($postData);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }

    public function card($type){
        ini_set('memory_limit', -1);
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);

        $arr1 =[0 => 'ciid'];
        $arr2 = array_keys(oo::cfg('lang')['lang_card']);
        $arr3 = [
            15 => 'cgid',
            16 => 'cgposition',
            17 => 'ci_star_rank',
            18 => 'ci_lockRank',
            19 => 'ci_picture',
            20 => 'grade',
            21 => 'weights',
        ];
        $header = array_merge($arr1,$arr2,$arr3);

        $retData=[];
        foreach ($dataArray as $key=>$row){
            if(empty(array_filter($row))){
                continue;
            }
            $ciid = $row[0];

            if ($type == 1 && $ciid < 100000) {
                return $this->response(1, '限时卡组卡片ID不能小于100000');
            }
            if ($type == 0 && $ciid > 100000) {
                return $this->response(1, '常规卡组卡片ID不能大于100000');
            }

            $dataRow = [];
            foreach ($header as $idx => $keyH){
                $dataRow[$keyH] = $row[$idx]?? '';
            }
            $retData[] =$dataRow;
        }

        $tb = otable::cardinfo_config();
        $sql = "SELECT `ciid` FROM {$tb} WHERE 1";
        $ret = oo::commonOprDb('slavedb')->getAll($sql);
        $ciids = array_column($ret, 'ciid');

        foreach ($retData as $row){
            if (in_array($row['ciid'], $ciids)) {
                $sql = funs::db_updateSQL($tb, $row, "ciid={$row['ciid']}");
            } else {
                $sql = funs::db_insertSQL($tb, $row);
            }

            oo::commonOprDb('games')->query($sql);
        }

        $this->updateCardCache();
        $this->actionSyncJson('CardCollect' . time() . '.json');
        return $this->response(0, '操作成功');
    }

    public function cardgroup($type)
    {
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);

        $tb = otable::cardgroup_config();
        $sql = "SELECT `cgid` from {$tb} WHERE 1";
        $ret = oo::commonOprDb('slavedb')->getAll($sql);
        $allCgids = array_column($ret, 'cgid');

        $sql = "SELECT `cgid` from {$tb} WHERE cg_type={$type}";
        $ret = oo::commonOprDb('slavedb')->getAll($sql);
        $curTypeCgids = array_column($ret, 'cgid');

        $arr1 = [0 => 'cgid'];
        $arr2 = array_keys(oo::cfg('lang')['lang_card_group']);
        $arr3 = [
            15 => 'cg_coin_reward',
            16 => 'cg_spin_reward',
            17 => 'cg_lock_rank',
            18 => 'cg_petFeed_reward',
            19 => 'cg_petExp_reward',
            20 => 'cg_title_img_id',
        ];
        $header = array_merge($arr1, $arr2, $arr3);

        $retData = [];
        foreach ($dataArray as $key => $row) {
            if (empty(array_filter($row))) {
                continue;
            }

            //校验cgid的合法性
            $cgid = $row[0];
            if ($type == 1 && $cgid < 10000) {
                return $this->response(1, '限时卡组ID不能小于10000');
            }
            if ($type == 0 && $cgid > 10000) {
                return $this->response(1, '常规卡组ID不能大于10000');
            }

            //更新不属于此类型的卡组，错误
            if (in_array($cgid, $allCgids) && !in_array($cgid, $curTypeCgids)) {
                return $this->response(1, "不能更新不属于此卡组类型的卡组，卡组ID：{$cgid}");
            }

            //没有卡片配置的卡组 不能上传
            $cardTb = otable::cardinfo_config();
            $sql = "SELECT `ciid` FROM {$cardTb} WHERE cgid={$cgid}";
            $ret = oo::commonOprDb('slavedb')->getAll($sql);
            $ciids = array_column($ret, 'ciid');
            if (empty($ciids)) {
                return $this->response(1, "此卡组未配置卡片，卡组ID：{$cgid}");
            }

            $dataRow = [];
            foreach ($header as $idx => $keyH) {
                $dataRow[$keyH] = $row[$idx] ?? '';

                //新增的卡组，添加type
                if (!in_array($cgid, $allCgids)) {
                    $dataRow['cg_type'] = $type;
                }

            }
            $retData[] = $dataRow;
        }

        foreach ($retData as $row) {
            if (in_array($row['cgid'], $allCgids)) {
                $sql = funs::db_updateSQL($tb, $row, "cgid={$row['cgid']}");
            } else {
                $sql = funs::db_insertSQL($tb, $row);
            }

            oo::commonOprDb('games')->query($sql);
        }

        oo::commonOprRedis('games')->delete(okeys::CardGroupConfig());

        $this->actionSyncJson('CardCollect' . time() . '.json');
        return $this->response(0, '操作成功');
    }

    /**
     * 导入更新公告
     */
    public function announceNews() {
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $ret = [];
        foreach ($dataArray as $key=>$row){
            $lang = substr($row[0], 0, strpos($row[0], '('));
            $ret[$lang] = [
                'title'      => $row[1],
                'content'    => $row[2],
                'time_desc'  => $row[3],
                'range_desc' => $row[4],
            ];
        }
        exit(json_encode($ret));
    }

    public function actionSyncJson($filename = "CardCollect.json"){
        $posts = $this->postData;
        $posts['mod'] = 'card';
        $posts['act'] = 'makeCardJson';
        $posts['filename'] = $filename;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        if($retData['code'] == 1){
            $data = $retData['data'];

            $dir = $this->staticPath;
            if (!is_dir($dir))
            {
                $old = umask(0);
                //mkdir($dir, PRODUCTION_SERVER ? 0775 : 0777, true);
                mkdir($dir,0775 , true);
                umask($old);
            }
            $filepath = "{$dir}{$filename}";
            file_put_contents($filepath, json_encode($data));
        }
    }

    public function level(){
        $dataArray = $this->getExcelSheetsArray();
        $retData = ConfigModel::levelBasicConfImport($dataArray);

        //出现错误
        if ($retData[0] === -1) {
            return $this->response(1, $retData[1]);
        }

        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'saveLevelConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['data'] = json_encode($retData);

        $uniqid = 'CARD_CFG:'.uniqid().':'.time();
        $posts['uniqidKey'] = $uniqid;
        oo::commonOprRedis('statistics')->hMset($uniqid, $posts);
        unset($posts['data']);

        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            $this->actionSyncMinigJson("Mining".time().".json");
            return $this->response(0, '操作成功');
        }
    }

    public function CardChest(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        foreach ($dataArray as $key=>$row){
            $retData[] = [
                'levelId'=>$row[0],
                'woodenChest'=>$row[1],
                'goldenChest'=>$row[2],
                'magicalChest'=>$row[3],
                'superChest'=>$row[4],
            ];
        }

        $posts = $this->postData;
        $posts['mod'] = 'Shop';
        $posts['act'] = 'saveCardChest';
        $posts['data'] = json_encode($retData);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }

    public function turnPlus(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        unset($dataArray[1]);
        $import = [];
        foreach ($dataArray as $key=>$row){
            $temp = [];
            $temp['levelId'] = intval($row[0]);
            $count = count($row) - 1;
            $actionCount = $count/3;
            $id  = 0;
            $pro = [];
            for ($i=0;$i<$actionCount;$i++){
                $pro[] = [
                    'id'   => $id,
                    'v'    => $row[$i*3+1],
                    'type' => $row[$i*3+2],
                    'num'  => $row[$i*3+3],
                ];
                $id++;
            }
            $temp['slotpro'] = json_encode($pro,JSON_NUMERIC_CHECK);
            $import[] = $temp;
        }

        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'saveTurnConfig';
        $posts['type'] = 'plus';
        $posts['data'] = json_encode($import,JSON_UNESCAPED_UNICODE);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,true);
        self::SaveJson($retData['data'],$retData['filename']);
        return $this->response(0, '操作成功');
    }

    public function makeBeginGuideJson(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'makeBeginGuideJson';
        $retData = $this->curl->req($this->config->item('officialUrl'), $posts);
        $retData = json_decode($retData,true);
        self::SaveJson($retData['data'],$retData['filename']);
    }

	//导入打金币配置
    public function attackCoin(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);

		$upload = [];
        foreach ($dataArray as $key=>$row){
            $upload[$row[0]]['level'] = $row[0];
            $upload[$row[0]]['shield'] = $row[1];
            $upload[$row[0]]['no_shield'] = $row[2];
        }

        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'saveAttackCoinConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['data'] = json_encode($upload,JSON_UNESCAPED_UNICODE);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }

    public function activityCoins()
    {
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);

        $tb = otable::ActivityCoins();

        $ret = oo::commonOprDb('slavedb')->getAll("Select levelId From $tb");
        $levelIdArr = array_column($ret, "levelId");

        foreach ($dataArray as $key => $row) {
            $columnIdx = 0;
            $levelId = $row[$columnIdx++];
            $one = [
                "collect" => $row[$columnIdx++],
                "rank" => $row[$columnIdx++],
                "treasureCollect" => $row[$columnIdx++],
                "treasureReward" => $row[$columnIdx++],
                "treasureBet" => $row[$columnIdx++],
                "luckyDiceCollect" => $row[$columnIdx++],
                "luckyDiceReward" => $row[$columnIdx++],
                "luckyDiceBet" => $row[$columnIdx++],
                "architecture" => $row[$columnIdx++],
                "accumulated_pay" => $row[$columnIdx++],
                "super_serial_pack" => $row[$columnIdx++],
                "super_balloon" => $row[$columnIdx++],
                "easter_egg" => $row[$columnIdx++],
                "coin_push_mania" => $row[$columnIdx++],
                "jackpot_coin" => $row[$columnIdx++],
            ];

            // 更新
            if (in_array($levelId, $levelIdArr)) {
                $sql = funs::db_updateSQL($tb, $one, "levelId = $levelId");
            } else {
                $sql = funs::db_insertSQL($tb, $one);
            }
            oo::commonOprDb('games')->query($sql);
        }

        oo::commonOprModel('config')->upActivtityCoinCache();
        if ($ret == 0) {
            return $this->response(1, '操作失败');
        } else {
            return $this->response(0, '操作成功');
        }
    }

    public function levelBaseCoins()
    {
        $sheetsData = $this->getExcelSheetsArray();
        if (empty($sheetsData)) {
            $this->response(-1, "导入的数据为空，请重新上传");
        }

        $typeMap = ['默认' => 0];
        $dataArray = $sheetsData[0];
        unset($dataArray[0]);

        $tb = otable::LvCoinsConfig();

        foreach ($dataArray as $key => $row) {
            $levelId = $row[0];
            foreach ($typeMap as $tn => $type) {
                $one = [
                    "lv" => $levelId,
                    "type" => $type,
                    "value" => $row[$type + 1],
                ];

                $sql = funs::db_replaceSQL($tb, $one);
                oo::commonOprDb('games')->query($sql);
            }
        }

        oo::commonOprModel('config')->updateLvBaseCoinsCache();
        return $this->response(0, '操作成功');
    }

    public function collect()
    {
        $sheetsData = $this->getExcelSheetsArray();
        if (empty($sheetsData)) {
            $this->response(-1, "导入的数据为空，请重新上传");
        }

        $curTime = time();
        $data = [
            "act_skin" => "",
            "tag_name" => "",
            "basic_conf" => ["groupId" => 0],
            "reward" => [],
            "status" => 0,
            "create_ts" => $curTime,
            "update_ts" => $curTime,
        ];

        $collectType = ["特殊收集" => 2, "特殊收集+偷" => 3, "特殊收集+打" => 4, "偷特殊" => 8, "打特殊" => 9];

        $sheet1 = $sheetsData[0];
        $sheet2 = $sheetsData[1];

        foreach ($sheet1 as $row => $item) {
            $key = trim($item[0]);
            $val = trim($item[1]);
            if (empty($val)) {
                continue;
            }
            switch ($key) {
                case "活动皮肤":
                    $data['act_skin'] = $val;
                    break;
                case "备注":
                    $data['tag_name'] = $val;
                    break;
                case "收集类型":
                    $data['basic_conf']['groupId'] = $collectType[$val] ?? 0;
                    break;
                case "一连击":
                    $data['basic_conf']['one_hit'] = $val;
                    break;
                case "二连击":
                    $data['basic_conf']['two_hit'] = $val;
                    break;
                case "三连击":
                    $data['basic_conf']['three_hit'] = $val;
                    break;
                case "三个偷":
                case "偷":
                    $data['basic_conf']['steal_success'] = $val;
                    $data['basic_conf']['steal_break'] = $val;
                    break;
                case "三个打":
                case "打":
                    $data['basic_conf']['attack_success'] = $val;
                    $data['basic_conf']['attack_break'] = $val;
                    break;
                case "一个偷":
                    $data['basic_conf']['one_steal'] = $val;
                    break;
                case "两个偷":
                    $data['basic_conf']['two_steal'] = $val;
                    break;
                case "一个打":
                    $data['basic_conf']['one_attack'] = $val;
                    break;
                case "两个打":
                    $data['basic_conf']['two_attack'] = $val;
                    break;
            }
        }


        for ($i = 1; $i < count($sheet2); $i++) {
            $row = $sheet2[$i];
            list($stage, $stepnum, $reward1, $isFix1, $num1, $reward2, $isFix2, $num2, $reward3, $isFix3, $num3, $reward4, $isFix4, $num4) = $row;
            if (empty($stage)) {
                continue;
            }

            $reward = ["stage" => $stage, "stepnum" => $stepnum, "prize" => []];
            for ($ri = 1; $ri <= 4; $ri++) {
                if (${"reward$ri"}) {
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${"reward$ri"}, $i);
                    $reward['prize'][] = [
                        "propsId" => $type,
                        "rtype" => ${"isFix$ri"} == '是' ? 1 : 2,
                        "num" => ${"num$ri"},
                        "skin" => $skin
                    ];
                }
            }

            $data['reward'][] = $reward;
        }

        $sql = funs::db_insertSQL(otable::NewUserCollectConf(), $data);

        $ret = oo::commonOprDb('games')->query($sql);
        if (!$ret) {
            return $this->response(1, '操作失败');
        } else {
            $id = oo::commonOprDb('games')->insertID();
            $cache = [
                "act_skin" => $data['act_skin'],
                "basic_conf" => $data['basic_conf'],
                "reward" => $data['reward'],
            ];
            oo::commonOprRedis('games')->set(okeys::NewPlayerCollectReward($id), json_encode($cache, JSON_NUMERIC_CHECK));
            return $this->response(0, '操作成功');
        }
    }

    public function treasurePro($version = ''){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $tb  = otable::TreasureProConfig($version);
        $column = $version ? 'taskId' : 'levelId';
        $sql = "SELECT {$column} FROM {$tb}";
        $ret = oo::commonOprDb('slavedb')->getAll($sql,MYSQLI_ASSOC);
        $levelIdArr = array_column($ret,$column);
        foreach ($dataArray as $key=>$row){
            $pro        = [];
            $superBet   = [];
            $levelId    = $row[0];
            for($i=2;$i<=22;$i++){
                $pro[] = [
                    'id'  => $i/2,
                    'pro' => $row[$i-1],
                    'bet' => $row[$i],
                ];
                $i++;
            }
            for($i=24;$i<=36;$i++){
                $superBet[] = [
                    'id'  => (($i-22)/2),
                    'pro' => $row[$i-1],
                    'bet' => $row[$i],
                ];
                $i++;
            }
            $pro      = json_encode($pro,JSON_NUMERIC_CHECK);
            $superBet = json_encode($superBet,JSON_NUMERIC_CHECK);
            if(in_array($levelId,$levelIdArr)){
                $ret = oo::commonOprDb('games')->query("UPDATE {$tb} SET pro='{$pro}',superBet='{$superBet}' WHERE {$column}={$levelId}");
            }else{
                $ret = oo::commonOprDb('games')->query("INSERT INTO {$tb} VALUES({$levelId}, '{$pro}', '{$superBet}')");
            }
        }
        oo::commonOprRedis('games')->delete(okeys::TreasureProConfig($version));
        if($ret == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }
    public function treasureGroupWeights($gid){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $tb  = otable::treasureProGroupsConfig();
        $column = 'taskId';
        $sql = "SELECT {$column} FROM {$tb} where gid=".$gid;
        $ret = oo::commonOprDb('slavedb')->getAll($sql,MYSQLI_ASSOC);
        $taskIds = array_column($ret,$column);
        foreach ($dataArray as $key=>$row){
            $row = array_filter($row);
            $pro        = [];
            $superBet   = [];
            $taskId = 0;
            foreach ($row as $k=>$v){
                if($k == 0){
                    $taskId    = $v;
                    continue;
                }
                $idx = ceil($k/2);
                if($idx<=11){
                    $arrName = 'pro';
                }else{
                    $arrName = 'superBet';
                }
                if(empty($$arrName[$idx])){
                    $$arrName[$idx] = [
                        'id' => $idx,
                        'pro' => $v,
                    ];
                }else{
                    $$arrName[$idx]['bet'] = $v;
                }

            }
            $pro = array_values($pro);
            $superBet = array_values($superBet);
            $proJson      = json_encode($pro,JSON_NUMERIC_CHECK);
            $superBetJson = json_encode($superBet,JSON_NUMERIC_CHECK);
            $row = [
                'taskId' => $taskId,
                'pro' => $pro,
                'superBet' => $superBet,
            ];
//            echo json_encode($row);die;
            if(in_array($taskId,$taskIds)){
                $sql = "UPDATE {$tb} SET pro='{$proJson}',`superBet`='{$superBetJson}' WHERE taskId={$taskId} and gid={$gid}";
            }else{
                $sql = "INSERT INTO {$tb} (gid, taskId,pro,superBet) VALUES ({$gid}, {$taskId},'{$proJson}','{$superBetJson}')";
            }
            $rs = oo::commonOprDb('games')->query($sql);
            oo::commonOprRedis('games')->hset(okeys::treasureProGroupsCfg(),$gid . '_'.$taskId, json_encode($row));
        }
        if($ret == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }

    public function jackpotGroupWeights($gid){
        $gid = intval($gid);
        $tb  = otable::jackpotGroupsWeights();
        $headers = Jackpot::$headers;
        $dataArray = $this->getImportData();
        unset($dataArray[0]);
        $inserts = [];
        foreach ($dataArray as $key=>$row){
            $pro = [];
            $taskId = $row[0];
            foreach ($headers as $idx => $header){
                $tmpIdx = $idx * 2 + 1;
                $pro[] = [
                    'id' => $idx + 1,
                    'pro' => $row[$tmpIdx++],
                    'bet' => $row[$tmpIdx],
                ];

            }
            $inserts[] = [
                'gid' => $gid,
                'taskId' => $taskId,
                'pro' => addslashes(json_encode($pro, 32|JSON_UNESCAPED_UNICODE)),
            ];
        }
        $deleteSql = "delete from {$tb} where gid = {$gid}";
        $insertSql = funs::db_intsertArrSQL($tb, $inserts);

        oo::commonOprDb('games')->Start();
        $res = oo::commonOprDb('games')->query($deleteSql);
        if(!$res){
            oo::commonOprDb('games')->Rollback();
            $this->response(__LINE__, "删除旧数据失败，请重试", [$deleteSql]);
        }
        $res = oo::commonOprDb('games')->query($insertSql);
        if(!$res){
            oo::commonOprDb('games')->Rollback();
            $this->response(__LINE__, "插入新数据失败，请重试", [$insertSql]);
        }
        oo::commonOprDb('games')->Commit();
        $this->response(0, "上传成功");
    }

    public function chestWeight($from,$type,$id){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $num = count($dataArray[1]);
        $weight = [];
        for($i=1;$i<$num;$i++){
            $weight[$i] = $dataArray[1][$i];
        }
        unset($dataArray[1]);
        $data = [];
        foreach ($dataArray as $key=>$row){
            $vArr = [];
            for($i=1;$i<$num;$i++){
                $vArr[] = [
                    'num'=>$row[$i],
                    'v'  =>$weight[$i],
                ];
            }
            $data[] = [
                'lv'    => $row[0],
                'weight'=> $vArr,
            ];
        }
        if($from == 1){
            $data = addslashes(json_encode($data));
            $tb = otable::StarExchange(2);
            $ret = oo::commonOprDb('games')->query("UPDATE {$tb} SET `{$type}`='{$data}' WHERE propsId={$id}");
        }else{
            if($from == 2){
                $tb = otable::ChestSkinConfig(2);
                $key= "id";
            }else if($from == 3){
                $tb = otable::ChestConfig(2);
                $key= "propsId";
            }
            $ret= oo::commonOprDb('slavedb')->getOne("SELECT * FROM {$tb} WHERE `{$key}`={$id}",MYSQLI_ASSOC);
            $reward = json_decode($ret['reward'],true);
            $reward = array_column($reward,null,"propsId");
            if($type == "spinsNum"){
                $reward[15]['pro'] = $data;
            }else if($type == "petExp"){
                $reward[8]['pro']  = $data;
            }
            $reward = array_values($reward);
            $reward = addslashes(json_encode($reward,JSON_NUMERIC_CHECK));
            $ret = oo::commonOprDb('games')->query("UPDATE {$tb} SET `reward`='{$reward}' WHERE `{$key}`={$id}");
        }
        if($ret == 0){
            return $this->response(1, '操作失败');
        }else{
            if($from == 1){
                oo::commonOprRedis('games')->delete(okeys::StarExchangeConfig(2));
            }else if($from == 2){
                oo::commonOprRedis('games')->delete(okeys::ChestSkinConfig($id));
            }else if($from == 3){
                oo::commonOprRedis('games')->delete(okeys::ChestConfig($id));
            }
            return $this->response(0, '操作成功');
        }
    }

    public function lang(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $tb    = otable::languageConfig(2);
        foreach ($dataArray as $key=>$row){
           $lang    = $row[0];
           $key     = $row[1];
           $content = $row[2];
           $sql = "REPLACE INTO {$tb} (`lang`,`key`,`content`) VALUES ('{$lang}','{$key}','{$content}')";
           oo::commonOprDb('games')->query($sql);
        }
        oo::commonOprModel("language")->setLangJson();
        return $this->response(0, '操作成功');
    }

    public function shareTranslate(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        if(__FUNCTION__ != $Sheets->getSheet(0)->getTitle()){
            return $this->response(-1, '禁止上传非法文件');
        }
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);

        $tb = otable::languageConfig();
        $ret= oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb} WHERE `type`='SHARE'",MYSQLI_ASSOC);
        $data = [];
        foreach ($ret as $row){
            $data[$row["lang"]] = json_decode(base64_decode($row['content']),true);
        }
        foreach ($dataArray as $key=>$row){
            $lang    = $row[0];
            $key     = $row[1];
            $title   = $row[2];
            $desc    = $row[3];
            $data[$lang][$key]['title'] = $title;
            $data[$lang][$key]['desc']  = $desc;
        }
        foreach ($data as $lang=>$row){
            oo::commonOprModel("language")->saveJson('SHARE',$lang,$row);
        }
        return $this->response(0, '操作成功');
    }

    public function shareTranslate2(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        if(__FUNCTION__ != $Sheets->getSheet(0)->getTitle()){
            return $this->response(-1, '禁止上传非法文件');
        }
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        foreach ($dataArray as $key=>$row){
            $key     = $row[0];
            $lang    = $row[1];
            $title   = $row[2];
            $desc    = $row[3];
            $data[$key][$lang]['title'] = $title;
            $data[$key][$lang]['desc']  = $desc;
        }
        $tb = otable::shareConfig();
        foreach ($data as $key=>$val){
            $content = addslashes(json_encode($val));
            oo::commonOprDb('games')->query("UPDATE {$tb} SET `content`='{$content}' WHERE `key`='{$key}'");
        }

        oo::commonOprModel("language")->setLangJson();

        return $this->response(0, '操作成功');
    }

    //导入规则礼包配置
    public function gift(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        if(__FUNCTION__ != $Sheets->getSheet(0)->getTitle()){
            return $this->response(-1, '禁止上传非法文件');
        }
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $input = [];
        foreach ($dataArray as $key=>$row){
            $gid = $row[0];
            $gname = $row[1];
            $gsku = $row[2];
            $gdesc = $row[3];
            $gprice = $row[4];
            $gdiscount = $row[5];
            $gExpire = $row[6];
            $gaddRatio = $row[7];
            $gMax = $row[8];
            $gShowCountry = empty($row[9])?"":$row[9];
            $gShowGroup = empty($row[10])?"":explode(",",$row[10]);
            $coins = $row[11];
            $bet = $row[12];
            $spins = $row[13];
            $i = 14;
            for($j = 0;$j < 3;$j++){
                if(empty($row[$i])){
                    continue;
                }
                $input[$gid]['gbaseReward']['props']['propsId'][$j] = $row[$i++];
                $input[$gid]['gbaseReward']['props']['num'][$j] = $row[$i++];
                $input[$gid]['gbaseReward']['props']['skin'][$j] = $row[$i++];
            }
            $input[$gid]['gname'] = $gname;
            $input[$gid]['gsku'] = $gsku;
            $input[$gid]['gdesc'] = $gdesc;
            $input[$gid]['gprice'] = $gprice;
            $input[$gid]['gdiscount'] = $gdiscount;
            $input[$gid]['gExpire'] = $gExpire;
            $input[$gid]['gaddRatio'] = $gaddRatio;
            $input[$gid]['gMax'] = $gMax;
            $input[$gid]['gShowCountry'] = $gShowCountry;
            $input[$gid]['gShowGroup'] = $gShowGroup;
            $input[$gid]['gbaseReward']['coins']['coins'] = $coins;
            $input[$gid]['gbaseReward']['coins']['bet'] = $bet;
            $input[$gid]['gbaseReward']['spins'] = $spins;
        }
        foreach ($input as $key=>$row){
            if(empty($row['gbaseReward']['props'])){
                $row['gbaseReward']['props'] = [];
            }else{
                $temp = [];
                foreach ($row['gbaseReward']['props']['propsId'] as $propsKey=>$propsId){
                    $tProps = [
                        'propsId' => $propsId,
                        'num'     => $row['gbaseReward']['props']['num'][$propsKey]
                    ];
                    if($propsId == 19){
                        $tProps['skin'] = !empty($row['gbaseReward']['props']['skin'][$propsKey]) ? $row['gbaseReward']['props']['skin'][$propsKey] : 1;
                    }
                    $temp[] = $tProps;
                }
                $row['gbaseReward']['props'] = $temp;
            }
            $row['gShowGroup'] = !empty($row['gShowGroup']) ? implode(',', $row['gShowGroup']) : '';
//            $cache[$key]['gbaseReward'] =$row['gbaseReward'];
            $row['gbaseReward'] = json_encode($row['gbaseReward'],JSON_NUMERIC_CHECK);
            if(!empty($row['ext'])){
                $row['ext'] = json_encode($row['ext']);
//                $cache[$key]['ext'] = json_decode($row['ext'],1);
            }
            unset($row['gid']);
            $input[$key] = $row;
//            $cache[$key] = json_encode($row);
        }
        $posts = $this->postData;
        $posts['mod'] = 'Shop';
        $posts['act'] = 'setSerialPack';
        $posts['data'] = json_encode($input);
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData2 = 1;
        oo::logs()->adminlog('导入规则礼包配置'.$this->router->fetch_method());
        if($retData == 0 && $retData2 == 0){
            return $this->response(1, '操作失败');
        }else{
            oo::commonOprModel('Json')->giftWeightsJson();
            return $this->response(0, '操作成功');
        }
    }

    //导入水果机金币配置
    public function lvFruitBaseCoinsIn(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
//        if(__FUNCTION__ != $Sheets->getSheet(0)->getTitle()){
//            return $this->response(-1, '禁止上传非法文件');
//        }
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        foreach ($dataArray as $row){
            $data[]= [
                "lv"=>$row[0],
                "coins"=>$row[1],
            ];
            $cacheData[$row[0]] = $row[1];
        }
        $tb=otable::fruitBaseConfig();
        $w = "type='baseCoins'";
        $updata =["config"=>json_encode($data)];
        $sql = funs::db_updateSQL($tb,$updata,$w);
        $res = oo::commonOprDb("games")->query($sql,1);
        if($res){
            oo::commonOprRedis('games')->hMset(okeys::FruitGameBaseCoinsCfg(),$cacheData);
            $ret  =$this->response(0, '操作成功',$dataArray);
        }else{
            $ret  =$this->response(1, '操作失败',$dataArray);
        }
        return $ret;
    }
    //导入水果机等级配置
    public function lvFruitGameCfgIn(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
        $tb = otable::fruitLvConfig();
        $sql= "SELECT * FROM {$tb}";
        $configs2 = oo::commonOprDb('games')->getAll($sql, 1);
        $arrLv = array_column($configs2,"lv");
        foreach ($dataArray as $k=>$row){
            $lv = intval($row[0]);
            $one=[
                "lv"=>$row[0],
                "maxExp"=>$row[1],
            ];
            $ce=[];
            for($i=2;$i<14;$i++){
                $ce[]=[
                    "id"=>$i-1,
                    "ce"=>$row[$i]
                ];
            }
            $one["upCeCfg"] = json_encode($ce);
            $w= "lv={$lv}";
            if(in_array($lv,$arrLv)){
                $sql = funs::db_updateSQL($tb,$one,$w);
            }else{
                $sql = funs::db_insertSQL($tb,$one);
            }
            $res = oo::commonOprDb('games')->query($sql,1);
            if($res){
                $key=okeys::FruitGameLvCfg($lv);
                oo::commonOprRedis('games')->hMset($key,$one);
            }
        }
        oo::commonOprRedis('games')->delete(okeys::FruitMaxLv());
        return $this->response(0, '操作成功',$one);
    }

    public  function mainBg(){
        $dataArray = $this->getImportData();
        unset($dataArray[0]);
        $config = [];
        foreach ($dataArray as $k => $line){
            list($levelId, $bg1, $color1, $bg2, $color2, $animation, $animation2) = $line;
            $config[$k] = [
                'levelId' => $levelId,
                'bg1' => $bg1,
                'color1' => $color1,
                'bg2' => $bg2,
                'color2' => $color2,
                'animation' => $animation,
                'animation2' => $animation2,
            ];
        }

        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'setMainBgConfig';
        $posts['data']= json_encode($config);
        $posts['filename']= "MainBgConfig".time().".json";
        $url  = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        oo::logs()->adminlog($this->router->fetch_method());

        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            $json = $config;
            sort($json);
            self::SaveJson($json,$posts['filename']);
            return $this->response(0, '操作成功');
        }
    }
    private function getImportData(){
        $file = $this->uploader->getFileInfo();
        $ext = trim($file['type'],'.');
        switch($ext){
            case 'csv':
                $xlsReader = IOFactory::createReader('CSV');break;
            default:
                $xlsReader = IOFactory::createReader('Excel2007');break;
        }
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
//        if(__FUNCTION__ != $Sheets->getSheet(0)->getTitle()){
//            return $this->response(-1, '禁止上传非法文件');
//        }
        $dataArray = $Sheets->getSheet(0)->toArray();
        return $dataArray;
    }

    public function stealCoin(){
        $importData = $this->getImportData();
        $post = [];
        foreach ($importData as $i =>$item){
            if($i == 0)continue;
            list($levelId, $maxCoin) = $item;
            if(empty($levelId) || empty($maxCoin))continue;
            $post[] = [
                'levelId' => $levelId,
                'maxCoin' => $maxCoin,
            ];
        }
        $data = json_encode($post);
        $tbl = otable::commonConfig();
        $type = 'stealMaxMoney';
        $title = '偷金币配置';
        $config = oo::commonOprDb('slavedb')->getOne("select * from {$tbl} where type='{$type}'",1);

        if($config){
            $sql = "UPDATE {$tbl} SET conf='".$data."' where type='{$type}'";
        }else{
            $sql = "INSERT INTO {$tbl}(name, type, conf) VALUES('{$title}','{$type}', '{$data}')";
        }
        $res = oo::commonOprDb('games')->query($sql);
        if ($res){
            $updata = array_column($post, 'maxCoin', 'levelId');
            $key = okeys::stealCoinConf();
            oo::commonOprRedis('games')->delete($key);
            oo::commonOprRedis('games')->hMset($key,$updata);
            return $this->response(0, '操作成功',[$updata, $res]);
        }else{
            return $this->response(1, '操作失败');
        }
    }
    public function petConfig($petId){
        $tb  = otable::PetExpConfig2();
        $importData = $this->getImportData();
        $petConfig = oo::commonOprDb('games')->getAll("select * from {$tb} where petId='{$petId}' ", 1);
        $petLvs = array_column($petConfig, 'lv', 'lv');
        $maxLv = 0;
        foreach ($importData as $item){
            $line = array_filter($item);
            if(empty($line))continue;
            list($lv, $star, $exp, $skill) = $item;
            $maxLv = max($lv, $maxLv);
            if(in_array($lv, $petLvs)){
                $ret = oo::commonOprDb('games')->query("UPDATE {$tb} SET `star`='{$star}',`exp`='{$exp}',`skill`='{$skill}' WHERE lv='{$lv}' AND petId={$petId}");
            }else{
                $ret = oo::commonOprDb('games')->query("insert into {$tb} (`petId`,`lv`,`star`,`exp`,`skill`) values  ('{$petId}','{$lv}','{$star}','{$exp}','{$skill}') ");
            }
        }
        if($ret == 0){
            return $this->response(1, '操作失败');
        }else{
            oo::commonOprRedis('games')->delete(okeys::PetLevelConfig($petId));
            oo::commonOprRedis('games')->hset(okeys::PetMaxLv(), $petId, $maxLv);
            return $this->response(0, '操作成功');
        }
    }

    public function pushConfig(){
        $tb = otable::fasebasePushConf();
        $importData = $this->getImportData();
        if(empty($importData))$this->response(-1 * __LINE__, '数据为空');
        $heaers = $importData[0];
        unset($importData[0]);
        foreach ($importData as $row){
            $row = array_combine($heaers, $row);
            $id = $row['id'];
            $conf = [];
            foreach ($row as $k => $v){
                if(strpos($k, '-') === false)continue;
                list($lang, $column) = explode('-', $k);
                $conf[$lang][$column] = $v;
            }
            $conf = addslashes(json_encode($conf,256));
            oo::commonOprDb('games')->query("set names utf8mb4");
            $sql = "UPDATE {$tb} SET conf='{$conf}'  WHERE id='{$id}' ";
            $ret = oo::commonOprDb('games')->query($sql);
            if(!$ret)$this->response(-1 * __LINE__, '更新数据失败');
        }

        $this->getPushConf(true);
        $this->response(1, '更新成功');
    }
    //体力瓶权重导入
    public function spinsPotWeightIn(){
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
//        if(__FUNCTION__ != $Sheets->getSheet(0)->getTitle()){
//            return $this->response(-1, '禁止上传非法文件');
//        }
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);
//        return $this->response(0, '操作成功',$dataArray);
        $tb=otable::spinsPotWeight();
        $sqlArr =[];
        foreach ($dataArray as $row){
            $one= [
                "levelId"=>$row[0],
                "weightOne"=>$row[1],
                "scoreOne"=>$row[2],
                "weightTwo"=>$row[3],
                "scoreTwo"=>$row[4],
            ];
            $data[] = $one;
            $Onejson = json_encode($one, JSON_NUMERIC_CHECK);
            $w = " levelId={$one['levelId']} ";
            $sql = "Select * from {$tb} where $w";
            $have = oo::commonOprDb('slavedb')->getOne($sql,1);
            if($have){
                $updata =["config"=>$Onejson];
                $sql = funs::db_updateSQL($tb,$updata,$w);
            }else{
                $insertData = ["levelId"=>$one['levelId'],"config"=>$Onejson];
                $sql = funs::db_insertSQL($tb,$insertData);
            }
            $sqlArr[]= $sql;
            $res = oo::commonOprDb("games")->query($sql,1);
            if($res) {
                oo::commonOprRedis('games')->hSet(okeys::spinsPotWeight(),$one['levelId'] ,$Onejson);
            }
        }
        return $this->response(0, '操作成功',$sqlArr);
    }

    public function spinsPotGiftIn()
    {
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();

        $tb = otable::spinsPotGift();
        oo::commonOprDb("games")->query("DELETE FROM {$tb}");

        $cacheMap = [];
        foreach ($dataArray as $k => $one) {
            if (empty($k)) continue;
            list($startlv, $endlv, $initval, $firstSpins, $firstPrice, $againSpins, $againPrice, $longtimeSpins, $longtimePrice) = $one;
            $item = [
                'startlv' => $startlv,
                'endlv' => $endlv,
                'initval' => $initval,
                'firstcfg' => ["maxNum" => $firstSpins, "price" => $firstPrice, "sku" => $this->getSkuByPrice($firstPrice)],
                'againcfg' => ["maxNum" => $againSpins, "price" => $againPrice, "sku" => $this->getSkuByPrice($againPrice)],
                'longtimecfg' => ["maxNum" => $longtimeSpins, "price" => $longtimePrice, "sku" => $this->getSkuByPrice($longtimePrice)],
            ];
            for ($i = $item['startlv']; $i <= $item['endlv']; $i++) {
                $one = [
                    'levelId' => $i,
                    'startlv' => $item['startlv'],
                    'endlv' => $item['endlv'],
                    'initval' => $item['initval'],
                    'firstcfg' => json_encode($item['firstcfg'], JSON_NUMERIC_CHECK),
                    'againcfg' => json_encode($item['againcfg'], JSON_NUMERIC_CHECK),
                    'longtimecfg' => json_encode($item['longtimecfg'], JSON_NUMERIC_CHECK),
                ];
                $item['levelId'] = $i;

                $sql = funs::db_insertSQL($tb, $one);
                $res = oo::commonOprDb("games")->query($sql, 1);
                if (!$res) {
                    $this->response(-1, '操作失败');
                }

                $cacheMap[$i] = json_encode($item, JSON_NUMERIC_CHECK);
            }
        }
        oo::commonOprRedis('games')->delete(okeys::spinsPotGift());
        oo::commonOprRedis('games')->hMset(okeys::spinsPotGift(), $cacheMap);

        $this->response(0, '操作成功', $dataArray);
    }
    private function getSkuByPrice($price){
        $goodSku =oo::cfg('sku');
        foreach ($goodSku as $skuPrice){
            if($skuPrice['price'] == $price){
                $sku = $skuPrice['sku'];
                return $sku;
            }
        }
        return '';
    }

    private function updateCardCache()
    {
        $tb = otable::cardinfo_config();
        $sql = "SELECT * FROM {$tb}";
        $ret = oo::commonOprDb('slavedb')->getAll($sql, 1);
        if (!empty($ret)) {
            $cacheKey = okeys::CardConfig();
            oo::commonOprRedis('games')->delete($cacheKey);
            foreach ($ret as $k => $v) {
                $arr[$v['ciid']] = $v;
                $cache[$v['ciid']] = json_encode($v);
            }
            oo::commonOprRedis('games')->hMset($cacheKey, $cache);
        }
    }

    # 皮肤宝箱基础配置
    public function chestSkinBasic(){
        $tb  = otable::ChestSkinConfig(2);
        $chestConfig = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb} ORDER BY id",MYSQLI_ASSOC);
        $chestConfig = array_column($chestConfig, 'reward', 'id');
        foreach ($chestConfig as $id => $config){
            $config = @json_decode($config, true) ?? [];
            $chestConfig[$id] = array_column($config, null, 'propsId');
        }

        $importArray = $this->getExcelSheetsArray()[0]??[];
        foreach ($importArray as $k => $item){
            if($k < 1)continue;
            if(empty($item))continue;
            list($id, $skinId, $name, $cardNum, $jokerNum, $feedNum) = $item;
            if(empty($chestConfig[$id]))continue;
            $chestConfig[$id][17] = [
                'propsId' => 17,
                'num' => intval($cardNum)
            ];
            $chestConfig[$id][18] = [
                'propsId' => 18,
                'num' => intval($jokerNum)
            ];
            $chestConfig[$id][9] = [
                'propsId' => 9,
                'num' => intval($feedNum)
            ];

            $skinId = intval($skinId);
            $skinId = empty($skinId) ? $id : $skinId;
            $item = array_values($chestConfig[$id]);
            $reward = json_encode($item);
            $sql = "UPDATE {$tb} SET  `reward`='{$reward}',`name`='{$name}', `skinResourceId`='{$skinId}' WHERE id ='{$id}'";
            $res[$id] = oo::commonOprDb('games')->query($sql);
            oo::commonOprRedis('games')->delete(okeys::ChestSkinConfig($id));
            oo::commonOprRedis('games')->delete(okeys::NewChestSkinConfig($id));
        }

        $this->response(1 , '导入成功', $res);
    }
    # 皮肤宝箱体力,宠物粮食配置
    public function chestSkinRewards($type){
        if(!in_array($type, [8, 14, 15]))$this->response(-1 * __LINE__ , '非法操作', $type);
        $tb  = otable::ChestSkinConfig(2);
        $chestConfig = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb} ORDER BY id",MYSQLI_ASSOC);
        $chestConfig = array_column($chestConfig, 'reward', 'id');
        foreach ($chestConfig as $id => $config){
            $config = @json_decode($config, true) ?? [];
            $chestConfig[$id] = array_column($config, null, 'propsId');
        }
        $chestWeights = [];
        $importArray = $this->getExcelSheetsArray();
        $weightConfig = $importArray[0] ?? [];
        $valuesConfig = $importArray[1] ?? [];
        foreach ($weightConfig as $k => $item){
            if($k < 1)continue;
            if(empty($item))continue;
            $id = 0;
            foreach ($item as $k1 => $v1){
                if($k1 == 0){
                    $id = $v1;
                    continue;
                }
                $chestWeights[$id][$type] = $chestWeights[$id][$type] ?? [
                        'propsId' => $type,
                        'weights' => [],
                    ];
                $chestWeights[$id][$type]['weights'][] = $v1;
            }
        }
        $lvSpinsPro = [];
        foreach ($valuesConfig as $k => $item){
            if($k < 1)continue;
            $line = $k +1;
            if(empty($item))continue;
            $id = intval($item[0]);
            $lv = intval($item[1]);
            if(empty($id) || empty($lv))$this->response(-1 * __LINE__ , $line.'行 等级或id配置异常', $item);
            unset($item[0], $item[1]);
            if(count($chestWeights[$id][$type]['weights']) != count($item))$this->response(-1 * __LINE__ , $line.'体力奖励个数和权重个数不匹配', [$chestWeights[$id][$type]['weights'], $item]);
            $item = array_values($item);
            $lvSpinsPro[$id][$lv] = $lvSpinsPro[$id][$lv] ?? [
                    'lv' => $lv,
                    'weight' => [],
                ];
            foreach ($item as $k1 => $v1){
                $lvSpinsPro[$id][$lv]['weight'][] = [
                    'num' => $v1,
                    'v' => $chestWeights[$id][$type]['weights'][$k1],
                ];
            }
        }
        $res = [];
        foreach ($chestConfig as $id => $item){
            $lvSpinsPro[$id] = array_values($lvSpinsPro[$id]);
            $item[$type] = [
                'propsId' => $type,
                'pro' => $lvSpinsPro[$id],
            ];
            $item = array_values($item);
            $reward = json_encode($item);
            $sql = "UPDATE {$tb} SET  `reward`='{$reward}'  WHERE id ='{$id}'";
            $res[$id] = oo::commonOprDb('games')->query($sql);
            oo::commonOprRedis('games')->delete(okeys::ChestSkinConfig($id));
            oo::commonOprRedis('games')->delete(okeys::NewChestSkinConfig($id));
        }
        $this->response(1 , '导入成功', $res);
    }
    public function chestSkinProbs(){
        $tb  = otable::ChestSkinConfig(2);
        $cardTypes = [
            '常规卡' => 0,
            '限时卡' => 1,
            '全部'   => 2,
        ];
        $importArray = $this->getExcelSheetsArray()[0]??[];
        foreach ($importArray as $k => $item){
            if($k < 1)continue;
            if(empty($item))continue;
            list($id, $star1, $star2, $star3, $star4, $star5,$goldNum, $blackGoldNum, $blackGoldKValue, $cardType) = $item;
            if(!isset($cardTypes[$cardType]))$this->response(-1 , '开卡类型不存在:'.$cardType, $item);
            $config = [
                'pro' => [
                    ['star' => 1, 'v' => intval($star1)],
                    ['star' => 2, 'v' => intval($star2)],
                    ['star' => 3, 'v' => intval($star3)],
                    ['star' => 4, 'v' => intval($star4)],
                    ['star' => 5, 'v' => intval($star5)],
                ],
                'maxGoldCard' => intval($goldNum),
                'maxBlackGoldCard' => intval($blackGoldNum),
                'blackGoldCardKValue' => intval($blackGoldKValue),
                'cardType' => $cardTypes[$cardType],
            ];
            $reward = json_encode($config);
            $sql = "UPDATE {$tb} SET  `starPro`='{$reward}' WHERE id ='{$id}'";
            $res[$id] = oo::commonOprDb('games')->query($sql);
            oo::commonOprRedis('games')->delete(okeys::ChestSkinConfig($id));
            oo::commonOprRedis('games')->delete(okeys::NewChestSkinConfig($id));
            oo::commonOprRedis('games')->delete(okeys::ChestSkinStarProConfig($id));
        }

        $this->response(1 , '导入成功', $res);
    }

    /**
     * Notes:导入真老虎机权重配置
     * User: wsc
     * Time: 2022/6/9 10:45
     * @param $gid
     * @return json
     * @throws PHPExcel_Reader_Exception
     */
    public function RealSlotGroupWeights($gid){
        $tb = otable::realSlotWeightGroupsCfg();
        $sql = "SELECT * from {$tb} where gid={$gid}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $arr = [];
        $temp = [];
        foreach ($rs as $k=>$v){
            $arr[$v["type"]][$v['levelId']] = json_decode($v['slotpro'],true);
            if(!isset($temp[$v["type"]])){
                $temp[$v["type"]] =[];
            }
            array_push($temp[$v["type"]],(int)$v['levelId']);
        }

        $retData = $arr;

        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $AllSheets= $Sheets->getAllSheets();

        $arr2 =$arr3= [];
        foreach ($AllSheets as $index=>$item){
            $upload =[];
            $type = $index+1;
            $length  = count($retData[$type]);
            $macData = $retData[$type][max(count($retData[$type]) - 1,0)];

            $dataArray  =$item->toArray();
            unset($dataArray[0]);
//            return $this->response(1, '操作失败',$dataArray);
            foreach ($dataArray as $key => $row) {
                $row = array_filter($row, "strlen");
                if (empty($row)) continue;

                $resNum = count($row);
                $retData[$type][$row[0]] = [];
                for ($j = 1; $j < $resNum; $j++) {

                    $tempItem['id'] = $j == ($resNum - 1) ? 99 : $j;
                    $tempItem['v'] = $row[$j];
                    $retData[$type][$row[0]][$tempItem['id']] = $tempItem;
                }
            }
            foreach ($retData[$type] as $key=>$row){
                $upload[] = [
                    'level'=>$key,
                    'slotpro' =>array_values($row),
                ];
            }
//            $upload = json_decode(json_encode($upload,32));
            $arr2[]=$upload;
            foreach ($upload as $row){
                $tempData = json_encode($row["slotpro"],32);
                if(in_array($row["level"],$temp[$type])){
                    $sql = "UPDATE {$tb} SET slotpro='{$tempData}' WHERE levelId={$row['level']} and gid={$gid} and type={$type}";
                }else{
                    $sql = "INSERT INTO {$tb} (gid,levelId,type,slotpro) VALUES ({$gid},{$row['level']},{$type},'{$tempData}')";
                }

                $rs2 = oo::commonOprDb('games')->query($sql);
                if($rs2){
                    oo::commonOprRedis('games')->hset(okeys::RealSlotWeightConfig($gid,$row["level"]),$type, $tempData);
                }
            }
        }

        $res = $rs2?$rs2:0;
        if($res == 0){
            return $this->response(1, '操作失败',$arr2);
        }else{
            return $this->response(0, '操作成功');
        }
    }

    /**
     * Notes:导入真老虎机金币
     * User: wsc
     * Time: 2022/6/9 11:04
     * @return json
     * @throws PHPExcel_Exception
     * @throws PHPExcel_Reader_Exception
     */
    public function RealSlotCoin(){
        $tb = otable::realSlotCoinCfg();
        $sql = "SELECT * from {$tb}";
        $res = oo::commonOprDb('slavedb')->getAll($sql,1);
        $arr = [];
        foreach ($res as $item){
            if(!isset($arr[$item["level"]])){
                $arr[$item["level"]] = [];
            }
            array_push($arr[$item["level"]],$item["stype"]);
        }


        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);


        foreach ($dataArray as  $item){
            $arr2 = $item;
            $lv = $item[0];
            unset($arr2[0]);
            foreach ($arr2 as $type=>$coin){
                if(in_array($type,$arr[$lv])){
                    $sql = funs::db_updateSQL($tb,["coins"=>$coin],"level = {$lv} and stype={$type}");
                }else{
                    $sql = funs::db_insertSQL($tb,["level"=>$lv,"stype"=>$type,"coins"=>$coin]);
                }
                $re = oo::commonOprDb("games")->query($sql);
                if($re){
                    $key = okeys::SlotRewardCoinsConfig($lv,$type);
                    oo::commonOprRedis('games')->set($key,$coin);
                }
            }
        }
        if($re == 0){
            return $this->response(1, '操作失败',$arr2);
        }else{
            return $this->response(0, '操作成功');
        }
    }

    public function trackers($country = 'DEFAULT'){
        $country = ltrim($country,'L');
        if($country == 'DEFAULT') $countrys = array_merge(oo::cfg('lang')['lang_upper2'], ['DEFAULT' => '默认']);
        else $countrys = [$country => $country];
        $tb  = otable::shareConfig();
        $importArray = $this->getExcelSheetsArray()[0]??[];
        $res = [];
        foreach ($importArray as $k => $item){
            if($k < 1)continue;
            list($key, $name, $d, $a, $b) = $item;

            $sql = "select * from {$tb} WHERE `key` = '{$key}' ";
            $config = oo::commonOprDb('games')->getOne($sql);
            $tracks = json_decode($config['track'], true);
            foreach ($countrys as $ck => $country){
                $tracks[$ck] = [
                    'd' => $d,
                    'a' => $a,
                    'b' => $b,
                ];
            }
            $tracks = json_encode($tracks);
            $sql = "UPDATE {$tb} SET  `track`='{$tracks}' WHERE `key` ='{$key}'";
            $res[$key] = oo::commonOprDb('games')->query($sql);
        }

        // 生成新JSON文件
        JsonModel::saveShareConfigJson();
        return $this->response(-1, '操作成功', $res);
    }

    /**
     * Notes:导入幸运骰子结果权重配置
     */
    public function luckyDiceGroupWeights($gid)
    {
        $tb = otable::luckyDicePointGroupsConf();
        $sql = "SELECT * from {$tb} where gid={$gid}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql, 1);
        $arr = [];
        $temp = [];
        foreach ($rs as $k => $v) {
            $arr[$v["type"]][$v['taskId']] = json_decode($v['pro'], true);
            if (!isset($temp[$v["type"]])) {
                $temp[$v["type"]] = [];
            }
            array_push($temp[$v["type"]], (int)$v['taskId']);
        }

        $retData = $arr;

        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $AllSheets = $Sheets->getAllSheets();

        $arr2 = [];
        foreach ($AllSheets as $index => $item) {
            $upload = [];
            $type = $index + 1;

            $dataArray = $item->toArray();
            unset($dataArray[0]);
            foreach ($dataArray as $key => $row) {
                $row = array_filter($row, "strlen");
                if (empty($row)) continue;

                $resNum = count($row);
                $retData[$type][$row[0]] = [];
                for ($j = 1; $j < $resNum; $j++) {

                    $tempItem['id'] = $j == ($resNum - 1) ? 99 : $j;
                    $tempItem['pro'] = $row[$j];
                    $retData[$type][$row[0]][$tempItem['id']] = $tempItem;
                }
            }
            foreach ($retData[$type] as $key => $row) {
                $upload[] = [
                    'level' => $key,
                    'pro' => array_values($row),
                ];
            }
            $arr2[] = $upload;
            foreach ($upload as $row) {
                $tempData = json_encode($row["pro"], 32);
                if (in_array($row["level"], ($temp[$type] ?? []))) {
                    $sql = "UPDATE {$tb} SET pro='{$tempData}' WHERE taskId={$row['level']} and gid={$gid} and type={$type}";
                } else {
                    $sql = "INSERT INTO {$tb} (gid,taskId,type,pro) VALUES ({$gid},{$row['level']},{$type},'{$tempData}')";
                }

                $rs2 = oo::commonOprDb('games')->query($sql);
            }
        }

        oo::commonOprRedis('games')->delete(okeys::LuckyDicePointGroupsConfig());

        $res = $rs2 ? $rs2 : 0;
        if ($res == 0) {
            return $this->response(1, '操作失败', $arr2);
        } else {
            return $this->response(0, '操作成功');
        }
    }

    /**
     * Notes:导入幸运骰子转盘权重配置
     */
    public function luckyDiceWinGroupWeights($gid)
    {
        $file = $this->uploader->getFileInfo();
        $xlsReader = IOFactory::createReader('Excel2007');
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray();
        unset($dataArray[0]);

        $tb = otable::luckyDiceWheelGroupsConf();
        $column = 'taskId';
        $sql = "SELECT {$column} FROM {$tb} where gid=" . $gid;
        $ret = oo::commonOprDb('slavedb')->getAll($sql);
        $taskIds = array_column($ret, $column);
        foreach ($dataArray as $key => $row) {
            $row = array_filter($row, "strlen");
            if (empty($row)) continue;

            $pro = [];
            $taskId = 0;
            foreach ($row as $k => $v) {
                if ($k == 0) {
                    $taskId = $v;
                    continue;
                }
                $idx = ceil($k / 2);

                if (empty($pro[$idx])) {
                    $pro[$idx] = ['id' => $idx, 'pro' => $v];
                } else {
                    $pro[$idx]['bet'] = $v;
                }
            }

            $pro = array_values($pro);
            $proJson = json_encode($pro, JSON_NUMERIC_CHECK);
            $row = [
                'taskId' => $taskId,
                'pro' => $pro,
            ];

            if (in_array($taskId, $taskIds)) {
                $sql = "UPDATE {$tb} SET pro='{$proJson}' WHERE taskId={$taskId} and gid={$gid}";
            } else {
                $sql = "INSERT INTO {$tb} (gid, taskId,pro) VALUES ({$gid}, {$taskId},'{$proJson}')";
            }
            $rs = oo::commonOprDb('games')->query($sql);
        }

        oo::commonOprRedis('games')->delete(okeys::LuckyDiceWheelGroupsConfig());

        if ($ret == 0) {
            return $this->response(1, '操作失败');
        } else {
            return $this->response(0, '操作成功');
        }
    }

    public function coinPushPro(){
        $list = $this->getImportData();
        array_shift($list);
        $bets = [];
        $keys = ['bet' =>1, 'spins' =>2, 'pro'=>3];
        $inserts = [];
        foreach ($list as $line => $item){
            $lineNum = $line+1;
            $item = array_combine(array_keys($keys), $item);
            foreach ($item as $k => $v){
                $v = intval($v);
                if(empty($v))$this->response(__LINE__, "第{$lineNum}行, 第{$keys[$k]}个异常");
            }
            if(in_array($item['bet'], $bets))$this->response(__LINE__, "第{$lineNum}行, 倍率 {$item['bet']} 重复");
            $bets = $item['bet'];
            $inserts[] = $item;
        }
        $tb = otable::coinPushPro();
        $deleteSql = 'delete from '.$tb;
        $insertSql = funs::db_intsertArrSQL($tb, $inserts);
        oo::commonOprDb('games')->Start();
        $res = oo::commonOprDb('games')->query($deleteSql);
        if(!$res){
            oo::commonOprDb('games')->Rollback();
            $this->response(__LINE__, "上传失败，请重试");
        }
        $res = oo::commonOprDb('games')->query($insertSql);
        if(!$res){
            oo::commonOprDb('games')->Rollback();
            $this->response(__LINE__, "上传失败，请重试", [$insertSql]);
        }
        oo::commonOprDb('games')->Commit();
        $this->response(0, "上传成功");
    }
}
