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

/**
 * 配置相关
 */
class Export extends MY_Controller
{
    //大转盘title
    private $_turn_table = ['关卡','id0(概率,支付概率,广告概率,金币)','id1(概率,支付概率,广告概率,金币)','id2(概率,支付概率,广告概率,金币)','id3(概率,支付概率,广告概率,金币)','id4(概率,支付概率,广告概率,金币)','id5(概率,支付概率,广告概率,金币)','id6(概率,支付概率,广告概率,金币)','id7(概率,支付概率,广告概率,金币)'];
    private $_turn_table2 = ['关卡','id0(概率,支付概率,广告概率,金币)','id1(概率,支付概率,广告概率,金币)','id2(概率,支付概率,广告概率,金币)','id3(概率,支付概率,广告概率,金币)','id4(概率,支付概率,广告概率,金币)','id5(概率,支付概率,广告概率,金币)','id6(概率,支付概率,广告概率,金币)','id7(概率,支付概率,广告概率,金币)','id8(概率,支付概率,广告概率,金币)','id9(概率,支付概率,广告概率,金币)','id10(概率,支付概率,广告概率,金币)','id11(概率,支付概率,广告概率,金币)'];

    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')  //允许的文件格式
        );
        $this->load->library('uploader', $config);
        $this->load->library('PHPExcel');
        $this->load->library('PHPExcel/PHPExcel/IOFactory');
        $this->load->library('curl');
    }

    public function base($objPHPExcel,$outPutFileName){
        // 设置第一个sheet为工作的sheet
        $objPHPExcel->setActiveSheetIndex(0);

        header('Content-Type: applicationnd.ms-excel');
        header('Content-Disposition: attachment;filename="'.$outPutFileName.'.xlsx"');
        header('Cache-Control: max-age=0');
        $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save('php://output');
        exit;
    }

    public function build()
    {
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getBuildConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 1000;

        $retData = $this->httpPost($posts);
        $headerTable = ['关卡ID', '物件',
            '1级', '奖励', '是否固定值(非金币奖励均为固定值)', '数值(宝箱等部分奖励数量固定为1)',
            '2级', '奖励', '是否固定值(非金币奖励均为固定值)', '数值(宝箱等部分奖励数量固定为1)',
            '3级', '奖励', '是否固定值(非金币奖励均为固定值)', '数值(宝箱等部分奖励数量固定为1)',
            '4级', '奖励', '是否固定值(非金币奖励均为固定值)', '数值(宝箱等部分奖励数量固定为1)',
            '5级', '奖励', '是否固定值(非金币奖励均为固定值)', '数值(宝箱等部分奖励数量固定为1)',
        ];

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

        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char . '1', $v);
            if ($char == 'Z') {
                $char = 'AA';
            } else {
                $char = chr(ord($char) + 1);
            }
        }

        $buildName = ['建筑', '雕像', '风景', '生物', '科技'];
        //处理数据
        $i = 2;
        $j = 0;
        foreach ($data as $kb => $vb) {
            foreach ($vb as $index => $value) {
                $oneReward = $reward[$kb][$index];
                $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $kb);
                $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $buildName[$j % 5]);
                $objPHPExcel->getActiveSheet()->setCellValue("C" . $i, $value[0]);

                if (!empty($oneReward[0][0])) {
                    $objPHPExcel->getActiveSheet()->setCellValue("D" . $i, ConfigModel::getPropsNameById($oneReward[0][0]));
                    $objPHPExcel->getActiveSheet()->setCellValue("E" . $i, $oneReward[0][0]['rtype'] == 1 ? '是' : '否');
                    $objPHPExcel->getActiveSheet()->setCellValue("F" . $i, $oneReward[0][0]['num']);
                }
                $objPHPExcel->getActiveSheet()->setCellValue("G" . $i, $value[1]);
                if (!empty($oneReward[1][0])) {
                    $objPHPExcel->getActiveSheet()->setCellValue("H" . $i, ConfigModel::getPropsNameById($oneReward[1][0]));
                    $objPHPExcel->getActiveSheet()->setCellValue("I" . $i, $oneReward[1][0]['rtype'] == 1 ? '是' : '否');
                    $objPHPExcel->getActiveSheet()->setCellValue("J" . $i, $oneReward[1][0]['num']);
                }
                $objPHPExcel->getActiveSheet()->setCellValue("K" . $i, $value[2]);
                if (!empty($oneReward[2][0])) {
                    $objPHPExcel->getActiveSheet()->setCellValue("L" . $i, ConfigModel::getPropsNameById($oneReward[2][0]));
                    $objPHPExcel->getActiveSheet()->setCellValue("M" . $i, $oneReward[2][0]['rtype'] == 1 ? '是' : '否');
                    $objPHPExcel->getActiveSheet()->setCellValue("N" . $i, $oneReward[2][0]['num']);
                }
                $objPHPExcel->getActiveSheet()->setCellValue("O" . $i, $value[3]);
                if (!empty($oneReward[3][0])) {
                    $objPHPExcel->getActiveSheet()->setCellValue("P" . $i, ConfigModel::getPropsNameById($oneReward[3][0]));
                    $objPHPExcel->getActiveSheet()->setCellValue("Q" . $i, $oneReward[3][0]['rtype'] == 1 ? '是' : '否');
                    $objPHPExcel->getActiveSheet()->setCellValue("R" . $i, $oneReward[3][0]['num']);
                }
                $objPHPExcel->getActiveSheet()->setCellValue("S" . $i, $value[4]);
                if (!empty($oneReward[4][0])) {
                    $objPHPExcel->getActiveSheet()->setCellValue("T" . $i, ConfigModel::getPropsNameById($oneReward[4][0]));
                    $objPHPExcel->getActiveSheet()->setCellValue("U" . $i, $oneReward[4][0]['rtype'] == 1 ? '是' : '否');
                    $objPHPExcel->getActiveSheet()->setCellValue("V" . $i, $oneReward[4][0]['num']);
                }
                $i++;
                $j++;
            }
        }
        foreach ($data as $key => $row) {
            $start = 2 + ($key - 1) * 5;
            $end = 6 + ($key - 1) * 5;
            $objPHPExcel->getActiveSheet()->mergeCells("A" . $start . ':' . "A" . $end);
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '建筑数据_' . date('Y-m-d');
        $this->base($objPHPExcel, $outPutFileName);
    }

    public function symbol(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getSymbolConfig';
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $headerTable = ['进度','数量','奖励类型(1金币，2体力)','奖励数量'];
        $bodyTable = $retData['data'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            if($char == 'Z') {
                $char = 'AA';
            }else {
                $char = chr(ord($char) + 1);
            }
        }


        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $vb['stage']);
            $objPHPExcel->getActiveSheet()->setCellValue('B'.$i, $vb['num']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb['type']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb['reward']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '金蛋数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function turn($version = ''){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getTurnConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 1000;
        $posts['conf_ver'] = $version;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $headerTable = $version ? $this->_turn_table2 : $this-> _turn_table;
        $bodyTable = $retData['data'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            if($char == 'Z') {
                $char = 'AA';
            }else {
                $char = chr(ord($char) + 1);
            }
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $kb);
            $objPHPExcel->getActiveSheet()->setCellValue('A'.($i+1), $kb);
            $objPHPExcel->getActiveSheet()->setCellValue('A'.($i+2), $kb);
            $objPHPExcel->getActiveSheet()->setCellValue('A'.($i+3), $kb);
            $char = "A";
            foreach ($vb as $value){
                $char = chr(ord($char) + 1);
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $value['v']);
                $objPHPExcel->getActiveSheet()->setCellValue($char.($i+1), $value['pv']);
                $objPHPExcel->getActiveSheet()->setCellValue($char.($i+2), $value['av']);
                $objPHPExcel->getActiveSheet()->setCellValue($char.($i+3), $value['prize']);
            }
            $i+=4;
        }

        foreach ($bodyTable as $key=>$row){
            $start = 2 + ($key-1)*4;
            $end   = 5 + ($key-1)*4;
            $objPHPExcel->getActiveSheet()->mergeCells("A".$start.':'."A".$end);
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '大转盘数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function mining(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getMiningConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 1000;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);

        $headerTable = ['岛等级','矿工升级','价格','每日收益','基础上限','成长上限'];
        $bodyTable = $retData['data'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $config = json_decode($vb['config'],true);
            foreach ($config as $key=>$value){
                $objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $vb['id']);
                $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $key+1);
                $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $value[0]);
                $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $value[1]);
                $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $vb['initIncome']);
                $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $vb['growIncome']);
                $i++;
            }
        }

        foreach ($bodyTable as $key=>$row){
            $start = 2 + ($key)*5;
            $end   = 6 + ($key)*5;
            $objPHPExcel->getActiveSheet()->mergeCells("A".$start.':'."A".$end);
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '矿工数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    /**
     * 导出更新公告
     */
    public function announceNews($id = 0) {
        $tb = otable::announcement(2);
        $time = time();
        $sql = "SELECT * FROM {$tb} WHERE id = {$id}";
        $ret = oo::commonOprDb('games')->getOne($sql, true);
        if(empty($ret)){
            return $this->response(1, '没有找到公告记录');
        }

        $langs = oo::commonOprModel('config')->getCurLangs();
        $headerTable = ["国家", "起头", "正文", "更新时间", "更新范围"];

        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        $title = json_decode($ret['title'], true);
        $content = json_decode($ret['content'], true);
        $timeDesc = json_decode($ret['time_desc'], true);
        $rangeDesc = json_decode($ret['range_desc'], true);
        foreach ($langs as $kb => $vb) {
            $t  = isset($title[$kb]) ? $title[$kb] : '';
            $c  = isset($content[$kb]) ? $content[$kb] : '';
            $ti = isset($timeDesc[$kb]) ? $timeDesc[$kb] : '';
            $r  = isset($rangeDesc[$kb]) ? $rangeDesc[$kb] : '';
            $objPHPExcel->getActiveSheet()->setCellValue('A'.$i, "{$kb}({$vb})");
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $t);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $c);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $ti);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $r);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '更新公告_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function slotpro(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getSoltConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 1000;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $headerTable = ['关卡', '攻击', '偷袭', '体力', '护盾', '1个金币', '2个金币', '3个金币', '1个钱袋', '2个钱袋', '3个钱袋', '没有奖励', '活动'];
        $bodyTable = $retData['data'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $kb);
            $char = "B";
            for($j=0;$j<12;$j++){
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $vb[$j]['v']);
                $char = chr(ord($char) + 1);
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '老虎机概率数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    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);
        }

        $headerTable = ['关卡', '攻击', '偷袭', '体力', '护盾', '1个金币', '2个金币', '3个金币', '1个钱袋', '2个钱袋', '3个钱袋', '没有奖励', '活动物品1','活动物品2','活动物品3', '小玩法物品1','小玩法物品2','小玩法物品3','一个偷','两个偷','一个打','两个打','1个体力瓶','2个体力瓶'];
        $bodyTable = $arr;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $kb);
            $char = "B";
            for($j=0;$j<23;$j++){
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $vb[$j]['v']);
                $char = chr(ord($char) + 1);
            }
            $i++;
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '老虎机概率数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }
    public function slotGroupWeights($gid){
        $tb = otable::slotWeightGroupsCfg();
        $sql = "SELECT * from {$tb} where gid={$gid}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $arr = [];
        foreach ($rs as $k=>$v){
            $arr[$v['levelId']] = json_decode($v['slotpro'],true);
        }

        $headerTable = ['关卡', '攻击', '偷袭', '体力', '护盾', '1个金币', '2个金币', '3个金币', '1个钱袋', '2个钱袋', '3个钱袋', '没有奖励', '活动物品1','活动物品2','活动物品3', '小玩法物品1','小玩法物品2','小玩法物品3','一个偷','两个偷','一个打','两个打','1个体力瓶','2个体力瓶'];
        $bodyTable = $arr;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $kb);
            $char = "B";
            for($j=0;$j<23;$j++){
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $vb[$j]['v']);
                $char = chr(ord($char) + 1);
            }
            $i++;
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '老虎机概率数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }
    public function slotGroupCoins($gid){
        $tb = otable::slotWeightGroupsCfg();
        $sql = "SELECT * from {$tb} where gid={$gid}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $arr = [];
        foreach ($rs as $k=>$v){
            $arr[$v['levelId']] = json_decode($v['slotpro'],1);
        }

        $headerTable = ['关卡', '1个金币', '2个金币', '3个金币', '1个钱袋', '2个钱袋', '3个钱袋'];
        $bodyTable = $arr;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $kb);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb[4]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb[5]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb[6]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $vb[7]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $vb[8]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("G".$i, $vb[9]['prize']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '老虎机金币数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function slotActivity(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getSlotActivityConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 1000;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $headerTable = ['关卡', '有奖励 1个活动', '有奖励 2个活动', '无奖励 1个活动', '无奖励 2个活动'];
        $bodyTable = $retData['data'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $kb);
            $char = "B";
            for($j=0;$j<4;$j++){
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $vb[$j]['v']);
                $char = chr(ord($char) + 1);
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '老虎机活动概率数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function slotWeightChange($ctype){
        $tb = otable::slotWeightChangeCfg();
        $sql = "SELECT * FROM {$tb}";
        $datas = oo::commonOprDb('games')->getAll($sql,1);
        $data = array_column($datas,'config','type');
        $arr = json_decode($data[$ctype],true);
//        foreach ($arr as $k=>$v){
//            array_unshift ($arr[$k],$k);
//        }
        $first =$ctype=='spinsLost'?'体力倍率':($ctype=='spinsLostDay'?'体力总消耗':'次数');
        $headerTable = [$first, '攻击', '偷袭', '体力', '护盾', '1个金币', '2个金币', '3个金币', '1个钱袋', '2个钱袋', '3个钱袋', '没有奖励', '活动物品1','活动物品2','活动物品3', '小玩法物品1','小玩法物品2','小玩法物品3','一个偷','两个偷','一个打','两个打','1个体力瓶','2个体力瓶'];
        $bodyTable = $arr;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $kb);
            $char = "B";
            for($j=1;$j<22;$j++){
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $vb[$j]);
                $char = chr(ord($char) + 1);
            }
            $i++;
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '老虎机权重修正_'.$first.'_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function slotSpinsReturnRateCfg($ctype){
        $headerTable = [
            0=>"A\B",
            1=>"0",
            2=>"0.1",
            3=>"0.2",
            4=>"0.3",
            5=>"0.4",
            6=>"0.5",
            7=>"0.6",
            8=>"0.7",
            9=>"0.8",
            10=>"0.9",
            11=>"1.0",
        ];

        $tb = otable::slotSpinsReturnRateCfg();
        $sql = "SELECT * FROM {$tb} where `type`='{$ctype}'";
        $datas = oo::commonOprDb('games')->getOne($sql,1);
        $tables = [];
        $config = json_decode($datas['config'], 1);
//        var_dump($config);die;
        foreach ($config as $a => $bArr){
            $tables[] = array_merge([$a], $bArr);
        }
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($tables as  $line) {
            $char = 'A';
            foreach ($line as $cell){
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $cell);
                $char++;
            }
            $i++;
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '老虎机体力返比配置'.$ctype.date('YmdHis');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function slotFreezePointCfg($ctype){
        $headerTable = [
            0=>"A\B",
            1=>"0",
            2=>"0.1",
            3=>"0.2",
            4=>"0.3",
            5=>"0.4",
            6=>"0.5",
            7=>">0.5",
        ];

        $tb = otable::slotFreezePointCfg();
        $sql = "SELECT * FROM {$tb} where `type`='{$ctype}'";
        $datas = oo::commonOprDb('games')->getOne($sql,1);
        $tables = [];
        $config = json_decode($datas['config'], 1);
//        var_dump($config);die;
        foreach ($config as $a => $bArr){
            $tables[] = array_merge([$a], $bArr);
        }
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($tables as  $line) {
            $char = 'A';
            foreach ($line as $cell){
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $cell);
                $char++;
            }
            $i++;
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '收集活动卡点'.$ctype.date('YmdHis');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function slotcoin(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getSoltConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 1000;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $headerTable = ['关卡', '1个金币', '2个金币', '3个金币', '1个钱袋', '2个钱袋', '3个钱袋'];
        $bodyTable = $retData['data'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $kb);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb[4]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb[5]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb[6]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $vb[7]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $vb[8]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("G".$i, $vb[9]['prize']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '老虎机金币数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    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);
        }

        $headerTable = ['关卡', '1个金币', '2个金币', '3个金币', '1个钱袋', '2个钱袋', '3个钱袋'];
        $bodyTable = $arr;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $kb);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb[4]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb[5]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb[6]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $vb[7]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $vb[8]['prize']);
            $objPHPExcel->getActiveSheet()->setCellValue("G".$i, $vb[9]['prize']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '老虎机金币数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function card($type)
    {
        $cardTb = otable::cardinfo_config();
        $cardGroupTb = otable::cardgroup_config();
        $sql = "select * from {$cardTb} where {$cardTb}.cgid in  (SELECT cgid FROM {$cardGroupTb} where cg_type={$type})";
        $bodyTable = oo::commonOprDb('slavedb')->getAll($sql);

        $arr1 = ['ciid' => '卡片ID'];
        $arr2 = oo::cfg('lang')['lang_card'];
        $arr3 = [
            'cgid' => '卡组ID'
            , 'cgposition' => '卡片位置'
            , 'ci_star_rank' => '卡片星级'
            , 'ci_lockRank' => '解锁等级'
            , 'ci_picture' => '图片ID'
            , 'grade' => '金卡(1普2金3黑金)'
            , 'weights' => '权重'];
        $headerTable = array_merge($arr1, $arr2, $arr3);

        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char . '1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $char = 'A';
            foreach ($headerTable as $hk => $hv) {
                $objPHPExcel->getActiveSheet()->setCellValue($char . $i, $vb[$hk] ?? '');
                $char++;
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        $outPutFileName = ($type == 0 ? '常规' : '限时') . '卡组卡片数据_' . date('Y-m-d') . uniqid('_');
        $this->base($objPHPExcel, $outPutFileName);
    }

    public function skucoin(){
        $posts = $this->postData;
        $posts['mod'] = 'Shop';
        $posts['act'] = 'level';
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,true);
        $headerTable = ['等级ID','coin01', 'coin02', 'coin03', 'coin04', 'coin05', 'coin06'];
        $bodyTable = $retData['data'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        $base = "com.sa.crazygod.";
        $base = "com.unioncity.crazycoin.";
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['levelId']);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb[$base.'coins01']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb[$base.'coins02']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb[$base.'coins03']);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $vb[$base.'coins04']);
            $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $vb[$base.'coins05']);
            $objPHPExcel->getActiveSheet()->setCellValue("G".$i, $vb[$base.'coins06']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '商店金币数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    //卡组配置导出
    public function cardgroup($type)
    {
        $tb = otable::cardgroup_config();
        $sql = "SELECT * from {$tb} WHERE cg_type={$type}";
        $bodyTable = oo::commonOprDb('slavedb')->getAll($sql);

        $arr1 = ['cgid' => '卡组ID'];
        $arr2 = oo::cfg('lang')['lang_card_group'];
        $arr3 = ['cg_coin_reward' => '金币奖励', 'cg_spin_reward' => '体力奖励', 'cg_lock_rank' => '解锁等级', 'cg_petFeed_reward' => "粮食奖励", 'cg_petExp_reward' => "经验奖励", 'cg_title_img_id' => "标题颜色"];
        $headerTable = array_merge($arr1, $arr2, $arr3);

        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char . '1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $char = 'A';
            foreach ($headerTable as $hk => $hv) {
                $objPHPExcel->getActiveSheet()->setCellValue($char . $i, $vb[$hk] ?? '');
                $char++;
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        $outPutFileName = ($type == 0 ? '常规' : '限时') . '卡组数据_' . date('Y-m-d') . uniqid('_');
        $this->base($objPHPExcel, $outPutFileName);
    }

    public function level(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getLevelConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 1000;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $arr1 =['levelId' => '关卡'];
        $arr2 = oo::cfg('lang')['lang_level'];
        $arr3 = ['pictureId' => '图标ID'];
        $headerTable = array_merge($arr1,$arr2,$arr3);

        $bodyTable = ConfigModel::formatLevelRewardConfig($retData['data']);
        $objPHPExcel = new PHPExcel();
        $curActivitySheet = $objPHPExcel->setActiveSheetIndex();

        // 工作表1

        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $curActivitySheet->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }

        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $char = 'A';
            foreach ($headerTable as $k => $v) {
                $curActivitySheet->setCellValue($char.$i, $vb[$k] ?? '');
                $char++;
            }
            $i++;
        }

        // 工作表2
        $objPHPExcel->createSheet(1);
        $curActivitySheet = $objPHPExcel->setActiveSheetIndex(1);

        //处理表头
        $headerTable = ['levelId' => '关卡'];
        for ($i = 0; $i < 5; $i++) {
            $headerTable["{$i}-propsId"] = "奖励" . ($i + 1);
            $headerTable["{$i}-rtype"] = "是否固定值(非金币奖励均为固定值)";
            $headerTable["{$i}-num"] = "数值(宝箱等部分奖励数量固定为1)";
        }

        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $curActivitySheet->setCellValue($char . '1', $v);
            $char = chr(ord($char) + 1);
        }

        //处理数据
        $i = 2;
        foreach ($bodyTable as $vb) {

            $char = 'A';
            foreach ($headerTable as $hk => $hv) {
                $reward = json_decode($vb['reward'], true);

                $rewardSize = count($reward);
                $fields = explode('-', $hk);
                if ($fields[0] >= $rewardSize) {
                    continue;
                }

                if ($char == 'A') {
                    $val = $vb['levelId'];
                } else {
                    $val = $reward[$fields[0]][$fields[1]] ?? '';
                    switch ($fields[1]){
                        case 'propsId':
                            $val = ConfigModel::getPropsNameById($reward[$fields[0]]);
                            break;
                        case 'rtype':
                            $val = $val == 1 ? '是' : '否';
                            break;
                    }
                }
                $curActivitySheet->setCellValue($char . $i, $val);

                $char++;
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '关卡数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function CardChest(){
        $posts = $this->postData;
        $posts['mod'] = 'Shop';
        $posts['act'] = 'CardChest';
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $headerTable = ['等级ID','木箱','银宝箱','黄金宝箱','高级黄金宝箱'];
        $bodyTable = $retData['data'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['levelId']);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['woodenChest']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb['goldenChest']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb['magicalChest']);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $vb['superChest']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '卡片宝箱_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function welcome(){
        $getData = $this->input->get();
        $date[] = $getData['etime'];
        $date[] = $getData['stime'];
        $dateNum = $getData['etime'] - $getData['stime'];
        for($i=0;$i<$dateNum;$i++){
            $date[] = $getData['stime'] + 1 + $i;
        }
        $date = array_unique($date);
        $date = implode(',',$date);
        $posts = $this->postData;
        $posts['mod'] = 'Statistics';
        $posts['act'] = 'BaseDataSta';
        $posts['date'] = $date;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $bodyTable = json_decode($retData,1);
        $headerTable = ['日期','新增用户','活跃用户','付费用户','付费金额','首次付费用户','新增付费用户','自传播占比','付费率','ARPU','ARPPU','累计付费用户','人均时长'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['date']);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['todayNew']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb['todayLogin']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb['todaySuccessPayNum']);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $vb['todayPayMoney']);
            $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $vb['firstPayPlayerNum']);
            $objPHPExcel->getActiveSheet()->setCellValue("G".$i, $vb['newPayNum']);
            $objPHPExcel->getActiveSheet()->setCellValue("H".$i, $vb['AARRR']);
            $objPHPExcel->getActiveSheet()->setCellValue("I".$i, $vb['payRate']);
            $objPHPExcel->getActiveSheet()->setCellValue("J".$i, $vb['payARPU']);
            $objPHPExcel->getActiveSheet()->setCellValue("K".$i, $vb['payARPPU']);
            $objPHPExcel->getActiveSheet()->setCellValue("L".$i, $vb['allPayNum']);
            $objPHPExcel->getActiveSheet()->setCellValue("M".$i, $vb['loginAvg']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '基础数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function turnPlus(){
        $headerTable = ['概率', '类型', '数量'];
        $objPHPExcel = new PHPExcel();
        $char = 'A';
        $objPHPExcel->getActiveSheet()->setCellValue($char.'1', '关卡');
        $objPHPExcel->getActiveSheet()->setCellValue($char.'2', '关卡');
        $objPHPExcel->getActiveSheet()->mergeCells("A1".':'."A2");
        $prefix = '';
        $char = "B";
        for($i=0;$i<8;$i++){
            $startChar = $char;
            foreach ($headerTable as $row){
                $objPHPExcel->getActiveSheet()->setCellValue($char.'1', 'ID'.($i+1));
                $objPHPExcel->getActiveSheet()->setCellValue($char.'2', $row);
                $endChar = $char;
                if($char == 'Z') {
                    $char = 'AA';
                    $prefix = 'A';
                }else {
                    $char = $prefix.chr(ord($char) + 1);
                }
            }
            $objPHPExcel->getActiveSheet()->mergeCells("{$startChar}1".':'."{$endChar}1");
        }

        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getTurnConfig';
        $posts['type']= 'plus';
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,true);

        foreach ($retData as $k=>$v){
            $arr[$v['levelId']] = $v['slotpro'];
        }
        $i = 3;
        foreach ($retData as $k=>$v) {
            $char = "A";
            $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $v['levelId']);
            $char = $prefix.chr(ord($char) + 1);
            foreach ($v['slotpro'] as $row){
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $row['v']);
                $char = $prefix.chr(ord($char) + 1);
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $row['type']);
                $char = $prefix.chr(ord($char) + 1);
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $row['num']);
                $char = $prefix.chr(ord($char) + 1);
            }
            $i++;
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '大转盘升级版_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }
	
	//打金币配置
    public function attackCoin(){
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getAttackCoinConfig';
        $posts['lid'] = '1';
        $posts['sid'] = '1';
        $posts['page'] = 1;
        $posts['page_size'] = 1500;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $headerTable = ['关卡', '有盾', '无盾'];
        $bodyTable = $retData['data'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['levelId']);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['shield']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb['no_shield']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '打金币配置_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function activityCoins()
    {
        $tb = otable::ActivityCoins();
        $bodyTable = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb}");

        $this->exportData(ACTIVITY_COIN_HEADERS, $bodyTable, '活动金币配置');
    }

    public function levelBaseCoins()
    {
        $tb = otable::LvCoinsConfig();
        $headerTable = ['default' => '默认'];
        $bodyTable = oo::commonOprDb('slavedb')->getAll("select * from {$tb}");

        $typeMap = [0 => 'default'];
        $data = [];
        foreach ($bodyTable as $row) {
            $type = $typeMap[$row['type']] ?? '';
            if (empty($type)){
                continue;
            }
            $data[$row['lv']][$type] = $row['value'];
        }

        $objPHPExcel = new PHPExcel();
        $curActivitySheet = $objPHPExcel->setActiveSheetIndex();

        //处理表头
        $curActivitySheet->setCellValue('A1', '等级');

        $char = 'B';
        foreach ($headerTable as $k => $v) {
            $curActivitySheet->setCellValue($char . '1', $v);
            $char = chr(ord($char) + 1);
        }

        //处理数据
        $i = 2;
        foreach ($data as $lv => $vb) {
            $curActivitySheet->setCellValue('A' . $i, $lv);

            $char = 'B';
            foreach ($headerTable as $hk => $hv) {
                $curActivitySheet->setCellValue($char . $i, $vb[$hk] ?? '');
                $char++;
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        $outPutFileName = '等级基础金币配置数据_' . date('Y-m-d') . uniqid('_');
        $this->base($objPHPExcel, $outPutFileName);
    }

    public function treasurePro($version = ''){
        $tb  = otable::TreasureProConfig($version);
        $ret = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb}",MYSQLI_ASSOC);
        $headerTable = ['关卡','转盘','小王子*3','狐狸*3','小王子*2','王冠*3','小王子*1','黑桃*3','红桃*3','方块*3','黑桃+红桃+方块','没有奖励','转盘1','转盘2','转盘3','转盘4','转盘5','转盘6','转盘7'];
        foreach ($ret as $key=>$row){
            $ret[$key]['pro'] = json_decode($row['pro'],true);
            $ret[$key]['superBet'] = json_decode($row['superBet'],true);
        }

        $column = $version ? 'taskId' : 'levelId';
        $bodyTable = $ret;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $objPHPExcel->getActiveSheet()->setCellValue('A1', $headerTable[0]);
        $char    = 'B';
        $charArr = [];
        $header = "";
        foreach ($headerTable as $k=>$v){
            if($k >= 1){
                $charArr[] = $char;
                $objPHPExcel->getActiveSheet()->setCellValue($header.$char.'1', $v);
                $ord = ord($char);
                if($ord >= 90){
                    $header = "A";
                    $ord = ord('A') - 1;
                }
                $char = chr(ord(chr($ord + 1)) + 1);
            }
        }
        $header = ['B1', 'D1', 'F1', 'H1', 'J1', 'L1', 'N1', 'P1', 'R1', 'T1', 'V1', 'X1', 'Z1', 'AB1', 'AD1', 'AF1', 'AH1', 'AJ1'];
        $end    = ['C1', 'E1', 'G1', 'I1', 'K1', 'M1', 'O1', 'Q1', 'S1', 'U1', 'W1', 'Y1', 'AA1', 'AC1', 'AE1', 'AG1', 'AI1','AK1'];
        foreach ($header as $key=>$row){
            $objPHPExcel->getActiveSheet()->mergeCells($row.':'.$end[$key]);
        }
        //处理数据
        $i = 2;
        $header = "";
        $char   = 'A';
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("{$header}{$char}{$i}", $vb[$column]);
            foreach (['pro','superBet'] as $d){
                foreach ($vb[$d] as $row){
                    $ord  = ord($char);
                    if($ord == 90){
                        $char = "@";
                        $header = "A";
                    }
                    $char = chr(ord($char) + 1);
                    $objPHPExcel->getActiveSheet()->setCellValue("{$header}{$char}{$i}", $row['pro']);
                    $ord  = ord($char);
                    if($ord == 90){
                        $char = "@";
                        $header = "A";
                    }
                    $char = chr(ord($char) + 1);
                    $objPHPExcel->getActiveSheet()->setCellValue("{$header}{$char}{$i}", $row['bet']);
                }
            }
            $header = "";
            $char = "A";
            $i++;
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '宝藏活动概率配置2_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }
    public function treasureGroupWeights($gid){
        $tb  = otable::treasureProGroups();
        $treasureGroup = oo::commonOprDb('slavedb')->getOne("SELECT * FROM {$tb} where id=".$gid,MYSQLI_ASSOC);
        $tb  = otable::treasureProGroupsConfig();
        $ret = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb} where gid=".$gid,MYSQLI_ASSOC);
        $headerTable = ['关卡','转盘','小王子*3','狐狸*3','小王子*2','王冠*3','小王子*1','黑桃*3','红桃*3','方块*3','黑桃+红桃+方块','没有奖励','转盘1','转盘2','转盘3','转盘4','转盘5','转盘6','转盘7'];
        foreach ($ret as $key=>$row){
            $ret[$key]['pro'] = json_decode($row['pro'],true);
            $ret[$key]['superBet'] = json_decode($row['superBet'],true);
        }
        $column = 'taskId';
        $bodyTable = $ret;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $objPHPExcel->getActiveSheet()->setCellValue('A1', $headerTable[0]);
        $char    = 'A';
        foreach ($headerTable as $k=>$v){
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            if($k > 0){
                $objPHPExcel->getActiveSheet()->mergeCells($char.'1:'.++$char.'1');
            }
            $char++;
        }

        //处理数据
        $i = 2;
        $columnsArray = ['pro','superBet'];
        $proItems = ['pro', 'bet'];
        foreach ($bodyTable as $vb) {
            $char   = 'A';
            $objPHPExcel->getActiveSheet()->setCellValue("$char{$i}", $vb[$column]);
            foreach ($columnsArray as $d){
                foreach ($vb[$d] as $row){
                    foreach ($proItems as $item) {
                        $char++;
                        $objPHPExcel->getActiveSheet()->setCellValue("{$char}{$i}", $row[$item]);
                    }
                }
            }
            $i++;
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = $treasureGroup['name'].'-金币老虎机概率倍率配置'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function jackpotGroupWeights($gid){
        $ret = JackpotModel::getGroupsWeights($gid);
        $headerTable = Jackpot::$headers;
        foreach ($ret as $key=>$row){
            $ret[$key]['pro'] = json_decode($row['pro'],true);
        }
        $column = 'taskId';
        $bodyTable = $ret;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char    = 'A';
        $objPHPExcel->getActiveSheet()->setCellValue($char.'1', '关卡');
        foreach ($headerTable as $k=>$v){
            $char++;
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v.'(权重|倍率)');
            $objPHPExcel->getActiveSheet()->mergeCells($char.'1:'.++$char.'1');
        }

        //处理数据
        $i = 2;
        $proItems = ['pro', 'bet'];
        foreach ($bodyTable as $vb) {
            $char   = 'A';
            $objPHPExcel->getActiveSheet()->setCellValue("$char{$i}", $vb[$column]);

            foreach ($vb['pro'] as $row){
                foreach ($proItems as $item) {
                    $char++;
                    $objPHPExcel->getActiveSheet()->setCellValue("{$char}{$i}", $row[$item]);
                }
            }
            $i++;
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = 'Jackpot老虎机概率倍率配置-'.$gid.'-'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

	//导出用户流水
	public function userlog($uid = 0, $day=''){
        if(empty($day)){
            $date = date("Ymd");
        }else{
            $date = strtotime($day) ? date('Ymd', strtotime($day)) : date('Ymd');
        }

        $dayStamp = strtotime($date);
        $oos_debug = $this->config->item('oos_debug');
        if(!$oos_debug && time() - $dayStamp >= 8 * 24 * 3600){
            $database = 'log2';
            $tb = otable::Assetslog2($date, $uid);
        }else{
            $database = 'log';
            $tb = otable::Assetslog($date, $uid);
        }

		$sql = "SELECT * FROM {$tb} WHERE uid={$uid} ORDER BY time DESC";
		$list = oo::commonOprDb($database)->getAll($sql, MYSQLI_ASSOC);
        $reason = oo::commonOprModel('statistics')->reason;
		$headerTable = ['类型','数量','增减','来源','最终值','时间','当时等级',"rid"];
		$bodyTable = $list;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        $propCfg = oo::cfg('props');
        foreach ($bodyTable as $kb => $vb) {
            $typeName = (is_numeric($vb['type']) && isset($propCfg[$vb['type']])) ? $propCfg[$vb['type']]['name'] : $vb['type'];
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $typeName);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['num']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb['crease']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb['reason']);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $vb['last_num']);
            $objPHPExcel->getActiveSheet()->setCellValue("F".$i, date("Y-m-d H:i:s",$vb['time']));
            $objPHPExcel->getActiveSheet()->setCellValue("G".$i, $vb['levelId']);
            $objPHPExcel->getActiveSheet()->setCellValue("H".$i, $reason[$vb['rid']]);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '用户'.$uid.'流水_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
	}

    public function userDiamond() {
        $userid = (int)get_cookie('userid');
        $tb = otable::gh_gameserver();
        $sql = "SELECT * FROM {$tb} WHERE diamond > 0";
        if($userid > 0){
            $sql .= " AND mid = ${userid}";
        }
        $sql .= " ORDER BY diamond DESC";
        $list = oo::commonOprDb('slavedb')->getAll($sql,1);
		$headerTable = ['用户id','用户等级','钻石数量','体力数量','金币数量','星星数量'];
		$bodyTable = $list;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['mid']);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['levelId']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb['diamond']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb['spins']);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $vb['money']);
            $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $vb['star']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '钻石留存_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
	}

	public function userGroup($date,$id,$num = 10){
        $tb  = otable::UserGroupConfig(2);
        $ret = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb}",MYSQLI_ASSOC);
        $groupName = array_column($ret,"name","id");
        $tb   = otable::UserGroupSta();
        $like = "%#{$id}#%";
        $sql  = "SELECT uid,groupId,data FROM {$tb} WHERE date='{$date}' AND groupId LIKE '{$like}' ORDER BY RAND() LIMIT {$num}";
        $res  = oo::commonOprDb('statistics')->getAll($sql, MYSQLI_ASSOC);
        $headerTable = ['用户ID','分组', '平台', '设备', 'VIP', '首冲', 'VIP积分', '等级', '活跃天数(天)', '累计游戏时长(分)', '注册时长(天)', '好友数量', '好友排行', '国家排行', '世界排行', '国家分组', 'Adjust来源分组'];
        $objPHPExcel = new PHPExcel();
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        $i = 2;
        foreach ($res as $row){
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $row['uid']);
            $groupArr = array_filter(explode('#',$row['groupId']));
            $gName = "";
            foreach ($groupArr as $gid){
                if(!empty($groupName[$gid])){
                    $gName .= $groupName[$gid].",";
                }
            }
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, trim($gName,','));
            $userData = json_decode($row['data'],true);

            /** 平台 */
            if(isset($userData['userInfo']['login_plat'])){
                $temp = $userData['userInfo']['login_plat'] == 1 ? "安卓":"IOS";
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $temp);

            /** 设备 */
            if(isset($userData['userInfo']['isFb'])){
                $temp = $userData['userInfo']['isFb'] == 1 ? "FB":"游客";
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $temp);

            /** VIP */
            if(isset($userData['userInfo']['vip'])){
                $temp = $userData['userInfo']['vip'] == 1 ? "VIP":"非VIP";
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $temp);

            /** 首冲 */
            if(isset($userData['isFirstPay'])){
                $temp = $userData['isFirstPay'] == 1 ? "首冲":"非首冲";
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $temp);

            /** VIP积分 */
            if(isset($userData['userInfo']['vipPoint'])){
                $temp = $userData['userInfo']['vipPoint'];
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("G".$i, $temp);

            /** 等级 */
            if(isset($userData['levelId'])){
                $temp = $userData['levelId'];
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("H".$i, $temp);

            /** 活跃天数(天) */
            if(isset($userData['userDynamics']['activeDay'])){
                $temp = $userData['userDynamics']['activeDay'];
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("I".$i, $temp);

            /** 累计游戏时长(分) */
            if(isset($userData['loginTime'])){
                $temp = $userData['loginTime'];
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("J".$i, $temp);

            /** 注册时长(天) */
            if(isset($userData['userInfo']['createtime'])){
                $temp = intval((time() - $userData['userInfo']['createtime']) / 84600);
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("K".$i, $temp);

            /** 好友数量 */
            if(isset($userData['friends'])){
                $temp = $userData['friends'];
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("L".$i, $temp);

            /** 好友排行 */
            if(isset($userData['userRankData']['friend'])){
                $temp = $userData['userRankData']['friend'];
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("M".$i, $temp);

            /** 国家排行 */
            if(isset($userData['userRankData']['country'])){
                $temp = $userData['userRankData']['country'];
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("N".$i, $temp);

            /** 世界排行 */
            if(isset($userData['userRankData']['world'])){
                $temp = $userData['userRankData']['world'];
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("O".$i, $temp);

            /** 国家分组 */
            if(isset($userData['country']['country_code'])){
                $temp = $userData['country']['country_code'];
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("P".$i, $temp);

            /** Adjust来源分组 */
            if(isset($userData['userAdjustGroup'])){
                $temp = $userData['userAdjustGroup'];
            }else{
                $temp = "未加载";
            }
            $objPHPExcel->getActiveSheet()->setCellValue("Q".$i, $temp);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '用户分组_'.$date;
        $this->base($objPHPExcel,$outPutFileName);
    }

    //导出用户分组统计
    public function userGroupSta($stime = '',$etime = ''){
        $stime = empty($stime) ? date('Y-m-d', strtotime("-6 days")) : $stime;
        $etime = empty($etime) ? date('Y-m-d') : $etime;
        $dayList = array_reverse(oo::getDateRange($stime,$etime));
        $tb   = otable::UserGroupSta();
        $staTb = otable::staData();
        $config = oo::commonOprModel('config')->getUserGroupConfig2();
        array_multisort(array_column($config,'sort'),SORT_ASC,$config);

        $headerTable = ['日期','分群ID','分群名','人数','付费人数','付费率','ARPU','ARPPU','付费总额'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($dayList as $date){
            $date = str_replace('-', '', $date);
            $sql = "SELECT * FROM {$staTb} WHERE date = '{$date}' AND type = 'todayUserGroupSta'";
            $ret = oo::commonOprDb('statistics')->getOne($sql, MYSQLI_ASSOC);
            $staData = json_decode($ret['data'],true);
            foreach ($config as $key=>$row) {
                $id = $row['id'];
                $like = "%#{$id}#%";
                $sql = "SELECT count(*) as count FROM {$tb} WHERE date='{$date}' AND groupId LIKE '{$like}'";
                $ret = oo::commonOprDb('statistics')->getOne($sql, MYSQLI_ASSOC);
                $list = empty($staData['list'][$id])?[]:$staData['list'][$id];

                $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $date);
                $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $row['groupId']);
                $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $row['name']);
                $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $ret['count']);
                $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $list['payNum']);
                $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $list['payRate']);
                $objPHPExcel->getActiveSheet()->setCellValue("G".$i, $list['ARPU']);
                $objPHPExcel->getActiveSheet()->setCellValue("H".$i, $list['ARPPU']);
                $objPHPExcel->getActiveSheet()->setCellValue("I".$i, $list['payTotal']);
                $i++;
            }
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '用户分组统计_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    //导出体力盈亏数据
    public function spinsAddLow($time1 = '',$time2 = '',$start_level = 0,$end_level = 0){

        $where = '';
        if($start_level && $end_level){
            $where .= " AND levelId >= {$start_level} AND levelId <= {$end_level}";
        }
        $uidList = oo::commonOprModel('statistics')->getAllPlayer(date("Ymd",strtotime($time2)), 2);//登陆玩家
        if(!empty($uidList)){
            $uidListStr = implode(",",$uidList);
            $where .= " AND uid in($uidListStr)";
        }
        $tb = otable::TodaySpinsLog(date("Ymd",strtotime($time1)));
        $sql = "SELECT * FROM {$tb} WHERE 1=1 {$where}";
        $ret = oo::commonOprDb('statistics')->getAll($sql,1);

        $uidArr = [];
        foreach($ret as $row){
            $uidArr[$row['uid']] = $row['num'];
        }

        $tb = otable::TodaySpinsLog(date("Ymd",strtotime($time2)));
        $sql = "SELECT * FROM {$tb} WHERE 1=1 {$where}";
        $ret2 = oo::commonOprDb('statistics')->getAll($sql,1);

        $out = [];
        foreach($ret2 as $row){
            $uid = $row['uid'];
            $moveNum = (empty($uidArr[$uid])?0:$uidArr[$uid]) - $row['num'];
            $out[$uid] = $moveNum;
        }

        $headerTable = ['UID','盈亏'];
        $bodyTable = $out;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $kb);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '体力盈亏数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    //导出卡片存量
    public function cardSta($uid = "",$type = "",$i = 0){
        $tb = otable::cardinfo_config();
        $sql = "SELECT ci_name_zh,ciid,ci_star_rank,ci_lockRank,grade FROM {$tb} WHERE 1";
        $temp = oo::commonOprDb('slavedb')->getAll($sql,1);
        foreach ($temp as $key=>$row){
            if($type == 'cardGold' && $row['grade'] != 2){
                continue;
            }
            $t = $row;
            unset($t['ciid']);
            $t['owner'] = 0;
            $t['num'] = 0;
            $t['ci_name_zh'] = str_replace(["\n","\\n","\r","
                    "],"",$t['ci_name_zh']);
            $card[$row['ciid']] = $t;
        }

        if(!empty($uid)){
            $uid = intval($uid);
            $tb = otable::usercard_config($uid);
            $sql = "SELECT * FROM {$tb} WHERE uid={$uid}";
            $temp = oo::commonOprDb('slavedb')->getOne($sql,1);
            $ciid = json_decode($temp['ciid'],true);
            foreach ($ciid as $c=>$r){
                if($type == 'cardGold' && $card[$c]['grade'] != 2){
                    continue;
                }
                $card[$c]['owner'] += 1;
                $card[$c]['num'] += $r;
            }
            $retData['data']['card'] = $card;
            $retData['uid'] = $uid;
            $retData['type'] = $type;

            $headerTable = ['卡片','存量'];
            $bodyTable = $card;
            $objPHPExcel = new PHPExcel();
            //处理表头
            $char = 'A';
            foreach ($headerTable as $k => $v) {
                $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
                $char = chr(ord($char) + 1);
            }
            //处理数据
            $i = 2;
            foreach ($bodyTable as $kb => $vb) {
                $vb['ci_name_zh'] = (str_replace(["\n","\\n","\r","
                    "],"",$vb['ci_name_zh']));
                $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['ci_name_zh']);
                $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['num']);
                $i++;
            }

            $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
            $outPutFileName = '卡片存量_'.$uid."_".date('Y-m-d');
            $this->base($objPHPExcel,$outPutFileName);
        }else{
            $tb = otable::cardgroup_config();
            $sql = "SELECT * FROM {$tb} WHERE 1";
            $temp = oo::commonOprDb('slavedb')->getAll($sql,1);
            foreach ($temp as $row){
                $group[$row['cgid']] = 0;
            }

            $ret = oo::commonOprModel('statistics')->getAllPlayer(date("Ymd"), 2);
            $where = '';
            if(!empty($ret)){
                $uidStr = implode(",",$ret);
                $where .= " AND uid in($uidStr)";
            }
            $tb = otable::usercard_config(1);
            $sql = "SELECT ciid FROM {$tb} WHERE ciid <> '{}' {$where}";
            $temp = oo::commonOprDb('slavedb')->getAll($sql,1);
            foreach ($temp as $row){
                $ciid = json_decode($row['ciid'],true);
                foreach ($ciid as $c=>$r){
                    if($type == 'cardGold' && $card[$c]['grade'] != 2){
                        continue;
                    }
                    $card[$c]['owner'] += 1;
                    $card[$c]['num'] += (int)$r;
                }
                $group[$row['card_group_total']] += 1;
            }

            $retData['data'] = ['group'=>$group,'card'=>$card,'type'=>$type];

            if($i){
                $headerTable = ['卡片','存量'];
                $bodyTable = $card;
                $objPHPExcel = new PHPExcel();
                //处理表头
                $char = 'A';
                foreach ($headerTable as $k => $v) {
                    $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
                    $char = chr(ord($char) + 1);
                }
                //处理数据
                $i = 2;
                foreach ($bodyTable as $kb => $vb) {
                    $vb['ci_name_zh'] = (str_replace(["\n","\\n","\r","
                    "],"",$vb['ci_name_zh']));
                    $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['ci_name_zh']);
                    $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['num']);
                    $i++;
                }

                $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                $outPutFileName = '卡片存量_'.date('Y-m-d');
                $this->base($objPHPExcel,$outPutFileName);
            }else{
                $headerTable = ['卡片','用户量'];
                $bodyTable = $card;
                $objPHPExcel = new PHPExcel();
                //处理表头
                $char = 'A';
                foreach ($headerTable as $k => $v) {
                    $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
                    $char = chr(ord($char) + 1);
                }
                //处理数据
                $i = 2;
                foreach ($bodyTable as $kb => $vb) {
                    $vb['ci_name_zh'] = (str_replace(["\n","\\n","\r","
                    "],"",$vb['ci_name_zh']));
                    $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['ci_name_zh']);
                    $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['owner']);
                    $i++;
                }

                $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                $outPutFileName = '卡片用户量_'.date('Y-m-d');
                $this->base($objPHPExcel,$outPutFileName);
            }
        }
    }

    //导出卡片发放数据
    public function cardGrantSta($type = "",$date = ''){
        if(empty($date)){
            $date = date('Y-m-d',  strtotime('-1 days'));
        }
        $tb = otable::cardinfo_config();
        $sql = "SELECT * FROM {$tb} WHERE 1";
        $card = oo::commonOprDb('slavedb')->getAll($sql,1);

        $date = date("Ymd",strtotime($date));
        $tb = otable::staData();
        $sql = "SELECT * FROM {$tb} WHERE type = 'cardGrantSta' AND date = '{$date}'";
        $ret = oo::commonOprDb("statistics")->getOne($sql,1);
        $ret['data'] = json_decode($ret['data'],1);
        if($type == "cardGold"){
            $data['data'] = $ret['data']['cardGold'];
        }else{
            $data['data'] = $ret['data']['card'];
        }
        $data['stime'] = $date;
        $data['card'] = $card;
        $data['type'] = $type;

        $headerTable = ['卡片','发放量'];
        $bodyTable = $card;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $vb['ci_name_zh'] = (str_replace(["\n","\\n","\r","
                    "],"",$vb['ci_name_zh']));
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['ci_name_zh']);
            $num = empty($data['data'][$vb['ciid']])?0:$data['data'][$vb['ciid']];
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $num);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '卡片发放量_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function chestWeight($from,$type,$id){
        if($from == 1){
            $tb = otable::StarExchange(2);
            $ret= oo::commonOprDb('slavedb')->getOne("SELECT * FROM {$tb} WHERE propsId={$id}",MYSQLI_ASSOC);
            $value = json_decode($ret[$type],true);
        }else{
            if($from == 2){
                $tb = otable::ChestSkinConfig(2);
                $ret= oo::commonOprDb('slavedb')->getOne("SELECT * FROM {$tb} WHERE id={$id}",MYSQLI_ASSOC);
            }else if($from == 3){
                $tb = otable::ChestConfig(2);
                $ret= oo::commonOprDb('slavedb')->getOne("SELECT * FROM {$tb} WHERE propsId={$id}",MYSQLI_ASSOC);
            }
            $reward = json_decode($ret['reward'],true);
            $reward = array_column($reward,null,"propsId");

            $value = $reward[$type]['pro'];
//            if($type == "spinsNum"){
//                $value = $reward[15]['pro'];
//            }else if($type == "petExp"){
//                $value = $reward[8]['pro'];
//            }
        }
        $title[] = "等級";
        $weight[] = "等級";
        $i = 1;
        foreach (array_column($value[0]["weight"],"v") as $v){
            $title[] = "权重{$i}";
            $weight[] = $v;
            $i++;
        }

        $objPHPExcel = new PHPExcel();
        $char = 'A';
        foreach ($title as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        $char = 'A';
        foreach ($weight as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'2', $v);
            $char = chr(ord($char) + 1);
        }
        $objPHPExcel->getActiveSheet()->mergeCells("A1:A2");
        //处理数据
        $i = 3;
        $char = 'A';
        foreach ($value as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $vb['lv']);
            foreach ($vb['weight'] as $v){
                $char = chr(ord($char) + 1);
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $v['num']);
            }
            $char = 'A';
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '权重配置_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function lang(){
        $tb    = otable::languageConfig(2);
        $list  = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb} ORDER BY lang",MYSQLI_ASSOC);
        $langs = array_keys(oo::cfg('lang')['lang_upper']);
        $langsKeyMapping = [];
        $totalKeys = [];
        foreach ($list as $item){
            $langsKeyMapping[$item['lang']] =  $langsKeyMapping[$item['lang']] ?? [];
            $langsKeyMapping[$item['lang']][$item['key']] =  $item['content'];
            $totalKeys[$item['key']] =  $item['key'];
        }
        $objPHPExcel = new PHPExcel();
        $objPHPExcel->getActiveSheet()->setCellValue('A1',"语言");
        $objPHPExcel->getActiveSheet()->setCellValue('B1',"语言键");
        $objPHPExcel->getActiveSheet()->setCellValue('C1',"语言值");
        //处理数据
        $i = 2;
        $char = 'A';
        foreach ($langs as $lang){
            foreach ($totalKeys as $key){
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $lang);
                $char = chr(ord($char) + 1);
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $key);
                $char = chr(ord($char) + 1);
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $langsKeyMapping[$lang][$key]??'');
                $char = 'A';
                $i++;
            }
        }
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '语言配置_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function info($id){
        include_once APPPATH . '/libraries/Ip2Region.class.php';
        $dbfile = APPPATH."/libraries/ipdb/ip2region.db";
        $obj = new Ip2Region($dbfile);
        $tb    = "crazyGod_log.t_userinfo";

        $objPHPExcel = new PHPExcel();
        $objPHPExcel->getActiveSheet()->setCellValue('A1',"Uid");
        $objPHPExcel->getActiveSheet()->setCellValue('B1',"FbId");
        $objPHPExcel->getActiveSheet()->setCellValue('C1',"Email");
        $objPHPExcel->getActiveSheet()->setCellValue('D1',"First Name");
        $objPHPExcel->getActiveSheet()->setCellValue('E1',"Last Name");
        $objPHPExcel->getActiveSheet()->setCellValue('F1',"Country");
        $objPHPExcel->getActiveSheet()->setCellValue('G1',"Zip");
        $objPHPExcel->getActiveSheet()->setCellValue('H1',"DeviceId");
        //处理数据
        $i = 2;
        for($j=0;$j<200;$j++){
            $page  = $j * 10000;
            $list  = oo::commonOprDb('slavedb')->getAll("SELECT uid,siteuid,email,nick,locale FROM {$tb} WHERE uid%10={$id} AND m_picture = '' AND status=1 AND lasttime<1617855411 order by uid desc limit {$page},10000",MYSQLI_ASSOC);
            if(empty($list)){
                break;
            }
            foreach ($list as $kb => $vb) {
                $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['uid']);
                $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['siteuid']);
                $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb['email']);
                $nick = explode(' ',$vb['nick']);
                $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $nick[0]);
                $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $nick[1] ?? "");
                $country = explode('|',$obj->memorySearch($vb['locale'])['region']);
                $countryName = "";
                if(!empty($country[0])){
                    $countryName = $country[0];
                }
                $address = [];
                foreach ($country as $row){
                    if(!empty($row)){
                        $address[] = $row;
                    }
                }
                $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $countryName);
                $objPHPExcel->getActiveSheet()->setCellValue("G".$i, $address);
                $tb2  = "crazyGod_log.t_adjust_sta_".$vb['uid']%100;
                $ret = oo::commonOprDb('slavedb')->getOne("SELECT * FROM {$tb2} WHERE uid='{$vb['uid']}' LIMIT 1",MYSQLI_ASSOC);
                $deviceId = "";
                if(!empty($ret)){
                    if(!empty($ret['android'])){
                        $deviceId = $ret['android'];
                      }
                    if(!empty($ret['ios'])){
                        $deviceId = $ret['android'];
                    }
                }
                $objPHPExcel->getActiveSheet()->setCellValue("H".$i, $deviceId);
                $i++;
            }
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '语言配置_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function shareTranslate(){
        $tb = otable::languageConfig();
        $ret= oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb} WHERE `type`='SHARE'",MYSQLI_ASSOC);
        $data = [];
        foreach ($ret as $row){
            $content = json_decode(base64_decode($row['content']),true);
            foreach ($content as $key=>$value){
                if($key == "DEFAULT2"){
                    continue;
                }
                $data[] = [
                    "lang"    => $row['lang'],
                    "key"     => $key,
                    "title"   => $value['title'],
                    "desc"    => $value['desc'],
                ];
            }
        }
        $headerTable = ['语言键','分享键','标题','内容'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($data as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['lang']);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['key']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb['title']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb['desc']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->setTitle(__FUNCTION__);
        $outPutFileName = '分享翻译_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function shareTranslate2(){
        $tb = otable::shareConfig();
        $ret= oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb}",MYSQLI_ASSOC);
        $data = [];
        $langKeys = array_keys(oo::cfg('lang')['lang_upper']);
        foreach ($ret as $row){
            $content = json_decode($row['content'],true);
            foreach ($langKeys as $langKey){
                $data[] = [
                    "lang"    => $row['key'],
                    "key"     => $langKey,
                    "title"   => $content[$langKey]['title'] ?? '',
                    "desc"    => $content[$langKey]['desc'] ?? '',
                ];
            }
        }
        $headerTable = ['分享键','语言键','标题','内容'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($data as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['lang']);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['key']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb['title']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb['desc']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->setTitle(__FUNCTION__);
        $outPutFileName = '分享翻译_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function getGiftData($pid = 161,$type = 16){
        $posts = $this->postData;
        $posts['mod'] = 'Shop';
        $posts['act'] = 'config';
        $posts['type'] = $type;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $temp = [];
        $name = [];
        foreach ($retData['data'] as $row){
            $name[$row['gpid']] = $row['gname'];
            if($pid != $row['gpid']){
                continue;
            }
            $row['gbaseReward']  = json_decode($row['gbaseReward'],true);
            $row['goriginReward']= json_decode($row['goriginReward'],true);
            if(!empty($row['ext'])){
                $row['ext'] =json_decode($row['ext'],1);
            }
            $temp[]      = $row;
        }
        $posts['mod'] = 'Config';
        $posts['act'] = 'getPropsConfig';
        $url = $this->config->item('officialUrl');
        $retData = json_decode($this->curl->req($url, $posts),true);
        $data['idData'] = $retData['props'];
        $data['list'] = $temp;
        $data['name'] = $name;
        $data['type'] = $type;
        //sku价格配置
        $data['skuPrice'] = oo::commonOprModel('Payment')->getSkuPrice();
        $posts['mod'] = 'config';
        $posts['act'] = 'getAllCountry';
        $retData = $this->curl->req($url, $posts);
        $data['country'] = json_decode($retData,true);
        $data['userGroup2'] = array_column(oo::commonOprModel('config')->getUserGroupConfigByCid(2),'name','id');
        $data['chestSkin']  = array_column(oo::commonOprModel('config')->chestSkin(),'name','id');
        $data['easterEggSkin']  = array_column(oo::commonOprModel('config')->getActivityActionList('easter_egg'),'name','id');
        $data['treasureSkin']  = array_column(oo::commonOprModel('config')->getActivityActionList('treasure'),'name','id');//宝藏活动
        $data['crazyCardGroup']  = array_column(oo::commonOprModel('config')->getActivityActionList('crazy_card_group'),'name','id');
        $data['gpid'] = $pid;
        return $data;
    }

    //导出规则礼包配置
    public function gift($pid = 161,$type = 16){
        $data = $this->getGiftData($pid,$type);
        $headerTable = ['商品GID','商品名称','商品SKU','商品简介','商品价格','商品折扣','商品有效期*(秒)','商品额外优惠','商品限购次数','展现国家','添加RFM分组','金币','倍率','体力数量','道具-1-ID','道具-1-数量','道具-1-皮肤','道具-2-ID','道具-2-数量','道具-2-皮肤','道具-3-ID','道具-3-数量','道具-3-皮肤','道具-4-ID','道具-4-数量','道具-4-皮肤'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        foreach ($headerTable as $k => $v) {
            $strTemp = strval($this->headerTableChar($k).'1');
            $objPHPExcel->getActiveSheet()->setCellValue($strTemp, $v);
        }
        //处理数据
        $i = 2;
        foreach ($data['list'] as $kb => $vb) {
            $j = 0;
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gid']);//商品GID
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gname']);//商品名称
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gsku']);//商品SKU
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gdesc']);//商品简介
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gprice']);//商品价格
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gdiscount']);//商品折扣
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gExpire']);//商品有效期*(秒)
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gaddRatio']);//商品额外优惠
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gMax']);//商品限购次数
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gShowCountry']);//展现国家
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gShowGroup']);//添加RFM分组
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gbaseReward']['coins']['coins']);//金币
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gbaseReward']['coins']['bet']);//倍率
            $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $vb['gbaseReward']['spins']);//体力数量
            $num = 0;
            foreach($vb['gbaseReward']['props'] as $k => $reward){
                if($k > 2){
                    continue;
                }
                $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $reward['propsId']);//道具ID
                $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $reward['num']);//道具数量
                $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, $reward['skin']);//皮肤
                $num++;
            }
            for(;$num<2;$num++){
                $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, '');
                $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, '');
                $objPHPExcel->getActiveSheet()->setCellValue($this->headerTableChar($j++).$i, '');
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->setTitle(__FUNCTION__);
        $outPutFileName = '规则礼包配置_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    //获取表头字母
    function headerTableChar($k){
        $char = 'A';
        $prefix  = '';
        for($i = 0;$i < $k; $i++){
            if($char == 'Z') {
                $char = 'AA';
                $prefix = 'A';
            }else {
                if(strlen($char) == 2){
                    $char = $prefix.chr(ord(substr($char,1,1)) + 1);
                }else{
                    $char = $prefix.chr(ord($char) + 1);
                }
            }
        }
        return $char;
    }

    public $tableTitles =["A","B","C","D","E","F","G","H","I","J","K","L","M","N"];
    //导出水果机金币配置
    public function lvFruitBaseCoinsOut(){
        $tb=otable::fruitBaseConfig();
        $sql = "SELECT * FROM {$tb} where type='baseCoins'";
        $config = oo::commonOprDb('games')->getOne($sql, 1);
        $data = json_decode($config['config'],true);

        $headerTable = ['用户等级','基础金币值'];
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($data as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['lv']);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['coins']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->setTitle(__FUNCTION__);
        $outPutFileName = '水果机用户等级金币配置_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }
    //导出水果机等级配置
    public function lvFruitGameCfgOut(){
        $headerTable = ['等级','经验值'];
        for($a=1;$a<13;$a++){
            array_push($headerTable,$a."号修正系数");
        }
        $tb2=otable::fruitLvConfig();
        $sql2= "SELECT * FROM {$tb2}";
        $configs2 = oo::commonOprDb('games')->getAll($sql2, 1);
        foreach ($configs2 as $k=>$cfg){
            $data[$k]['lv'] = $cfg['lv'];
            $data[$k]['maxExp'] = $cfg['maxExp'];
            $data[$k]["upCeCfg"] = json_decode($cfg["upCeCfg"],true);
//            $data[$k]["lvRewardCfg"] = json_decode($cfg["lvRewardCfg"],true);
        }
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($data as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $vb['lv']);
            $objPHPExcel->getActiveSheet()->setCellValue("B".$i, $vb['maxExp']);
            foreach ($vb['upCeCfg'] as $k=>$v){
                $objPHPExcel->getActiveSheet()->setCellValue($this->tableTitles[$k+2].$i, $v['ce']);
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->setTitle(__FUNCTION__);
        $outPutFileName = '水果机等级配置_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }


    public  function mainBg(){
        $header = [
            "levelId"  =>  '岛屿ID',
            "bg1"  =>  '背景1',
            "color1"  =>  '背景1云朵色号',
            "bg2"  =>  '背景2',
            "color2"  =>  '背景2云朵色号',
            "animation"  =>  '动画',
            "animation2"  =>  '动画2',
        ];
        $posts = $this->postData;
        $posts['mod'] = 'Config';
        $posts['act'] = 'getMainBgConfig';
        $url  = $this->config->item('officialUrl');
        $config = $this->curl->req($url, $posts);
        if(is_string($config))$config = json_decode($config, true);

        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($header as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char++;
        }
        //处理数据
        $i = 2;
        foreach ($config['config'] as $kb => $vb) {
            $char = 'A';
            foreach ($header as $k => $v) {
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $vb[$k]);
                $char++;
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->setTitle(__FUNCTION__);
        $outPutFileName = '主页背景配置'.date('YmdHis');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function petConfig($petId){
//        $tb  = otable::PetConfig();
//        $petInfo = oo::commonOprDb('slavedb')->getOne("SELECT * FROM {$tb} WHERE id={$petId} LIMIT 1",MYSQLI_ASSOC);
//        $petInfo['addExp']    = json_decode($petInfo['addExp'],true);
//        $petInfo['skillBase'] = json_decode($petInfo['skillBase'],true);
        $tb  = otable::PetExpConfig2();
        $ret = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb} WHERE petId={$petId}",MYSQLI_ASSOC);
        $file_name = '宠物配置-'.date('YmdHis') . '.csv';
        $headers = [
            'lv' => '等级',
            'star' => '星星',
            'exp' => '经验值',
            'skill' => '技能增益',
        ];
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename='.$file_name );
        header('Cache-Control: max-age=0');
        $f = fopen('php://output',"a");
        fputcsv($f, array_values($headers));
        foreach ($ret as $item){
            $line = [];
            foreach ($headers as $k => $v){
                $line[] = $item[$k];
            }
            fputcsv($f, $line);
        }
    }

    public function stealCoin(){
        $tbl = otable::commonConfig();
        $type = 'stealMaxMoney';
        $title = '偷金币配置';
        $config = oo::commonOprDb('slavedb')->getOne("select * from {$tbl} where type='{$type}'",1);
        $config = json_decode($config['conf'], true);

        $file_name = '偷金币配置-'.date('YmdHis') . '.csv';
        $headers = [
            'levelId' => '等级',
            'maxCoin' => '最大金币',
        ];
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename='.$file_name );
        header('Cache-Control: max-age=0');
        $f = fopen('php://output',"a");
        fputcsv($f, array_values($headers));
        foreach ($config as $item){
            $line = [];
            foreach ($headers as $k => $v){
                $line[] = $item[$k];
            }
            fputcsv($f, $line);
        }
        fclose($f);
    }

    public function pushConfig(){
        $tb = otable::fasebasePushConf();
        oo::commonOprDb('slavedb')->query("set names utf8mb4");
        $sql = "SELECT * FROM {$tb}";
        $arr = oo::commonOprDb('slavedb')->getAll($sql,1);
        foreach ((array)$arr as  $k => $v){
            $arr[$k]['conf'] = json_decode($v['conf'],true);
        }
        $columns = [
            'title' => '标题',
            'content' => '内容',
        ];
        $headers = [
            'id',
            '推送点名称',
        ];


        $objPHPExcel = new PHPExcel();
        foreach ($this->_langList as $langKey => $langText){
            foreach ($columns as $column =>$str){
                $headers[] = $langKey . '-' . $column;
            }
        }
        $char = 'A';
        foreach ($headers as $header){
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $header);
            $char++;
        }
        $i = 2;
        $strlenArr = [];
        foreach ($arr as $item){
            $line = [$item['id'], $item['name']];
            foreach ($this->_langList as $langKey => $langText){
                foreach ($columns as $column => $str){
                    $line[] = $item['conf'][$langKey][$column] ?? '';
                }
            }
            $char = 'A';
            foreach ($line as $cellValue){
                $strlenArr[$char] = max(strlen($cellValue), $strlenArr[$char]);
                $objPHPExcel->getActiveSheet()->getColumnDimension($char)->setWidth($strlenArr[$char]);
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $cellValue);
                $char++;
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '推送点多语言配置'.date('YmdHi');
        $this->base($objPHPExcel,$outPutFileName);
    }

    /**
     * Notes:体力瓶权重导出
     * User: wsc
     * Time: 2022/3/30 15:48
     */
    public function spinsPotWeightOut(){
        $tb=otable::spinsPotWeight();
        $sql = "SELECT * FROM {$tb}";
        $list = oo::commonOprDb('slavedb')->getAll($sql,1);
        $retData =[];
        foreach ($list as $item){
            $retData[] = json_decode($item['config'],true);
        }
        $headerTable = ['用户等级','一个瓶权重','一个瓶分值','两个瓶权重','两个瓶分值'];
        $bodyTable = $retData;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            if($char == 'Z') {
                $char = 'AA';
            }else {
                $char = chr(ord($char) + 1);
            }
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $vb['levelId']);
            $objPHPExcel->getActiveSheet()->setCellValue('B'.$i, $vb['weightOne']);
            $objPHPExcel->getActiveSheet()->setCellValue("C".$i, $vb['scoreOne']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $vb['weightTwo']);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $vb['scoreTwo']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->setTitle(__FUNCTION__);
        $outPutFileName = '体力瓶权重_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    /**
     * Notes:体力瓶礼包导出
     * User: wsc
     * Time: 2022/4/8 21:11
     */
    public function spinsPotGiftOut(){
        $tb = otable::spinsPotGift();
        $sql = "Select * from {$tb} GROUP BY startlv,endlv";
        $retData = oo::commonOprDb('slavedb')->getAll($sql,1);

        $headerTable = ["开始等级","结束等级","起始值","首次体力值","首次价格","复购体力值","复购价格","长时间未购体力值","长时间未购价格"];
        $bodyTable = $retData;
        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            if($char == 'Z') {
                $char = 'AA';
            }else {
                $char = chr(ord($char) + 1);
            }
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $a = json_decode($vb['firstcfg'],true);
            $b = json_decode($vb['againcfg'],true);
            $c = json_decode($vb['longtimecfg'],true);
            $objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $vb['startlv']);
            $objPHPExcel->getActiveSheet()->setCellValue('B'.$i, $vb['endlv']);
            $objPHPExcel->getActiveSheet()->setCellValue('C'.$i, $vb['initval']);
            $objPHPExcel->getActiveSheet()->setCellValue("D".$i, $a['maxNum']);
            $objPHPExcel->getActiveSheet()->setCellValue("E".$i, $a['price']);
            $objPHPExcel->getActiveSheet()->setCellValue("F".$i, $b['maxNum']);
            $objPHPExcel->getActiveSheet()->setCellValue("G".$i, $b['price']);
            $objPHPExcel->getActiveSheet()->setCellValue("H".$i, $c['maxNum']);
            $objPHPExcel->getActiveSheet()->setCellValue("I".$i, $c['price']);
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->setTitle(__FUNCTION__);
        $outPutFileName = '体力瓶礼包配置_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);


    }

    public function chestSkinBasic(){
        $tb  = otable::ChestSkinConfig(2);
        $chestConfig = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb} ORDER BY id",MYSQLI_ASSOC);

        $headers = [
            'id' => '宝箱ID',
            'skinResourceId' => '宝箱皮肤资源ID',
            'name' => '宝箱名称',
            'card' => '卡片数量',
            'joker' => '小丑卡兑换数量',
            'feeds' => '宠物粮食',
        ];
        $objPHPExcel = new PHPExcel();
        $lineNum = 1;
        $column = 'A';
        foreach ($headers as $header){
            $objPHPExcel->getActiveSheet()->setCellValue($column.$lineNum, $header);
            $column++;
        }
        $lineNum++;
        foreach ($chestConfig as $item){
            $rewards = @json_decode($item['reward'], true) ?? [];
            $rewards = array_column($rewards, null, 'propsId');
            $line = [
                'id' => $item['id'],
                'skinResourceId' => $item['skinResourceId'],
                'name' => $item['name'],
                'card' => $rewards['17']['num'],
                'joker' => $rewards['18']['num'],
                'feeds' => $rewards['9']['num'],
            ];

            $column = 'A';
            foreach ($headers as $k => $header){
                $objPHPExcel->getActiveSheet()->setCellValue($column.$lineNum, $line[$k]);
                $column++;
            }
            $lineNum++;
        }
        $objPHPExcel->getActiveSheet()->setTitle(__FUNCTION__);
        $outPutFileName = '皮肤宝箱基础配置'.date('Ymd');
        $this->base($objPHPExcel,$outPutFileName);
    }
    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);
        $weights = $configs = [];
        foreach ($chestConfig as $item){
            $rewards = @json_decode($item['reward'], true) ?? [];
            $rewards = array_column($rewards, null, 'propsId');
            if(empty($rewards[$type]['pro']))continue;
            $weights[$item['id']] = [];
            $configs[$item['id']] = [];
            foreach ($rewards[$type]['pro'] as $k => $lvItems){
                $configs[$item['id']][$lvItems['lv']] = [];
                foreach ($lvItems['weight'] as $weightItem){
                    if($k == 0) $weights[$item['id']][] = $weightItem['v'];
                    $configs[$item['id']][$lvItems['lv']][] = $weightItem['num'];
                }
            }
        }
        $objPHPExcel = new PHPExcel();
        $lineNum = 1;
        $column = 'A';
        $objPHPExcel->getActiveSheet()->setTitle('权重配置');
        $objPHPExcel->getActiveSheet()->setCellValue($column.$lineNum, '宝箱ID');
        $i = 1;
        while($i < 17){
            $column++;
            $objPHPExcel->getActiveSheet()->setCellValue($column.$lineNum, '权重'.$i);
            $i++;
        }
        foreach ($weights as $id => $weight){
            $lineNum++;
            $column = 'A';
            $objPHPExcel->getActiveSheet()->setCellValue($column.$lineNum, $id);
            foreach ($weight as $value){
                $column++;
                $objPHPExcel->getActiveSheet()->setCellValue($column.$lineNum, $value);
            }
        }

        switch ($type){
            case 8:$headerText = '宠物经验';break;
            case 15:$headerText = '体力';break;
            case 14:$headerText = '金币';break;
            default:$this->response(-1 * __LINE__ , '非法操作', $type);
        }
        $secondSheet = $objPHPExcel->createSheet();
        $secondSheet->setTitle($headerText.'配置');
        $lineNum = 1;
        $column = 'A';
        $secondSheet->setCellValue($column.$lineNum, '宝箱ID');
        $secondSheet->setCellValue(++$column.$lineNum, '等级');
        $i = 1;
        while($i < 17){
            $secondSheet->setCellValue(++$column.$lineNum, $headerText.$i++);
        }
        foreach ($configs as $id => $lvItems){
            foreach ($lvItems as $lv => $values){
                $lineNum++;
                $column = 'A';
                $secondSheet->setCellValue($column++.$lineNum, $id);
                $secondSheet->setCellValue($column++.$lineNum, $lv);
                foreach ($values as $value){
                    $secondSheet->setCellValue($column++.$lineNum, $value);
                }
            }
        }
        $outPutFileName = '皮肤宝箱'.$headerText.'配置'.date('Ymd');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function chestSkinProbs(){
        $tb  = otable::ChestSkinConfig(2);
        $chestConfig = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb} ORDER BY id",MYSQLI_ASSOC);

        $cardTypes = [
            0 => '常规卡'  ,
            1 => '限时卡'  ,
            2 => '全部'    ,
        ];
        $headers = [
            'id' => '宝箱ID',
            'star1' => '一星级概率',
            'star2' => '二星级概率',
            'star3' => '三星级概率',
            'star4' => '四星级概率',
            'star5' => '五星级概率',
            'goldNum' => '金卡数量(-1,不设限制)',
            'blackGoldNum' => '黑金卡数量(-1,不设限制)',
            'blackGoldKValue' => '黑卡保底值',
            'cardType' => '开卡类型(常规卡，限时卡，全部)',
        ];
        $exportData = [];
        foreach ($chestConfig as $item){
            $starPro = json_decode($item['starPro'], true);
            $tempData = [
                'id' => $item['id'],
                'goldNum' => intval($starPro['maxGoldCard']),
                'blackGoldNum' => intval($starPro['maxBlackGoldCard']),
                'blackGoldKValue' => intval($starPro['blackGoldCardKValue']),
                'cardType' => $cardTypes[$starPro['cardType']] ?? '-',
            ];
            foreach ($starPro['pro'] as $tmp){
                $tempData['star'.$tmp['star']] = $tmp['v'];
            }
            $exportData[] = $tempData;
        }

        $objPHPExcel = new PHPExcel();
        $lineNum = 1;
        $column = 'A';
        foreach ($headers as $header){
            $objPHPExcel->getActiveSheet()->setCellValue($column++.$lineNum, $header);
        }
        foreach ($exportData as $exportDatum){
            $lineNum++;
            $column = 'A';
            foreach ($headers as $k => $header){
                $objPHPExcel->getActiveSheet()->setCellValue($column++.$lineNum, $exportDatum[$k]);
            }
        }
        $objPHPExcel->getActiveSheet()->setTitle(__FUNCTION__);
        $outPutFileName = '皮肤宝箱概率配置'.date('Ymd');
        $this->base($objPHPExcel,$outPutFileName);
    }

    /**
     * Notes:导出真老虎机权重配置
     * User: wsc
     * Time: 2022/6/8 19:15
     * @param $gid
     * @throws PHPExcel_Exception
     */
    public function realSlotGroupWeights($gid){
        $tb = otable::realSlotWeightGroupsCfg();
        $sql = "SELECT * from {$tb} where gid={$gid}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $arr = [];
        foreach ($rs as $k=>$v){
           $arr[$v["type"]][$v['levelId']] = json_decode($v['slotpro'],true);
        }

        $headerTable = ['关卡', '攻击', '偷袭', '体力', '护盾', '金币','金币袋','收集物品','惊喜事件牌','万能福'];

        $objPHPExcel = new PHPExcel();
        $limit = count($arr);
        for($s=1;$s<=$limit;$s++){
            $bodyTable = $arr[$s];
            if($s!=3){
                $objPHPExcel->createSheet($s);
            }
            //处理表头
            $char = 'A';
            foreach ($headerTable as $k => $v) {
                $objPHPExcel->getSheet($s-1)->setCellValue($char.'1', $v);
                $char = chr(ord($char) + 1);
            }
            //处理数据
            $i = 2;
            foreach ($bodyTable as $kb => $vb) {
                $objPHPExcel->getSheet($s-1)->setCellValue("A".$i, $kb);
                $char = "B";
                for($j=0;$j<count($headerTable);$j++){
                    $objPHPExcel->getSheet($s-1)->setCellValue($char.$i, $vb[$j]['v']);
                    $char = chr(ord($char) + 1);
                }
                $i++;
            }
        }


        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '真*老虎机概率数据_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }

    /**
     * Notes:导出真老虎机金币
     * User: wsc
     * Time: 2022/6/9 14:50
     * @throws PHPExcel_Exception
     */
    public function RealSlotCoin(){
        $tb = otable::realSlotCoinCfg();
        $sql = "SELECT * from {$tb}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
        $arr = [];
        foreach ($rs as $k=>$v){
            $arr[$v['level']][$v["stype"]] = intval($v["coins"]);
        }

        $headerTable = ['关卡', '一个金币', '两个金币', '三个金币', '一个金币袋', '两个金币袋','三个金币袋'];

        $objPHPExcel = new PHPExcel();

        $bodyTable =$arr;

        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char.'1', $v);
            $char = chr(ord($char) + 1);
        }
        //处理数据
        $i = 2;
        foreach ($bodyTable as $kb => $vb) {
            $objPHPExcel->getActiveSheet()->setCellValue("A".$i, $kb);
            $char = "B";
            for($j=1;$j<7;$j++){
                $objPHPExcel->getActiveSheet()->setCellValue($char.$i, $vb[$j]);
                $char = chr(ord($char) + 1);
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '真*老虎机金币_'.date('Y-m-d');
        $this->base($objPHPExcel,$outPutFileName);
    }


    // 导出偷保底配置
    public function stealLuckConf()
    {
        $headerTable = ['stealTimes' => '偷次数', 'min' => '下限值', 'max' => '上限值'];
        $bodyTable = oo::commonOprModel('config')->getCommonConf(okeys::StealLuckCfg());
        unset($bodyTable['9999']);

        $objPHPExcel = new PHPExcel();
        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char . '1', $v);
            $char = chr(ord($char) + 1);
        }

        //处理数据
        $i = 2;
        foreach ($bodyTable as $stealTimes => $vb) {
            list($min, $max) = $vb;

            $char = 'A';
            foreach ($headerTable as $hk => $hv) {
                $objPHPExcel->getActiveSheet()->setCellValue($char . $i, ${$hk} ?? '');
                $char++;
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        $outPutFileName = '老虎机保底-偷保底-Export-' . date('Y-m-d') . uniqid('_');
        $this->base($objPHPExcel, $outPutFileName);
    }

    // 导出体力瓶保底配置
    public function spinsLuckConf()
    {
        $spinsLuckConf = oo::commonOprModel('config')->getCommonConf(okeys::SpinBottleConf());
        $randConf = $spinsLuckConf['rand'];
        $mulSpendConf = $spinsLuckConf['mulSpend'];

        // 工作表1
        $objPHPExcel = new PHPExcel();
        $curActivitySheet = $objPHPExcel->setActiveSheetIndex(0);

        $curActivitySheet->setCellValue('A1', "随机浮点数");
        $curActivitySheet->setCellValue('B1', $randConf['min']);
        $curActivitySheet->setCellValue('C1', $randConf['max']);

        // 工作表2
        $objPHPExcel->createSheet(1);
        $curActivitySheet = $objPHPExcel->setActiveSheetIndex(1);

        //处理表头
        $char = 'A';
        $headerTable = ['mul' => '倍率', 'spend' => '消耗值'];
        foreach ($headerTable as $k => $v) {
            $curActivitySheet->setCellValue($char . '1', $v);
            $char = chr(ord($char) + 1);
        }

        //处理数据
        $i = 2;
        foreach ($mulSpendConf as $vb) {
            $char = 'A';
            foreach ($headerTable as $hk => $hv) {
                $curActivitySheet->setCellValue($char . $i, $vb[$hk] ?? '');
                $char++;
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        $outPutFileName = '老虎机保底-体力瓶保底-Export-' . date('Y-m-d') . uniqid('_');
        $this->base($objPHPExcel,$outPutFileName);
    }

    public function assistantSlotsRewardBasic()
    {
        $headerTable = ['lv' => '等级', 'coins' => '金币', 'spins' => '骰子'];
        $tb = otable::assistantSlotRewardBasicCfg();
        $bodyTable = oo::commonOprDb('slavedb')->getAll("select * from {$tb}");

        $objPHPExcel = new PHPExcel();
        $curActivitySheet = $objPHPExcel->setActiveSheetIndex();

        //处理表头
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $curActivitySheet->setCellValue($char . '1', $v);
            $char = chr(ord($char) + 1);
        }

        //处理数据
        $i = 2;
        foreach ($bodyTable as $vb) {
            $char = 'A';
            foreach ($headerTable as $hk => $hv) {
                $curActivitySheet->setCellValue($char . $i, $vb[$hk] ?? '');
                $char++;
            }
            $i++;
        }


        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        $outPutFileName = '副老虎机金币骰子基准配置数据_' . date('Y-m-d') . uniqid('_');
        $this->base($objPHPExcel, $outPutFileName);
    }

    public function assistantSlotWeights()
    {
        // 等级	金币	骰子	能量	WILD	JACKPOT	收集物
        $headerTable = ['lv' => '等级', 'coins' => '金币', 'spins' => '骰子', 'energy' => '能量', 'wild' => 'WILD', 'jackpot' => 'JACKPOT', 'collection' => '收集物'];
        $tb = otable::assistantSlotWeightCfg();
        $allDataInfo = oo::commonOprDb('slavedb')->getAll("select * from {$tb}");

        $tableInfo = [];
        foreach ($allDataInfo as $row) {
            $type = $row['type'];
            $slotpro = json_decode($row['slotpro'],true);
            if (!isset($tableInfo[$type])) {
                $tableInfo[$type] = [];
            }
            $oneRowInfo = ['lv' => $row['lv'],];

            foreach ($slotpro as $onepro) {
                $value = $onepro['v'];
                switch ($onepro['id']) {
                    case 1:
                        $oneRowInfo['coins'] = $value;
                        break;
                    case 2:
                        $oneRowInfo['spins'] = $value;
                        break;
                    case 3:
                        $oneRowInfo['energy'] = $value;
                        break;
                    case 4:
                        $oneRowInfo['wild'] = $value;
                        break;
                    case 5:
                        $oneRowInfo['jackpot'] = $value;
                        break;
                    case 6:
                        $oneRowInfo['collection'] = $value;
                        break;
                }
            }

            $tableInfo[$type][] =$oneRowInfo;
        }


        $objPHPExcel = new PHPExcel();

        foreach ($tableInfo as $type=>$bodyTable){
            $objPHPExcel->createSheet($type);
            $curActivitySheet = $objPHPExcel->setActiveSheetIndex($type);

            //处理表头
            $char = 'A';
            foreach ($headerTable as $k => $v) {
                $curActivitySheet->setCellValue($char . '1', $v);
                $char = chr(ord($char) + 1);
            }

            //处理数据
            $i = 2;
            foreach ($bodyTable as $vb) {
                $char = 'A';
                foreach ($headerTable as $hk => $hv) {
                    $curActivitySheet->setCellValue($char . $i, $vb[$hk] ?? '');
                    $char++;
                }
                $i++;
            }
        }

        $objPHPExcel->removeSheetByIndex();

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        $outPutFileName = '副老虎机概率数据_' . date('Y-m-d') . uniqid('_');
        $this->base($objPHPExcel, $outPutFileName);
    }

    public function trackers($country = 'DEFAULT'){
        $tb  = otable::shareConfig();
        $list = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb}",MYSQLI_ASSOC);
        $active = $langData = $track = [];
        $trackers = [];
        foreach($list as $key => $row){
            $curTrack = json_decode($row['track'],true) ?? [];
            $trackers[$row['key']] = $curTrack[$country] ?? $curTrack[ltrim($country,'L')] ;
            $trackers[$row['key']]['key'] = $row['key'];
            $trackers[$row['key']]['name'] = $row['name'];
        }

        $objPHPExcel = new PHPExcel();
        $curActivitySheet = $objPHPExcel->setActiveSheetIndex(0);

        $headers = [
            'key' => "分享点标识",
            'name'  => '分享点名称',
            'd'  => '跟踪链默认',
            'a'  => '跟踪链A',
            'b'  => '跟踪链B',
        ];
        $lineIdx = 1;
        $columnIdx = 'A';
        foreach ($headers as $header){
            $curActivitySheet->setCellValue($columnIdx++.$lineIdx, $header);
        }

        foreach ($trackers as $tracker){
            $columnIdx = 'A';
            $lineIdx++;
            foreach ($headers as $headerKey => $h){
                $curActivitySheet->setCellValue($columnIdx++.$lineIdx, $tracker[$headerKey]);
            }
        }
        $outPutFileName = "分享点跟踪标识-{$country}-" . date('Y-m-d') . uniqid('_');
        $this->base($objPHPExcel, $outPutFileName);
    }

    /**
     * Notes:导出幸运骰子结果权重配置
     */
    public function luckyDiceGroupWeights($gid)
    {
        $tb = otable::luckyDicePointGroupsConf();
        $sql = "SELECT * from {$tb} where gid={$gid}";
        $rs = oo::commonOprDb('slavedb')->getAll($sql, 1);

        $arr = [];
        foreach ($rs as $k => $v) {
            $arr[$v["type"]][$v['taskId']] = json_decode($v['pro'], true);
        }

        $headerTable = ['任务阶段', '1点', '2点', '3点', '4点', '5点', '6点', '万能符'];

        $objPHPExcel = new PHPExcel();
        $limit = count($arr);
        for ($s = 1; $s <= $limit; $s++) {
            $bodyTable = $arr[$s];
            if ($s != 3) {
                $objPHPExcel->createSheet($s);
            }
            //处理表头
            $char = 'A';
            foreach ($headerTable as $k => $v) {
                $objPHPExcel->getSheet($s - 1)->setCellValue($char . '1', $v);
                $char = chr(ord($char) + 1);
            }
            //处理数据
            $i = 2;
            foreach ($bodyTable as $kb => $vb) {
                $objPHPExcel->getSheet($s - 1)->setCellValue("A" . $i, $kb);
                $char = "B";
                for ($j = 0; $j < count($headerTable); $j++) {
                    $objPHPExcel->getSheet($s - 1)->setCellValue($char . $i, $vb[$j]['pro']);
                    $char = chr(ord($char) + 1);
                }
                $i++;
            }
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '幸运骰子结果权重配置数据_' . date('Y-m-d');
        $this->base($objPHPExcel, $outPutFileName);
    }

    public function luckyDiceWinGroupWeights($gid)
    {
        $headerTable = ['任务阶段', '转盘1', '转盘2', '转盘3', '转盘4', '转盘5', '转盘6'];

        $objPHPExcel = new PHPExcel();

        //处理表头
        $objPHPExcel->getActiveSheet()->setCellValue('A1', $headerTable[0]);
        $char = 'A';
        foreach ($headerTable as $k => $v) {
            $objPHPExcel->getActiveSheet()->setCellValue($char . '1', $v);
            if ($k > 0) {
                $objPHPExcel->getActiveSheet()->mergeCells($char . '1:' . ++$char . '1');
            }
            $char++;
        }

        $tb = otable::luckyDiceWheelGroupsConf();
        $bodyTable = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb} where gid=" . $gid);

        foreach ($bodyTable as $key => &$row) {
            $row['pro'] = json_decode($row['pro'], true);
        }

        //处理数据
        $i = 2;
        $proItems = ['pro', 'bet'];
        foreach ($bodyTable as $vb) {
            $char = 'A';
            $objPHPExcel->getActiveSheet()->setCellValue("$char{$i}", $vb["taskId"]);
            foreach ($vb["pro"] as $row2) {
                foreach ($proItems as $item) {
                    $char++;
                    $objPHPExcel->getActiveSheet()->setCellValue("{$char}{$i}", $row2[$item]);
                }
            }
            $i++;
        }

        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $outPutFileName = '幸运骰子转盘权重倍率配置_' . date('Y-m-d');
        $this->base($objPHPExcel, $outPutFileName);
    }

    public function coinPushPro(){
        $config = ActivityModel::getCoinPushPro();
        $headers = [
            'bet' => '倍率',
            'spins' => '体力消耗',
            'pro' => '概率（ 0-100）',
        ];
        $this->exportData($headers, $config, '推金币收集物概率配置');
    }
}
