<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Created by liqx.
 * User: Administrator
 * Date: 2018/1/31
 * Time: 11:35
 */
class Activity extends MY_Controller
{
    private $superCollectPreviewUsers = [];
    private $symbol_type = ['进度','数量','奖励类型(1金币,2体力,3卡片)','奖励数量(卡片ID)'];
    public $postData = array('frombg' => 1, 'mod' => '', 'act' => '', 'lid' => 1, 'sid' => 1);
    private $_rewardList = ['money'=>'筹码', 'props'=>'道具', 'diamond'=>'钻石', 'exp'=>'经验', 'speaker' => '喇叭'];
    private $_matchlevelList = [1=>'初级', 2=>'中级', 3=>'高级'];
    private $_goodsTypeList = [1 => '筹码', 2 =>  '钻石',  3 => '道具', 4 => 'VIP' ];
    private $_payTypeList = [999 => '官方渠道', 2=> 'SMS', 4 => 'Bluecoins', 5 => 'Truemoney', 6 => '12call', 7 => 'dtac', 0 => '全部'];
    public  $_langList = ['en'=>'英文','zh'=>'中文','tw'=>'中文（台湾）','fr'=>'法语','de'=>'德语','es'=>'西班牙','pt'=>'葡萄牙','th'=>'泰语'];
    public $country =['TH'=>"泰国",'DE'=>"德国",'BR'=>"巴西",'FR'=>"法国",'US'=>"美国",'IN'=>"印度",'RO'=>"罗马尼亚",'GB'=>"英国",'IT'=>"意大利",'ES'=>"西班牙",'BE'=>"比利时",'VN'=>"越南",'NO'=>"挪威"];
    public $_langBtn =['en'=>'Join Now!','zh'=>'立即参加!','tw'=>'立即參加!','fr'=>'Adhésion immédiate','de'=>'Jetzt beitreten!','es'=>'¡Únete ahora!','pt'=>'Entrar!','th'=>'เข้าร่วมเดี๋ยวนี้!'];
    private $_gotoList = [
        0=>'打开首充弹框',
        1=>'打开FB好友邀请',
        2=>'同playnow逻辑',
        3=>'跳转应用商店',
        4=>'打开大转盘',
        5=>'跳转到指定的场次',
        6=>'跳转到指定的选场界面',
        7=>'跳转到奥马哈选场',
        8=>'跳转到德州百人场',
        9=>'跳转到私人房创建',
        10=>'打开单桌赛界面',
        11=>'打开锦标赛界面',
        12=>'打开商城',
        13=>'打开兑换码界面',
        14=>'跳转到世界杯',
        15=>'跳转到粉丝页'
    ];
    protected $pageConfig = array(
        'first_tag_open' => '<li>',
        'first_tag_close' => '</li>',
        'last_tag_open' => '<li>',
        'last_tag_close' => '</li>',
        'next_tag_open' => '<li>',
        'next_tag_close' => '</li>',
        'prev_tag_open' => '<li>',
        'prev_tag_close' => '</li>',
        'cur_tag_open' => "<li class='active'><a hef='#'>",
        'cur_tag_close' => "</a></li>",
        'num_tag_open' => "<li>",
        'num_tag_close' => "</li>",
    );
    private $_limit = 6;
    //'1.6.3.0','1.6.3.1','1.6.3.2','1.6.3.4','1.6.4.0','1.6.5.0','1.6.6.0','1.6.7.0','1.6.7.2','1.6.8.0','1.6.8.1','1.6.9.0','1.6.9.1',
    public $versions = ['1.7.5.0','1.7.6.0','1.7.7.0','1.7.8.0','1.7.9.0','1.8.0.0','1.8.5.0','1.8.6.0','1.9'];

    public $goodSku  = [];

    public function __construct()
    {
        parent::__construct();
        $config = array(
            'savePath' => 'Excel/uploads',             //存储文件夹
            'maxSize'  => 1024*50,                   //允许的文件最大尺寸，单位KB
            'allowFiles' => array('.xls','.xlsx','.json', '.png','.jpg')  //允许的文件格式
        );
        $this->load->library('uploader', $config);
        $this->load->library('PHPExcel');
        $this->load->library('PHPExcel/PHPExcel/IOFactory');

        $this->load->helper('url');
        $this->load->helper('cookie');
        $this->load->library('curl');
        $this->load->library('pagination');
        //请求地址
        $this->env = get_cookie($this->_wenenv);
        $this->_url = $this->config->item('officialUrl');

        $this->versions = oo::commonOprModel('config')->versions;
        $this->goodSku = oo::cfg('sku');

    }

    /**
     * 活动列表
     */
    public function index($page = 0)
    {
        if( $this->env == 1 ){
            $baseUrl = $this->config->item('officialBaseUrl');
        }else{
            $baseUrl = $this->config->item('localBaseUrl');
        }
        //获取数据
        $postData = $this->postData;
        $postData['mod'] = 'Activitycfg';
        $postData['act'] = 'getActivity';
        $this->env == 2 && $postData['demo'] = 1;
        $res = $this->curl->req($this->_url, $postData);
        $list['list'] = json_decode($res, TRUE);
        $maxid = 1;
        foreach ($list['list'] as $row){
            if($row['id'] > $maxid){
                $maxid = $row['id'];
            }
        }
        $list['max_id'] = $maxid;
        $list['baseUrl'] = $baseUrl;
        $list['total'] = count($list['list']);
        //截取数组
        $list['list'] = array_slice($list, $page, $this->_limit, true);
        //分页
        $pageConfig = $this->pageConfig;
        $pageConfig['base_url'] = base_url('#activity/index');
        $pageConfig['total_rows'] = $list['total'];
        $pageConfig['per_page'] = $this->_limit;
        $this->pagination->initialize($pageConfig);
        $pageurl = $this->pagination->create_links();
        $list['pageurl'] = $pageurl;

        $this->load->view('activity/index', $list);

    }

    /**
     * 加载新增活动页面
     */
    public function add()
    {
        if( $this->env == 1 ){
            $url = $this->config->item('officialBaseUrl').'/api/activityimgupload.php';
            $baseUrl = $this->config->item('officialBaseUrl');
        }else{
            $url = $this->config->item('localBaseUrl').'/api/activityimgupload.php';
            $baseUrl = $this->config->item('localBaseUrl');
        }

        //获取数据
        $postData = $this->postData;
        $postData['mod'] = 'Activitycfg';
        $postData['act'] = 'getGameLevel';
        $this->env == 2 && $postData['demo'] = 1;
        $res = $this->curl->req($this->_url, $postData);
        $list = json_decode($res, TRUE);
        $data['id'] = $this->input->get('id');
        $data['url'] = $url;
        $data['baseUrl'] = $baseUrl;
        $data['langList'] = $this->_langList;
        $data['rewardList'] = $this->_rewardList;
        $data['gotoList'] = $this->_gotoList;
        $data['matchlevelList'] = $this->_matchlevelList;
        $data['goodsTypeList'] = $this->_goodsTypeList;
        $data['payTypeList'] = $this->_payTypeList;
        $data['androidPackageList'] = $this->androidPackageList + $this->oldAnPackageList;
        $data['iosPackageList'] = $this->iosPackageList + $this->oldIosPackageList;
        $data['blindList'] = $list;
        $this->load->view('activity/add', $data);
    }

    /**
     * 进行新增操作
     */
    public function addAction()
    {
        $id = $this->input->post('id');
        $titleList = $this->input->post('title');
        $stime = $this->input->post('stime');
        $etime = $this->input->post('etime');
        $online = $this->input->post('online');
        $sort = $this->input->post('sort');
        $packageList = $this->input->post('package');
        $uplangImg = $this->input->post('uplang');
        $stimeHour = $this->input->post('stimeHour');//玩牌每天的时间段
        $etimeHour = $this->input->post('etimeHour');
        $actType = $this->input->post('actType');
        $bname = $this->input->post('bname');
        $bcolor = $this->input->post('bcolor');
        $openlv = $this->input->post('openlv');
        $pro = $this->input->post('pro');
        $img = $this->input->post('img');
        if(array_sum($pro) != 0){
            die($this->response(1, '概率调整总值不为0'));
        }
        if(empty($uplangImg)) {
            die($this->response(1, '活动图片不能为空'));
        }

        if(empty($stime) || empty($etime)) {
            die($this->response(1, '活动时间不能为空'));
        }
        foreach ($uplangImg as $key=>$row){
            if(!empty($row)){
                $uplangImg[$key] = 'https://god.superant.vip/images/activity/'.$key."/".$row;
            }
        }
        $stime = $stime." ".$stimeHour;
        $etime = $etime." ".$etimeHour;
        $stime = strtotime($stime);
        $etime = strtotime($etime);
        if($stime > $etime) {
            die($this->response(1, '活动开始时间不能大于结束时间'));
        }

        $postData = $this->postData;
        $postData['name'] = $titleList['zh'];
        $postData['name_en'] = $titleList['en'];
        $postData['is_online'] = $online;
        $postData['image'] = json_encode($uplangImg);
        $postData['start_time'] = $stime;
        $postData['end_time'] = $etime;
        $postData['sort'] = $sort;
        $postData['actType'] = $actType;
        $postData['bname'] = $bname['zh'];
        $postData['bname_en'] = $bname['en'];
        $postData['bcolor'] = $bcolor;
        $postData['openlv'] = intval($openlv);
        $postData['package'] = implode(',',$packageList);
        $postData['pro'] = json_encode($pro);
        $this->env == 2 && $postData['demo'] = 1;
        $postData['mod'] = 'Activitycfg';
        $postData['act'] = 'saveActivity';
        $postData['action'] = 'add';
        $postData['id'] = $id;
        $res = $this->curl->req($this->_url, $postData);

        oo::logs()->adminlog($this->router->fetch_method());

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

    /**
     * 加载编辑活动页面
     */
    public function edit($id){
        if( $this->env == 1 ){
            $url = $this->config->item('officialBaseUrl').'/api/activityimgupload.php';
            $baseUrl = $this->config->item('officialBaseUrl');
        }else{
            $url = $this->config->item('localBaseUrl').'/api/activityimgupload.php';
            $baseUrl = $this->config->item('localBaseUrl');
        }

        if(empty($id) || $id <1) {
            $data['info'] = [];
            $this->load->view('activity/edit', $data);exit;
        }
        //获取数据
        $postData = $this->postData;
        $postData['id'] = $id;
        $postData['mod'] = 'Activitycfg';
        $postData['act'] = 'getActivity';
        $this->env == 2 && $postData['demo'] = 1;
        $res = $this->curl->req($this->_url, $postData);
        $list = json_decode($res, TRUE);
        $img = json_decode($list['image'],true);
        $imgName = json_decode($list['imgName'],true);
        $data['id'] = $id;
        $data['url'] = $url;
        $data['baseUrl'] = $baseUrl;
        $data['langList'] = $this->_langList;
        $data['info'] = $list;
        $data['info']['title_name_zh'] = $list['name'];
        $data['info']['title_name_en'] = $list['name_en'];
        $data['info']['bname_zh'] = $list['bname'];
        $data['info']['bname_en'] = $list['bname_en'];
        $data['info']['img']['zh'] = $img['zh'];
        $data['info']['img']['en'] = $img['en'];
        $data['packageList'] = explode(',',$list['package']);
        $data['androidPackageList'] = $this->androidPackageList+$this->oldAnPackageList;
        $data['iosPackageList'] = $this->iosPackageList + $this->oldIosPackageList;
        $data['pro'] = json_decode($list['pro'],true);
        $data['img'] = $list['img'];
        $data['imgName'] = $imgName;
        $data['action_time'] = $list['action_time'];
        $data['lock_time']   = $list['lock_time'];
        $data['reward_time'] = $list['reward_time'];
        $data['textColor']   = json_decode($list['textColor'],true);
        $this->load->view('activity/edit', $data);
    }

    /**
     * 进行修改操作
     */
    public function editAction()
    {
        $id          = $this->input->post('id');
        $titleList   = $this->input->post('title');
        $stime       = $this->input->post('stime');
        $etime       = $this->input->post('etime');
        $online      = $this->input->post('online');
        $sort        = $this->input->post('sort');
        $packageList = $this->input->post('package');
        $uplangImg   = $this->input->post('uplang');
        $stimeHour   = $this->input->post('stimeHour');
        $etimeHour   = $this->input->post('etimeHour');
        $actType     = $this->input->post('actType');
        $bname       = $this->input->post('bname');
        $bcolor      = $this->input->post('bcolor');
        $openlv      = $this->input->post('openlv');
        $pro         = $this->input->post('pro');
        $img         = $this->input->post('img');
        $imgName     = $this->input->post('imgName');
        $action_time = $this->input->post('action_time');
        $lock_time   = $this->input->post('lock_time');
        $textColor   = $this->input->post('textColor');

        if(array_sum($pro) != 0){
            die($this->response(1, '概率调整总值不为0'));
        }

        if(empty($uplangImg)) {
            die($this->response(1, '活动图片不能为空'));
        }

        if(empty($stime) || empty($etime)) {
            die($this->response(1, '活动时间不能为空'));
        }
        foreach ($uplangImg as $key=>$row){
            if(!empty($row)){
                $uplangImg[$key] = 'https://god.superant.vip/images/activity/'.$key."/".$row;
            }
        }

        $stime = $stime." ".$stimeHour;
        $etime = $etime." ".$etimeHour;
        $stime = strtotime($stime);
        $etime = strtotime($etime);
        if($stime > $etime) {
            die($this->response(1, '活动开始时间不能大于结束时间'));
        }
        $reward_time = 0;
        if(in_array($id,[13])){
            $rtime       = $this->input->post('rtime');
            $rtimeHour   = $this->input->post('rtimeHour');
            $rtime       = $rtime." ".$rtimeHour;
            $reward_time = strtotime($rtime);
            if($etime < $reward_time || $reward_time < $stime) {
                die($this->response(1, '活动领取奖励时间错误'));
            }
        }
        $postData                = $this->postData;
        $postData['name']        = $titleList['zh'];
        $postData['name_en']     = $titleList['en'];
        $postData['is_online']   = $online;
        $postData['image']       = json_encode($uplangImg);
        $postData['start_time']  = $stime;
        $postData['end_time']    = $etime;
        $postData['sort']        = $sort;
        $postData['actType']     = $actType;
        $postData['bname']       = $bname['zh'];
        $postData['bname_en']    = $bname['en'];
        $postData['bcolor']      = $bcolor;
        $postData['img']         = $img;
        $postData['imgName']     = $imgName;
        $postData['pro']         = json_encode($pro);
        $postData['openlv']      = intval($openlv);
        $postData['package']     = implode(',',$packageList);
        $this->env == 2 && $postData['demo'] = 1;
        $postData['mod']         = 'Activitycfg';
        $postData['act']         = 'saveActivity';
        $postData['action']      = 'edit';
        $postData['id']          = $id;
        $postData['action_time'] = $action_time;
        $postData['lock_time']   = $lock_time;
        $postData['reward_time'] = $reward_time;
        $postData['textColor']   = implode(',',$textColor);
        $res = $this->curl->req($this->_url, $postData);

        oo::logs()->adminlog($this->router->fetch_method());

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

    /**
     * 设置登录时是否弹出活动弹窗
     */
    public function showActivity()
    {
        $showActivity = $this->input->post('showActivity');
        $postData = $this->postData;
        $this->env == 2 && $postData['demo'] = 1;
        $postData['showActivity'] = $showActivity;
        $postData['mod'] = 'Activitycfg';
        $postData['act'] = 'showActivity';
        $res = $this->curl->req($this->_url, $postData);
        die($res);
    }

    public function blevel($type = 1){
        $postData = $this->postData;
        $postData['mod'] = 'Activitycfg';
        $postData['act'] = 'getLevel';
        $postData['type'] = $type;
        $res = $this->curl->req($this->_url, $postData);
        $data['baseTitle'] = '活动关卡等级配置修改';
        $data['title'] = ['ID','等级','关卡','含义'];
        $data['list']  = json_decode($res,true);
        $data['type']  = $type;
        $this->load->view('activity/paylevel', $data);
    }

    public function paylevel($type = 2){
        $postData = $this->postData;
        $postData['mod'] = 'Activitycfg';
        $postData['act'] = 'getLevel';
        $postData['type'] = $type;
        $res = $this->curl->req($this->_url, $postData);
        $data['baseTitle'] = '活动支付等级配置修改';
        $data['title'] = ['ID','等级','付费','含义'];
        $data['list']  = json_decode($res,true);
        $data['type']  = $type;
        $this->load->view('activity/paylevel', $data);
    }

    public function actionLevel(){
        $type = $this->input->post('type');
        $data = $this->input->post('data');
        $posts = $this->postData;
        $posts['mod'] = 'Activitycfg';
        $posts['act'] = 'saveLevel';
        $posts['type'] = $type;
        $posts['data'] = $data;
        $retData = $this->curl->req($this->_url, $posts);

        oo::logs()->adminlog($this->router->fetch_method());

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

    public function refreshActivity(){
        $id = $this->input->post('id');
        $posts = $this->postData;
        $posts['mod'] = 'Activitycfg';
        $posts['act'] = 'refreshActivity';
        $posts['id'] = $id;
        $retData = $this->curl->req($this->_url, $posts);
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }

    public function clearBuyNum(){
        $id = $this->input->post('id');
        $posts = $this->postData;
        $posts['mod'] = 'Activitycfg';
        $posts['act'] = 'clearBuyNum';
        $posts['id'] = $id;
        $retData = $this->curl->req($this->_url, $posts);

        oo::logs()->adminlog($this->router->fetch_method());

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

    public function sta($id = 2,$time = '',$page = 10,$roomId = 1){
        if($time == 'null'){
            $time = '';
        }

        if($page == 10){
            $page = 10;
        }else{
            $page += 10;
        }

        if($id == 2){
            $name = '金蛋';
        }else if($id == 3){
            $name = '气球';
        }else if($id == 6){
            $name = '偷打';
        }else if($id == "13"){
            $name = '排行榜';
        }else if($id == '13-rank'){
            $name = '排行榜 - 排名';
        }

        $template = 'activity/sta';
        if($id == '13-rank'){
            $template = 'activity/sta_rank';
        }

        $posts = $this->postData;
        $posts['mod'] = 'Activitycfg';
        $posts['act'] = 'activitySta';
        if($id == '13-rank'){
            $posts['id']  = 13;
        }else{
            $posts['id']  = $id;
        }
        $posts['page']= $page/10;
        $posts['page_size'] = 10;
        if(!empty($time)){
            $posts['time'] = str_replace('%20',' ',$time);
        }
        $retData = $this->curl->req($this->config->item('officialUrl'), $posts);

        $list = json_decode($retData,1);
        $interval = [];
        foreach ($list['interval'] as $v){
            $interval[$v] = 0;
        }

        $ret = [];

        if($id == "13"){
            $ret = $list['data']['number'];
            for ($i=0;$i<=20;$i++){
                $progress[] = $i;
            }
            $progressData = [];
            foreach($list['data']['progress'] as $row){
                foreach ($progress as $v){
                    if($row<=$v){
                        $progressData[$v] += 1;
                        break;
                    }
                }
            }
            $list['progress'] = $progress;
            $list['progressData'] = $progressData;

        }else if($id == "13-rank"){
            if($uid = get_cookie("uid")){
                foreach($list['data']['rank'] as $room => $users){
                    foreach($users as $u_id => $num){
                        if($uid == $u_id){
                            $roomId = $room;
                            break;
                        }
                    }
                }
            }
            $roomData = array_keys($list['data']['rank']);
            krsort($roomData);
            $list['roomData'] = $roomData;
            $list['rankData'] = $list['data']['rank'][$roomId];
            asort($list['rankData']);
            $list['roomId'] = $roomId;
        }else{
            $ret = $list['data'];
        }
        foreach ($ret as $row){
            foreach ($list['interval'] as $v){
                if($row<=$v){
                    $interval[$v] += 1;
                    break;
                }
            }
        }

        $pageConfig = $this->pageConfig;
        $pageConfig['base_url'] = base_url('#activity/sta/'.$id.'/'.$time);
        $pageConfig['total_rows'] = $list['total'];
        $pageConfig['per_page'] = 10;
        $this->pagination->initialize($pageConfig);
        $pageurl = $this->pagination->create_links();
        $list['pageurl'] = $pageurl;
        $list['data'] = $interval;
        $list['page'] = $page;
        $list['id'] = $id;
        $list['uid'] = $uid;
        $list['time'] = str_replace('%20',' ',$time);
        $list['name'] = $name;
        $this->load->view($template, $list);
    }

    public function config($id,$version = ''){
        if($id==2){
            if(empty($type)){
                $type = 0;
            }
            $title = ($type == 0) ?'金蛋':'感恩节';
            $posts = $this->postData;
            $posts['mod'] = 'Config';
            $posts['act'] = 'getSymbolConfig';
            $posts['type'] = $type;
            $url = $this->config->item('officialUrl');
            $retData = $this->curl->req($url, $posts);
            $retData = json_decode($retData,1);
            if(!empty($list)){
                $list = [];
            }else{
                $list = $retData['data'];
            }
            $data['title']= $title;
            $data['menu'] = $this->symbol_type;
            $data['list'] = $list;
            $data['type'] = $type;
            $this->load->view('config/symbolConfig', $data);
            return;
        }
        $posts = $this->postData;
        $posts['mod'] = 'Activitycfg';
        $posts['act'] = 'config';
        $posts['id'] = $id;
        if($id == 6){
            $retData = $this->curl->req($this->_url, $posts);
            $reward = json_decode($retData,true);
            $data['reward'] = $reward['reward'];
        }

        if($id == 7){
            $retData = $this->curl->req($this->_url, $posts);
            $reward = json_decode($retData,true);
            $reward['title'] = json_decode($reward['title'],true);
            $reward['titleCard'] = json_decode($reward['titleCard'],true);
            foreach ($reward['reward'] as $key=>$row){
                $reward['reward'][$key]['chest'] = json_decode($row['chest'],true);
            }
            $data['reward'] = $reward;

            $posts = $this->postData;
            $posts['mod'] = 'Shop';
            $posts['act'] = 'config';
            $posts['type'] = 9;
            $retData = $this->curl->req($this->_url, $posts);
            $good = json_decode($retData,true);
            $good = $good['data'];
            foreach ($good as $key=>$row){
                $temp = json_decode($row['gbaseReward'],true);
                $reward = [];
                foreach ($temp as $k=>$v){
                    if($v['type'] == 1){
                        $reward['money'] = $v['num'];
                    }else if($v['type'] == 2){
                        $reward['spins'] = $v['num'];
                    }else if($v['type'] == 3){
                        $reward['chest'] = [
                            'num'=>$v['num'],
                            'id'=>$v['id'],
                        ];
                    } else if($v['type'] == 4){
                        $reward['festival'] = $v['num'];
                    }
                }
                $good[$key]['gbaseReward'] = $reward;
            }
            $data['lang'] = ['en'=>'英文','zh'=>'中文','tw'=>'中文（台湾）','fr'=>'法语','de'=>'德语','es'=>'西班牙','pt'=>'葡萄牙','th'=>'泰语'];
            $data['good'] = $good;
        }
        if($id == 8){
            $retData = $this->curl->req($this->_url, $posts);
            $reward = json_decode($retData,true);
            foreach ($reward['reward'] as $key=>$row){
                $reward['reward'][$key]['chest'] = json_decode($row['chest'],true);
            }
            $data['reward'] = $reward['reward'];
        }
        if($id == 9){
//            $posts = $this->postData;
//            $posts['mod'] = 'Config';
//            $posts['act'] = 'getCrazyBetConfig';
//            $url  = $this->config->item('officialUrl');
//            $crazyBetConfig = $this->curl->req($url, $posts);
//            $crazyBetConfig1 = json_decode($crazyBetConfig,true);

            $tb = otable::CrazyBetConfig();
            $sql = "SELECT * FROM {$tb} WHERE 1";
            $ret = oo::commonOprDb('slavedb')->getAll($sql,MYSQLI_ASSOC);
            $crazyBetConfig = [
                'config'        => $ret,
                'actSpinsLimit' => oo::commonOprModel('config')->getSysCon('activtity14',"actSpinsLimit"),
                'actLevelLimit' => oo::commonOprModel('config')->getCon('basic',"actLevelLimit"),
            ];
            $data = [];
            foreach ($crazyBetConfig['config'] as $item) {
                if($item['actData'] == 1){
                    $data[] = $item;
                }
            }
            $data = [
                'crazyBetConfig' => $data,
                'actSpinsLimit'  => $crazyBetConfig['actSpinsLimit'],
            ];
        }
        if($id == 13){
            $config = $this->curl->req($this->_url, $posts);
            $data = json_decode($config,true);
            foreach ($data['rankConfig'] as  $key=>$row){
                $data['rankConfig'][$key]['props'] = json_decode($row['props'],true);
            }
            foreach ($data['rankProgressConfig'] as  $key=>$row){
                $data['rankProgressConfig'][$key]['props'] = json_decode($row['props'],true);
            }

            $posts = $this->postData;
            $posts['mod'] = 'Config';
            $posts['act'] = 'getPropsConfig';
            $url  = $this->config->item('officialUrl');
            $config = $this->curl->req($url, $posts);

            $data['propsConfig'] = json_decode($config,true);
            $temp = [
                'type'=>3,
                'id'=>0,
                'msg'=>'卡片',
                'max'=>5,
            ];

            array_unshift($data['propsConfig']['props'],$temp);
        }
        if($id == 14){
            $config = $this->curl->req($this->_url, $posts);
            $data = json_decode($config,true);
        }
        if($id == 16){
            $tb  = otable::TreasureConfig($version);
            $ret = oo::commonOprDb('slavedb')->getAll("SELECT * FROM {$tb}",MYSQLI_ASSOC);
            $posts = $this->postData;
            $posts['mod'] = 'Config';
            $posts['act'] = 'getPropsConfig';
            $url = $this->config->item('officialUrl');
            $retData = json_decode($this->curl->req($url, $posts),true);
            foreach ($ret as $key=>$row){
                $ret[$key]['props'] = json_decode($row['props'],true) ?? [];
                $ret[$key]['bet'] = json_decode($row['bet'],true);
            }
            $data['list'] = $ret;
            $data['idData'] = $retData['props'];
            $data['version'] = $version;
        }

        $data['id'] = $id;
        $this->load->view("activity/config{$id}", $data);
    }

    public function actionConfig(){
        $input = $this->input->post();

        oo::logs()->adminlog("活动ID".$input['id']." ".$this->router->fetch_method());
        if($input['id'] == 6){
            $reward = $input['reward'];
            sort($reward);
            $filename = "StealAttackConfig".time().".json";
            $posts = $this->postData;
            $posts['mod'] = 'Activitycfg';
            $posts['act'] = 'saveConfig';
            $posts['id']  = 6;
            $posts['data'] = json_encode($reward,JSON_UNESCAPED_UNICODE);
            $posts['filename'] = $filename;
            $url = $this->config->item('officialUrl');
            $retData = $this->curl->req($url, $posts);
            $retData = json_decode($retData,true);
            if($retData == 0){
                return $this->response(1, '操作失败');
            }else{
                self::SaveJson($reward,$filename);
                return $this->response(0, '操作成功');
            }
        }
        else if($input['id'] == 7){
            if($input['type'] == 'config'){
                $title = [];
                foreach ($input['title'] as $key=>$row){
                    $title[strtoupper($key)] = $row;
                }

                $titleCard = [];
                foreach ($input['titleCard'] as $key=>$row){
                    $titleCard[strtoupper($key)] = $row;
                }
                $reward = $input['reward'];
                sort($reward);
                $data = [
                    'title' =>$title,
                    'titleCard'=>$titleCard,
                    'reward'=>$reward,
                ];
                $filename = "HolidayCollectConfig".time().".json";
                $posts = $this->postData;
                $posts['mod'] = 'Activitycfg';
                $posts['act'] = 'saveConfig';
                $posts['id']  = 7;
                $posts['data'] = json_encode($data,JSON_UNESCAPED_UNICODE);
                $posts['filename'] = $filename;
                $url = $this->config->item('officialUrl');
                $retData = $this->curl->req($url, $posts);

                $rewardJson = [];
                foreach ($reward as $row){
                    $chest = $row['chest'];
                    $chest['type'] = 3;
                    $rewardJson[] = [
                        'stage'=>$row['stage'],
                        'max'  =>$row['max'],
                        'reward' =>[
                            ['type'=>2,'num'=>$row['spins']],
                            ['type'=>1,'num'=>$row['money']],
                            $chest,
                        ],
                    ];
                }
                $json = [
                    'reward' => $rewardJson,
                    'cardTitle' => $titleCard,
                    'title' => $title,
                ];
                self::SaveJson($json,$filename);
                if($retData == 0){
                    return $this->response(1, '操作失败');
                }else{
                    return $this->response(0, '操作成功');
                }
            }else if($input['type'] == 'good'){
                $data = $input['good'];
                sort($data);
                foreach ($data as $key=>$row){
                    $temp = $row['gbaseReward'];
                    $reward = [];
                    foreach ($temp as $k=>$v){
                        if($k == 'money'){
                            $reward[] = [
                                'type'=>1,
                                'num'=>$v,
                            ];
                        }else if($k == 'spins'){
                            $reward[] = [
                                'type'=>2,
                                'num'=>$v,
                            ];
                        }else if($k == 'chest'){
                            $reward[] = [
                                'type'=>3,
                                'num' =>$v['num'],
                                'id'  =>$v['id'],
                            ];
                        }else if($k == 'festival'){
                            $reward[] = [
                                'type'=>4,
                                'num'=>$v,
                            ];
                        }
                    }
                    $data[$key]['gbaseReward'] = json_encode($reward);
                }
                $posts = $this->postData;
                $posts['mod'] = 'Shop';
                $posts['act'] = 'saveConfig';
                $posts['type'] = 9;
                $posts['data'] = json_encode($data);
                $url = $this->config->item('officialUrl');
                $retData = $this->curl->req($url, $posts);
                if($retData == 0){
                    return $this->response(1, '操作失败');
                }else{
                    return $this->response(0, '操作成功');
                }
            }
        }
        if($input['id'] == 8){
            $reward = $input['reward'];
            foreach ($reward as $key=>$row){
                $reward[$key]['chest'] = json_encode($row['chest']);
            }
            sort($reward);
            $filename = "BuildMaster".time().".json";
            $posts = $this->postData;
            $posts['mod'] = 'Activitycfg';
            $posts['act'] = 'saveConfig';
            $posts['id']  = 8;
            $posts['data'] = json_encode($reward,JSON_UNESCAPED_UNICODE);
            $posts['filename'] = $filename;
            $url = $this->config->item('officialUrl');
            $retData = $this->curl->req($url, $posts);
            $retData = json_decode($retData,true);
            if($retData == 0){
                return $this->response(1, '操作失败');
            }else{
                self::SaveJson($retData['json'],$retData['filename']);
                return $this->response(0, '操作成功');
            }
        }
        if($input['id'] == 9){
            $input = $this->input->post();
            $posts = $this->postData;
            $posts['mod'] = 'Config';
            $posts['act'] = 'setCrazyBetConfig';
            $posts['data']= json_encode($input['config']);
            $posts['filename']= "CrazyBetConfig".time().".json";
            $url  = $this->config->item('officialUrl');
            $retData = $this->curl->req($url, $posts);
            if($retData == 0){
                return $this->response(1, '操作失败');
            }else{
                $posts['act'] = 'getCrazyBetConfig';
                $crazyBetConfig = $this->curl->req($url, $posts);
                $crazyBetConfig = json_decode($crazyBetConfig,true);
                $data = [];
                foreach ($crazyBetConfig['config'] as $item) {
                    $temp = [
                        "bet"    =>$item['bet'],
                        "levelId"=>$item['levelId'],
                        "spins"  =>$item['spins'],
                        "spinsLimit"  =>$item['spinsLimit'],
                    ];
                    if($item['actData'] == 0){
                        $data['normalConfig'][] = $temp;
                    }else if($item['actData'] == 1){
                        $data['superBetConfig'][] = $temp;
                    }
                }
                $data['actSpinsLimit'] = $crazyBetConfig['actSpinsLimit'];
                self::SaveJson($data,$posts['filename']);
                return $this->response(0, '操作成功');
            }
        }
        if($input['id'] == 13){
            $posts = $this->postData;
            $posts['mod'] = 'Activitycfg';
            $posts['act'] = 'saveConfig';
            $posts['id']  = 13;
            $time = time();
            if($input['type'] == 'rank'){
                $posts['filename'] = "ActivityRankConfig{$time}.json";
                $posts['type'] = "rank";
                $jsonData = $input['rank'];
                foreach ($input['rank'] as $key=>$row){
                    $input['rank'][$key]['props'] = json_encode($row['props'],JSON_NUMERIC_CHECK);
                }
                $data = json_encode($input['rank'],JSON_NUMERIC_CHECK);
            }else if($input['type'] == 'progress'){
                $posts['filename'] = "ActivityRankProgressConfig{$time}.json";
                $posts['type'] = "progress";
                $jsonData = $input['progress'];
                foreach ($input['progress'] as $key=>$row){
                    if(isset($row['props'])){
                        $temp = [];
                        foreach($row['props']['propsId'] as $propsKey => $propsId){
                            if($propsId == 0){
                                $propsId = -1;
                            }
                            $temp[$propsKey]['propsId'] = $propsId;
                            $temp[$propsKey]['num'] = $row['props']['num'][$propsKey];
                        }

                        $input['progress'][$key]['props'] = json_encode($temp,JSON_NUMERIC_CHECK);

                    }
                }
                foreach ($jsonData as $key=>$row){
                    $temp = [];
                    if(isset($row['props'])){
                        foreach($row['props']['propsId'] as $propsKey => $propsId){
                            if($propsId == 0){
                                $propsId = -1;
                            }
                            $temp[$propsKey]['propsId'] = $propsId;
                            $temp[$propsKey]['num'] = $row['props']['num'][$propsKey];
                        }

                        $jsonData[$key]['props'] = $temp;
                    }else{
                        $temp['propsId'] = 0;
                        $temp['num'] = 0;
                        $jsonData[$key]['props'] = $temp;
                    }
                }

                $data = json_encode($input['progress'],JSON_NUMERIC_CHECK);
            }
            $posts['data'] = $data;
            $url = $this->config->item('officialUrl');
            $retData = $this->curl->req($url, $posts);
            sort($jsonData);
            self::SaveJson($jsonData,$posts['filename']);
            if($retData == 0){
                return $this->response(1, '操作失败');
            }else{
                return $this->response(0, '操作成功');
            }
        }
        if($input['id'] == 14){
            $posts = $this->postData;
            $posts['mod'] = 'Activitycfg';
            $posts['act'] = 'saveConfig';
            $posts['id']  = 14;
            $data = $input['config'];
            $posts['data'] = json_encode($data);
            $url = $this->config->item('officialUrl');
            $retData = $this->curl->req($url, $posts);
            if($retData == 0){
                return $this->response(1, '操作失败');
            }else{
                return $this->response(0, '操作成功');
            }
        }
        if($input['id'] == 16){
            $input = $this->input->post();
            $version = $this->input->post('version');
            foreach ($input['config'] as $key=>$row){
                $temp = [];
                $propsId  = $row['props']['propsId'];
                $propsNum = $row['props']['num'];
                $propsType = $row['props']['type'];
                foreach ($propsId as $k=>$p){
                    if($p == 13){
                        $temp[] = [
                            'propsId' => $p,
                            'num'     => $propsNum[$k],
                            'type'    => $propsType[$k],
                        ];
                    }else{
                        $temp[] = [
                            'propsId' => $p,
                            'num'     => $propsNum[$k],
                        ];
                    }
                }
                $input['config'][$key]['props'] = json_encode($temp,JSON_NUMERIC_CHECK);
                $input['config'][$key]['bet']   = json_encode($row['bet'],JSON_NUMERIC_CHECK);
            }
            $tb  = otable::TreasureConfig($version);
            foreach ($input['config'] as $row){
                oo::commonOprDb('games')->query("UPDATE {$tb} SET taskType='{$row['taskType']}',target='{$row['target']}',special='{$row['special']}',coins='{$row['coins']}',spins='{$row['spins']}',props='{$row['props']}',bet='{$row['bet']}' WHERE id={$row['id']}");
            }
            oo::commonOprRedis('games')->delete(okeys::TreasureConfig($version));
            $retData = 1;
        }
        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            return $this->response(0, '操作成功');
        }
    }
    public function delCrazyBetCfg($type){
        $input = $this->input->post();
        if($type == 9){
            // 删除记录
            $id = intval($input['id']);
            if(empty($id))$this->response(__LINE__, '非法操作');
            $tb = otable::CrazyBetConfig();
            $sql = "delete  FROM {$tb} WHERE id=" . $id;
            $res = oo::commonOprDb('games')->query($sql);
            if(!$res)$this->response(__LINE__, '删除失败');
            #查询新纪录，生成新的json配置
            $sql = "SELECT * FROM {$tb} WHERE 1";
            $ret = oo::commonOprDb('slavedb')->getAll($sql,MYSQLI_ASSOC);
            $crazyBetConfig = [
                'config'        => $ret,
                'actSpinsLimit' => oo::commonOprModel('config')->getSysCon('activtity14',"actSpinsLimit"),
                'actLevelLimit' => oo::commonOprModel('config')->getCon('basic',"actLevelLimit"),
            ];
            $filename = "CrazyBetConfig".time().".json";
            $data = [];
            foreach ($crazyBetConfig['config'] as $item) {
                $temp = [
                    "bet"    =>$item['bet'],
                    "levelId"=>$item['levelId'],
                    "spins"  =>$item['spins'],
                    "spinsLimit"  =>$item['spinsLimit'],
                ];
                if($item['actData'] == 0){
                    $data['normalConfig'][] = $temp;
                }else if($item['actData'] == 1){
                    $data['superBetConfig'][] = $temp;
                }
            }
            $data['actSpinsLimit'] = $crazyBetConfig['actSpinsLimit'];
            self::SaveJson($data,$filename);

            $tb = otable::StaticConfig();
            $sql = "UPDATE {$tb} SET path='{$filename}' WHERE config='CrazyBetConfig'";
            oo::commonOprDb('games')->query($sql);
            oo::commonOprRedis('games')->hSet(okeys::StaticConfig(),'CrazyBetConfig',$filename);

            return $this->response(0, '操作成功');
        }
        if(empty($id))$this->response(__LINE__, '非法操作');
    }

    public function setRankModel(){
        $input = $this->input->post();
        $posts = $this->postData;
        $posts['mod'] = 'Activitycfg';
        $posts['act'] = 'setRankModel';
        $posts['model'] = $input['model'];
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);

        oo::logs()->adminlog($this->router->fetch_method());

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

    public function setActSpinsLimit(){
        $input = $this->input->post();
        $posts = $this->postData;
        $posts['mod'] = 'Activitycfg';
        $posts['act'] = 'setActSpinsLimit';
        $posts['actSpinsLimit'] = $input['actSpinsLimit'];
        $posts['filename'] = "CrazyBetConfig".time().".json";
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);

        oo::logs()->adminlog($this->router->fetch_method());

        if($retData == 0){
            return $this->response(1, '操作失败');
        }else{
            $posts['mod'] = 'Config';
            $posts['act'] = 'getCrazyBetConfig';
            $crazyBetConfig = $this->curl->req($url, $posts);
            $crazyBetConfig = json_decode($crazyBetConfig,true);
            $data = [];
            foreach ($crazyBetConfig['config'] as $item) {
                $temp = [
                    "bet"    =>$item['bet'],
                    "levelId"=>$item['levelId'],
                    "spins"  =>$item['spins'],
                ];
                if($item['actData'] == 0){
                    $data['normalConfig'][] = $temp;
                }else if($item['actData'] == 1){
                    $data['superBetConfig'][] = $temp;
                }
            }
            $data['actSpinsLimit'] = $crazyBetConfig['actSpinsLimit'];
            self::SaveJson($data,$posts['filename']);
            return $this->response(0, '操作成功');
        }
    }

    public function getCollection(){
        $postData = $this->postData;
        $postData['mod'] = 'Activitycfg';
        $postData['act'] = 'getCollection';
        $res = $this->curl->req($this->_url, $postData);
        $collection = json_decode($res,true);
        $data['collection'] = $collection;
        return $data;
    }

    public function getVersion(){
        $postData = $this->postData;
        $postData['mod'] = 'Gameupdate';
        $postData['act'] = 'getList';
        $res = $this->curl->req($this->_url, $postData);
        $collection = json_decode($res,true);
        $data = [];
        foreach ($collection as $row){
            $data[$row['gu_device']][]= $row;
        }
        return ['versionList'=>$data];
    }


    /**
     * 活动排期
     * @return json
     * Created by: Owen
     * Created on: 2020/4/20 20:36
     */
    public function actionSchedule(){
        $input = $this->input->post();
        $schedule = [
            'activityId' =>$input['activityId'],
            'collection' =>addslashes(json_encode($input['collection'])),
            'startTime'  =>strtotime($input['startDay']." ".$input['startHour']),
            'rewardTime' =>strtotime($input['rewardDay']." ".$input['rewardHour']),
            'endTime'    =>strtotime($input['endDay']." ".$input['endHour']),
            'isCycle'    =>$input['isCycle'],
            'openNum'    =>$input['openNum'],
            'closeNum'   =>$input['closeNum'],
            'isVisitor'  =>$input['isVisitor']??0,
            'isLv'       =>$input['isLv']??0,
            'minLv'      =>$input['minLv'],
            'maxLv'      =>$input['maxLv'],
            'isVip'      =>$input['isVip']??0,
            'isVipLv'    =>$input['isVipLv']??0,
            'minVipLv'   =>$input['minVipLv'],
            'maxVipLv'   =>$input['maxVipLv'],
            'isVersion'  =>$input['isVersion']??0,
            'minAndroidVersion'=>$input['minAndroidVersion'],
            'minIosVersion'    =>$input['minIosVersion']
        ];
        $postData= $this->postData;
        $postData['data'] = json_encode($schedule);
        $postData['mod'] = 'Activitycfg';
        $postData['act'] = 'saveSchedule';
        $res = $this->curl->req($this->_url, $postData);

        oo::logs()->adminlog($this->router->fetch_method());

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

    public function actionCollection(){
        $data = $this->input->post('data');
        $data = json_decode($data,true);
        $dbData = [];
        foreach ($data['activityId'] as $key=>$row){
            $dbData[] = [
                'activityId'   => $row,
                'collectionId' => $data['collectionId'][$key],
                'name' => $data['name'][$key],
                'path' => $data['path'][$key],
            ];
        }
        $postData= $this->postData;
        $postData['data'] = json_encode($dbData);
        $postData['mod'] = 'Activitycfg';
        $postData['act'] = 'setCollection';
        $res = $this->curl->req($this->_url, $postData);

        oo::logs()->adminlog($this->router->fetch_method());

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

    }

    public function hconfig($id){
        $this->load->view('activity/h5/config', []);
    }

    public function refreshActivityMd5(){
        oo::commonOprModel('Filemd5')->makeActivityMd5();
        return $this->response(0, '操作成功');
    }

//========================================================
    public function getDateFromServer($postData){
        $data =  $this->curl->req($this->_url, $postData);
        return json_decode($data,true);
    }

    public function exportJson($aid = 0){
        if(empty($aid)){
            echo '<script>alert("非法操作");window.close()</script>';
            die;
        }
        $data = $this->editData($aid);
        $outPutFileName = $data['info']['name'].'.json';
        header('Content-Type: applicationnd.ms-excel');
        header('Content-Disposition: attachment;filename="'.$outPutFileName);
        header('Cache-Control: max-age=0');
        unset($data['info']['id']);
        echo json_encode($data['info']);
//        $objWriter->save('php://output');
        exit;
    }

    public function importJson(){
        $config = array(
            'savePath' => 'Excel/uploads',             //存储文件夹
            'maxSize'  => 1024*50,                   //允许的文件最大尺寸，单位KB
            'allowFiles' => array('.json')  //允许的文件格式
        );
        $this->load->library('uploader', $config);
        $file = $this->uploader->getFileInfo();
        $jsonStr = file_get_contents($file['url']);

        $data = $this->editData(1);
        $data['info'] = json_decode($jsonStr, true);
        $data['id'] = 0;
        $data['jigsawSources'] = $this->getJigSourcesList();
        $data['priceSkuMap'] = json_encode(array_column($this->goodSku, 'sku', 'price'));
//        echo json_encode($data['info']);die;
        $this->load->view('activity/h5/importJson', $data);
    }
    public function indexData($sn_time = "",$typeArr = []){
//        date_default_timezone_set('ETC/GMT+11');
        $postData = $this->postData;
        $w = " where 1=1 ";
        $s_status = get_cookie('status');
        $uc_type = get_cookie('uc_type');
        $s_status = $s_status?$s_status:1;
        $uc_type  = $uc_type?$uc_type:0;
        if(empty($sn_time)){
            $sn_time = get_cookie('sn_time');
        }
        $type = get_cookie('type');
        set_cookie('status',0,0);
        set_cookie('sn_time',0,0);
        set_cookie('uc_type',0,0);
        set_cookie('type','all',0);
        if($s_status){
            if($s_status==2) $w .=" and is_online=1";
            if($s_status==3) $w .=" and start_time>".time();
            if($s_status==4) $w .=" and is_online=0";
        }
        if($uc_type){
            $w .= ' and uc_type='.$uc_type;
        }
        if($sn_time&&$s_status>0&&$s_status!=3){
            $times = explode(" - ",$sn_time);
            $w .=" and start_time>=".strtotime($times[0]);
            $w .=" and end_time<=".strtotime($times[1]);
        }else{
//            $ts = time()-86400*7;
//            $w .=" and end_time>{$ts}";//超过七天不显示
        }
        if(!empty($typeArr)){
            if($type&&$type!='all'){
                $w .=" and type='{$type}'";
            }else{
                $typeArr = "'".implode("','",$typeArr)."'";
                $w .=" and type IN ({$typeArr})";
            }
        }else{
            if($type&&$type!='all'){
                $w .=" and type='{$type}'";
            }
        }

        $w .= " ORDER BY id DESC LIMIT 500";

        $postData['w'] = $w;
        $postData['mod'] = 'Activitynew';
        $postData['act'] = 'getActivity';
        $res = $this->curl->req($this->_url, $postData);

        $res = json_decode($res, TRUE);
        $maxId = 1;
        $indexData = [];
        $time = time();
        $rankCollectStaTb = otable::rankCollectSta();
        foreach ($res['list'] as $row){
            $commonConf = @json_decode($res['conf'][$row['id']], true) ?? [];
            if($row['id'] > $maxId){
                $maxId = $row['id'];
            }
            if($row['is_online']){
                $online = 0;
                $class  = "btn-danger";
                $do     = "下线";
            }else{
                $online = 1;
                $class  = "btn-success ";
                $do     = "上线";
            }
            if($row['start_time'] < $time){
                $status = '<button class="btn  btn-primary btn-sm">活动进行中</button>';
            }
            if($row['type']=='rank' || $row['type']=='rank2'){
                if(!empty($row['reward_time']) && $row['reward_time'] < $time){
                    $status = '<button class="btn badge-success btn-sm">奖励领取中</button>';
                }
            }
            if($row['is_online']==0){
                $status = '<button class="btn btn-warning btn-sm">活动已下线</button>';
            }
            if($row['start_time'] > $time){
                $status = '<button class="btn badge-default btn-sm">未开始</button>';
            }
            if($row['end_time'] < $time){
                $status = '<button class="btn btn-danger btn-sm">活动已结束</button>';
            }
            if($row['uc_type'] == 1){
                $priority = '<button class="btn btn-danger btn-sm">道具活动</button>';
            }else{
                $priority = '<button class="btn btn-success btn-sm">常规活动</button>';
            }
            $priority .= '<button class="btn btn-info btn-sm">活动优先级：'.$row['priority'].'</button>';
            $userGroup = '<div class="btn-group">';
            $level_section =  explode("-",$row['user_level_section']);
            $vip_section = explode("-",$row['user_vip_section']);
            $score_section =  explode("-",$row['user_score_section']);
            $click = $row['client']?($row['client']==1?"安卓":"IOS"):"全部";
            $click .= $row['user_type']?($row['user_type']==1?"-FB":"-游客"):"-全部";
            $lv = !$level_section[0]&&$level_section[0]==$level_section[1]?"全部":"{$level_section[0]}-{$level_section[1]}";
            $vip = !$vip_section[0]&&$vip_section[0]==$vip_section[1]?"全部":"{$vip_section[0]}-{$vip_section[1]}";
            $score = !$score_section[0]&&$score_section[0]==$score_section[1]?"全部":"{$score_section[0]}-{$score_section[1]}";
            $userGroup .= '<button class="btn btn-outline btn-warning btn-xs">客户端:'.$click.'</button>';
            $userGroup .= '<button class="btn btn-outline btn-success btn-xs">关卡:'.$lv.'</button>';
            $userGroup .= '<button class="btn btn-outline btn-danger btn-xs">vip:'.$vip.'</button>';
            $userGroup .= '<button class="btn btn-outline btn-danger btn-xs">分数:'.$score.'</button>';
            $userGroup .= '<button class="btn btn-outline btn-info btn-xs">折扣:' . $commonConf['showDiscountVal'] ?? 0 . '</button>';
            if($commonConf['appointUid']){
                $userGroup .= '<button class="btn btn-outline btn-danger btn-xs">指定UID参与</button>';
            }
            $userGroup .= '</div>';
            $action = '<a href="#activity/hedit/'.$row['id'].'" type="button" class="btn  btn-success ">配置</a>&nbsp&nbsp';
            $action .= '<a href="#activity/hadd/'.$row['id'].'" class="btn  btn-warning" type="button">复制新建</a>&nbsp&nbsp';
            $action .= '<a target="_blank" href="activity/exportJson/'.$row['id'].'" class="btn  btn-info" type="button">导出JSON</a>&nbsp&nbsp';
            if($this->config->item('oos_debug')||in_array(get_cookie('username'),['wsc','xwy','tjt','owen','ty','ybh','wx','yjb','sjz','zld','crk'])){
                $action .= '<button type="button" class="btn '.$class.' " onclick="online('.$row['id'].','.$online.')" >'.$do.'</button>&nbsp&nbsp';
                if($row['type'] == "fund"){
                    $action .= '<button type="button" class="btn btn-danger" onclick="confirmMsg('.$row['id'].','."'基金活动最少保留14天'".')" >删除</button>&nbsp&nbsp';
                }else{
                    $action .= '<button type="button" class="btn btn-danger" onclick="del('.$row['id'].')" >删除</button>&nbsp&nbsp';
                }
            }
//            if($row['type'] == 'superCollect'){
//
//                $action .= '<a type="button" class="btn btn-danger" target="_blank"  href="/activity/superCollectPreview/'.$row['id'].'" >数据预览</a>&nbsp&nbsp';
//            }

            /*
            //显示统计按钮
            $sql = "SELECT * FROM {$rankCollectStaTb} WHERE aid = {$row['id']}";
            $rankCollectRet = oo::commonOprDb("statistics")->getOne($sql,1);
            if($rankCollectRet){
                $action .= '<a href="#activitysta/speedTable/'.$row['id'].'" type="button" class="btn  btn-success ">统计</a>&nbsp&nbsp';
            }
            */

            $indexData[] = [
                'activityId'    => $row['id'],
                'id'            => '<a href="#activitysta/index/'.$row['id'].'" >'.$row['id'].'</a>',
                'name'          => $row['name'],
                'type'          => @$res['act_type'][$row['type']]['tips'],
                'priority'      => $priority,
                'status'        => $status,
                'userGroup'     => $userGroup,
                'lastUpdateTime'=> date("Y-m-d H:i:s",$row['start_time']),
                'lastEndTime'   => date("Y-m-d H:i:s",$row['end_time']),
                'action'        => $action,
            ];
        }

        $data['collect_cfg'] = $res['conf']['collect'];

        $data['mydata'] = json_encode($indexData);
        $data['list']   = $indexData;
        $data['s_status'] = $s_status;
        $data['act_type'] = $res['act_type'];
        unset($data['act_type']['collect'],$data['act_type']['collect_only'],$data['act_type']['steal'],$data['act_type']['attack'],$data['act_type']['first_pay'],$data['act_type']['balloon_tg']);
        $data['selType'] = $type;
        return $data;
    }

    public function h5(){
        $data = $this->indexData();
        $importActs = [
            SUPER_COLLECT       => [ 'title' => '导入收集活动层数配置', 'href' => 'activity/importCollect',],
            SUPER_SERIAL_PACK   => [ 'title' => '导入超级连环礼包层数配置', 'href' => 'activity/importSerialPack',],
            SUPER_SERIAL_PACK2  => [ 'title' => '导入超级连环礼包2层数配置', 'href' => 'activity/importSerialPack2',],
            SUPER_SERIAL_PACK3  => [ 'title' => '导入六格连环礼包层数配置', 'href' => 'activity/importSerialPack3',],
            SUPER_SERIAL_PACK4  => [ 'title' => '导入六格连环礼包2层数配置', 'href' => 'activity/importSerialPack4',],
            RANK                => [ 'title' => '导入排行榜配置', 'href' => 'activity/importRank',],
            RANK2               => [ 'title' => '导入排行榜无进度配置', 'href' => 'activity/importRank2',],
            TREASURE            => [ 'title' => '导入宝藏活动配置', 'href' => 'activity/importTreasure',],
            EASTER_EGG          => [ 'title' => '导入四选一-复活彩蛋活动配置', 'href' => 'activity/importEasterEgg',],
            SPINS_MASTER        => ['title' => '导入体力大师活动配置', 'href' => 'activity/importExcel/' . SPINS_MASTER,],
            JIGSAW              => ['title' => '导入拼图活动配置', 'href' => 'activity/importExcel/' . JIGSAW,],
            FOX_HAMMER          => [ 'title' => '导入狐狸之锤配置', 'href' => 'activity/importFoxHammer',],
            MAYA_WHEEL          => ['title' => '导入玛雅转盘配置', 'href' => 'activity/importExcel/' . MAYA_WHEEL],
            THEME_PACK          => [ 'title' => '导入主题礼包', 'href' => 'activity/importThemePack',],
            THEME_PACK2         => [ 'title' => '导入主题礼包', 'href' => 'activity/importThemePack2',],
            SAFE_SURPRISE       => [ 'title' => '导入安全惊喜礼包', 'href' => 'activity/importSafeSurprise'],
            SHOP_PROMOTION      => [ 'title' => '导入优惠券', 'href' => 'activity/importShopPromotion'],
            PICK_ONE            => [ 'title' => '导入三选一配置', 'href' => 'activity/importPickOne'],
            CHOOSE_YOU_WANT     => [ 'title' => '导入随心配', 'href' => 'activity/importChooseYouWant'],
            ONE_PLUS_GIFT       => [ 'title' => '导入1+1配置', 'href' => 'activity/importOnePlus'],
            CALLBACK_SCORE      => [ 'title' => '导入好友召回配置', 'href' => 'activity/importCallbackScore'],
            CLUB_TOURNAMENT     => [ 'title' => '导入公会锦标赛配置', 'href' => 'activity/importClubTournament'],
            CLUB_GARDEN         => [ 'title' => '导入公会花园', 'href' => 'activity/importClubGarden'],
            LUCKY_FOX           => ['title' => '导入幸运狐狸配置', 'href' => 'activity/importExcel/' . LUCKY_FOX],
            SUPER_BOMB          => ['title' => '导入超级炸弹配置', 'href' => 'activity/importExcel/' . SUPER_BOMB],
            CRAZY_BUILD         => ['title' => '导入疯狂建造配置', 'href' => 'activity/importExcel/' . CRAZY_BUILD],
            DRIFT_TREASURE      => ['title' => '导入漂流的宝藏', 'href' => 'activity/importExcel/' . DRIFT_TREASURE],
            SPECIAL_NOTICE      => ['title' => '导入特殊公告配置', 'href' => 'activity/importExcel/' . SPECIAL_NOTICE],
            SUPER_GASHAPON      => ['title' => '导入超级扭蛋配置', 'href' => 'activity/importExcel/' . SUPER_GASHAPON],
            GREAT_MEMORIES      => ['title' => '导入回归签到', 'href' => 'activity/importGreatMemories'],
            BUILD_RANK          => ['title' => '导入建筑锦标赛', 'href' => 'activity/importBuildRank'],
            PINATA              => ['title' => '导入皮纳塔', 'href' => 'activity/importPinata'],
            SUPER_SERIAL_PACK5  => ['title' => '导入有进度六格连环礼包', 'href' => 'activity/importExcel/' . SUPER_SERIAL_PACK5],
            SUPER_SERIAL_PACK6  => ['title' => '导入有进度连环礼包1', 'href' => 'activity/importExcel/' . SUPER_SERIAL_PACK6],
            SUPER_SERIAL_PACK7  => ['title' => '导入有进度连环礼包2', 'href' => 'activity/importExcel/' . SUPER_SERIAL_PACK7],
            TRAVEL_DIARY        => ['title' => '导入旅行日记', 'href' => 'activity/importExcel/' . TRAVEL_DIARY],
            TIME_LIMITED_CARD   => ['title' => '导入限时卡组', 'href' => 'activity/importExcel/' . TIME_LIMITED_CARD],
            SURPRISE_CARD       => ['title' => '导入惊喜事件牌', 'href' => 'activity/importExcel/' . SURPRISE_CARD],
            TAROT               => ['title' => '导入塔罗牌', 'href' => 'activity/importExcel/'.TAROT],
            CLUB_FARM           => ['title' => '导入公会农场', 'href' => 'activity/importExcel/'.CLUB_FARM],
            TRAFFIC_PERMIT      => ['title' => '导入通行证配置', 'href' => 'activity/importExcel/' . TRAFFIC_PERMIT],
            LUCKY_DICE          => ['title' => '导入幸运骰子', 'href' => 'activity/importExcel/'.LUCKY_DICE],
            COIN_PUSH_MANIA     => ['title' => '导入推金币活动', 'href' => 'activity/importExcel/'.COIN_PUSH_MANIA],
            SURPRISE_COLLECT    => ['title' => '导入惊喜付费收集-偷', 'href' => 'activity/importExcel/'.SURPRISE_COLLECT],
            JACKPOT             => ['title' => '导入Jackpot', 'href' => 'activity/importExcel/'.JACKPOT],
        ];
        $data['importActs'] = $importActs;
        $this->load->view("activity/h5/index", $data);
    }
    public function onlineOrNo(){
        $data = $this->input->post();
        if(!$data['id']){
            return $this->response(1, '操作失败,id不为空');
        }
        $postData =$this->postData;
        $postData['mod'] = 'Activitynew';
        $postData['act'] = 'saveActivity';
        $postData['id'] = intval($data['id']);
        $postData['is_online'] = intval($data['is_online']);
        $res = $this->curl->req($this->_url, $postData);

        oo::logs()->adminlog($this->router->fetch_method().'--活动：'.$data['id']);

        $ret = json_decode($res,true);
        if($ret['code']==1){
            $this->response(0, $ret['msg']);
        }else{
            $this->response(1, $ret['msg']);
        }

    }

    /**
     * Notes:获取连环礼包配置
     * User: wsc
     * Time: 2020/8/18 11:28
     * @return false|string
     */
    public function chainGiftcCfg(){
        $posts = $this->postData;
        $posts['mod'] = 'Shop';
        $posts['act'] = 'config';
        $posts['type'] = 7;
        $url = $this->config->item('officialUrl');
        $retData = $this->curl->req($url, $posts);
        $retData = json_decode($retData,1);
        $temp = [];
        foreach ($retData['data'] as $row){
            if(in_array($row['gid'],[710,711,712])){
                $gsku        = json_decode($row['gsku'],true);
                $row['gsku'] = is_array($gsku) ? "" : $row['gsku'];
                $row['gsku1']= is_array($gsku) ? $gsku : ['coins'=>'coins01','bet'=>0];
                $row['gbaseReward']  = json_decode($row['gbaseReward'],true);
                $row['goriginReward']= json_decode($row['goriginReward'],true);
                $temp[]      = $row;
            }
        }
        return $this->response(0, '',$temp);
    }

    /**
     * 0默认,1初级vip,2感恩节,3圣诞节,4中级vip,5高级vip,6至尊头像框,7 2020版感觉节
     * Created by: Owen
     * Created on: 2020/10/23 12:18
     */
    public function getAvatarBoxData(){
        $allAvatarBox = [0=>'默认', 1=>'初级vip', 2=>'感恩节', 3=>'圣诞节', 4=>'中级vip', 5=>'高级vip',6=>"至尊vip头像框",7=>"2020版感觉节",8=>'XX VIP头像框'];
        $propsBox = [2,3,7,8];
        foreach ($allAvatarBox as $key=>$row){
            if(!in_array($key,$propsBox)){
                unset($allAvatarBox[$key]);
            }
        }
        return $allAvatarBox;
    }


    /**
     * 加载编辑活动页面
     */
    public function hadd($id=''){
        $postData =$this->postData;
        $postData['mod'] = 'Activitynew';
        $postData['act'] = 'getTypeConf';
        $types = $this->getDateFromServer($postData);
        $types['imgNames'] = oo::commonOprModel('config')->getActiveImgNameConfig();
        $types['imgNames']['super_serial_pack4'] = $types['imgNames']['super_serial_pack3'];

        $data['act_type'] = $types['act_type'];//活动模板
        unset($data['act_type']['collect'],$data['act_type']['collect_only'],$data['act_type']['steal'],$data['act_type']['attack'],$data['act_type']['first_pay'],$data['act_type']['balloon_tg']);
        $data['collect_type'] = $types['imgNames']['super_collect'];//活动收集物品
        $data['slotGroups'] = oo::commonOprDb('slavedb')->getAll("select * from  ". otable::realSlotWeightGroups());
        $data['actPropsIds'] = array_column($types['actProps'], 'propsId');//活动道具Id列表
        $data['imgNames'] = json_encode($types['imgNames']);//活动资源文件夹名
        $data['skips'] = $types['skips'];//跳转规则
        $data['info']['start_time'] =strtotime(date("Y-m-d"))+86400;
        $data['info']['end_time'] =$data['info']['start_time']+86400;
        $data['info']['reward_time'] =$data['info']['end_time']-300;
        $data['info']['act_version'] = [];
        $list['info']['country'] = [];
        if($id){
            $postData['id'] = $id;
            $postData['mod'] = 'Activitynew';
            $postData['act'] = 'getActivity';
            $res = $this->curl->req($this->_url, $postData);
            $list = json_decode($res, TRUE);

            $data['collect_type'] = $types['imgNames'][$list['type']];//活动收集物品
            $level_section =  explode("-",$list['user_level_section']);
            $vip_section = explode("-",$list['user_vip_section']);
            $score_section =  explode("-",$list['user_score_section']);
            unset($list['user_level_section'],$list['user_vip_section'],$list['user_score_section']);
            $list['s_lv'] = $level_section[0];
            $list['e_lv'] = $level_section[1];
            $list['s_vip'] = $vip_section[0];
            $list['e_vip'] = $vip_section[1];
            $list['s_score'] = $score_section[0];
            $list['e_score'] = $score_section[1];
            $list['bname'] = json_decode($list['bname'],true);
            $list['show_title'] = json_decode($list['show_title'],true);
            $list['extraData'] = json_decode($list['extraData'],true);
            $list['act_version']=!empty($list['act_version'])?json_decode($list['act_version'],true):[];
            $list['country']=!empty($list['country'])?json_decode($list['country'],true):[];
            $list['commonConf'] = ActivityModel::getCommonConf($id);        // 添加公共配置

            switch ($list['type']){
                case 'lucky_fox':
                    $list['reward_info'] = ActivityModel::serializeLuckyFoxConf($list['reward_info']);
                    break;
            }

            unset($list['id']);
            $data['info'] = $list;
        }

        $data['versions'] = $this->versions;
        $data['country'] =$this->country;
        $data['goodSku'] = json_encode($this->goodSku);
        $data['priceSkuMap'] = json_encode(array_column($this->goodSku, 'sku', 'price'));
        $data['langs'] = $this->_langList;
        $data['langsBtn'] = $this->_langBtn;
        $data['userGroup2'] = array_column(oo::commonOprModel('config')->getUserGroupConfigByCid(2),'name','id');
        $data['userGroup3'] = array_column(oo::commonOprModel('config')->getUserGroupConfigByCid(3),'name','id');
        $data['userGroup5'] = array_column(oo::commonOprModel('config')->getUserGroupConfigByCid(5),'name','id');

        $rewardsType = [];
        $skins = oo::commonOprModel('config')->getPropsConfigFromLocal() ;
        $skinsArr = [];
        foreach ($skins as $k => $v){
            $rewardsType[$v['id']] = $v;
            if(!empty($v['skinList']) && is_array($v['skinList'])){
                $skinsArr[$v['id']] = array_column($v['skinList'], 'name', 'id');
            }
        }
        $data['reward_type'] = json_encode($rewardsType);
        $data['skinsArr']  = $skinsArr;
        $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['jigsawSkin']  = array_column(oo::commonOprModel('config')->getActivityActionList('collect_jigsw'),'name','id');

        $data['hideSSGroup'] = oo::commonOprModel('config')->hideSSGroup($data['userGroup5']);
        $data['userGroup5'] = $data['hideSSGroup'];
        //收集活动 限时奖励 兼容旧版本时间
        if(isset($list['type']) && $list['type'] == 'super_collect'){
            $data['info']['extraData']['ts'] = $this->superCollectTsTime($data['info']['extraData']['ts']);
        }
        //二选一兼容版本
        $data['info']['extra_reward'] = json_decode($data['info']['extra_reward'],true);
        if(isset($list['type']) && $list['type'] == 'choose_one' && !isset($data['info']['extra_reward']['groupRid'])){
            $data['info']['extra_reward']['groupRid'] = 2;
        }
        $data['info']['extra_reward'] = json_encode($data['info']['extra_reward'],true);

        $data['jigsawSources'] = $this->getJigSourcesList();
        $data['asyncId'] = $id;
        $this->load->view('activity/h5/edit', $data);
    }

    public function editData($id){
        $postData= $this->postData;
        $postData['mod'] = 'Activitynew';
        $postData['act'] = 'getTypeConf';
        $types = $this->getDateFromServer($postData);
        $types['imgNames'] = oo::commonOprModel('config')->getActiveImgNameConfig();
        $types['imgNames']['super_serial_pack4'] = $types['imgNames']['super_serial_pack3']??"";
//        echo json_encode($types['imgNames']);die;
        $data['act_type'] = $types['act_type'];//活动模板
        unset($data['act_type']['collect'],$data['act_type']['collect_only'],$data['act_type']['steal'],$data['act_type']['attack'],$data['act_type']['first_pay'],$data['act_type']['balloon_tg']);

        $rewardsType = [];
        $skins = oo::commonOprModel('config')->getPropsConfigFromLocal() ;
        $skinsArr = [];
        foreach ($skins as $k => $v){
            $rewardsType[$v['id']] = $v;
            if(!empty($v['skinList']) && is_array($v['skinList'])){
                $skinsArr[$v['id']] = array_column($v['skinList'], 'name', 'id');
            }
        }
        $data['reward_type'] = json_encode($rewardsType);
        $data['imgNames'] = json_encode($types['imgNames']);//活动资源文件夹名
        $data['skips'] = $types['skips'];//跳转规则
        $data['actPropsIds'] = array_column($types['actProps'], 'propsId');//活动道具Id列表
        $types['actProps'] = array_column($types['actProps'],'version','propsId');
        $data['actProps'] = json_encode($types['actProps']);//活动道具
        $postData['id'] = $id;
        $postData['mod'] = 'Activitynew';
        $postData['act'] = 'getActivity';
        $res = $this->curl->req($this->_url, $postData);
        $list = json_decode($res, TRUE);
        if(isset($list['type']) && in_array($list['type'],["choose_one","safe_surprise"])){
            $rewardInfo = $list['reward_info'] ? (array)json_decode($list['reward_info'], true) : [];
            if($rewardInfo && !isset($rewardInfo[0])){
                $list['reward_info'] = json_encode([['data' => $rewardInfo, 'gid' => [0]]]);
            }
        }
//echo json_encode($list);die;
        switch ($list['type']){
            case SUPER_SERIAL_PACK://连环礼包
            case SUPER_SERIAL_PACK2://连环礼包2
            case SUPER_SERIAL_PACK3://六格连环礼包
            case SUPER_SERIAL_PACK4://六格连环礼包2
            case SUPER_SERIAL_PACK5://六格连环礼包2
            case SUPER_SERIAL_PACK6://有进度连环礼包1
            case SUPER_SERIAL_PACK7://有进度连环礼包2
                $extraReward = json_decode($list['extra_reward'], true);
                foreach ($extraReward as $idx1 => $items1){
                    foreach ($items1['stages'] as $idx2 => $items2){
                        $extraReward[$idx1]['stages'][$idx2]['list'] = [];
                    }
                }
                $list['extra_reward'] = json_encode($extraReward);
                break;

            case SPINS_MASTER:  //体力大师
                $list['extra_reward'] = ActivityModel::formatSpinsMasterConf($list['extra_reward']);
                break;

            case DRIFT_TREASURE:case TRAVEL_DIARY:    // 漂流的宝藏,旅行日记
            $list['reward_info'] = ActivityModel::unsetThirdRewardConf($list['reward_info']);
            break;

            case SUPER_GASHAPON:    // 超级扭蛋
                $list['reward_info'] = ActivityModel::unsetSecondRewardConf($list['reward_info']);
                break;

            case EASTER_EGG:    // 四选一
                $list['reward_info'] = ActivityModel::formatEasterEggConf($list['reward_info']);
                break;

            case JIGSAW:    // 拼图活动
                $list['reward_info'] = ActivityModel::formatCollectJigsawConf($list['reward_info']);
                break;

            case 'super_collect'://收集活动
                $list['reward_info'] = ActivityModel::formatSuperCollectConf($list['reward_info']);
                break;

            case LUCKY_FOX:
                $list['reward_info'] = ActivityModel::serializeLuckyFoxConf($list['reward_info']);
                break;

            case CRAZY_BUILD:
                $list['reward_info'] = ActivityModel::emptyCrazyBuildConf($list['reward_info']);
                break;

            case SPECIAL_NOTICE:
                $list['reward_info'] = json_encode(oo::commonOprModel('config')->getCurLangs());
                break;
            case TREASURE:
                $extraData = json_decode($list['extraData'], true);
                foreach ($extraData['yStages'] as $idx1 => $items1){
                    $extraData['yStages'][$idx1]['groups'] = [];
//                    foreach ($items1['groups'] as $idx2 => $items2){
//                       $extraData['yStages'][$idx1]['groups'][$idx2]['reward'] = [];
//                    }
                }
                $list['extraData'] = json_encode($extraData);
                unset($extraData);
                break;
            case RANK:
            case RANK2:
                $list['extraData'] = ActivityModel::formatRankRoomAllotConf($list['extraData']);
                break;
        }

        if(empty($list['imgName']))$list['cid']=0;
        $data['collect_type'] = $types['imgNames'][$list['type']] ?? [];//活动收集物品
        $level_section =  explode("-",$list['user_level_section']);
        $vip_section = explode("-",$list['user_vip_section']);
        $score_section =  explode("-",$list['user_score_section']);
        unset($list['user_level_section'],$list['user_vip_section'],$list['user_score_section']);
        $list['s_lv'] = $level_section[0];
        $list['e_lv'] = $level_section[1];
        $list['s_vip'] = $vip_section[0];
        $list['e_vip'] = $vip_section[1];
        $list['s_score'] = $score_section[0];
        $list['e_score'] = $score_section[1];
        $list['bname'] = json_decode($list['bname'],true);
        $list['show_title'] = json_decode($list['show_title'],true);
        $list['extraData'] = json_decode($list['extraData'],true);
        $list['act_version'] = json_decode($list['act_version'],true);
        $list['country'] = json_decode($list['country'],true);
        $list['commonConf'] = ActivityModel::getCommonConf($id);        // 添加公共配置
        $data['info'] = $list;
        $data['id'] = $id;
        $data['langs'] = $this->_langList;
        $data['langsBtn'] = $this->_langBtn;
        $data['versions'] = $this->versions;
        $data['country'] =$this->country;
        $data['goodSku'] = json_encode($this->goodSku);
        $data['userGroup2'] = array_column(oo::commonOprModel('config')->getUserGroupConfigByCid(2),'name','id');
        $data['userGroup3'] = array_column(oo::commonOprModel('config')->getUserGroupConfigByCid(3),'name','id');
        $data['userGroup5'] = array_column(oo::commonOprModel('config')->getUserGroupConfigByCid(5),'name','id');
        $data['chestSkin']  = array_column(oo::commonOprModel('config')->chestSkin(),'name','id');

        $skins = oo::commonOprModel('config')->getPropsConfigFromLocal() ;
        $skinsArr = [];
        foreach ($skins as $k => $v) {
            if (!empty($v['skinList']) && is_array($v['skinList'])) {
                foreach ($v['skinList'] as $oneSkin) {
                    if (isset($oneSkin['ishide']) && $oneSkin['ishide']) {
                        continue;
                    }
                    $skinsArr[$v['id']][$oneSkin['id']] = $oneSkin['name'];
                }
            }
        }
        $data['skinsArr']  = $skinsArr;
        $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['jigsawSkin']  = array_column(oo::commonOprModel('config')->getActivityActionList('collect_jigsw'),'name','id');

        $data['hideSSGroup'] = oo::commonOprModel('config')->hideSSGroup($data['userGroup5']);
        $data['userGroup5']  = $data['hideSSGroup'];

        //收集活动 限时奖励 兼容旧版本时间
        if(isset($list['type']) && $list['type'] == 'super_collect'){
            $data['info']['extraData']['ts'] = $this->superCollectTsTime($data['info']['extraData']['ts']);
        }
        //二选一兼容版本
        $data['info']['extra_reward'] = json_decode($data['info']['extra_reward'],true);
        if(isset($list['type']) && $list['type'] == 'choose_one' && !isset($data['info']['extra_reward']['groupRid'])){
            $data['info']['extra_reward']['groupRid'] = 2;
        }
        $data['info']['extra_reward'] = json_encode($data['info']['extra_reward'],true);

        return $data;
    }

    /**
     * 加载编辑活动页面
     */
    public function hedit($id){
        if(empty($id) || $id <1) {
            return $this->response(1, '活动不存在');
        }
        $data = $this->editData($id);
        $data['jigsawSources'] = $this->getJigSourcesList();
        $data['priceSkuMap'] = json_encode(array_column($this->goodSku, 'sku', 'price'));
        $data['asyncId'] = $id;
//        echo json_encode($data['info']);die;

        $data['slotGroups'] = oo::commonOprDb('slavedb')->getAll("select * from  ". otable::realSlotWeightGroups());
        $this->load->view('activity/h5/edit', $data);
    }
    private function getJigSourcesList(){
        $sourceList = [];
        $tb = otable::ActiveImgNameConfig();
        $cache = oo::commonOprDb('slavedb')->getOne("SELECT * FROM {$tb} where name='collect_puzzle'",1);
        $content = @json_decode($cache['content'], true);
        foreach ((array)$content as $item){
            $sourceList[$item['name']] = strtolower($item['type']);
        }
        return $sourceList;
//        $rootDir = PATH_DAT . '../public/game/crazyfox/activity/Android/';
//        if(!is_dir($rootDir))return [];
//        $dirReader = opendir($rootDir);
//        while($dir = readdir($dirReader)){
//            if(strpos($dir,'jigsaw') === false)continue;
//            $sourceList[] = $dir;
//        }
//        return $sourceList;
    }
    public function hdel(){
        $data = $this->input->post();
        if(!$data['id']){
            return $this->response(1, '操作失败,id不为空');
        }

        $tb = otable::activityConf();
        $sql = "SELECT * FROM {$tb} WHERE id = {$data['id']}";
        $ret = oo::commonOprDb('slavedb')->getOne($sql,MYSQLI_ASSOC);


        $postData =$this->postData;
        $postData['mod'] = 'Activitynew';
        $postData['act'] = 'delActivity';
        $postData['id'] = intval($data['id']);
        $res = $this->curl->req($this->_url, $postData);

        oo::logs()->adminlog($this->router->fetch_method());

        $ret = json_decode($res,true);
        if($ret['code']==1){
            $this->response(0, $ret['msg']);
        }else{
            $this->response(1, $ret['msg']);
        }
    }
    /**
     * Notes:保存
     * User: wsc
     * Time: 2020/7/15 11:12
     */
    public function hsave($importData = []){
//        date_default_timezone_set('ETC/GMT+11');
        $oos_debug = $this->config->item('oos_debug');
        $data = empty($importData) ? $this->input->post() : $importData;
//        $this->response(-1, 'test',$data);
        $data['name'] = strtr($data['name'], ["\r\n" => '',"\t" => '',"\n" => '']);
        $data['name'] = trim($data['name']);
        $isImport = !empty($importData);
        if($data["id"]&&$data["old_type"]!=$data["type"]){
            $this->response(1, '保存失败，已发布的活动不能变更活动类型');
        }
//        if($data['id'] && !$this->config->item('oos_debug')){
        if($data['id']
            && !$this->config->item('oos_debug')
            && !in_array(get_cookie('username'),['wsc','xwy','ty','tjt'])
        ){
            $now = time();
            $rowData = $this->editData($data['id']);
            if(
                $rowData['info']['start_time'] < $now &&
                $rowData['info']['end_time']   > $now &&
                ($rowData['info']['is_online'] != 0) &&
                ($rowData['info']['uc_type'] == 0)
            ){
                $this->response(1, '保存失败，进行中的非道具型活动禁止修改！！');
            }

            $times = explode(" - ",$data['sn_time']);
            $end_time   =strtotime(date('YmdHi',strtotime($times[1])));
            if(
                $rowData['info']['start_time'] < $now &&
                $rowData['info']['end_time']   > $now &&
                ($rowData['info']['is_online'] != 0) &&
                ($end_time < ($now + 5 * 60))
            ){
                $this->response(1, '保存失败，进行中的活动结束时间必须大于当前五分钟之后的时间！');
            }
        }
        if(!$isImport ){
            $this->checkActParams($data);
        }
        $this->checkSku($data);
        if(empty($data['abType'])||!in_array($data['abType'], [1,2])){
            $data['abTest'] = $data['taTest'] = 0;
        }
        $lvStages = [];
        unset($data["old_type"]);

        // 公共配置
        $commonConf = ActivityModel::buildCommonConf($data);
        $appointUid = explode(",", $commonConf['appointUid']);
        if (count($appointUid) > 1000) {
            $this->response(1, '保存失败，指定UID参与活动的数量不能超过1000人！');
        }

        // 分活动类型处理数据
        $staticArr =[];//静态配置
        switch($data['type']){
            case 'super_collect':
                # 收集类型处理
                $groupId = intval($data['groupId']);
                $reward_conf = [
                    "attack_success"=>intval($data['attack_success']),//普通打
                    "attack_break"=>intval($data['attack_break']),//打破
                    "steal_success"=>intval($data['steal_success']),//偷
                    "steal_break"=>intval($data['steal_break']),//完美偷
                    "one_hit"=>intval($data['one_hit']),//一连
                    "two_hit"=>intval($data['two_hit']),//二连
                    "three_hit"=>intval($data['three_hit']),//三连
                    "weightGroupId"=>intval($data['weightGroupId']),//老虎机权重分组
                ];
                if(!$groupId||$groupId==7) $this->response(1, '保存失败，不支持分收集类型');
                if(in_array($groupId,[4,9])){//特殊收集+打,打收集
                    $reward_conf['attack_break'] = intval($data['attack_success']);
                    if($groupId==9){
                        $reward_conf['one_attack']=intval($data['one_attack']);
                        $reward_conf['two_attack']=intval($data['two_attack']);
                    }
                }
                if(in_array($groupId,[3,8])){//特殊收集+偷,偷收集
                    $reward_conf['steal_break'] = intval($data['steal_success']);
                    if($groupId==8){
                        $reward_conf['one_steal']=intval($data['one_steal']);
                        $reward_conf['two_steal']=intval($data['two_steal']);
                    }
                }
                $reward_conf['groupId'] = $groupId;
                $reward_conf['confType'] = 1;
                $data['reward_conf'] = $reward_conf;
                unset($data['groupId']);
                unset($data['weightGroupId']);

                # 限时处理
                $data['extraData']['open'] = $data['extraData']['open'][0] ?? 0;
                $data['extraData']['open_ts'] = $data['extraData']['open_ts'][0] ?? 0;
                if($data['extraData']['ts']){
                    $timesTemp = explode(" - ",$data['sn_time']);
                    $startTimeTemp = strtotime(date('YmdHi',strtotime($timesTemp[0])));//只能精确到分钟
                    $endTimeTemp = strtotime(date('YmdHi',strtotime($timesTemp[1])));//只能精确到分钟
                    $tsArr = [];
                    $tempK = 1;
                    foreach ($data['extraData']['ts'] as $k=>$v){
                        $tss = [];
                        $arr = explode('~',$v);
                        $tss['s'] = date('Y-m-d H:i',strtotime($arr[0]));
                        $tss['e'] = date('Y-m-d H:i',strtotime($arr[1]));
                        $data['extraData']['ts'][$k] = $tss;
                        if($data['extraData']['open']>0 && strtotime($tss['s']) < $startTimeTemp || $data['extraData']['open']>0 && strtotime($tss['e']) > $endTimeTemp){
                            $this->response(__LINE__, '保存失败，开启限时设置限时时间超过游戏开启时间范围');
                        }
                        $tsArr[$tempK] = $tss;
                        $tempK++;
                    }
                    $data['extraData']['ts'] = $tsArr;
                    unset($tsArr);
                }else{
                    $data['extraData']['ts'] = [];
                }
                if($data['extraData']['open']>0&&(!$data['extraData']['ts'][1]['s']||!$data['extraData']['ts'][1]['e'])){
                    $this->response(1, '保存失败，开启限时却未设置限时时间');
                }
                if($data['extraData']['bet_ts']){
                    foreach ($data['extraData']['bet_ts'] as $k=>$v){
                        $tss = [];
                        $arr = explode('~',$v);
                        $tss['s'] = $arr[0];
                        $tss['e'] = $arr[1];
                        $data['extraData']['bet_ts'][$k] = $tss;
                    }
                }else{
                    $data['extraData']['bet_ts'] = [];
                }
                if($data['extraData']['open_ts']>0&&(!$data['extraData']['bet_ts'][1]['s']||!$data['extraData']['bet_ts'][1]['e'])){
                    $this->response(1, '保存失败，开启限时却未设置限时bet时间');
                }
                $data['extraData']['openPro'] = 0;
                $data['extraData'] =json_encode($data['extraData'], 32);

                # 处理奖励
                foreach ($data['superCollectConfig'] as $lvIdx => $lvItem) {
                    if (empty($lvItem['stages'])) {
                        $this->response(-1 * __LINE__, "等级层级: {$lvIdx} ,未配置体力层级");
                    }
                    foreach ($lvItem['stages'] as $spinsIdx => $spinsItem) {
                        if (empty($spinsItem['stages'])) {
                            $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} ,未配置数数层级");
                        }

                        $hasDefaultShushu = false;
                        foreach ($spinsItem['stages'] as $shushuIdx => $shushuItem) {
                            if (in_array(0, $shushuItem['shushu'])) {
                                $hasDefaultShushu = true;
                            }
                            if (empty($shushuItem['list'])) {
                                $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 数数层级: {$shushuIdx} ,未配置奖励层级");
                            }
                            foreach ($shushuItem['list'] as $rewardIdx => $rewardItem) {
                                if (empty($rewardItem['prize'])) {
                                    $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 数数层级: {$shushuIdx} 奖励层级: {$rewardIdx} ,未配置奖励");
                                }
                            }
                        }
                        if (!$hasDefaultShushu) {
                            $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} ,未配置默认数数分组");
                        }
                    }
                }

                $data['reward_info'] = json_encode($data['superCollectConfig'], JSON_NUMERIC_CHECK);

                unset($data['spinStage']);
                unset($data['scoreStage']);
                unset($data['scoreCGType']);
                unset($data['rewardnew']);
                unset($data['superCollectConfig']);
                break;
            case SPINS_MASTER:
                if (empty($data['spinsMasterConfig'])) {
                    $this->response(1, '保存失败，未配置等级层级');
                }

                # 处理奖励
                foreach ($data['spinsMasterConfig'] as $lvIdx => $lvItem) {
                    if (empty($lvItem['stages'])) {
                        $this->response(-1 * __LINE__, "等级层级: {$lvIdx} ,未配置体力层级");
                    }
                    foreach ($lvItem['stages'] as $spinsIdx => $spinsItem) {
                        if (empty($spinsItem['stages'])) {
                            $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} ,未配置数数层级");
                        }

                        $hasDefaultShushu = false;
                        foreach ($spinsItem['stages'] as $shushuIdx => $shushuItem) {
                            if (in_array(0, $shushuItem['shushu'])) {
                                $hasDefaultShushu = true;
                            }
                            if (empty($shushuItem['reward'])) {
                                $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 数数层级: {$shushuIdx} ,未配置奖励层级");
                            }
                            foreach ($shushuItem['reward'] as $rewardIdx => $rewardItem) {
                                if (empty($rewardItem['prize'])) {
                                    $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 数数层级: {$shushuIdx} 奖励层级: {$rewardIdx} ,未配置奖励");
                                }
                            }
                        }
                        if (!$hasDefaultShushu) {
                            $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} ,未配置默认数数分组");
                        }
                    }
                }
                $data['extra_reward'] = json_encode($data['spinsMasterConfig'], JSON_NUMERIC_CHECK);
                unset($data['spinsMasterConfig']);
                break;
            case SUPER_GASHAPON:
                if (empty($data['superGashaponConfig'])) {
                    $this->response(1, '保存失败，未配置等级层级');
                }

                # 处理奖励
                foreach ($data['superGashaponConfig'] as $lvIdx => &$lvItem) {
                    if (empty($lvItem['stages'])) {
                        $this->response(-1 * __LINE__, "等级层级: {$lvIdx} ,未配置体力层级");
                    }

                    foreach ($lvItem['stages'] as $spinsIdx => &$spinsItem) {
                        if (empty($spinsItem['reward'])) {
                            $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} ,未配置奖励层级");
                        }

                        $prizeStat = [];
                        foreach ($spinsItem['reward'] as $rewardIdx => &$rewardItem) {
                            if (!isset($rewardItem['prize'])) {
                                $rewardItem['prize'] = [];
                            }

                            if ($rewardItem['gashType'] != 2) {
                                if (count($rewardItem['prize']) != 1) {
                                    $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 奖励层级: {$rewardIdx} ,奖励必须配置且唯一");
                                }
                            } else {
                                if (!empty($rewardItem['prize'])) {
                                    $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 奖励层级: {$rewardIdx} ,幸运蛋不能配置奖励");
                                }
                            }

                            $prizeStat[$rewardItem['layer']][] = $rewardItem['gashType'] == 2 ? 1 : 0;
                        }

                        foreach ($prizeStat as $layer => $prizeInfo) {
                            // 幸运蛋最多只能有一个
                            if (array_sum($prizeInfo) > 1) {
                                $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 扭蛋层级: {$layer} ,每层幸运蛋最多一个");

                            }
                            // 总奖励数最多10个
                            if (count($prizeInfo) > 10) {
                                $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 扭蛋层级: {$layer} ,每层扭蛋不能超10个");

                            }
                        }
                    }
                }

                $data['reward_info'] = json_encode($data['superGashaponConfig'], JSON_NUMERIC_CHECK);
                unset($data['superGashaponConfig']);
                break;
            case 'collect_jigsw':
                if (empty($data['jigsawConfig'])) {
                    $this->response(1, '保存失败，未配置等级层级');
                }

                # 处理奖励
                foreach ($data['jigsawConfig'] as $lvIdx => $lvItem) {
                    if (empty($lvItem['stages'])) {
                        $this->response(-1 * __LINE__, "等级层级: {$lvIdx} ,未配置体力层级");
                    }
                    foreach ($lvItem['stages'] as $spinsIdx => $spinsItem) {
                        if (empty($spinsItem['stages'])) {
                            $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} ,未配置数数层级");
                        }

                        $hasDefaultShushu = false;
                        foreach ($spinsItem['stages'] as $shushuIdx => $shushuItem) {
                            if (in_array(0, $shushuItem['shushu'])) {
                                $hasDefaultShushu = true;
                            }
                            if (empty($shushuItem['reward'])) {
                                $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 数数层级: {$shushuIdx} ,未配置奖励层级");
                            }
                            foreach ($shushuItem['reward'] as $rewardIdx => $rewardItem) {
                                if (empty($rewardItem['prize'])) {
                                    $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 数数层级: {$shushuIdx} 奖励层级: {$rewardIdx} ,未配置奖励");
                                }
                            }
                        }
                        if (!$hasDefaultShushu) {
                            $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} ,未配置默认数数分组");
                        }
                    }
                }
                $data['reward_info'] = json_encode($data['jigsawConfig'], JSON_NUMERIC_CHECK);
                unset($data['jigsawConfig']);
                break;
            case RANK:
            case RANK2:
            case BUILD_RANK:
            case BUILD_RANK2:
                //奖励积分处理
                $data['pro'] = $data['buildRankConfig'];
                //奖励积分处理
                if (in_array($data['type'], [RANK2, RANK])) {
                    $data['buildScoreSetting'] = [
                        "attack_success" => intval($data['attack_success'] ?? 0),//普通打
                        "attack_break" => intval($data['attack_break'] ?? 0),//打破
                        "steal_success" => intval($data['steal_success' ?? 0]),//偷
                        "steal_break" => intval($data['steal_break'] ?? 0),//完美偷
                        "one_hit" => intval($data['one_hit'] ?? 0),//一连
                        "two_hit" => intval($data['two_hit'] ?? 0),//二连
                        "three_hit" => intval($data['three_hit'] ?? 0),//三连
                        "confType" => 1,//三连
                    ];
                }

                $data['reward_conf'] = $data['buildScoreSetting'];
                foreach ($data['pro'] as $idx1 => $item1){
                    $lvStages[]  = [$item1['start'],  $item1['end']];
                    if(empty($item1['stages']))$this->response(1, "第{$idx1}层等级区间配置为空");
                    foreach ($item1['stages'] as $idx2 => $item2){
                        if(empty($item2['stages']))$this->response(1, "第{$idx1}层等级区间，第{$idx2}层体力区间配置为空");
                        foreach ($item2['stages'] as $idx3 => $item3){
                            if(in_array( $data['type'],[BUILD_RANK, RANK] )){
                                if(empty($item3['stages']['stages']))$this->response(1, "第{$idx1}层等级区间，第{$idx2}层体力区间，第{$idx3}层数数区间,阶段奖励配置为空", $item3);
                                foreach ($item3['stages']['stages'] as $idx4 => $item4){
                                    if(empty($item4['prize']))$this->response(1, "第{$idx1}层等级区间，第{$idx2}层体力区间，第{$idx3}层数数区间,阶段 {$idx4}奖励为空", $item3);
                                }
                            }
                            if(empty($item3['stages']['ranks']))$this->response(1, "第{$idx1}层等级区间，第{$idx2}层体力区间，第{$idx3}层数数区间,排行奖励配置为空", $item3);
                            foreach ($item3['stages']['ranks'] as $idx4 => $item4){
                                if(empty($item4['prize']))$this->response(1, "第{$idx1}层等级区间，第{$idx2}层体力区间，第{$idx3}层数数区间,排名{$idx4}奖励为空", $item3);
                            }
                        }
                    }
                }

                //机器人配置
                $robotConf = [
                    'setType' => 2,
                    'robot' => $data['robot'],
                    'rankLimit' => $data['rankLimit']
                ];

                if (in_array($data['type'], [RANK2, RANK])) {
                    $robotConf['setType'] = 10;// 等级体力分组
                    $robotConf['roomAllotConf'] = $data['roomAllotConf'];
                } else {
                    $robotConf['userLvSet'] = $data['userLvSet'];
                    $robotConf['userLvSetRobotStop'] = $data['userLvSetRobotStop'];
                }
                $data['extraData'] = json_encode($robotConf, JSON_NUMERIC_CHECK);

                unset($data['rank'], $data['groupId'], $data['spinStage'], $data['rewardnew'], $data['buildRankConfig'], $data['buildScoreSetting'], $data['userLvSet'], $data['userLvSetRobotStop'], $data['roomAllotConf']);
                break;
            case EASTER_EGG:
                foreach ($data['easterRewardConfig'] as $lvIdx => $lvItem){
                    $maxRewards=[];
                    $lvStages[] = [$lvItem['start'], $lvItem['end']];
                    $listlimit = 0;
                    $hasDefaultShushu = false;
                    foreach ($lvItem['shushuStages'] as $shushuIdx => $shushuItem){
                        if(empty($shushuItem['shushu']) || !is_array($shushuItem['shushu']))$this->response(__LINE__ * -1, '数数分组不能为空');
                        if(in_array(0, $shushuItem['shushu']))$hasDefaultShushu = true;
                        $listlimit =count($shushuItem['stages']);
                        foreach ($shushuItem['stages'] as $stageIdx => $stageItem){
                            foreach ($stageItem['list'] as $rewardIdx => $rewardItem){
                                $oneList = @json_decode(urldecode($rewardItem['prize']), true) ?? [];
                                $data['easterRewardConfig'][$lvIdx]['shushuStages'][$shushuIdx]['stages'][$stageIdx]['list'][$rewardIdx]['prize'] = $oneList;
                                if(count($shushuItem['stages'])==$stageIdx){
                                    if(!empty($oneList)){
                                        $arrOne = ActivityModel::getPropsShowArr($oneList,$lvItem['start']);
                                        array_push($maxRewards,$arrOne);
                                    }
                                }
                            }
                        }
                        //静态海报配置
                        $staticOne = [
                            'last_gate_reward'=>$maxRewards,
                            'start_lv'=>$lvItem['start'],
                            'end_lv'=>$lvItem['end'],
                            'gate_num'=>$listlimit
                        ];
                        $staticArr["info"][] = $staticOne;
                        if(!$hasDefaultShushu)$this->response(__LINE__ * -1, '未配置默认数数分组');
                    }
                }
                $staticArr["act_coupon_skin"] = $data['act_coupon_skin'];
                $staticArr["type"] = EASTER_EGG;
                $reward_conf = $data['common_conf'] ?? [];

                $data['easterBasicConfig']['confType'] = 1;
                $data['reward_conf'] = $reward_conf;
                $data['extra_reward'] = json_encode($data['easterRewardConfig'],256);
                $data['extraData'] = json_encode($data['extraData'],JSON_NUMERIC_CHECK);
                $data['reward_info'] = json_encode($data['easterBasicConfig'],JSON_NUMERIC_CHECK);
                unset($data['easterBasicConfig']);
                unset($data['easterRewardConfig']);
                break;
            case SUPER_SERIAL_PACK://连环礼包
            case SUPER_SERIAL_PACK2://连环礼包2
            case SUPER_SERIAL_PACK3://六格连环礼包
            case SUPER_SERIAL_PACK4://六格连环礼包2
                $hasDefaultShushu = false;
                foreach ($data['superSerialConfig'] as $lvIdx => $lvItem){
                    $minLv = intval($lvItem['start']);
                    $maxLv = intval($lvItem['end']);
                    $lvStages[] = [$minLv, $maxLv];

                    $data['superSerialConfig'][$lvIdx]['start'] = $minLv;
                    $data['superSerialConfig'][$lvIdx]['end'] = $maxLv;
                    foreach ($lvItem['stages'] as $shushuIdx => $shushuItem){
                        if(empty($shushuItem['shushu']) || !is_array($shushuItem['shushu']))$this->response(__LINE__ * -1, '数数分组不能为空');
                        if(in_array(0, $shushuItem['shushu']))$hasDefaultShushu = true;

                        foreach ($shushuItem['list'] as $rewardIdx => $rewardItem){
                            $data['superSerialConfig'][$lvIdx]['stages'][$shushuIdx]['list'][$rewardIdx]['gMax'] = intval($rewardItem['gMax']);
                            $data['superSerialConfig'][$lvIdx]['stages'][$shushuIdx]['list'][$rewardIdx]['mtype'] = intval($rewardItem['mtype']);
                            $data['superSerialConfig'][$lvIdx]['stages'][$shushuIdx]['list'][$rewardIdx]['stage'] = intval($rewardItem['stage']);
                            $data['superSerialConfig'][$lvIdx]['stages'][$shushuIdx]['list'][$rewardIdx]['bet'] = intval($rewardItem['bet']);
                            $tmpPrize = @json_decode(urldecode($rewardItem['prize']), true) ?? [];
                            if($rewardItem['mtype'] == 2 && empty($rewardItem['price']))
                                $this->response(__LINE__ * -1, '美元商品价格不能为空');
                            foreach ($tmpPrize as $pIdx =>$prize){
                                if(!is_scalar($prize)){
                                    foreach ($prize as $k => $v){
                                        $tmpPrize[$pIdx][$k] = intval($v);
                                    }
                                }
                            }
                            $data['superSerialConfig'][$lvIdx]['stages'][$shushuIdx]['list'][$rewardIdx]['prize'] = $tmpPrize;
                        }
                        if(!$hasDefaultShushu)$this->response(__LINE__ * -1, '未配置默认数数分组');
                    }
                }
                $data['extra_reward'] = json_encode($data['superSerialConfig'],256);
                $data['reward_info'] = json_encode(['scoreCGType' => 3]);
                unset($data['superSerialConfig']);
                unset($data['scoreCGType']);
                break;
            case SUPER_SERIAL_PACK5://有进度六格连环礼包
            case SUPER_SERIAL_PACK6://有进度连环礼包1
            case SUPER_SERIAL_PACK7://有进度连环礼包2
                $hasDefaultShushu = false;
                foreach ($data['superSerialProgressConfig'] as $lvIdx => &$lvItem){
                    $minLv = intval($lvItem['start']);
                    $maxLv = intval($lvItem['end']);
                    $lvStages[] = [$minLv, $maxLv];

                    $data['superSerialProgressConfig'][$lvIdx]['start'] = $minLv;
                    $data['superSerialProgressConfig'][$lvIdx]['end'] = $maxLv;
                    foreach ($lvItem['stages'] as $shushuIdx => &$shushuItem){
                        if(empty($shushuItem['shushu']) || !is_array($shushuItem['shushu']))$this->response(__LINE__ * -1, '数数分组不能为空');
                        if(in_array(0, $shushuItem['shushu']))$hasDefaultShushu = true;
                        if(!$hasDefaultShushu)$this->response(__LINE__ * -1, '未配置默认数数分组');

                        foreach ($shushuItem['list'] as $rewardIdx => &$rewardItem) {
                            foreach ($rewardItem as &$oneReward) {
                                $tmpPrize = @json_decode(urldecode($oneReward['prize']), true) ?? [];
                                if ($rewardIdx=="stages"&&$oneReward['mtype'] == 2 && empty($oneReward['price']))
                                    $this->response(__LINE__ * -1, '美元商品价格不能为空');
                                foreach ($tmpPrize as $pIdx => $prize) {
                                    if (!is_scalar($prize)) {
                                        foreach ($prize as $k => $v) {
                                            $tmpPrize[$pIdx][$k] = intval($v);
                                        }
                                    }
                                }
                                $oneReward["prize"] = $tmpPrize;
                            }
                        }
                    }
                }
                $data['extra_reward'] = json_encode($data['superSerialProgressConfig'],JSON_NUMERIC_CHECK);
                $data['reward_info'] = json_encode(['scoreCGType' => 3]);
                unset($data['superSerialProgressConfig']);
                unset($data['scoreCGType']);
                break;
            case THEME_PACK://主题
            case THEME_PACK2://主题2
                foreach ($data['themePackConfig'] as $lvIdx => $lvItem){
                    $hasDefaultShushu = false;
                    $data['themePackConfig'][$lvIdx]['start'] = intval($lvItem['start']);
                    $data['themePackConfig'][$lvIdx]['end'] = intval($lvItem['end']);
                    if(
                        empty($data['themePackConfig'][$lvIdx]['start'])
                        || empty($data['themePackConfig'][$lvIdx]['end'])
                        || ($data['themePackConfig'][$lvIdx]['start'] > $data['themePackConfig'][$lvIdx]['end'])
                    )$this->response(__LINE__ * -1, '等级区间配置异常! (Tips:等级不能配置0)');

                    $lvStages[] = [intval($lvItem['start']), intval($lvItem['end'])];
                    foreach ($lvItem['stages'] as $shushuIdx => $shushuItem){
                        if(empty($shushuItem['shushu']) || !is_array($shushuItem['shushu']))$this->response(__LINE__ * -1, '数数分组不能为空');
                        if(in_array(0, $shushuItem['shushu']))$hasDefaultShushu = true;
                        foreach ($shushuItem['list'] as $rewardIdx => $rewardItem){
                            $data['themePackConfig'][$lvIdx]['stages'][$shushuIdx]['list'][$rewardIdx]['stage'] = $rewardIdx;
                            $data['themePackConfig'][$lvIdx]['stages'][$shushuIdx]['list'][$rewardIdx]['prize'] = @json_decode(urldecode($rewardItem['prize']), true) ?? [];
                            if(empty($rewardItem['price']))$this->response(__LINE__ * -1, '付费礼包价格不能配0');
                            if(empty($rewardItem['times']))$this->response(__LINE__ * -1, '购买次数不能为空');
                            if(empty($data['themePackConfig'][$lvIdx]['stages'][$shushuIdx]['list'][$rewardIdx]['prize']))
                                $this->response(__LINE__ * -1, '奖励不能为空');
                        }
                        $data['themePackConfig'][$lvIdx]['stages'][$shushuIdx]['list'] = array_values($data['themePackConfig'][$lvIdx]['stages'][$shushuIdx]['list']);
                    }
                    if(!$hasDefaultShushu)$this->response(__LINE__ * -1, $lvIdx.'层未配置默认数数分组');
                }
                $data['reward_conf'] = $data['themePackConfig'];
                unset($data['themePackConfig']);
                break;
            case 'safe_surprise':  //安全惊喜礼包
//                $this->response(__LINE__ * -1,'test' ,$data['SafeSurpriseConfig']);
                foreach ($data['SafeSurpriseConfig'] as $lvIdx => $lvItem){
                    $hasDefaultShushu = false;
                    $data['SafeSurpriseConfig'][$lvIdx]['start'] = intval($lvItem['start']);
                    $data['SafeSurpriseConfig'][$lvIdx]['end'] = intval($lvItem['end']);
                    if(
                        empty($data['SafeSurpriseConfig'][$lvIdx]['start'])
                        || empty($data['SafeSurpriseConfig'][$lvIdx]['end'])
                        || ($data['SafeSurpriseConfig'][$lvIdx]['start'] > $data['SafeSurpriseConfig'][$lvIdx]['end'])
                    )$this->response(__LINE__ * -1, '等级区间配置异常! (Tips:等级不能配置0)',$data['SafeSurpriseConfig'][$lvIdx]);

                    $lvStages[] = [intval($lvItem['start']), intval($lvItem['end'])];
                    foreach ($lvItem['data'] as $shushuIdx => $shushuItem){
                        if(empty($shushuItem['shushu']) || !is_array($shushuItem['shushu']))$this->response(__LINE__ * -1, '数数分组不能为空',$shushuItem);
                        if(in_array(0, $shushuItem['shushu']))$hasDefaultShushu = true;
                        foreach ($shushuItem['data'] as $rewardIdx => $rewardItem){
                            $data['SafeSurpriseConfig'][$lvIdx]['data'][$shushuIdx]['data'][$rewardIdx]['prizes'] = @json_decode(urldecode($rewardItem['prizes']), true) ?? [];
                            if(empty($rewardItem['gprice']))$this->response(__LINE__ * -1, '付费礼包价格不能配0');
                            if(empty($rewardItem['gdiscount']))$this->response(__LINE__ * -1, '商品折扣不能为空');
                            if(empty($data['SafeSurpriseConfig'][$lvIdx]['data'][$shushuIdx]['data'][$rewardIdx]['prizes']))
                                $this->response(__LINE__ * -1, '奖励不能为空');
                        }
//                        $data['SafeSurpriseConfig'][$lvIdx]['data'][$shushuIdx]['data'] = array_values($data['SafeSurpriseConfig'][$lvIdx]['data'][$shushuIdx]['data']);
                    }
                    if(!$hasDefaultShushu)$this->response(__LINE__ * -1, $lvIdx.'层未配置默认数数分组');
                }
                $data['reward_info'] = json_encode($data['SafeSurpriseConfig'],32);
//                $this->response(__LINE__ * -1,'test' ,$data['SafeSurpriseConfig']);
                unset($data['SafeSurpriseConfig']);
                break;
            case PICK_ONE:  //安全惊喜礼包
//                $this->response(__LINE__ * -1,'test' ,$data['ChooseOneConfig']);
                $configData = $data['ChooseOneConfig'];
                unset($data['ChooseOneConfig']);
                foreach ($configData as $lvIdx => $lvItem){
                    $hasDefaultShushu = false;
                    $configData[$lvIdx]['start'] = intval($lvItem['start']);
                    $configData[$lvIdx]['end'] = intval($lvItem['end']);
                    if(
                        empty($configData[$lvIdx]['start'])
                        || empty($configData[$lvIdx]['end'])
                        || ($configData[$lvIdx]['start'] > $configData[$lvIdx]['end'])
                    )$this->response(__LINE__ * -1, '等级区间配置异常! (Tips:等级不能配置0)',$configData[$lvIdx]);
                    $lvStages[] = [intval($lvItem['start']), intval($lvItem['end'])];
                    foreach ($lvItem['data'] as $shushuIdx => $shushuItem){
                        if(empty($shushuItem['shushu']) || !is_array($shushuItem['shushu']))$this->response(__LINE__ * -1, '数数分组不能为空',$shushuItem);
                        if(in_array(0, $shushuItem['shushu']))$hasDefaultShushu = true;
                        foreach ($shushuItem['data'] as $rewardIdx => $rewardItem){
                            $configData[$lvIdx]['data'][$shushuIdx]['data'][$rewardIdx]['prizes'] = @json_decode(urldecode($rewardItem['prizes']), true) ?? [];
                            if(empty($rewardItem['price']))$this->response(__LINE__ * -1, '付费礼包价格不能配0');
                            if(empty($configData[$lvIdx]['data'][$shushuIdx]['data'][$rewardIdx]['prizes']))
                                $this->response(__LINE__ * -1, '奖励不能为空');
                        }
                    }
                    if(!$hasDefaultShushu)$this->response(__LINE__ * -1, $lvIdx.'层未配置默认数数分组');
                }
                $data['reward_info'] = json_encode($configData,32);
                break;
            case 'shop_promotion':  //优惠券
//                $this->response(__LINE__ * -1,'test' ,$data['shopPromotionConfig']);
                foreach ($data['shopPromotionConfig'] as $lvIdx => $lvItem){
                    $hasDefaultShushu = false;
                    $data['shopPromotionConfig'][$lvIdx]['start'] = intval($lvItem['start']);
                    $data['shopPromotionConfig'][$lvIdx]['end'] = intval($lvItem['end']);
                    if(
                        empty($data['shopPromotionConfig'][$lvIdx]['start'])
                        || empty($data['shopPromotionConfig'][$lvIdx]['end'])
                        || ($data['shopPromotionConfig'][$lvIdx]['start'] > $data['shopPromotionConfig'][$lvIdx]['end'])
                    )$this->response(__LINE__ * -1, '等级区间配置异常! (Tips:等级不能配置0)',$data['shopPromotionConfig'][$lvIdx]);
                    $lvStages[] = [intval($lvItem['start']), intval($lvItem['end'])];
                    foreach ($lvItem['stages'] as $shushuIdx => $shushuItem){
                        if(empty($shushuItem['shushu']) || !is_array($shushuItem['shushu']))$this->response(__LINE__ * -1, '数数分组不能为空',$shushuItem);
                        if(in_array(0, $shushuItem['shushu']))$hasDefaultShushu = true;

                        $data['shopPromotionConfig'][$lvIdx]['stages'][$shushuIdx]['data']['list'] = array_values($shushuItem['data']['list']);
                    }
                    if(!$hasDefaultShushu)$this->response(__LINE__ * -1, $lvIdx.'层未配置默认数数分组');
                }
                $data['reward_conf'] = $data['shopPromotionConfig'];
                unset($data['shopPromotionConfig']);
                break;
            case 'one_plus_gift':  //1+1
//                $this->response(__LINE__ * -1,'test' ,$data['onePlusConfig']);
                $configData = $data['onePlusConfig'];
                unset($data['onePlusConfig']);
                foreach ($configData as $lvIdx => $lvItem){
                    $hasDefaultShushu = false;
                    $configData[$lvIdx]['start'] = intval($lvItem['start']);
                    $configData[$lvIdx]['end'] = intval($lvItem['end']);
                    if(
                        empty($configData[$lvIdx]['start'])
                        || empty($configData[$lvIdx]['end'])
                        || ($configData[$lvIdx]['start'] > $configData[$lvIdx]['end'])
                    )$this->response(__LINE__ * -1, '等级区间配置异常! (Tips:等级不能配置0)',$configData[$lvIdx]);
                    $lvStages[] = [intval($lvItem['start']), intval($lvItem['end'])];
                    foreach ($lvItem['data'] as $shushuIdx => $shushuItem){
                        if(empty($shushuItem['shushu']) || !is_array($shushuItem['shushu']))$this->response(__LINE__ * -1, '数数分组不能为空',$shushuItem);
                        if(in_array(0, $shushuItem['shushu']))$hasDefaultShushu = true;
                        foreach ($shushuItem['data'] as $rewardIdx => $rewardItem){
                            $configData[$lvIdx]['data'][$shushuIdx]['data'][$rewardIdx]['prizes'] = @json_decode(urldecode($rewardItem['prizes']), true) ?? [];
                            if($rewardIdx == 1837 && empty($rewardItem['gprice']) )$this->response(__LINE__ * -1, '付费礼包价格不能配0');
                            if($rewardIdx == 1838 ){    # 1+1 第二项商品取第一项商品的价格和sku
                                $configData[$lvIdx]['data'][$shushuIdx]['data'][$rewardIdx]['gprice'] = $configData[$lvIdx]['data'][$shushuIdx]['data'][1837]['gprice'];
                                $configData[$lvIdx]['data'][$shushuIdx]['data'][$rewardIdx]['gsku'] = $configData[$lvIdx]['data'][$shushuIdx]['data'][1837]['gsku'];
                            }
                            if(empty($configData[$lvIdx]['data'][$shushuIdx]['data'][$rewardIdx]['prizes']))
                                $this->response(__LINE__ * -1, "{$lvIdx}-{$shushuIdx}-{$rewardIdx}奖励不能为空");

                        }
                    }
                    if(!$hasDefaultShushu)$this->response(__LINE__ * -1, $lvIdx.'层未配置默认数数分组');
                }
                $data['reward_info'] = json_encode($configData,32);
                break;
            case 'choose_you_want':
                $extraData = $rewardInfo=$rewardArr=[];$gid = 1845;
                $extraData['buy_times'] = intval($data['chooseYouWantBaseConfig']['buyCnt']);

                foreach ($data['chooseYouWantRewardConfig'] as $k=>$val1){
                    $rewardOne =[];
                    foreach ($val1 as $key=>$prize){
                        $one = @json_decode(urldecode($prize['prize']), true)[0];
                        $one['id'] = $key;
                        $rewardOne[] = $one;
                    }
                    $rewardArr[$k]=$rewardOne;
                }
//                $this->response(1, 'test',$data['chooseYouWantConfig']);
                foreach ($data['chooseYouWantConfig'] as $spinIdx=>$value){
                    $rewardInfo[$spinIdx]['start'] = $value['start'];
                    $rewardInfo[$spinIdx]['end'] = $value['end'];
                    $lvStages[] = [intval($value['start']), intval($value['end'])];
                    foreach ($value['data'] as $shushuIdx=>$item){
                        $rewardInfo[$spinIdx]['data'][$shushuIdx]["shushu"] =$item['shushu'];
                        $rewardInfo[$spinIdx]['data'][$shushuIdx]['data']['price'] = $item['data']['price'];
                        $rewardInfo[$spinIdx]['data'][$shushuIdx]['data']['sku'] = $item['data']['sku'];
                        $rewardInfo[$spinIdx]['data'][$shushuIdx]['data']['discount'] = $item['data']['discount'];
                        $rewardInfo[$spinIdx]['data'][$shushuIdx]['data']['gid'] = $gid;
                        $rewards = [
                            "left" => [
                                "prizes" => $rewardArr["left_{$spinIdx}_{$shushuIdx}"]
                            ],
                            "right" => [
                                "prizes" =>$rewardArr["right_{$spinIdx}_{$shushuIdx}"]
                            ]
                        ];
                        $rewardInfo[$spinIdx]['data'][$shushuIdx]['data']['gid'] = $gid;
                        $rewardInfo[$spinIdx]['data'][$shushuIdx]['data']['rewards'] = $rewards;
                    }
                }
                $data['reward_info'] = json_encode($rewardInfo);
                $data['extra_reward'] = json_encode($extraData);
//                $this->response(1, 'test',$rewardInfo);
                unset($data['chooseYouWantConfig'],$data['chooseYouWantRewardConfig'],$data['chooseYouWantBaseConfig']);
                break;
            case 'fox_hammer':
                $gid = 1846;
                if(
                    empty($data['foxHammerShuhuConfig'])
                    ||empty($data['foxHammerConfig'])
                    ||(count($data['foxHammerShuhuConfig']) != count($data['foxHammerConfig']))
                )
                    $this->response(1, '配置异常，'.__LINE__);

                $hasDefaultShushu = false;
                $rewardInfo = [];
//                $this->response(1, "test",["cfg"=>$data['foxHammerConfig'],"ss"=>$data['foxHammerShuhuConfig']]);
                foreach ($data['foxHammerConfig'] as $lvIdx=> $lvAndShushuInfo){
                    foreach ($lvAndShushuInfo['data'] as $idx => $items){
                        if(empty($data['foxHammerShuhuConfig'][$lvIdx]['data'][$idx]['shushu']))$this->response(1, '配置异常，'.__LINE__);
                        $tmpData = [];
                        $tmpData['shushu'] = array_map(function($v){return intval($v);}, $data['foxHammerShuhuConfig'][$lvIdx]['data'][$idx]['shushu']);
                        if(in_array(0, $tmpData['shushu']))$hasDefaultShushu = true;
                        $tmpData['data'] = [];
                        foreach ($items['data'] as $idx1 => $item){
                            if(empty($item['prize']))$this->response(1, '配置异常，'.__LINE__);
                            $min = $max = 0;
                            $prizes = [];
                            foreach ($item['prize'] as $tmpPrize){
                                $tmpPrize['spins'] = intval($tmpPrize['spins']);
                                $tmpPrize['weight'] = intval($tmpPrize['weight']);
                                if(empty($tmpPrize['spins']))$this->response(1, '配置异常，'.__LINE__);
                                $min = empty($min) ? $tmpPrize['spins'] : min($tmpPrize['spins'], $min);
                                $max = max($tmpPrize['spins'], $max);
                                $prizes[] = [
                                    'weight' => $tmpPrize['weight'],
                                    'reward' => [
                                        "id"=>1,
                                        "num"=>$tmpPrize['spins'],
                                        "type"=>15,
                                        "rtype"=>1,
                                        "skin"=>""
                                    ]
                                ];
                            }
                            $tmpData['data'][] = [
                                'price' => $item['price'],
                                'sku' => $item['sku'],
                                'discount' => 0,//empty($item['discount']) ? '0' : $item['discount'],
                                'gid' => $gid,
                                'stage' => $idx1,
                                'isFree' => empty($item['price']) ? 1 : 0,
                                'ton' => intval($item['ton']),
                                'prizes' => $prizes,
                                'spinsMin' => $min,
                                'spinsMax' => $max,
                            ];
                        }
                        $rewardShuShu[$lvIdx][$idx] = $tmpData;
                    }
                    $rewardInfo[$lvIdx]=[
                        "start"=>$data['foxHammerShuhuConfig'][$lvIdx]['start'],
                        "end"=>$data['foxHammerShuhuConfig'][$lvIdx]['end'],
                        "data"=>$rewardShuShu[$lvIdx]
                    ];

                    $lvStages[] = [intval($data['foxHammerShuhuConfig'][$lvIdx]['start']), intval($data['foxHammerShuhuConfig'][$lvIdx]['end'])];
                }

//                $this->response(1, "test",$rewardInfo);
                if(!$hasDefaultShushu)$this->response(1, "未配置默认数数分组");
                $data['reward_info'] = json_encode($rewardInfo);
                unset($data['foxHammerConfig'], $data['foxHammerShuhuConfig']);
                break;
            case 'callback_score':  //1+1
                $configData = $data['callbackScore'];
                unset($data['callbackScore']);
                foreach ($configData as $lvIdx => $lvItem){
                    $hasDefaultShushu = false;
                    $configData[$lvIdx]['start'] = intval($lvItem['start']);
                    $configData[$lvIdx]['end'] = intval($lvItem['end']);
                    if(
                        empty($configData[$lvIdx]['start'])
                        || empty($configData[$lvIdx]['end'])
                        || ($configData[$lvIdx]['start'] > $configData[$lvIdx]['end'])
                    )$this->response(__LINE__ * -1, '等级区间配置异常! (Tips:等级不能配置0)',$configData[$lvIdx]);
                    $lvStages[] = [intval($lvItem['start']), intval($lvItem['end'])];
                    foreach ($lvItem['data'] as $shushuIdx => $shushuItem){
                        if(empty($shushuItem['shushu']) || !is_array($shushuItem['shushu']))$this->response(__LINE__ * -1, '数数分组不能为空',$shushuItem);
                        if(in_array(0, $shushuItem['shushu']))$hasDefaultShushu = true;
                        $configData[$lvIdx]['data'][$shushuIdx]['data'] = @json_decode(urldecode($shushuItem['data']), true) ?? [];

//                        foreach ($shushuItem['data'] as $rewardIdx => $rewardItem){
//                            $configData[$lvIdx]['data'][$shushuIdx]['data'][$rewardIdx]['prizes'] = @json_decode(urldecode($rewardItem['prizes']), true) ?? [];
//                            if(empty($configData[$lvIdx]['data'][$shushuIdx]['data'][$rewardIdx]['prizes']))
//                                $this->response(__LINE__ * -1, "{$lvIdx}-{$shushuIdx}-{$rewardIdx}奖励不能为空");
//
//                        }
                    }
                    if(!$hasDefaultShushu)$this->response(__LINE__ * -1, $lvIdx.'层未配置默认数数分组');
                }
                $data['reward_info'] = json_encode($configData,32);
                break;
            case TIME_LIMITED_CARD :  //限时卡组
                $configData = $data['timeLimitedCards'];
                unset($data['timeLimitedCards']);
                if(empty($configData['progress']))$this->response(-1 * __LINE__, "阶段奖励不能为空");
                foreach ($configData['progress'] as $k => $item){
                    if(empty($item['target']))$this->response(-1 * __LINE__, "第{$item['stage']}阶段,阶段值不能为空");
                    $prize= json_decode(urldecode($item['rewards']), true);
                    if(empty($prize))$this->response(-1 * __LINE__, "第{$item['stage']}阶段,奖励不能为空");
                    $configData['progress'][$k]['rewards'] = $prize;
                }
                $data['extraData'] = json_encode($configData,32);
                break;
            case CLUB_TOURNAMENT:  //公会锦标赛
                $configData = $data['clubTournamentConfig'];
                $configData['preTimes'] = intval($configData['preTimes'] * 3600);
                unset($data['clubTournamentConfig']);
                $data['reward_conf'] = [
                    "attack_success"=>intval($data['attack_success']),//普通打
                    "attack_break"=>intval($data['attack_break']),//打破
                    "steal_success"=>intval($data['steal_success']),//偷
                    "steal_break"=>intval($data['steal_break']),//完美偷
                    "one_hit"=>intval($data['one_hit']),//一连
                    "two_hit"=>intval($data['two_hit']),//二连
                    "three_hit"=>intval($data['three_hit']),//三连
                    "confType"=>1,//三连
                ];
                $preEnd = null;
                $rankList = [
                    'clubRanks','userRanks'
                ];
                foreach ($configData['list'] as $idx1 => $items){
                    $start = intval($items['start']);
                    $end = intval($items['end']);
                    $clubNum = intval($items['clubNum']);
                    if($end < $start)$this->response(-1 * __LINE__, "星星区间配置异常:{$end}<{$start}");
                    if(empty($clubNum))$this->response(-1 * __LINE__, "房间最大俱乐部数不能为:".$items['clubNum']);
                    if(!is_null($preEnd)){
                        if($start != $preEnd+1)
                            $this->response(-1 * __LINE__, "星星区间不连续:{$preEnd}->{$start}");
                    }
                    $preEnd = $end;
                    foreach ($rankList as $rankTitle){
                        foreach ($items[$rankTitle] as $rankKey => $rankItem){
                            $tmpPrize = @json_decode(urldecode($rankItem['prizes']), true) ?? [];
                            if(empty($tmpPrize))$this->response(-1 * __LINE__, "排行:".$rankItem['rank'].'奖励为空');
                            $configData['list'][$idx1][$rankTitle][$rankKey]['prizes'] = $tmpPrize;
                        }
                    }
                }
                $data['extraData'] = json_encode($configData,32);
                break;
            case CLUB_GARDEN:  //公会花园
                $configData = $data['clubGardenConfig'];
                unset($data['clubGardenConfig']);
                $data['reward_conf'] = [
                    "attack_success"=>intval($data['attack_success']),//普通打
                    "attack_break"=>intval($data['attack_break']),//打破
                    "steal_success"=>intval($data['steal_success']),//偷
                    "steal_break"=>intval($data['steal_break']),//完美偷
                    "one_hit"=>intval($data['one_hit']),//一连
                    "two_hit"=>intval($data['two_hit']),//二连
                    "three_hit"=>intval($data['three_hit']),//三连
                    "confType"=>1,//三连
                ];
                $configData['clubMinStage'] = 1;
                $configData['preTimes'] = intval($configData['preTimes'] * 3600);
                $preEnd = null;
                foreach ($configData['clubStagesList'] as $idx1 => $items){
                    $start = intval($items['start']);
                    $end = intval($items['end']);
                    if($end < $start)$this->response(-1 * __LINE__, "星星区间配置异常:{$end}<{$start}");
                    if(!is_null($preEnd)){
                        if($start != $preEnd+1)
                            $this->response(-1 * __LINE__, "星星区间不连续:{$preEnd}-{$start}");
                    }
                    $preEnd = $end;
                    foreach ($items['stages'] as $idx2 => $items1){
                        $configData['clubStagesList'][$idx1]['stages'][$idx2]['prizes'] = @json_decode(urldecode($items1['prizes']), true) ?? [];
                        $configData['clubStagesList'][$idx1]['stages'][$idx2]['max_stage'] = count($items['stages']);
                        $stegeIdx = $idx2+1;
                        if(empty($items1['user_rank']))$this->response(-1 * __LINE__, "阶段:{$stegeIdx} 排名列表为空");
                        foreach ($items1['user_rank'] as $idx3 => $items2){
                            $prizeIdx = $idx3+1;
                            $prizeTmp = @json_decode(urldecode($items2['prizes']), true) ?? [];
                            if(empty($prizeTmp))$this->response(-1 * __LINE__, "阶段:{$stegeIdx} 排名:{$prizeIdx} 奖励为空");
                            $configData['clubStagesList'][$idx1]['stages'][$idx2]['user_rank'][$idx3]['prizes'] = @json_decode(urldecode($items2['prizes']), true) ?? [];
                        }
                    }
                }
                $data['extraData'] = json_encode($configData,32);
                break;
            case LUCKY_FOX : // 幸运狐狸
                $noError = ActivityModel::formatLuckyFoxConf($data['luckyFoxConfig']);
                if (!$noError) {
                    $this->response(-1, "存在空数值");
                }
                $data['reward_info'] = $data['luckyFoxConfig'];
                unset($data['luckyFoxConfig']);
                break;
            case SUPER_BOMB : // 超级炸弹
                $data['reward_info'] = json_encode($data['superBombConfig'], JSON_NUMERIC_CHECK);
                unset($data['superBombConfig']);
                break;
            case CRAZY_BUILD : // 疯狂建造
                if ($isImport){
                    $data['reward_info'] = json_encode($data['crazyBuildConfig'], JSON_NUMERIC_CHECK);
                }else{
                    $data['reward_info'] = ActivityModel::formatCrazyBuildConf($this, $data['crazyBuildConfig']);
                }

                $data['extraData'] = json_encode($data['extraData'], JSON_NUMERIC_CHECK);

                unset($data['crazyBuildConfig']);
                break;
            case SPECIAL_NOTICE : // 特殊公告
                $data['extraData'] = json_encode($data['specialNoticeConfig'], JSON_NUMERIC_CHECK);
                $data['extraData'] = str_replace(array('\r\n', '\r'), '\n', $data['extraData']);

                unset($data['specialNoticeConfig']);
                break;

            case PERFECT_RAID : // 完美偷袭
                break;
            case PERFECT_ATTACK : // 完美打
            case PERFECT_CHEST_SPINS : // 皮肤宝箱最大体力
            case PERFECT_RICH_KING : // richKing最大金币
                $data['ishide'] = 1;//强制隐藏
                $data['extraData'] = json_encode($data['extraData'], JSON_NUMERIC_CHECK);
                break;
            case DRIFT_TREASURE:case TRAVEL_DIARY:    // 漂流的宝藏,旅行日记
            if (empty($data['driftTreasureConfig'])) {
                $this->response(1, '保存失败，未配置等级层级');
            }

            # 处理奖励
            foreach ($data['driftTreasureConfig'] as $lvIdx => $lvItem) {
                if (empty($lvItem['stages'])) {
                    $this->response(-1 * __LINE__, "等级层级: {$lvIdx} ,未配置体力层级");
                }
                foreach ($lvItem['stages'] as $spinsIdx => $spinsItem) {
                    if (empty($spinsItem['stages'])) {
                        $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} ,未配置数数层级");
                    }

                    $hasDefaultShushu = false;
                    foreach ($spinsItem['stages'] as $shushuIdx => $shushuItem) {
                        if (in_array(0, $shushuItem['shushu'])) {
                            $hasDefaultShushu = true;
                        }
                        if (empty($shushuItem['reward'])) {
                            $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 数数层级: {$shushuIdx} ,未配置奖励层级");
                        }
                        foreach ($shushuItem['reward'] as $rewardIdx => $rewardItem) {
                            if (empty($rewardItem['prize'])) {
                                $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 数数层级: {$shushuIdx} 奖励层级: {$rewardIdx} ,未配置奖励");
                            }
                            if (count($rewardItem['prize'])!=1) {
                                $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} 数数层级: {$shushuIdx} 奖励层级: {$rewardIdx} ,奖励只能配置一个");
                            }
                        }
                    }
                    if (!$hasDefaultShushu) {
                        $this->response(-1 * __LINE__, "等级层级: {$lvIdx} 体力层级: {$spinsIdx} ,未配置默认数数分组");
                    }
                }
            }
            $data['reward_info'] = json_encode($data['driftTreasureConfig'], JSON_NUMERIC_CHECK);
            unset($data['driftTreasureConfig']);
            $data['reward_conf'] = json_decode(json_encode($data['reward_conf'],32),true);
            break;
            case GREAT_MEMORIES:    // 回归签到
                $actConfig = $data['greatMemoriesConfig'];
                unset($data['greatMemoriesConfig']);
                $data['extraData']['act_gap_time'] = intval($data['extraData']['act_gap_day'] * 86400);
                if ( empty($data['extraData']['reward_end_time']) )$this->response(1, '保存失败，奖励1倒计时不能为空');
                if ( empty($data['extraData']['act_gap_time']) )$this->response(1, '保存失败，再次触发活动间隔天数不能为空');
                if ( empty($actConfig) ) $this->response(1, '保存失败，阶段奖励不能为空');
                # 处理奖励
                foreach ($actConfig as $lvIdx => $lvItem) {
                    $lvStages[] = [$lvItem['lvStart'], $lvItem['lvEnd']];
                    if (empty($lvItem['stages'])) {
                        $this->response(-1 * __LINE__, "等级层级: {$lvIdx} ,未配置VIP积分层级");
                    }
                    foreach ($lvItem['stages'] as $spinsIdx => $spinsItem) {
                        if (empty($spinsItem['stages'])) {
                            $this->response(-1 * __LINE__, "等级层级: {$lvIdx} VIP积分层级: {$spinsIdx} ,未配置流失天数层级", $lvItem);
                        }

                        foreach ($spinsItem['stages'] as $shushuIdx => $shushuItem) {
                            if (empty($shushuItem['rewards'])) {
                                $this->response(-1 * __LINE__, "等级层级: {$lvIdx} VIP积分层级: {$spinsIdx} 流失天数层级: {$shushuIdx} ,未配置奖励层级");
                            }
                            foreach ($shushuItem['rewards'] as $rewardIdx => $rewardItem) {
                                if (empty($rewardItem['prizes'])) {
                                    $this->response(-1 * __LINE__, "等级层级: {$lvIdx} VIP积分层级: {$spinsIdx} 流失天数层级: {$shushuIdx} 奖励层级: {$rewardIdx} ,未配置奖励");
                                }
                            }
                        }
                    }
                }
                $data['reward_info'] = json_encode($actConfig, JSON_NUMERIC_CHECK);
                $data['extraData'] = json_encode($data['extraData'], JSON_NUMERIC_CHECK);
                break;
            case TREASURE:
                $maxStageCnt = 0;
                if(empty($data['treasure']))$this->response(1, '保存失败，奖励配置异常');
                $json = [];
                foreach ($data['treasure'] as $idx => $item){
                    $configsValue = [];
                    if(empty($item['stages']))$this->response(1, "第{$idx}层等级区间未配置Y值层");
                    $lvStages[] = [$item['start'], $item['end']];
                    foreach ($item['stages'] as $idx1 => $item1){

                        if(empty($item1['stages']))$this->response(1, "第{$idx}层等级区间，第{$idx1}层Y值区间未配置数数层");
                        foreach ($item1['stages'] as $idx2 => $item2){
                            $configsValue[$idx2]['shushu'] = array_map(function($v){return intval($v);}, $item2);

                            if(empty($item2['stages']))$this->response(1, "第{$idx}层等级区间，第{$idx1}层Y值区间，第{$idx2}层数数区间未配置关卡");
                            $maxStageCnt = max(count($item2['stages']), $maxStageCnt);
                            foreach ($item2['stages'] as $idx3 => $rewardItem){
                                $tmpPrize = array_values(json_decode(urldecode($rewardItem['prize']),true));
                                $tmpBet = array_values(json_decode(urldecode($rewardItem['bet']),true));
                                if(empty($tmpPrize) || empty($tmpBet))$this->response(1, "第{$idx}层等级区间，第{$idx1}层Y值区间，第{$idx2}层数数区间，第{$idx3}层任务未配置奖励或倍率");
                                sort($tmpBet);
                                $data['treasure'][$idx]['stages'][$idx1]['stages'][$idx2]['stages'][$idx3]['prize'] = $tmpPrize;
                                $data['treasure'][$idx]['stages'][$idx1]['stages'][$idx2]['stages'][$idx3]['bet'] = $tmpBet;
                                $configsValue[$idx2]['reward'][] = [
                                    'prize' => $tmpPrize,
                                    'bet' => $tmpBet,
                                    'frequency' => intval($rewardItem['frequency']),
                                    'target' => intval($rewardItem['target']),
                                    'taskType' => intval($rewardItem['taskType']),
                                    'id' => intval($rewardItem['id']),
                                ];
                            }
                        }
                    }
                    empty($json) && $json = $configsValue[$idx2]['reward'];
                }
                if(count($data['prdConf']) < $maxStageCnt)$this->response(1, "prd概率配置任务数:".count($data['prdConf']).",小于最大任务数:{$maxStageCnt}");
                $data['reward_info'] = json_encode($json,JSON_NUMERIC_CHECK);
                $data['extra_reward']= json_encode([
                    'fixCo' => $data['common_conf'] ?? [],
                    'waterLevelCoefficient'=>[],
                    'prdConf'=>$data['prdConf'],
                ],JSON_NUMERIC_CHECK);

                $data['extraData']   = json_encode([
                    'openLv'=> $data['treasureOpenLv'],
                    'spinsRatio'=> intval($data['spinsRatio']),
//                        'difficultyDegree'=> $data['difficultyDegree'],
//                        'taskDegree'=> $data['taskDegree'],
                    'yStages'=> $data['treasure']
                ],JSON_NUMERIC_CHECK);
                unset($data['spinsRatio'], $data['treasureWaterLevelCoefficient'],$data['prdConf'], $data['spins'], $data['spinStage'], $data['treasureShushu'], $data['difficultyDegree'], $data['taskDegree']);
                break;
            case PINATA:
                if(empty($data['pinataRewardConfig']))$this->response(-1, '保存失败，奖励配置为空');
                foreach ($data['pinataRewardConfig'] as $lvIdx => &$lvItem){
                    $lvStart = intval($lvItem['start']);
                    $lvEnd   = intval($lvItem['end']);
                    $lvStages[] = [$lvStart, $lvEnd];
                    if(empty($lvItem['stages']))$this->response(-1, "保存失败，第{$lvIdx}层等级区间配置为空");

                    foreach ($lvItem['stages'] as $spinIdx => &$spinItem){
                        if(empty($spinItem['stages']))$this->response(-1, "保存失败，第{$lvIdx}层等级区间,第{$spinIdx}层体力区间配置为空");

                        foreach ($spinItem['stages'] as $shushuIdx => &$shushuItem){
                            if(empty($shushuItem['shushu']))$shushuItem['shushu'] = [0];
                            if(empty($shushuItem['collect']))$this->response(-1, "保存失败，第{$lvIdx}层等级区间,第{$spinIdx}层体力区间,第{$shushuIdx}层数数区间，阶段配置为空");
                            if(empty($shushuItem['pinata']))$this->response(-1, "保存失败，第{$lvIdx}层等级区间,第{$spinIdx}层体力区间,第{$shushuIdx}层数数区间，关卡配置为空");
                            foreach($shushuItem['pinata'] as $stageIdx => &$stageItem){
                                if(empty($stageItem['rewards']))$this->response(-1, "保存失败，第{$lvIdx}层等级区间,第{$spinIdx}层体力区间,第{$shushuIdx}层数数区间，第{$stageIdx}关，配置为空");
                                $bonusCNt = 0;
                                foreach($stageItem['rewards'] as $pIdx => &$pItem){
                                    $pIdx++;
                                    $pItem['reward'] = @json_decode(urldecode($pItem['reward']), true) ?? [];
                                    switch ($pItem['type']){
                                        case PINATA_REWARD_TYPE_BONUS:
                                            $bonusCNt++;
                                        case PINATA_REWARD_TYPE_NORMAL:
                                            if(empty($pItem['reward']))
                                                $this->response(-1, "保存失败，第{$lvIdx}层等级区间,第{$spinIdx}层体力区间,第{$shushuIdx}层数数区间，第{$stageIdx}关，第{$pIdx}个  非纪念品奖励配置为空");
                                            break;
                                        case PINATA_REWARD_TYPE_COLLECTS:
                                            if(empty($pItem['collect_num']))
                                                $this->response(-1, "保存失败，第{$lvIdx}层等级区间,第{$spinIdx}层体力区间,第{$shushuIdx}层数数区间，第{$stageIdx}关，第{$pIdx}个  纪念品数量配置为空");
                                            break;
                                        default:$this->response(-1, "保存失败，第{$lvIdx}层等级区间,第{$spinIdx}层体力区间,第{$shushuIdx}层数数区间，第{$stageIdx}关，第{$pIdx}个  奖励类型异常：{$pItem['type']}");
                                            break;
                                    }
                                }

                            }

                            foreach($shushuItem['collect'] as $cIdx => &$cItem){
                                $cItem['rewards'] = @json_decode(urldecode($cItem['rewards']), true) ?? [];
                                if(empty($cItem['target']))$this->response(-1, "保存失败，第{$lvIdx}层等级区间,第{$spinIdx}层体力区间,第{$shushuIdx}层数数区间，第{$cIdx}阶段 阶段值为空");
                                if(empty($cItem['rewards']))$this->response(-1, "保存失败，第{$lvIdx}层等级区间,第{$spinIdx}层体力区间,第{$shushuIdx}层数数区间，第{$cIdx}阶段 奖励配置为空");
                            }
                        }
                    }
                }
                $data['extraData'] = $data['pinataRewardConfig'];
                unset($data['pinataRewardConfig']);
                break;
            default:
                if (in_array($data['type'], ActBaseModel::ACT_LIST)) {
                    ActBaseModel::getActModel($data['type'])->formatActData($data);
                    break;
                }
        }
        if($data['type'] == 'choose_one') {
            $tmp = $data['reward_conf'];
            $rewardInfo = [];
            foreach ($tmp as $k => $reward) {
                foreach ($reward as $gid => $val) {
                    $prize = isset($data['reward'][$k], $data['reward'][$k][$gid]) ? urldecode($data['reward'][$k][$gid]['prize']) : '[]';
                    $reward[$gid]['gid'] = $gid;
                    $reward[$gid]['prize'] = (array)json_decode($prize, true);
                    foreach ($reward[$gid]['prize'] as $kk => $v) {
                        if (empty($v['skin'])) {
                            unset($v['skin']);
                        }
                    }
                    $group = isset($data['scoreStage'][$k], $data['scoreStage'][$k]['gid']) ? $data['scoreStage'][$k]['gid'] : [];
                    $rewardInfo[] = ['data' => $reward, 'gid' => $group];
                }
                unset($data['reward_conf'], $data['scoreStage'], $data['reward']);
                $data['reward_info'] = json_encode($rewardInfo, JSON_NUMERIC_CHECK);
                break;
            }
        }
        if($data['type'] == 'spin_safe'){
            $reward_conf = [
                "one_hit"   => intval($data['one_hit']),//一连
                "two_hit"   => intval($data['two_hit']),//二连
                "three_hit" => intval($data['three_hit']),//三连
                "groupId"   => 10,
            ];
        }
        else if($data['type'] == 'one_plus_gift'){
            $reward_conf = [
                'maxNum' => intval($data['maxNum']), //最大购买次数
            ];
        }
        else{
            $reward_conf = @$data['reward_conf'];
        }
        $common_conf = $data['common_conf'] ?? [];
        if($data['type'] == 'speed_spins'){
            if(!in_array($reward_conf['bet'],[2,3,4,5])){
                $this->response(1, '保存失败，倍率只能取2,3,4,5');
            }
        }
        $data['reward_conf'] = json_encode($reward_conf ?? [], JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK);
        unset($data['confType'],$data['attack_success'],$data['attack_break'],$data['three_hit'],$data['three_hit'],$data['steal_success'],$data['steal_break'],$data['two_hit'],$data['one_hit'],$data['groupId'],$data['one_steal'],$data['two_steal'],$data['one_attack'],$data['two_attack'],$data['groupRid'],$data['maxNum']);
        //老虎机概率配置
        $data['reward_pro'] = !empty($data['pro'])?json_encode($data['pro'], 32):'';
        unset($data['pro']);
        //reward 配置项
        if($data['type'] == 'discounts_architecture'){
            if(empty($data['reward_conf'])
                ||empty($data['reward'])
            )$this->response(1, '保存失败，奖励配置异常' . __LINE__);

            $data['reward_info'] = json_encode($data['reward'],256);
            $data['reward_conf'] = $data['reward_conf'];
        }
        //含阶段奖励详细列表architecture(建筑大师),accumulated_pay(累计充值))
        if(in_array($data['type'],["daily_chest","architecture","accumulated_pay","crazy_bet","crazy_card_group"])){
            if(empty($data['reward'])) $this->response(1, '保存失败，奖励配置-不为空');
            $statucRewards =[];
            foreach ($data['reward'] as $k => $v) {
                if($v['prize']!="{}"&&$v['prize']!='null'&&!empty($v['prize'])){
                    $v['prize']=urldecode($v['prize']);
                    $data['reward'][$k]['prize'] =json_decode($v['prize']);
                    if($data['type']=='architecture'){//建筑大师活动券静态海报配置
                        $statucRewards[] =["key"=>$v["lv"],"value"=>ActivityModel::getPropsShowArr(json_decode($v['prize'],true),$v["lv"])];
                    }
                }
            }
            if($statucRewards){
                $staticArr["rewards"] = $statucRewards;
                $staticArr["act_coupon_skin"] = $data['act_coupon_skin'];
                $staticArr["type"] = 'architecture';
            }

            if($data['type'] == 'daily_chest'){
                $data['reward_conf'] = isset($data['reward'][1]) ? json_encode($data['reward'][1]) : [];
            }elseif($data['type'] == 'callback_score'){
                $data['reward_info'] = isset($data['reward']) ? $data['reward'] : [];
                $data['extra_reward'] = isset($data['extra_reward'])?json_encode($data['extra_reward']):[];
            }elseif($data['type'] == 'crazy_bet'){
                if ($data['reward']['conf'][1]['spinsLimit']=='undefined'){
                    $this->response(1, '保存失败，奖励配置异常, Code Line:' . __LINE__);
                }
                $data['reward_info'] = !empty($data['reward'])?json_encode($data['reward'],256):'';
            }else{
                $data['reward_info'] = !empty($data['reward'])?json_encode($data['reward'],256):'';
            }
        }
//        $this->response(1, '666',$staticArr);

        //金币大爆炸 倍率配置
        if($data['type'] == "coin_blast"){
            $typeMap = [
                0 => 'steal',
                1 => 'attack',
                2 => 'slot'
            ];
            $rewardInfo = [];
            foreach ($typeMap as $k => $v){
                if (empty($data['reward'][$k]['bet']))$this->response(1, "保存失败，奖励配置异常 k:{$k} line:".__LINE__);
                $rewardInfo[] = [
                    'type' => $v,
                    'bet'  => $data['reward'][$k]['bet'] ,//$data['reward'][$k]['bet'],
                ];
            }
            $data['reward_info'] = json_encode($rewardInfo);
        }
        unset($data['reward']);

        //连环礼包分积分阶段,超级气球bet分阶段
        $haveStageA = in_array($data['type'],['super_balloon']);
//        $haveStageB = $data['type']=='rank'&&$reward_conf['confType']>0?false:true;//兼容老版本锦标赛数据结构
        if($haveStageA){
            $index = count($data['rewardnew']);
            if($index<=0||empty($data['rewardnew'][1])){
                $this->response(1, '保存失败，奖励配置-分体力/分积分/分bet配置奖励不为空');
            }
            $nrconf = [];
            if($index>0){
                $scstage = $data['spinStage'];
                for ($i=1;$i<=$index;$i++){
                    if($scstage[$i]['star']>=$scstage[$i]['end']||intval($scstage[$i]['end'])==0){
                        $this->response(1, '保存失败，奖励配置-分体力或积分配置区间异常');
                    }
                    $nrconf[$i]['star'] = $scstage[$i]['star'];
                    $nrconf[$i]['end']  = $scstage[$i]['end'];

                    foreach ($data['rewardnew'][$i] as $k => $v) {
                        $nrconf[$i]['list'][$v['stage']]=$v;
                        if($v['prize']!="{}"&&$v['prize']!='null'&&!empty($v['prize'])){
                            $nrconf[$i]['list'][$v['stage']]['prize'] =json_decode($v['prize']);

                            #校验需要皮肤的奖励是否配置皮肤
                            foreach ($nrconf[$i]['list'][$v['stage']]['prize'] as $prizeItem){
                                if(in_array($prizeItem->type, $this->needSkinRewards) && empty($prizeItem->skin) && !$isImport){
//                                    $this->response(1, '保存失败，需要配置皮肤的奖励未配置皮肤');
                                }
                            }
                        }
                    }
                }
            }
            if($data['type']=='rank' || $data['type']=='rank2'){
                $data['reward_info'] = !empty($nrconf)?json_encode($nrconf):'';
            }else{
                $data['extra_reward'] = !empty($nrconf)?json_encode($nrconf,256):'';
                if(isset($data['scoreCGType'])){
                    $data['reward_info'] = json_encode(['scoreCGType' => $data['scoreCGType']]);
                }
            }

            unset($data['spinStage']);
            unset($data['scoreStage']);
            unset($data['scoreCGType']);
            unset($data['rewardnew']);
        }
        //超级气球
        if($data['type']=='super_balloon'){
            $balloonSet =[
                'moveType'=>intval($data['moveType']),
                'speed'=>intval($data['speed']),
                'outPut'=>$data['outPut'],
                "showPv"=>$data['showPv']

            ];
            unset($data['moveType'],$data['speed'],$data['outPut'],$data['showPv']);
            $data['extraData'] = json_encode($balloonSet,32);
        }

        //二选一礼包
        if($data['type']=='choose_one'){
            $data['extra_reward'] = isset($data['extra_reward'])?json_encode($data['extra_reward']):[];
        }

        $data['user_level_section'] = "{$data['s_lv']}-{$data['e_lv']}";//等级区间
        $data['user_vip_section'] ="{$data['s_vip']}-{$data['e_vip']}";//vip区间
        $data['user_score_section'] ="{$data['s_score']}-{$data['e_score']}";//分数区间

        //开始及结束时间
        $times = explode(" - ",$data['sn_time']);
        $data['start_time'] =strtotime(date('YmdHi',strtotime($times[0])));//只能精确到分钟
        $data['end_time']   =strtotime(date('YmdHi',strtotime($times[1])));//只能精确到分钟
        if($data['end_time'] <= $data['start_time'])$this->response(1, "保存失败，结束时间不大于开始时间");
        unset($data['sn_time']);
        //领奖及关闭时间
        $data['reward_time'] = strtotime($data['reward_time']);
        $data['lock_time'] = @strtotime($data['lock_time']);

        //国家控制
        $data['country'] = @json_encode($data['country'] ?? []);

        //资源
        $data['bname'] = json_encode($data['bname'],256);
        $data['show_title'] = json_encode($data['show_title'],256);

        $goldenCard = @$data['goldenCard'];
        if(!empty($goldenCard)){
            $data['extraData'] = json_encode($goldenCard,JSON_NUMERIC_CHECK);
        }
        if(isset($data['safeLimit'])){
            foreach ($data['safeLimit'] as $key=>$row){
                $temp = $row;
                $temp['prize'] = json_decode($temp['prize'],true);
                $json[] = $temp;
            }
            $data['reward_info'] = json_encode($json,JSON_NUMERIC_CHECK);
            $data['extra_reward'] = json_encode([
                'limit'  => array_values($data['limit']),
                'config' => array_values($data['config']),
                'n'      => $data['steelSafeN'],
            ],JSON_NUMERIC_CHECK);
        }
        if(isset($data['premium'])){
            $data['reward_conf'] = json_encode([
                'spins'    => $data['premiumSpins'],
                'groupArr' => array_values($data['premium'])
            ],JSON_NUMERIC_CHECK);
        }
        if(isset($data['trafficPermitBet'])){
            $data['extraData'] = json_encode([
                'bet'    => $data['trafficPermitBet'],
            ],JSON_NUMERIC_CHECK);
        }
        if(isset($data['chooseOne'])){
            foreach ($data['chooseOne'] as $key=>$row){
                $temp = $row;
                $temp['prize'] = json_decode($temp['prize'],true);
                $json[] = $temp;
            }
            $data['reward_info'] = json_encode(array_column($json,null,'gid'),JSON_NUMERIC_CHECK);
        }

        if(isset($data['fund'])){
            foreach ($data['fund'] as $key=>$row){
                $temp = $row;
                $temp['prize'] = json_decode($temp['prize'],true);
                $json[] = $temp;
            }
            $data['reward_info'] = json_encode($json,JSON_NUMERIC_CHECK);
            $rewardConf = [];
            $data['reward_conf'] = (array)json_decode($data['reward_conf'], true);
            foreach($data['reward_conf'] as $k => $v){
                if(isset($data['cond'][$k]) && !empty($data['scoreStage'])){
                    $data['scoreStage'][$k] = $data['cond'][$k];
                }
                $rewardConf[$k] = [
                    'data' => $v,
                    'gid' => isset($data['scoreStage'], $data['scoreStage'][$k]['gid']) ? $data['scoreStage'][$k]['gid'] : [0],
                ];
            }
            unset($data['scoreStage'], $data['cond']);
            $data['reward_conf'] = json_encode($rewardConf, JSON_NUMERIC_CHECK);
        }

        $unsetArr = ["trafficPermitMaxLevelExpGap","common_conf","fund","chooseOne","trafficPermitBet","goldenCard",'vipSet','spinsSet','robot','setType','vipSetSpins','spinsSetSpins','treasure','spins','trafficPermit', 'trafficPermitTask', 'trafficPermitTask2', 'trafficPermitOpenLv','trafficPermitGuideLv', 'trafficPermitUpLv','trafficPermitPassExp', 'trafficPermitItemColor','trafficPermitIconColor','treasureOpenLv','safeLimit','limit','config','steelSafeN','premium','premiumSpins',"rankLimit","rank2"];
        foreach ($unsetArr as $key){
            unset($data[$key]);
        }

        //数据验证
//        if($data['type']=='rank' || $data['type']=='rank2'){
//            if($data['reward_time']>$data['end_time']-280||!$data['reward_time']||!$data['end_time']||$data['reward_time']>=$data['end_time']||$data['reward_time']<=$data['start_time']){
//                $this->response(1, '结束时间与领奖时间间隔异常，请重新填写');
//            }
//            if(!$data['extra_reward']){
//                $this->response(1, '保存失败，排行榜奖励不为空');
//            }
//        }
        if($data['type']=='time_limit_invite'){
            if($data['reward_time']>$data['end_time']||$data['reward_time']<$data['start_time'])
                $this->response(1, '限时邀请-领奖时间!!!必须大于开始时间且小于结束时间');
            $data['reward_time'] = $data['end_time'];
            if(
                empty($data['timelimitInviteConf'])
                || empty($data['timelimitInvite'])
                || (count($data['timelimitInviteConf']) != count($data['timelimitInvite']))
            )$this->response(1, '保存失败，奖励配置异常' . __LINE__);
            $data['reward_conf'] = [];
            $data['reward_info'] = [];
            $extraRewards = [];
            foreach ($data['timelimitInvite'] as $idx1 => $items1){
                if(
                    empty($data['timelimitInviteConf'][$idx1]['shushu'])
                    || empty($data['timelimitInviteConf'][$idx1]['type'])
                )$this->response(1, '保存失败，奖励配置异常' . __LINE__);
                $shushuGroups = array_map(function($v){return intval($v);}, $data['timelimitInviteConf'][$idx1]['shushu']);
                $extraRewards[$idx1] = [
                    'shushu' => $shushuGroups,
                    'type'   => $data['timelimitInviteConf'][$idx1]['type'],
                    'ext_num'   => $data['timelimitInviteConf'][$idx1]['ext_num'],
                    'url'       => $data['timelimitInviteConf'][$idx1]['url'],
                    'msgId'   => $data['timelimitInviteConf'][$idx1]['msgId'],
                ];
                foreach ($items1 as $idx2 => $item2){
                    $items1[$idx2]['isShare'] = intval($item2['isShare']);
                    $items1[$idx2]['prize'] = json_decode(urldecode($item2['prize']), true);
                }
                if(empty($data['reward_info']))$data['reward_info'] = json_encode($items1);
                if(empty($data['reward_conf']))$data['reward_conf'] = json_encode([
                        'type' => $data['timelimitInviteConf'][$idx1]['type'],
                        'ext_num' => $data['timelimitInviteConf'][$idx1]['ext_num']]
                );
                $extraRewards[$idx1]['reward'] = $items1;
            }
            $data['extra_reward'] = json_encode($extraRewards);
            unset($data['timelimitInviteConf']);
            unset($data['timelimitInvite']);
        }
        if(empty($data['name'])){
            $this->response(1, '保存失败，请填写第一项-活动名称');
        }
//        if(in_array($data['type'],["rank"])&&empty($data['reward_info'])){
//            $this->response(1, '保存失败，阶段奖励不为空');
//        }

        //支持自动创建的活动类型
        $authType =["balloon","super_balloon","architecture","discounts_architecture","speed_spins","card","treasure","crazy_bet","crazy_card_group","golden_card_trade","coin_blast","rank","rank2"];
        $authDays = in_array($data['type'],$authType)&&$data['uc_type']!=1?intval($data['authDays']):0;
        unset($data['authDays']);
        //版本控制
        $data['act_version'] = $data['act_version'] ?? [];
        $data['act_version'] = json_encode($data['act_version']);
        $stime = $data['start_time'];$etime = $data['end_time'];$rtime = $data['reward_time'];

        if(!empty($lvStages)){
            $preItem = [];
            $isLessThanSlv = $isBiggerThanElv = false;
            foreach ($lvStages as $lvs){
                list($min, $max) = $lvs;
                if(!empty($preMax) && ($preMax+1) != $min){
                    $this->response(-1 * __LINE__, "等级区间不连续:{$preMax}-{$min}");
                }
                $preMax = $max;
                if($min <= $data['s_lv'])$isLessThanSlv = true;
                if($max >= $data['e_lv'])$isBiggerThanElv = true;
            }
            if(!$isLessThanSlv || !$isBiggerThanElv)
                $this->response(-1 * __LINE__, "等级区间配置未包含所有开放等级", [ $data['s_lv'],  $data['e_lv'],$lvStages]);
        }

        if (isset($data['extraData']) && is_array($data['extraData'])) {
            $data['extraData'] = json_encode($data['extraData'], JSON_NUMERIC_CHECK);
        }

        // 不在客户端可选的活动类型 客户端类型是全部
        if(!in_array($data['type'], CLIENT_FILTERED_ACT_TYPES)){
            $data['client'] = 0;
        }
        unset($data['s_lv'],$data['e_lv'],$data['s_vip'],$data['e_vip'],$data['s_score'],$data['e_score']);
        for ($i=0;$i<=$authDays;$i++){//循环创建活动
            $data['start_time'] = $stime+$i*86400;
            $data['end_time'] = $etime+$i*86400;
            if(in_array($data['type'],["rank","rank2"])){
                $data['reward_time'] = $rtime+$i*86400;
            }

            $uniqid = 'ACTIVITY_CFG:'.uniqid().':'.time();
            $postData = [];
            $postData['frombg'] = '1';
            $postData['lid'] = '1';
            $postData['sid'] = '1';
            $postData['mod'] = 'Activitynew';
            $postData['act'] = 'saveActivity';
            $postData['uniqidKey'] = $uniqid;
            $activityCfg = array_merge($data, $postData);
            unset($activityCfg['addTimeLimitDefaultHours']);
            oo::commonOprRedis('statistics')->hMset($uniqid, $activityCfg);
            $res = $this->curl->req($this->_url, $postData);
            $ret = json_decode($res,true);
            $activityId = empty($ret['data']['id'])?$data['id']:$ret['data']['id'];
            $data['aid'] = $activityId;
            oo::logs()->adminlog($this->router->fetch_method()."--活动类型：{$data['type']}活动：{$activityId}");

            if(empty($ret['code'])){
                $this->response(1, $ret['msg']);
            }
            $this->writeActConfCache($data);
            if($data['uc_type']==1&&!empty($staticArr)){
                $this->savePlacardStaticCfg($activityId,$staticArr);
            }
            unset($data['aid']);

            ActivityModel::setCommonConf($activityId, $commonConf);
        }

        //生成对应活动的md5下发缓存
        if(!empty($data['imgName'])){
            $md5Jons = oo::commonOprModel('FileMd5')->getActMd5Files($data['imgName']);
            if(!empty($md5Jons)){
                $expire = $data['end_time'] - time() + 60; //活动到期结束
                oo::commonOprRedis('games')->setex(okeys::activityM5Json($activityId), json_encode($md5Jons), $expire);
                oo::logs()->adminlog($this->router->fetch_method()."--写md5动态缓存失败,活动：{$activityId}");
            }
        }
        $this->response(0, $ret['msg'], $data);
    }

    //奖励海报配置
    public function savePlacardStaticCfg($aid,$data){
        $this->staticPath =  $this->staticPath."actPlacard/";
        $this->SaveJson($data,$aid.".json");
    }

    private function writeActConfCacheToDB($aid = 0){
        $aid = intval($aid);
        if(empty($aid))return;
        # redis key
        $conditionKeys   = okeys::activityConditionKeys($aid);
        $stageRewardKeys = okeys::activityRewardsStageKeys($aid);

        #表名
        $conditionTable = otable::actStageConditionConf();
        $rewardsTable = otable::actStageRewardsConf();

        # 清除老数据
        oo::commonOprDb('games')->query("delete from {$conditionTable} where aid={$aid}");
        oo::commonOprDb('games')->query("delete from {$rewardsTable} where aid={$aid}");
        # 获取redis 数据 写入数据库
        # condition数据
        $conditionConfig = oo::commonOprRedis('games')->hgetall($conditionKeys);
        foreach ((array)$conditionConfig as $stage => $condition){
            $conditionConfig[$stage] = json_decode($condition, true);
        }
        $conditionConfig = json_encode($conditionConfig, 32);
        $insertSql = "insert into {$conditionTable} (`aid`, `condition`) values ({$aid}, '{$conditionConfig}')";

        oo::commonOprDb('games')->query($insertSql);
        # rewards数据
        $rewardsConfig = oo::commonOprRedis('games')->hgetall($stageRewardKeys);
        if(!empty($rewardsConfig) && is_array($rewardsConfig)){
            $insertSql = "insert into {$rewardsTable} (`aid`,`stage`, `rewards`) values ";
            foreach ($rewardsConfig as $stage => $rewards){
                $insertSql .= " ({$aid}, '{$stage}', '{$rewards}'),";
            }
            $insertSql = trim($insertSql, ',');
            oo::commonOprDb('games')->query($insertSql);
        }
    }
    private function writeActConfCache($data){
        # 删除旧数据
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        oo::commonOprRedis('games')->expire($conditionKeys, 0);
        oo::commonOprRedis('games')->expire($stageRewardKeys, 0);
        switch ($data['type']){
            case 'super_collect':
                $this->writeSuperCollectConfCache($data);
                break;
            case SPINS_MASTER:
                $this->writeSpinsMasterConfCache($data);
                break;
            case 'time_limit_invite':
                $this->writeTimeLimitInviteConfCache($data);
                break;
            case 'collect_jigsw':
                $this->writeJigsawConfCache($data);
                break;
            case SUPER_SERIAL_PACK:
            case SUPER_SERIAL_PACK2:
            case SUPER_SERIAL_PACK3:
            case SUPER_SERIAL_PACK4:
            case SUPER_SERIAL_PACK5:
            case SUPER_SERIAL_PACK6:
            case SUPER_SERIAL_PACK7:
                $this->writeSuperSerialPackConfCache($data);
                break;
            case 'theme_pack':
            case 'theme_pack2':
                $this->writeThemePackConfCache($data);
                break;
            case 'shop_promotion':
                $this->writeShopPromotionConfCache($data);
                break;
            case 'safe_surprise':
                $this->writeSafeSurpriseConfCache($data);
                break;
            case 'pick_one':
                $this->writeChooseOneConfCache($data);
                break;
            case 'choose_you_want':
                $this->writechooseYouWantConfCache($data);
                break;
            case 'fox_hammer':
                $this->writeFoxHammerConfCache($data);
                break;
            case 'one_plus_gift':
                $this->writeOnePlusGiftConfCache($data);
                break;
            case 'callback_score':
                $this->writeCallbackScoreConfCache($data);
                break;
            case LUCKY_FOX:
                $this->writeLuckyFoxConfCache($data);
                break;
            case SUPER_BOMB:
                $this->writeSuperBombConfCache($data);
                break;
            case SUPER_GASHAPON:
                ActivityModel::writeSuperGashaponConfCache($data);
                break;
            case CRAZY_BUILD:
                ActivityModel::writeCrazyBuildConfCache($data);
                break;
            case DRIFT_TREASURE:
            case TRAVEL_DIARY:    // 漂流的宝藏,旅行日记
                ActivityModel::writeDriftTreasureConfCache($data);
                break;
            case EASTER_EGG:
                $this->writeEasterEggConfCache($data);
                break;
            case GREAT_MEMORIES:
                $this->writeEasterGreatMemoriesCache($data);
                break;
            case TREASURE:
                $this->writeTreasureConfCache($data);
                break;
            case PINATA:
                $this->writePinataConfCache($data);
                break;
            case RANK:
            case RANK2:
            case BUILD_RANK:
            case BUILD_RANK2:
                $this->writeBuildRankConfCache($data);
                break;
            default:
                if (in_array($data['type'],ActBaseModel::ACT_LIST)){
                    ActBaseModel::getActModel($data['type'])->writeActCache($data);
                    break;
                }
                return;
        }

        $this->writeActConfCacheToDB($data['aid']);
    }
    private function writeShopPromotionConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_conf'], true);
        foreach ($extraReward as $idx1 => $item1){
            foreach ($item1['stages'] as $idx2 => $item2){
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = [
                    'start' => intval($item1['start']),
                    'end' => intval($item1['end']),
                    'shushu' => $item2['shushu'],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions, 32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['data'], 32));
            }
        }
        $expireTime = max($data['end_time'] , time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }
    private function writeThemePackConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_conf'], true);
        foreach ($extraReward as $idx1 => $item1){
            foreach ($item1['stages'] as $idx2 => $item2){
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = [
                    'start' => intval($item1['start']),
                    'end' => intval($item1['end']),
                    'shushu' => $item2['shushu'],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions, 32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['list'], 32));
            }
        }
        $expireTime = max($data['end_time'] , time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }
    private function writeSuperSerialPackConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['extra_reward'], true);
        foreach ($extraReward as $idx1 => $item1){
            foreach ($item1['stages'] as $idx2 => $item2){
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = [
                    'start' => $item1['start']?intval($item1['start']):0,
                    'end' => $item1['end'],
                    'shushu' => $item2['shushu'],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions, 32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['list'], 32));
            }
        }
        $expireTime = max($data['end_time'] , time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }

    private function writeLuckyFoxConfCache($data)
    {
        $conditionKeys = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $rewardInfo = json_decode($data['reward_info'], true);
        $stageConditions = [];
        foreach ($rewardInfo as $idx1 => $item1) {
            $stageConditions[CONDITION_TYPE_LV] = [
                'start' =>  $item1['lvStart'],
                'end' =>  $item1['lvEnd'],
                'type' =>  CONDITION_TYPE_LV,
                'shushu' => [],
            ];
            foreach ($item1['stages'] as $idx2 => $item2) {
                $stageKey = "{$idx1}_{$idx2}";

                $stageConditions[CONDITION_TYPE_SPINS] = [
                    'start' =>  $item2['spinsStart'],
                    'end' =>  $item2['spinsEnd'],
                    'type' =>  CONDITION_TYPE_SPINS,
                    'shushu' => [],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode(array_values($stageConditions), 32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['list'], 32));
            }
        }
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }

    private function writeSuperBombConfCache($data)
    {
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        oo::commonOprRedis('games')->hset($stageRewardKeys, 1, $data['reward_info']);

        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }
    private function writeMayaWheelConfCache($data)
    {
        $conditionKeys = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraData = json_decode($data['extraData'], true);
        $mayaTotalCnt = $extraData['mayaWheelTotalCnt'];
        $mayaWheelSpend = $extraData['mayaWheelSpend'];
        $config = $extraData['rewards'] ?? [];
        foreach ($config as $idx1 => $items1){
            $condition = [];
            $lvStart = intval($items1['start']);
            $lvEnd   = intval($items1['end']);
            $condition[CONDITION_TYPE_LV] = [
                'shushu' => [],
                'start' => $lvStart,
                'end' => $lvEnd,
                'type' => CONDITION_TYPE_LV,
            ];
            foreach($items1['spinStages'] as $idx2 => $items2){
                $spinsStart = $items2['start'];
                $spinsEnd   = $items2['end'];
                $condition[CONDITION_TYPE_SPINS] = [
                    'shushu' => [],
                    'start' => $spinsStart,
                    'end' => $spinsEnd,
                    'type' => CONDITION_TYPE_SPINS,
                ];
                $stageRewardsConfig = [];
                foreach ($items2['rewards'] as $idx3 => $items3){
                    $rewardsConfig = [];
                    foreach ($items3['list'] as $idx4 => $items4){
                        $prize = @json_decode(urldecode($items4['prize']), true) ?? [];
                        if(empty($prize))$this->response(1, "保存失败，{$idx1}-{$idx2}-{$idx3}-{$idx4} 奖励配置为空" );
                        $rewardsConfig[] = [
                            'weight' => intval($items4['weight']),
                            'lastCnt' => intval($items4['lastCnt']),
                            'prize' => $prize,
                        ];
                    }
                    $stageRewardsConfig[$idx3] = [
                        'totalCnt' => $mayaTotalCnt,
                        'spendConfig' => $mayaWheelSpend,
                        'rewardConfig' => $rewardsConfig
                    ];
                }
                $idx = "{$idx1}_{$idx2}";
                oo::commonOprRedis('games')->hset($stageRewardKeys, $idx, json_encode($stageRewardsConfig, 32));
                oo::commonOprRedis('games')->hset($conditionKeys, $idx, json_encode(array_values($condition), 32));
            }
        }
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }

    private function writeSuperCollectConfCache($data)
    {
        $conditionKeys = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_info'], true);
        foreach ($extraReward as $idx1 => $item1) {
            foreach ($item1['stages'] as $idx2 => $item2) {
                foreach ($item2['stages'] as $idx3 => $item3) {
                    $stageKey = "{$idx1}_{$idx2}_{$idx3}";
                    $stageConditions = [
                        [
                            "start" => $item1['lvStart'],
                            "end" => $item1['lvEnd'],
                            "shushu" => [],
                            "type" => CONDITION_TYPE_LV
                        ],
                        [
                            "start" => $item2['spinsStart'],
                            "end" => $item2['spinsEnd'],
                            "shushu" => [],
                            "type" => CONDITION_TYPE_SPINS
                        ],
                        [
                            "start" => 0,
                            "end" => 0,
                            'shushu' => $item3['shushu'],
                            "type" => CONDITION_TYPE_SHUSHU
                        ],
                    ];
                    oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions, JSON_NUMERIC_CHECK));
                    oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item3['list'], JSON_NUMERIC_CHECK));
                }
            }
        }
        $expireTime = max($data['end_time'] , time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }
    private function writeSpinsMasterConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['extra_reward'], true);
        foreach ($extraReward as $idx1 => $item1) {
            foreach ($item1['stages'] as $idx2 => $item2) {
                foreach ($item2['stages'] as $idx3 => $item3) {
                    $stageKey = "{$idx1}_{$idx2}_{$idx3}";
                    $stageConditions = [
                        [
                            "start" => $item1['lvStart'],
                            "end" => $item1['lvEnd'],
                            "shushu" => [],
                            "type" => CONDITION_TYPE_LV
                        ],
                        [
                            "start" => $item2['spinsStart'],
                            "end" => $item2['spinsEnd'],
                            "shushu" => [],
                            "type" => CONDITION_TYPE_SPINS
                        ],
                        [
                            "start" => 0,
                            "end" => 0,
                            'shushu' => $item3['shushu'],
                            "type" => CONDITION_TYPE_SHUSHU
                        ],
                    ];
                    oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions, JSON_NUMERIC_CHECK));
                    oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item3['reward'], JSON_NUMERIC_CHECK));
                }
            }
        }

        $expireTime = max($data['end_time'] , time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }
    private function writeTimeLimitInviteConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['extra_reward'], true);
        foreach ($extraReward as $idx1 => $item1){
            $stageConditions = [
                'shushu' => $item1['shushu'],
            ];
            unset($item1['shushu']);
            oo::commonOprRedis('games')->hset($conditionKeys, $idx1, json_encode($stageConditions, 32));
            oo::commonOprRedis('games')->hset($stageRewardKeys, $idx1, json_encode($item1, 32));
        }
        $expireTime = max($data['end_time']+3600 , time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }
    private function writeJigsawConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_info'], true);
        foreach ($extraReward as $idx1 => $item1) {
            foreach ($item1['stages'] as $idx2 => $item2) {
                foreach ($item2['stages'] as $idx3 => $item3) {
                    $stageKey = "{$idx1}_{$idx2}_{$idx3}";
                    $stageConditions = [
                        [
                            "start" => $item1['lvStart'],
                            "end" => $item1['lvEnd'],
                            "shushu" => [],
                            "type" => CONDITION_TYPE_LV
                        ],
                        [
                            "start" => $item2['spinsStart'],
                            "end" => $item2['spinsEnd'],
                            "shushu" => [],
                            "type" => CONDITION_TYPE_SPINS
                        ],
                        [
                            "start" => 0,
                            "end" => 0,
                            'shushu' => $item3['shushu'],
                            "type" => CONDITION_TYPE_SHUSHU
                        ],
                    ];
                    oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions, JSON_NUMERIC_CHECK));
                    oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item3['reward'], JSON_NUMERIC_CHECK));
                }
            }
        }
        $expireTime = max($data['end_time'] + 3600 * 24 * 7, time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }
    private function writeRankConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        oo::commonOprRedis('games')->delete([$conditionKeys,$stageRewardKeys]);
        $extraReward = json_decode($data['reward_info'], true);
        foreach ($extraReward as $idx1 => $item1){
            foreach ($item1['stages'] as $idx2 => $item2){
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = [
                    'start' => $item1['start']?intval($item1['start']):0,
                    'end' => $item1['end'],
                    'shushu' => $item2['shushu'],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions, 32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['list'], 32));
            }
        }
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
    }
    private function writeSafeSurpriseConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_info'], true);
        foreach ($extraReward as $idx1 => $item1){
            foreach ($item1['data'] as $idx2 => $item2){
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = [
                    'start' => intval($item1['start']),
                    'end' => intval($item1['end']),
                    'shushu' => $item2['shushu'],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['data'],32));
            }
        }
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }
    private function writeChooseOneConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_info'], true);
        foreach ($extraReward as $idx1 => $item1){
            foreach ($item1['data'] as $idx2 => $item2){
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = [
                    'start' => intval($item1['start']),
                    'end' => intval($item1['end']),
                    'shushu' => $item2['shushu'],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['data'],32));
            }
        }
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
        return true;
    }
    private function writechooseYouWantConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_info'], true);
        foreach ($extraReward as $idx1 => $item1){
            foreach ($item1['data'] as $idx2 => $item2){
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = [
                    'start' => intval($item1['start']),
                    'end' => intval($item1['end']),
                    'shushu' => $item2['shushu'],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['data'],32));
//                return $this->response(1, "ttt",$stageConditions);
            }
        }
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
    }
    private function writeFoxHammerConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_info'], true);

        foreach ($extraReward as $idx1 => $item1){
            foreach ($item1['data'] as $idx2 => $item2){
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = [
                    'start' => intval($item1['start']),
                    'end' => intval($item1['end']),
                    'shushu' => $item2['shushu'],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['data'],32));
//                return $this->response(1, "ttt",$stageConditions);
            }
        }
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
    }
    private function writeOnePlusGiftConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_info'], true);

        foreach ($extraReward as $idx1 => $item1){
            foreach ($item1['data'] as $idx2 => $item2){
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = [
                    'start' => intval($item1['start']),
                    'end' => intval($item1['end']),
                    'shushu' => $item2['shushu'],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['data'],32));
//                return $this->response(1, "ttt",$stageConditions);
            }
        }
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
    }
    private function writeCallbackScoreConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_info'], true);
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        foreach ($extraReward as $idx1 => $item1){
            foreach ($item1['data'] as $idx2 => $item2){
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = [
                    'start' => intval($item1['start']),
                    'end' => intval($item1['end']),
                    'shushu' => $item2['shushu'],
                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['data'],32));
//                return $this->response(1, "ttt",$stageConditions);
            }
        }
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
    }
    private function writeEasterEggConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['extra_reward'], true);
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        foreach ($extraReward as $idx1 => $item1){
            $condition = [
                CONDITION_TYPE_LV =>  [
                    'shushu' => [],
                    'start' => $item1['start'],
                    'end' => $item1['end'],
                    'type' => CONDITION_TYPE_LV,
                ],
            ];
            foreach ($item1['shushuStages'] as $idx2 => $item2){
                $condition[CONDITION_TYPE_SHUSHU] = [
                    'shushu' => $item2['shushu'],
                    'start' => 0,
                    'end' => 0,
                    'type' => CONDITION_TYPE_SHUSHU,
                ];
                $stageKey = "{$idx1}_{$idx2}";
                $stageConditions = array_values($condition);
                unset($item2['shushu']);
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2,32));
            }
        }
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
    }
    private function writeEasterGreatMemoriesCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_info'], true);
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        foreach ($extraReward as $idx1 => $item1){
            $condition = [
                CONDITION_TYPE_LV =>  [
                    'shushu' => [],
                    'start' => $item1['lvStart'],
                    'end' => $item1['lvEnd'],
                    'type' => CONDITION_TYPE_LV,
                ],
            ];
            foreach ($item1['stages'] as $idx2 => $item2){
                $condition[CONDITION_TYPE_VIP_POINT] = [
                    'shushu' => [],
                    'start' => $item2['VipStart'],
                    'end' => $item2['VipEnd'],
                    'type' => CONDITION_TYPE_VIP_POINT,
                ];


                foreach ($item2['stages'] as $idx3 => $item3){
                    $condition[CONDITION_TYPE_LOST_HOUR] = [
                        'shushu' => [],
                        'start' => $item3['lostDayStart'],
                        'end' => $item3['lostDayEnd'],
                        'type' => CONDITION_TYPE_LOST_HOUR,
                    ];

                    $stageKey = "{$idx1}_{$idx2}_{$idx3}";
                    $stageConditions = array_values($condition);
                    unset($item3['lostDayStart']);
                    unset($item3['lostDayEnd']);
                    oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                    oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item3,32));
                }
            }
        }
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
    }
    private function writeTreasureConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['extraData'], true) ?? [];
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        foreach ($extraReward['yStages'] as $idx1 => $item1){
            $condition = [
                CONDITION_TYPE_LV =>  [
                    'shushu' => [],
                    'start' => $item1['start'],
                    'end' => $item1['end'],
                    'type' => CONDITION_TYPE_LV,
                ],
            ];
            foreach ($item1['stages'] as $idx2 => $item2){
                $condition[CONDITION_TYPE_COIN_Y] = [
                    'shushu' => [],
                    'start' => $item2['start'],
                    'end' => $item2['end'],
                    'type' => CONDITION_TYPE_COIN_Y,
                ];


                foreach ($item2['stages'] as $idx3 => $item3){
                    $condition[CONDITION_TYPE_SHUSHU] = [
                        'shushu' => $item3['shushu'],
                        'start' => 0,
                        'end' => 0,
                        'type' => CONDITION_TYPE_SHUSHU,
                    ];

                    $stageKey = "{$idx1}_{$idx2}_{$idx3}";
                    $stageConditions = array_values($condition);
                    unset($item3['start']);
                    unset($item3['end']);
                    oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                    oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item3['stages'],32));
                }
            }
        }
        $SpinsRatioKey   = okeys::treasureSpinsRatio($data['aid']);
        oo::commonOprRedis('games')->set($SpinsRatioKey, $extraReward['spinsRatio']);
        oo::commonOprRedis('games')->expireAt($SpinsRatioKey, oo::redisRandomExpire($expireTime));

        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
    }
    private function writeBuildRankConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_pro'], true) ?? [];
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        foreach ($extraReward as $idx1 => $item1){
            $condition = [
                CONDITION_TYPE_LV =>  [
                    'shushu' => [],
                    'start' => $item1['start'],
                    'end' => $item1['end'],
                    'type' => CONDITION_TYPE_LV,
                ],
            ];
            foreach ($item1['stages'] as $idx2 => $item2){
                $condition[CONDITION_TYPE_SPINS] = [
                    'shushu' => [],
                    'start' => $item2['start'],
                    'end' => $item2['end'],
                    'type' => CONDITION_TYPE_SPINS,
                ];


                foreach ($item2['stages'] as $idx3 => $item3){
                    $condition[CONDITION_TYPE_SHUSHU] = [
                        'shushu' => $item3['shushu'],
                        'start' => 0,
                        'end' => 0,
                        'type' => CONDITION_TYPE_SHUSHU,
                    ];

                    $stageKey = "{$idx1}_{$idx2}_{$idx3}";
                    $stageConditions = array_values($condition);
                    oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                    oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item3['stages'],32));
                }
            }
        }
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
    }
    private function writePinataConfCache($data){
        $conditionKeys   = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['extraData'], true) ?? [];
        $expireTime = max($data['end_time'], time() + 60);#redis最少一分钟
        foreach ($extraReward as $idx1 => $item1){
            $condition = [
                CONDITION_TYPE_LV =>  [
                    'shushu' => [],
                    'start' => $item1['start'],
                    'end' => $item1['end'],
                    'type' => CONDITION_TYPE_LV,
                ],
            ];
            foreach ($item1['stages'] as $idx2 => $item2){
                $condition[CONDITION_TYPE_SPINS] = [
                    'shushu' => [],
                    'start' => $item2['start'],
                    'end' => $item2['end'],
                    'type' => CONDITION_TYPE_SPINS,
                ];


                foreach ($item2['stages'] as $idx3 => $item3){
                    $condition[CONDITION_TYPE_SHUSHU] = [
                        'shushu' => $item3['shushu'],
                        'start' => 0,
                        'end' => 0,
                        'type' => CONDITION_TYPE_SHUSHU,
                    ];

                    $stageKey = "{$idx1}_{$idx2}_{$idx3}";
                    $stageConditions = array_values($condition);
                    unset($item3['shushu']);
                    oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions,32));
                    oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item3,32));
                }
            }
        }
        oo::commonOprRedis('games')->expireAt($conditionKeys, oo::redisRandomExpire($expireTime));
        oo::commonOprRedis('games')->expireAt($stageRewardKeys, oo::redisRandomExpire($expireTime));
    }
    //============================
    private function checkActParams($data){
        if(( empty($data['uc_type'] ) && (empty($data['s_lv']) || empty($data['e_lv'])) ) || ($data['e_lv'] < $data['s_lv'])){
            $this->response(1, '活动参与等级配置异常');
        }
        if($data['type'] == 'super_collect'){
            $collectItem = [
                'one_attack',
                'two_attack',
                'attack_success',
                'attack_break',
                'one_steal',
                'two_steal',
                'steal_success',
                'steal_break',
                'one_hit',
                'two_hit',
                'three_hit',
                'three_hit',
            ];
            #收集物是否全是
            $allEmpty = true;
            foreach ($collectItem as $item){
                if(!empty($data[$item])){
                    $allEmpty = false;
                    break;
                }
            }
            if($allEmpty)$this->response(1, '收集物不能全为空');
        }

        if ($data['type'] == 'rank' && !empty($data['rank'])) {
            foreach ($data['rank'] as $stage){
                foreach ($stage as $item){
                    if(empty($item['prize']))$this->response(-1,'体力区间奖励不能为空');
                    $prizes = json_decode($item['prize'], true);
                    foreach ($prizes as $prize){
                        if(in_array($prize['type'], $this->needSkinRewards) && empty($prize['skin']))$this->response(1, '保存失败，需要配置皮肤的奖励未配置皮肤');
                    }
                }
            }
        }
    }
    private function checkSku($data){
        $goodsSkuPriceMap = array_column($this->goodSku, 'price', 'sku');
        if($data['type'] == EASTER_EGG){
            foreach ($data['extraData'] as $extraData){
                if(
                    empty($goodsSkuPriceMap[$extraData['sku']])
                    || $goodsSkuPriceMap[$extraData['sku']] != $extraData['price']
                )$this->response(-1,"sku:{$extraData['sku']} 与价格:{$extraData['price']} 不匹配");
            }
        }
    }

    private function getSkuByPrice($price){
        foreach ($this->goodSku as $skuPrice){
            if($skuPrice['price'] == $price){
                $sku = $skuPrice['sku'];
                return $sku;
            }
        }
        return '';
    }

    public function importCollect()
    {
        $collectTypsMap = [
            "1" => "常规收集"
            , "2" => "特殊收集"
            , "3" => "特殊收集+偷"
            , "4" => "特殊收集+打"
            , "5" => "偷"
            , "6" => "打"
            , "7" => "特殊收集偷打(暂不支持)"
            , "8" => "偷特殊"
            , "9" => "打特殊"
        ];
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $stagesRewardsArray = $dataArray[2] ?? [];

        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $time = time();
        $baseConfig = [
            "id" => "",
            "name" => "收集活动导入体力层级配置-默认标题",
            "abType" => "0",
            "abTest" => "0",
            "taTest" => "0",
            "openPush" => "0",
            "old_type" => "",
            "type" => SUPER_COLLECT,
            "cid" => "1",
            "sn_time" => date('Y-m-d', $time) . " 00:00:00 - " . date('Y-m-d', $time + 86400) . " 00:00:00",
            "authDays" => "0",
            "reward_time" => date('Y-m-d H:i:s', $time),
            "loop_type" => "1",
            "loop_num" => "",
            "client" => "0",
            "user_type" => "0",
            "uc_type" => "0",
            "s_lv" => "",
            "e_lv" => "",
            "s_vip" => "",
            "e_vip" => "",
            "s_score" => "",
            "e_score" => "",
            "isComVersion" => "0",
            "act_version" => [
                "1.14.5"
            ],
            "imgName" => "",
            "show_title" => [
                "en" => "Symbol Event",
                "zh" => "收集活动",
                "tw" => "收集活動",
                "fr" => "Évent de Symbole",
                "de" => "Symbol-Event",
                "es" => "Evento de Símbolos",
                "pt" => "Evento de Símbolos",
                "th" => "Symbol Event"
            ],
            "bname" => [
                "en" => "Join Now!",
                "zh" => "立即参加!",
                "tw" => "立即參加!",
                "fr" => "Adhésion immédiate",
                "de" => "Jetzt beitreten!",
                "es" => "¡Únete ahora!",
                "pt" => "Entrar!",
                "th" => "เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" => "1",
            "bskip" => "0",
            "burl" => "",
            "extraData" => [
                "openPro" => "0"
            ],
            "groupId" => "1",
            "attack_success" => "0",
            "attack_break" => "0",
            "steal_success" => "0",
            "steal_break" => "0",
            "three_hit" => "0",
        ];

        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);

        # 关闭体力修正调整
        $baseConfig['extraData']['openPro'] = 0;
        foreach ($basicConfArray as $k => $item) {
            $line = $k + 1;
            if ($k == 0) continue;
            if ($item[0] == 'startTime') {
                $stime = $item[1];
                $etime = $item[3];
                $rwtime = $item[5];

                if ($item[2] != 'endTime'
                    || $item[4] != 'rewardTime'
                    || empty($stime)
                    || empty($etime)
                    || empty($rwtime)
                )
                    $this->response(-1, $line . '行时间格式错误');
                $stime = date('Y-m-d H:i:s', strtotime($stime));
                $etime = date('Y-m-d H:i:s', strtotime($etime));
                $rwtime = date('Y-m-d H:i:s', strtotime($rwtime));
                $baseConfig['sn_time'] = "{$stime} - {$etime}";
                $baseConfig['reward_time'] = $rwtime;
                $nextLine = '';
                continue;
            }

            if ($item[0] == '收集类型') {
                $collectType = trim($item[1]);
                if (empty($collectType) || !in_array($collectType, $collectTypsMap)) $this->response(-1, $line . '行收集类型异常');
                $baseConfig['groupId'] = array_search($collectType, $collectTypsMap);
                $nextLine = '';
                continue;
            }
            if ($item[0] == '收集物配置') {
                $nextLine = 'collectTypes';
                continue;
            }
            if ($item[0] == '层级') {
                $nextLine = '';
                continue;
            }

            if ($item[0] == '是否开启限时奖励') {
                switch ($item[1]) {
                    case '是':
                        $baseConfig['extraData']['open'] = [1];
                        break;
                    case '否':
                        $baseConfig['extraData']['open'] = [0];
                        break;
                    default:
                        $this->response(-1, $line . '行配置异常' . __LINE__);
                        break;
                }
                $nextLine = '';
                $fixStage = 0;
                continue;
            }
            if ($item[0] == '限时配置') {
                foreach ($item as $tsKey => $tsValue) {
                    if (empty($tsKey) || empty($tsValue)) continue;
                    $baseConfig['extraData']['ts'][$tsKey] = $tsValue;
                }
                $nextLine = '';
                continue;
            }
            if ($item[0] == '老虎机概率分组ID') {
                $baseConfig['weightGroupId'] = intval($item[1]);
                $nextLine = '';
                continue;
            }

            switch ($nextLine) {
                case 'collectTypes':
                    switch ($item[0]) {
                        case '打';
                            $baseConfig['attack_success'] = intval($item[1]);
                            break;
                        case '打到盾';
                            $baseConfig['attack_break'] = intval($item[1]);
                            break;
                        case '偷';
                            $baseConfig['steal_success'] = intval($item[1]);
                            break;
                        case '完美偷';
                            $baseConfig['steal_break'] = intval($item[1]);
                            break;
                        case '三个钻石';
                            $baseConfig['three_hit'] = intval($item[1]);
                            break;
                        case '一连击';
                            $baseConfig['one_hit'] = intval($item[1]);
                            break;
                        case '二连击';
                            $baseConfig['two_hit'] = intval($item[1]);
                            break;
                        case '三连击';
                            $baseConfig['three_hit'] = intval($item[1]);
                            break;
                        default:
                            $this->response(-1, $line . '行收集物配置异常' . __LINE__);
                            break;
                    }
                    break;
                default:
                    $this->response(-1 * __LINE__, '参数配置异常', $item);

            }
        }
        switch ($baseConfig['groupId']) {
            case 1:
                if (
                    empty($baseConfig['attack_success'])
                    && empty($baseConfig['attack_break'])
                    && empty($baseConfig['steal_break'])
                    && empty($baseConfig['steal_success'])
                    && empty($baseConfig['three_hit'])
                ) $this->response(-1, '收集物配置不能全为空' . __LINE__);
                break;
            case 2 :
                if (
                    empty($baseConfig['one_hit'])
                    && empty($baseConfig['two_hit'])
                    && empty($baseConfig['three_hit'])
                ) $this->response(-1, '收集物配置不能全为空' . __LINE__);
                break;
            case 3 :
                if (
                    empty($baseConfig['one_hit'])
                    && empty($baseConfig['two_hit'])
                    && empty($baseConfig['three_hit'])
                    && empty($baseConfig['steal_success'])
                ) $this->response(-1, '收集物配置不能全为空' . __LINE__);
                break;
            case 4 :
                if (
                    empty($baseConfig['one_hit'])
                    && empty($baseConfig['two_hit'])
                    && empty($baseConfig['three_hit'])
                    && empty($baseConfig['attack_success'])
                ) $this->response(-1, '收集物配置不能全为空' . __LINE__);
                break;
            case 5 :
                if (
                    empty($baseConfig['steal_success'])
                    && empty($baseConfig['steal_break'])
                ) $this->response(-1, '收集物配置不能全为空' . __LINE__);
                break;
            case 6 :
                if (
                    empty($baseConfig['attack_success'])
                    && empty($baseConfig['attack_break'])
                ) $this->response(-1, '收集物配置不能全为空' . __LINE__);
                break;
            default:
                $this->response(-1, '收集类型配置异常' . __LINE__);
        }

        # 解析映射关系
        $lvStageCnt = 0;
        $superCollectConfig = $lvMapping = $spinsMapping = $shushuMapping = $spinsCnt = $shushuCnt = $idxMapping = [];
        foreach ($stagesMappingArray as $k => $item) {
            if (empty($k)) continue;
            list($idx, $lvMin, $lvMax, $spinsMin, $spinsMax, $ssGroup) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            $spinsKey = "{$spinsMin}-$spinsMax";
            if (empty($lvMapping[$lvKey])) {
                $curLvStage = ++$lvStageCnt;
                $lvMapping[$lvKey] = $curLvStage;
                $spinsCnt[$lvKey] = 0;
                $spinsMapping[$lvKey] = [];

                $superCollectConfig[$curLvStage] = [
                    'lvStart' => $lvMin,
                    'lvEnd' => $lvMax,
                    'stages' => [],
                ];
            }
            if (empty($spinsMapping[$lvKey][$spinsKey])) {
                $curSpinsStage = ++$spinsCnt[$lvKey];
                $spinsMapping[$lvKey][$spinsKey] = $curSpinsStage;
                $shushuCnt[$lvKey][$spinsKey] = 0;

                $superCollectConfig[$lvMapping[$lvKey]]['stages'][$curSpinsStage] = [
                    'spinsStart' => $spinsMin,
                    'spinsEnd' => $spinsMax,
                    'stages' => [],
                ];

            }
            if (empty($shushuMapping[$lvKey][$spinsKey][$ssGroup])) {
                $curSSStage = ++$shushuCnt[$lvKey][$spinsKey];
                $shushuMapping[$lvKey][$spinsKey][$ssGroup] = $curSSStage;

                $superCollectConfig[$lvMapping[$lvKey]]['stages'][$spinsMapping[$lvKey][$spinsKey]]['stages'][$curSSStage] = [
                    'shushu' => $this->parseShushuGroups($ssGroup, $k + 1),
                    'list' => [],
                ];

            }
            $idxMapping[$idx] = [$lvMapping[$lvKey], $spinsMapping[$lvKey][$spinsKey], $shushuMapping[$lvKey][$spinsKey][$ssGroup]];
        }

        # 解析奖励配置
        foreach ($stagesRewardsArray as $k => $item) {
            $filterLine = array_filter($item);
            if (empty($filterLine)) continue;
            $line = $k + 1;
            if ($k == 0) continue;

            list($idx, $stepnum, $stageSpins,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,) = $item;


            if (empty($idxMapping[$idx])) $this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系");    #奖励不能为空
            list($lvStage, $spinsStage, $ssStage) = $idxMapping[$idx];

            $rewardStage = count($superCollectConfig[$lvStage]['stages'][$spinsStage]['stages'][$ssStage]['list']) + 1;

            $rewardsTemp = [];
            for ($i = 1; $i <= 4; $i++) {
                if (empty(${'reward' . $i})) {
                    continue;
                }
                if (!in_array(${'reward' . $i}, $multiNumTypeReward)) ${'isFixNum' . $i} = '是';   #非金币奖励，全部固定值奖励
                ${'isFixNum' . $i} = (${'isFixNum' . $i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward' . $i}, $line);
                $currentId = count($rewardsTemp) + 1;
                $is_ts = $i > 2 ? 1 : 0;
                $rewardsTemp[] = [
                    'id' => $currentId,
                    "num" => ${'rewardNum' . $i},
                    "type" => $type,
                    "rtype" => ${'isFixNum' . $i},
                    "skin" => $skin,
                    "ts" => 0,
                    "is_ts" => $is_ts,
                ];
            }

            if (empty($rewardsTemp)) $this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $superCollectConfig[$lvStage]['stages'][$spinsStage]['stages'][$ssStage]['list'][$rewardStage] = [
                'stage' => $rewardStage,
                'stepnum' => $stepnum,
                'stageSpins' => $stageSpins,
                'prize' => $rewardsTemp,
            ];
        }

        $baseConfig['superCollectConfig'] = $superCollectConfig;

        $this->hsave($baseConfig);
    }
    public function importThemePack($suffix = ''){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $moneyTypes = [
            '金币' =>1,
            '美元' =>2,
        ];
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $stagesRewardsArray = $dataArray[2] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $baseConfig = [
            "id" =>"",
            "name" =>"主题礼包配置导入 - 默认标题",
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  "theme_pack" . $suffix,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $themeStagesConfig = $spinsMapping = $shushuMapping = $shushuCnt = $idxMapping = [];
        $spinsStageCnt = 0;
        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $shushuGroups, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            if(empty($spinsMapping[$lvKey])){
                $spinsMapping[$lvKey] = ++$spinsStageCnt;
                $shushuCnt[$lvKey] = 0;
                $shushuMapping[$lvKey] = [];

                $themeStagesConfig[$spinsMapping[$lvKey]] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'stages' => [],
                ];
            }
            if(empty($shushuMapping[$lvKey][$shushuGroups])){
                $shushuMapping[$lvKey][$shushuGroups] = ++$shushuCnt[$lvKey];

                $themeStagesConfig[$spinsMapping[$lvKey]]['stages'][$shushuMapping[$lvKey][$shushuGroups]] = [
                    'shushu' => $this->parseShushuGroups($shushuGroups, $k+1),
                    'list' => [],
                ];

            }
            $idxMapping[$idx] = [$spinsMapping[$lvKey], $shushuMapping[$lvKey][$shushuGroups]];
        }
        # 解析奖励配置
        foreach ($stagesRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $lv, $limit, $price,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5,
                $reward6, $isFixNum6, $rewardNum6,
                $reward7, $isFixNum7, $rewardNum7,
                $reward8, $isFixNum8, $rewardNum8,
                $reward9, $isFixNum9, $rewardNum9,
                $reward10, $isFixNum10, $rewardNum10
                ) = $item;

            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系");    #奖励不能为空
            list($spinsStage, $shushuStage) = $idxMapping[$idx];

            $rewardStage = count($themeStagesConfig[$spinsStage]['stages'][$shushuStage]['list'])+1;
            if($rewardStage != $lv)$this->response(-1, "第{$line}行,层级配置异常");

            $limit = intval($limit);
            if($limit < 1)$this->response(-1, "第{$line}行,限量不能为{$limit}");

            $sku = '';
            foreach ($this->goodSku as $skuPrice){
                if($skuPrice['price'] == $price){
                    $sku = $skuPrice['sku'];
                    break;
                }
            }
            if(empty($sku))$this->response(-1, "第{$line}行,购买价格：{$price} 无对应sku");   # 金额无对应sku

            $rewardsTemp = [];
            for($i=1;$i<11;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }

            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $themeStagesConfig[$spinsStage]['stages'][$shushuStage]['list'][$rewardStage] = [
                'price' =>$price,
                'sku' =>$sku,
                'times' =>$limit,
                'prize' => urlencode(json_encode($rewardsTemp)),
            ];

        }
        $baseConfig['themePackConfig'] = $themeStagesConfig;
        $this->hsave($baseConfig);
    }
    public function importThemePack2(){
        $this->importThemePack(2);
    }
    public function importShopPromotion(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $moneyTypes = [
            '金币' =>1,
            '美元' =>2,
        ];
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $rewardArray = $dataArray[1] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $baseConfig = [
            "id" =>"",
            "name" =>"优惠券配置导入 - 默认标题",
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  "shop_promotion" ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $shopPromotionConfig = [];
        $lvCnt = $shushuCnt = 0;
        $shushuCnt = 1;
        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        # 解析映射关系
        foreach ($rewardArray as $k => $item){
            if(empty($k))continue;
            $lvCnt++;
            list($lvMin, $lvMax, $buyNum,$bet,
                $spins1,$spins2, $spins3, $spins4, $spins5, $spins6) = $item;
            $list = [];
            for($i = 1; $i<=6 ;$i++){
                $list[] = [
                    'id' => $i,
                    'gid' => intval($i)+100,
                    'name' => "体力{$i}",
                    'spins' => ${'spins'.$i},
                ];
            }
            $shopPromotionConfig[$lvCnt] = [
                'start' => intval($lvMin),
                'end' => intval($lvMax),
                'stages' => [
                    $shushuCnt => [
                        'shushu' => [0],
                        'data' => [
                            'buyNum' => $buyNum,
                            'bet' => $bet,
                            'list' => $list,
                        ],
                    ]
                ],
            ];
        }
        $baseConfig['shopPromotionConfig'] = $shopPromotionConfig;
        $this->hsave($baseConfig);
    }
    public function importSerialPack($version = ''){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $moneyTypes = [
            '金币' =>1,
            '美元' =>2,
        ];
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $stagesRewardsArray = $dataArray[2] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $baseConfig = [
            "id" =>"",
            "name" =>"超级连环礼包层级配置导入 - 默认标题",
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  "super_serial_pack".$version ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
            "scoreCGType" => "3",
        ];
        $serialConfig = $spinsMapping = $shushuMapping = $shushuCnt = $idxMapping = [];
        $spinsStageCnt = 0;
        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $shushuGroups, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            if(empty($spinsMapping[$lvKey])){
                $spinsMapping[$lvKey] = ++$spinsStageCnt;
                $shushuCnt[$lvKey] = 0;
                $shushuMapping[$lvKey] = [];

                $serialConfig[$spinsMapping[$lvKey]] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'stages' => [],
                ];
            }
            if(empty($shushuMapping[$lvKey][$shushuGroups])){
                $shushuMapping[$lvKey][$shushuGroups] = ++$shushuCnt[$lvKey];

                $serialConfig[$spinsMapping[$lvKey]]['stages'][$shushuMapping[$lvKey][$shushuGroups]] = [
                    'shushu' => $this->parseShushuGroups($shushuGroups, $k+1),
                    'list' => [],
                ];

            }
            $idxMapping[$idx] = [$spinsMapping[$lvKey], $shushuMapping[$lvKey][$shushuGroups]];
        }
        # 解析奖励配置
        foreach ($stagesRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $lv, $limit, $mType, $price, $sku,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5 ) = $item;

            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系");    #奖励不能为空
            list($spinsStage, $shushuStage) = $idxMapping[$idx];

            $rewardStage = count($serialConfig[$spinsStage]['stages'][$shushuStage]['list'])+1;
            if($rewardStage != $lv)$this->response(-1, "第{$line}行,层级配置异常不能为空");

            $limit = intval($limit);
            if($limit < 1)$this->response(-1, "第{$line}行,限量不能为{$limit}");
            if(empty($moneyTypes[$mType]))$this->response(-1, "第{$line}行,购买货币：{$mType}不存在");
            if($moneyTypes[$mType] == 2){   # 美元时，判断金额与 sku 是否匹配
                $bet = 0;
                $skuTemp = '';
                foreach ($this->goodSku as $skuPrice){
                    if($skuPrice['price'] == $price){
                        $skuTemp = $skuPrice['sku'];
                        break;
                    }
                }
                if(empty($skuTemp))$this->response(-1, "第{$line}行,购买价格：{$price} 无对应sku");   # 金额无对应sku
                if($skuTemp != $sku)$this->response(-1, "第{$line}行,购买价格：{$price} 与sku:{$sku} 不对应"); # 金额与sku 不对应
            }else{
                $sku = '';
                $bet = $price;
                $price = 0;
            }

            $rewardsTemp = [];
            for($i=1;$i<6;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }

            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $serialConfig[$spinsStage]['stages'][$shushuStage]['list'][$rewardStage] = [
                'stage' => $rewardStage,
                'name' => '连环礼包-'.$rewardStage,
                'gMax' =>$limit,
                'mtype' =>$moneyTypes[$mType],
                'coin' =>'coins01',
                'bet' =>$bet,
                'sku' =>$sku,
                'price' =>$price,
                'prize' => urlencode(json_encode($rewardsTemp)),
            ];

        }
        $baseConfig['superSerialConfig'] = $serialConfig;
        $this->hsave($baseConfig);
    }
    public function importSerialPack2(){
        return $this->importSerialPack(2);
    }
    public function importSerialPack3(){
        return $this->importSerialPack(3);
    }
    public function importSerialPack4(){
        return $this->importSerialPack(4);
    }
    public function importBuildRank($rankType = ''){
        $actType = BUILD_RANK . $rankType;
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $setTypesMap = [
            '等级' => 1,
        ];
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $basicConfArray2 = $dataArray[1] ?? [];
        $scoreConfig = $dataArray[2] ?? [];

        $vipSpinsConfig = $dataArray[3] ?? [];
        $robot = $dataArray[4] ?? [];
        $robotLimit = $dataArray[5] ?? [];

        $stagesMappingArray = $dataArray[6] ?? [];
        $ranksRewards = $dataArray[7] ?? [];
        $stagesRewardsArray = $dataArray[8] ?? [];

        $baseConfig = $this->getCommonBasicConfig($actType, $basicConfArray);
        $baseConfig = array_merge($baseConfig, (array)$this->getCommonBasicConfig2(BUILD_RANK, $basicConfArray2));
        $baseConfig['buildScoreSetting'] = [
            'minScore' => intval($baseConfig['buildScoreSettingMinScore']),
            'actionConfig' => [],
        ];
        $baseConfig['setType'] = $setTypesMap[$baseConfig['setType']] ?? 1;
        unset($baseConfig['buildScoreSettingMinScore']);
        $baseConfig['spinsSet'] = $baseConfig['vipSet'] = $baseConfig['spinsSetSpins'] = $baseConfig['vipSetSpins'] = [];
        foreach ($vipSpinsConfig as $k => $item){
            $tilterItem = array_filter($item);
            if(empty($k) || empty($tilterItem))continue;
            list($vipSet, $stopNum) = $item;
            $baseConfig['userLvSet'][] = intval($vipSet);
            $baseConfig['userLvSetRobotStop'][] = intval($stopNum);
        }

        $baseConfig['robot'] = [];
        foreach ($robot as $k => $item){
            $tilterItem = array_filter($item);
            if(empty($k) || empty($tilterItem) || $k > 11)continue;
            list($id, $pro, $num, $co1, $co2) = $item;
            $k = $k==11 ? 49 : $k;
            if($k <= 4)$num = 0;
            else $pro = 0;
            if($k > 2)$co1 = $co2 = 0;
            $baseConfig['robot'][$k] = [
                'id' => $id,
                'pro' => $pro,
                'num' => $num,
                'co1' => $co1,
                'co2' => $co2,
            ];
        }

        $baseConfig['rankLimit'] = [];
        foreach ($robotLimit as $k => $item){
            $tilterItem = array_filter($item);
            if(empty($k) || empty($tilterItem) || $k > 4)continue;
            list($time, $limit) = $item;
            $baseConfig['rankLimit'][] = [
                'time' => $time,
                'limit' => $limit,
            ];
        }
        $rewardsConfig = [];
        # 解析积分配置关系
        foreach ($scoreConfig as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $score1, $score2) = $item;
            $baseConfig['buildScoreSetting']['actionConfig'][] = [
                'minLv' => $lvMin,
                'maxLv' => $lvMax,
                'singleGet' => [$score1, $score2],
            ];
        }

        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $spinsMin, $spinsMax, $ssGroup, $idx) = $item;
            $spinsKey = "{$spinsMin}-{$spinsMax}";
            $lvKey = "{$lvMin}-$lvMax";

            $lvIdx = $this->getGroupMappingIdx(CONDITION_TYPE_LV, $lvKey);
            $spinsIdx = $this->getGroupMappingIdx(CONDITION_TYPE_SPINS, $spinsKey, $lvIdx);
            $ssIdx = $this->getGroupMappingIdx(CONDITION_TYPE_SHUSHU, $ssGroup,  "{$spinsIdx}_{$lvIdx}");

            if(empty($rewardsConfig[$lvIdx]))
                $rewardsConfig[$lvIdx] = [
                    'stages' => [],
                    'start' => $lvMin,
                    'end' => $lvMax,
                ];
            if(empty($rewardsConfig[$lvIdx]['stages'][$spinsIdx]))
                $rewardsConfig[$lvIdx]['stages'][$spinsIdx] = [
                    'stages' => [],
                    'start' => $spinsMin,
                    'end' => $spinsMax,
                ];

            $shushus = $this->parseShushuGroups($ssGroup);
            if(empty($rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]))
                $rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx] = [
                    'stages' => [
                        'stages' => [],
                        'ranks' => [],
                    ],
                    'shushu' => $shushus,
                ];


            $idxMapping[$idx] = [ $lvIdx, $spinsIdx, $ssIdx];
        }

        # 解析排行奖励
        foreach ($ranksRewards as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $staegIdx,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5 ) = $item;
            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
            list($idx1, $idx2, $idx3) = $idxMapping[$idx];
//            if(count($rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']['ranks']) != $staegIdx-1)$this->response(-1, "第{$line}行,任务阶段配置异常",[$item, $idxMapping]);    #奖励不能为空
            $rewardsTemp = [];
            for($i=1;$i<6;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }
            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空

            $rankIdx = count($rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']['ranks']) + 1;
            $rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']['ranks'][$rankIdx] = [
                'rankPos' => $staegIdx,
                'prize' => $rewardsTemp,
            ];
        }
        # 解析阶段奖励
        if(!empty($stagesRewardsArray) && empty($rankType)){
            foreach ($stagesRewardsArray as $k => $item){
                $filterLine = array_filter($item);
                if (empty($filterLine))continue;
                $line = $k + 1;
                if($k == 0)continue;

                list($idx, $staegIdx, $progressBar, $stepNum,
                    $reward1, $isFixNum1, $rewardNum1,
                    $reward2, $isFixNum2, $rewardNum2,
                    $reward3, $isFixNum3, $rewardNum3,
                    $reward4, $isFixNum4, $rewardNum4,
                    $reward5, $isFixNum5, $rewardNum5 ) = $item;
                if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
                list($idx1, $idx2, $idx3) = $idxMapping[$idx];
                if(count($rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']['stages']) != $staegIdx-1)$this->response(-1, "第{$line}行,任务阶段配置异常",[$item, $idxMapping]);    #奖励不能为空
                $rewardsTemp = [];
                for($i=1;$i<6;$i++){
                    if(!empty(${'reward'.$i})){
                        if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                        ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                        list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                        $currentId = count($rewardsTemp)+1;
                        $rewardsTemp[] = [
                            'id' => $currentId,
                            "num" => ${'rewardNum'.$i},
                            "type" => $type,
                            "rtype" => ${'isFixNum'.$i},
                            "skin" => $skin
                        ];
                    }
                }

                if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空

                $rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']['stages'][$staegIdx] = [
                    'stage' => $staegIdx,
                    'progressBarId' => $progressBar,
                    'stepnum' => $stepNum,
                    'prize' => $rewardsTemp,
                ];
            }
        }


        $baseConfig['buildRankConfig'] = $rewardsConfig;
//        $this->response(__LINE__, __LINE__, $rewardsConfig);
        $this->hsave($baseConfig);
    }
    public function importBuildRank2(){
        $this->importBuildRank(2);
    }
    public function importRank($rankType = ''){
        $actType = RANK . $rankType;
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型

        $dataArray = $this->getExcelSheetsArray();
        $sheetIdx = 0;
        $basicConfArray = $dataArray[$sheetIdx++] ?? [];
        $scoreConfig = $dataArray[$sheetIdx++] ?? [];

        $vipSpinsConfig = $dataArray[$sheetIdx++] ?? [];
        $robot = $dataArray[$sheetIdx++] ?? [];
        $robotLimit = $dataArray[$sheetIdx++] ?? [];

        $stagesMappingArray = $dataArray[$sheetIdx++] ?? [];
        $ranksRewards = $dataArray[$sheetIdx++] ?? [];
        $stagesRewardsArray = $dataArray[$sheetIdx++] ?? [];

        $baseConfig = $this->getCommonBasicConfig($actType, $basicConfArray);
        $baseConfig['roomAllotConf'] = $roomAllotConf = [];
        foreach ($vipSpinsConfig as $k => $item) {
            $tilterItem = array_filter($item);
            if (empty($k) || empty($tilterItem)) continue;
            list($lvStart, $lvEnd, $spinsStart, $spinsEnd, $stopNum) = $item;
            $roomAllotConf[$lvStart . "-" . $lvEnd][] = [
                "spinsStart" => $spinsStart,
                "spinsEnd" => $spinsEnd,
                "robotStop" => $stopNum
            ];
        }

        foreach ($roomAllotConf as $lvRange=>$spinsInfo){
            $lvRanges = explode('-', $lvRange);
            $baseConfig['roomAllotConf'][] = [
                "lvStart" => $lvRanges[0],
                "lvEnd" => $lvRanges[1],
                "stages"=>$spinsInfo
            ];
        }

        $baseConfig['robot'] = [];
        foreach ($robot as $k => $item){
            $tilterItem = array_filter($item);
            if(empty($k) || empty($tilterItem) || $k > 11)continue;
            list($id, $pro, $num, $co1, $co2) = $item;
            $k = $k==11 ? 49 : $k;
            if($k <= 4)$num = 0;
            else $pro = 0;
            if($k > 2)$co1 = $co2 = 0;
            $baseConfig['robot'][$k] = [
                'id' => $id,
                'pro' => $pro,
                'num' => $num,
                'co1' => $co1,
                'co2' => $co2,
            ];
        }

        $baseConfig['rankLimit'] = [];
        foreach ($robotLimit as $k => $item){
            $tilterItem = array_filter($item);
            if(empty($k) || empty($tilterItem) || $k > 4)continue;
            list($time, $limit) = $item;
            $baseConfig['rankLimit'][] = [
                'time' => $time,
                'limit' => $limit,
            ];
        }
        $rewardsConfig = [];
        # 解析积分配置关系
        foreach ($scoreConfig as $k => $item){
            list($scoreType, $score) = $item;
            switch ($scoreType){
                case '打':$baseConfig['attack_success'] = $score;break;
                case '打到盾':$baseConfig['attack_break'] = $score;break;
                case '偷':$baseConfig['steal_success'] = $score;break;
                case '完美偷':$baseConfig['steal_break'] = $score;break;
                case '三个钻石':$baseConfig['three_hit'] = $score;break;
            }
        }

        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $spinsMin, $spinsMax, $ssGroup, $idx) = $item;
            $spinsKey = "{$spinsMin}-{$spinsMax}";
            $lvKey = "{$lvMin}-$lvMax";

            $lvIdx = $this->getGroupMappingIdx(CONDITION_TYPE_LV, $lvKey);
            $spinsIdx = $this->getGroupMappingIdx(CONDITION_TYPE_SPINS, $spinsKey, $lvIdx);
            $ssIdx = $this->getGroupMappingIdx(CONDITION_TYPE_SHUSHU, $ssGroup,  "{$spinsIdx}_{$lvIdx}");

            if(empty($rewardsConfig[$lvIdx]))
                $rewardsConfig[$lvIdx] = [
                    'stages' => [],
                    'start' => $lvMin,
                    'end' => $lvMax,
                ];
            if(empty($rewardsConfig[$lvIdx]['stages'][$spinsIdx]))
                $rewardsConfig[$lvIdx]['stages'][$spinsIdx] = [
                    'stages' => [],
                    'start' => $spinsMin,
                    'end' => $spinsMax,
                ];

            $shushus = $this->parseShushuGroups($ssGroup);
            if(empty($rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]))
                $rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx] = [
                    'stages' => [
                        'stages' => [],
                        'ranks' => [],
                    ],
                    'shushu' => $shushus,
                ];


            $idxMapping[$idx] = [ $lvIdx, $spinsIdx, $ssIdx];
        }

        # 解析排行奖励
        foreach ($ranksRewards as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $staegIdx,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5 ) = $item;
            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
            list($idx1, $idx2, $idx3) = $idxMapping[$idx];
//            if(count($rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']['ranks']) != $staegIdx-1)$this->response(-1, "第{$line}行,任务阶段配置异常",[$item, $idxMapping]);    #奖励不能为空
            $rewardsTemp = [];
            for($i=1;$i<6;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }
            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空

            $rankIdx = count($rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']['ranks']) + 1;
            $rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']['ranks'][$rankIdx] = [
                'rankPos' => $staegIdx,
                'prize' => $rewardsTemp,
            ];
        }
        # 解析阶段奖励
        if(!empty($stagesRewardsArray) && empty($rankType)){
            foreach ($stagesRewardsArray as $k => $item){
                $filterLine = array_filter($item);
                if (empty($filterLine))continue;
                $line = $k + 1;
                if($k == 0)continue;

                list($idx, $staegIdx, $progressBar, $stepNum,
                    $reward1, $isFixNum1, $rewardNum1,
                    $reward2, $isFixNum2, $rewardNum2,
                    $reward3, $isFixNum3, $rewardNum3,
                    $reward4, $isFixNum4, $rewardNum4,
                    $reward5, $isFixNum5, $rewardNum5 ) = $item;
                if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
                list($idx1, $idx2, $idx3) = $idxMapping[$idx];
                if(count($rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']['stages']) != $staegIdx-1)$this->response(-1, "第{$line}行,任务阶段配置异常",[$item, $idxMapping]);    #奖励不能为空
                $rewardsTemp = [];
                for($i=1;$i<6;$i++){
                    if(!empty(${'reward'.$i})){
                        if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                        ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                        list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                        $currentId = count($rewardsTemp)+1;
                        $rewardsTemp[] = [
                            'id' => $currentId,
                            "num" => ${'rewardNum'.$i},
                            "type" => $type,
                            "rtype" => ${'isFixNum'.$i},
                            "skin" => $skin
                        ];
                    }
                }

                if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空

                $rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']['stages'][$staegIdx] = [
                    'stage' => $staegIdx,
                    'progressBarId' => $progressBar,
                    'stepnum' => $stepNum,
                    'prize' => $rewardsTemp,
                ];
            }
        }


        $baseConfig['buildRankConfig'] = $rewardsConfig;
//        $this->response(__LINE__, __LINE__, $baseConfig);
        $this->hsave($baseConfig);
    }
    public function importRank2(){
        $this->importRank(2);
    }
    public function importTreasure(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $sheetIdx = 0;
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[$sheetIdx++] ?? [];
        $basicConfArray2 = $dataArray[$sheetIdx++] ?? [];
        $prdConfSheet = $dataArray[$sheetIdx++] ?? [];
        $stagesMappingArray = $dataArray[$sheetIdx++] ?? [];
        $stagesRewardsArray = $dataArray[$sheetIdx++] ?? [];

        $baseConfig = $this->getCommonBasicConfig(TREASURE, $basicConfArray);
        $baseConfig = array_merge($baseConfig, (array)$this->getCommonBasicConfig2(TREASURE, $basicConfArray2));

        $rewardsConfig = [];

        $prdConf = [];
        $prdIdx = 0;
        foreach($prdConfSheet as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;
            list($prdLv, $co1, $co2) = $item;
            if($prdLv != count($prdConf) + 1)$this->response(-1, "第{$line}行,prd配置等级不连续");
            $prdConf[$prdLv] = [$co1, $co2];
        }


        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $yMin, $yMax, $ssGroup, $idx) = $item;
            $yKey = "{$yMin}-$yMax";
            $lvKey = "{$lvMin}-$lvMax";

            $lvIdx = $this->getGroupMappingIdx(CONDITION_TYPE_LV, $lvKey);
            $yIdx = $this->getGroupMappingIdx(CONDITION_TYPE_COIN_Y, $yKey, $lvIdx);
            $ssIdx = $this->getGroupMappingIdx(CONDITION_TYPE_SHUSHU, $ssGroup,  "{$yIdx}_{$lvIdx}");

            if(empty($rewardsConfig[$lvIdx]))
                $rewardsConfig[$lvIdx] = [
                    'stages' => [],
                    'start' => $lvMin,
                    'end' => $lvMax,
                ];
            if(empty($rewardsConfig[$lvIdx]['stages'][$yIdx]))
                $rewardsConfig[$lvIdx]['stages'][$yIdx] = [
                    'stages' => [],
                    'start' => $yMin,
                    'end' => $yMax,
                ];

            $shushus = $this->parseShushuGroups($ssGroup);
            if(empty($rewardsConfig[$lvIdx]['stages'][$yIdx]['stages'][$ssIdx]))
                $rewardsConfig[$lvIdx]['stages'][$yIdx]['stages'][$ssIdx] = [
                    'stages' => [],
                    'shushu' => $shushus,
                ];


            $idxMapping[$idx] = [ $lvIdx, $yIdx, $ssIdx];
        }
        # 解析阶段奖励配置
        $taskTypeMap = [
            1 => '下注次数',
            2 => '获得金币',
            3 => 'Bonus Wheel',
        ];


        foreach ($stagesRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $staegIdx, $taskType, $target, $frequency, $betStr,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5 ) = $item;
            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
            list($idx1, $idx2, $idx3) = $idxMapping[$idx];
            if(count($rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages']) != $staegIdx-1)$this->response(-1, "第{$line}行,任务阶段配置异常",[$item, $idxMapping]);    #奖励不能为空
            $rewardsTemp = [];
            for($i=1;$i<6;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }

            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空

            $taskType = array_search($taskType, $taskTypeMap);
            if(empty($taskType))$this->response(-1, "任务类型不存在：{$item[0]},line:$line,".__LINE__ );

            $betStr = strtr($betStr, ['，' => ',', ' ' => '']);
            $bet = explode(',',$betStr);
            $bet = array_filter($bet);
            $rewardsIdx = $staegIdx-1;
            $rewardsConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['stages'][$rewardsIdx] = [
                'id' => $staegIdx,
                'taskType' => $taskType,
                'target' => $target,
                'frequency' => $frequency,
                'prize' => urlencode(json_encode($rewardsTemp)),
                'bet' => urlencode(json_encode($bet)),
            ];
        }

        $baseConfig['treasure'] = $rewardsConfig;
        $baseConfig['prdConf'] = $prdConf;
//        $baseConfig['common_conf'] = $treasureBounsCoefficient;
//        $this->response(__LINE__, __LINE__, $rewardsConfig);
        $this->hsave($baseConfig);
    }
    public function importEasterEgg(){
        $priceSkuMap = array_column($this->goodSku, 'sku', 'price');
        $dataArray = $this->getExcelSheetsArray();
        $baseSheet = $dataArray[0] ?? [];
        $protectSheet = $dataArray[1] ?? [];
        $easterGiftSheet = $dataArray[2] ?? [];
        $easterIntervalSheet = $dataArray[3] ?? [];
        $stageCeSheet = $dataArray[4] ?? [];
        $mapSheet = $dataArray[5] ?? [];
        $rewardsSheet = $dataArray[6] ?? [];

        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $rewardTime = date('Y-m-d H:i:s', strtotime($tomorrow) - 3600);
        $baseConfig = [
            "id"=>"",
            "name"=>"import-".EASTER_EGG,
            "abType"=>"0",
            "abTest"=>"0",
            "taTest"=>"0",
            "openPush"=>"0",
            "old_type"=>EASTER_EGG,
            "type"=>EASTER_EGG,
            "sn_time"=>"{$today} - {$tomorrow}",
            "authDays"=>"0",
            "reward_time"=>"{$rewardTime}",
            "loop_type"=>"1",
            "loop_num"=>"",
            "client"=>"0",
            "user_type"=>"0",
            "uc_type"=>"0",
            "s_lv"=>"",
            "e_lv"=>"",
            "s_vip"=>"",
            "e_vip"=>"",
            "s_score"=>"",
            "e_score"=>"",
            "isComVersion"=>"0",
            "imgName"=>"",
            "show_title"=>[
                "en"=>"",
                "zh"=>"",
                "tw"=>"",
                "fr"=>"",
                "de"=>"",
                "es"=>"",
                "pt"=>"",
                "th"=>""
            ],
            "bname"=>[
                "en"=>"Join Now!",
                "zh"=>"立即参加!",
                "tw"=>"立即參加!",
                "fr"=>"Adhésion immédiate",
                "de"=>"Jetzt beitreten!",
                "es"=>"¡Únete ahora!",
                "pt"=>"Entrar!",
                "th"=>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor"=>"1",
            "bskip"=>"0",
            "burl"=>"",

            "extraData"=>[],
            "common_conf"=>[],
//            "spinStage"=>[],
//            "rewardnew"=>[],
        ];
        $baseConfig = $this->parseBasicConfig($baseConfig, $baseSheet);

        // 保护系数
        $easterBasicConfig = [
            'randConf'=>[],
            'protect'=>[],
        ];
        $randIdx = 0;
        $protectIdx = 0;
        foreach ($protectSheet as $k => $item){
            $line = $k + 1;
            switch ($item[0]){
                case '随机下限':
                    if($item[2] !== '随机上限')$this->response(__LINE__ * -1, "保护系数配置，{$line}行配置异常", $item);
                    $randIdx++;
                    $easterBasicConfig['randConf'][$randIdx] = [
                        'min' => $item[1],
                        'max' => $item[3],
                    ];
                    break;
                case '等级下限':
                    break;
                default:
                    $protectIdx++;
                    list($lvMin,$lvMax,$m, $maxBet, $minBet, $stage, $ce) = $item;
                    $easterBasicConfig['protect'][$protectIdx] = [
                        'lvMin' => $lvMin,
                        'lvMax' => $lvMax,
                        'm' => $m,
                        'maxBet' => $maxBet,
                        'minBet' => $minBet,
                        'stage' => $stage,
                        'ce' => $ce,
                    ];
                    break;
            }
        }
        // 复活礼包
        $extraData = [];
        $extraDataIdx = 0;
        foreach ($easterGiftSheet as $k => $item){
            if(empty($k))continue;
            $filterItem = array_filter($item);
            if(empty($filterItem))continue;
            $line = $k + 1;
            list($stage, $spins, $price) = $item;
            $sku = $this->getSkuByPrice($price);
            if(empty($sku))$this->response(__LINE__ * -1, "复活礼包配置,{$line}行价格配置异常", $item);
            $extraDataIdx++;
            $extraData[$extraDataIdx] = [
                'stage' => $stage,
                'spins' => $spins,
                'price' => $price,
                'sku' => $sku,
                'bet' => 1,
            ];
        }

        // 复活间隙
        $common_conf = [];
        $common_confIdx = 0;
        foreach ($easterIntervalSheet as $k => $item){
            if(empty($k))continue;
            $filterItem = array_filter($item);
            if(empty($filterItem))continue;
            $line = $k + 1;
            list($ri, $riCe) = $item;
            $common_confIdx++;
            $common_conf[$common_confIdx] = [
                'ri' => $ri,
                'riCe' => $riCe,
            ];
        }

        // 关卡修正
        $pro = [];
        $proIdx = 0;
        foreach ($stageCeSheet as $k => $item){
            if(empty($k))continue;
            $filterItem = array_filter($item);
            if(empty($filterItem))continue;
            $line = $k + 1;
            list($stage, $stageCe) = $item;
            $proIdx++;
            $pro[$proIdx] = [
                'stage' => $stage,
                'stageCe' => $stageCe,
            ];
        }

        // 映射关系解析
        $lvMaps = [];$lvIdx = 0;
        $shushuMaps = [];$shushuIdx = [];
        $idMaps = [];
        foreach ($mapSheet as $k => $item){
            if(empty($k))continue;
            $filterItem = array_filter($item);
            if(empty($filterItem))continue;
            $line = $k + 1;
            list($lvMin, $lvMax, $shushu, $ce, $id) = $item;
            $lvKey = "{$lvMin}-{$lvMax}";
            if(empty($lvMaps[$lvKey])){
                $lvIdx++;
                $lvMaps[$lvKey] = $lvIdx;
                $shushuIdx[$lvKey] = 0;
            }
            $shushuKey =$lvKey.'-'.$shushu;
            if(empty($shushuMaps[$shushuKey])){
                $shushuIdx[$lvKey]++;
                $shushuMaps[$shushuKey] = $shushuIdx[$lvKey];
            }
            $idMaps[$id] = [$lvMaps[$lvKey], $lvKey, $shushuMaps[$shushuKey], $shushu, $ce];
        }
        // 奖励配置
//        easterRewardConfig[1][shushuStages][1][stages][1][list][2][stepnum]
        $easterRewardConfig = [];
        foreach ($rewardsSheet as $k => $item){
            if(empty($k))continue;
            $filterItem = array_filter($item);
            if(empty($filterItem))continue;
            $line = $k + 1;
            list($id, $stageIdx, $rewardIdx, $stepnum,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,) = $item;
            if(empty($idMaps[$id]))$this->response(__LINE__, '映射关系异常', [$idMaps, $id]);
            list($lvIdx, $lvKey, $shushuIdx, $shushu, $ce) = $idMaps[$id];
            list($lvStart, $lvEnd) = explode('-', $lvKey);
            $rewardsTemp = [];
            for ($i = 1; $i <= 4; $i++) {
                if (empty(${'reward' . $i})) {
                    continue;
                }
                if (!in_array(${'reward' . $i}, $multiNumTypeReward)) ${'isFixNum' . $i} = '是';   #非金币奖励，全部固定值奖励
                ${'isFixNum' . $i} = (${'isFixNum' . $i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward' . $i}, $line);
                $currentId = count($rewardsTemp) + 1;
                $is_ts = $i > 2 ? 1 : 0;
                $rewardsTemp[] = [
                    'id' => $currentId,
                    "num" => ${'rewardNum' . $i},
                    "type" => $type,
                    "rtype" => ${'isFixNum' . $i},
                    "skin" => $skin,
                    "ts" => 0,
                    "is_ts" => $is_ts,
                ];
            }
            $easterRewardConfig[$lvIdx]['start']  = $lvStart;
            $easterRewardConfig[$lvIdx]['end']  = $lvEnd;
            $easterRewardConfig[$lvIdx]['shushuStages'][$shushuIdx]['shushu'] = $this->parseShushuGroups($shushu, $line);
            $easterRewardConfig[$lvIdx]['shushuStages'][$shushuIdx]['spinCe'] = $ce;
            $easterRewardConfig[$lvIdx]['shushuStages'][$shushuIdx]['stages'][$stageIdx]['star'] = $stageIdx;
            $easterRewardConfig[$lvIdx]['shushuStages'][$shushuIdx]['stages'][$stageIdx]['list'][$rewardIdx]['stage'] = $rewardIdx;
            $easterRewardConfig[$lvIdx]['shushuStages'][$shushuIdx]['stages'][$stageIdx]['list'][$rewardIdx]['stepnum'] = $stepnum;
            $easterRewardConfig[$lvIdx]['shushuStages'][$shushuIdx]['stages'][$stageIdx]['list'][$rewardIdx]['prize'] = urlencode(json_encode($rewardsTemp));
        }

        $baseConfig['easterBasicConfig'] = $easterBasicConfig;
        $baseConfig['extraData'] = $extraData;
        $baseConfig['common_conf'] = $common_conf;
        $baseConfig['pro'] = $pro;
        $baseConfig['easterRewardConfig'] = $easterRewardConfig;
        $this->hsave($baseConfig);
    }
    public function importPinata($actType = PINATA){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $setTypesMap = [
            '等级' => 1,
        ];
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $pinataRewardsArray = $dataArray[2] ?? [];
        $stagesRewardsArray = $dataArray[3] ?? [];

        $baseConfig = $this->getCommonBasicConfig($actType, $basicConfArray);

        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $spinsMin, $spinsMax, $ssGroup, $idx) = $item;
            $spinsKey = "{$spinsMin}-{$spinsMax}";
            $lvKey = "{$lvMin}-$lvMax";

            $lvIdx = $this->getGroupMappingIdx(CONDITION_TYPE_LV, $lvKey);
            $spinsIdx = $this->getGroupMappingIdx(CONDITION_TYPE_SPINS, $spinsKey, $lvIdx);
            $ssIdx = $this->getGroupMappingIdx(CONDITION_TYPE_SHUSHU, $ssGroup,  "{$spinsIdx}_{$lvIdx}");

            if(empty($rewardsConfig[$lvIdx]))
                $rewardsConfig[$lvIdx] = [
                    'stages' => [],
                    'start' => $lvMin,
                    'end' => $lvMax,
                ];
            if(empty($rewardsConfig[$lvIdx]['stages'][$spinsIdx]))
                $rewardsConfig[$lvIdx]['stages'][$spinsIdx] = [
                    'stages' => [],
                    'start' => $spinsMin,
                    'end' => $spinsMax,
                ];

            $shushus = $this->parseShushuGroups($ssGroup);
            if(empty($rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]))
                $rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx] = [
                    'collect' => [],
                    'pinata' => [],
                    'shushu' => $shushus,
                ];


            $idxMapping[$idx] = [ $lvIdx, $spinsIdx, $ssIdx];
        }
        $rewardTypes = [
            '大奖' => PINATA_REWARD_TYPE_BONUS,
            '纪念品' => PINATA_REWARD_TYPE_COLLECTS,
            '通用奖励' => PINATA_REWARD_TYPE_NORMAL,
        ];
        foreach ($pinataRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;
            $rewardBasic = array_slice($item, 0 , 7);
            $rewardsLine = array_slice($item, 7);
            list($idx, $stageIdx, $pinataIdx, $rewardType, $weight, $min_token_spend, $collect_num) = $rewardBasic;
            if(empty($rewardTypes[$rewardType]))$this->response(-1 * __LINE__, "第{$line}行,奖励类型:{$rewardType}不存在");
            $rewardType = $rewardTypes[$rewardType];
            @list($lvIdx, $spinsIdx, $ssIdx) = $idxMapping[$idx];
            if(empty($rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]))$this->response(-1 * __LINE__, "第{$line}行,分组映射id:{$idx}不存在");
            if(empty($rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]['pinata'][$stageIdx]))
                $rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]['pinata'][$stageIdx] = [
                    'stage' => $stageIdx,
                    'rewards' => [],
                ];
            $stageCnt = count($rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]['pinata']);
            if($stageCnt+1 != $stageIdx && $stageCnt != $stageIdx)$this->response(-1 * __LINE__, "第{$line}行,关卡序号不连续", [$stageCnt , $stageIdx]);
            $pinataCnt = count($rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]['pinata'][$stageIdx]['rewards']);
            if($pinataCnt+1 != $pinataIdx)$this->response(-1 * __LINE__, "第{$line}行,皮纳塔序号不连续");

            $rewardsTemp = $this->parseLineRewards($rewardsLine, $line);

            $rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]['pinata'][$stageIdx]['rewards'][] = [
                'id' => $pinataIdx,
                'type' => $rewardType,
                'weight' => $weight,
                'min_token_spend' => $min_token_spend,
                'collect_num' => $collect_num,
                'reward' => urlencode(json_encode($rewardsTemp)),
            ];
        }

        # 解析阶段奖励
        foreach ($stagesRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;
            $rewardBasic = array_slice($item, 0 , 3);
            $rewardsLine = array_slice($item, 3);

            list($idx, $stageIdx,  $target) = $rewardBasic;
            @list($lvIdx, $spinsIdx, $ssIdx) = $idxMapping[$idx];
            if(empty($rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]))$this->response(-1 * __LINE__, "阶段奖励配置，第{$line}行,分组映射id:{$idx}不存在");

            $stageCnt = count($rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]['collect']);
            if($stageCnt+1 != $stageIdx)$this->response(-1 * __LINE__, "阶段奖励配置，第{$line}行,阶段序号不连续");
            $rewardsTemp = $this->parseLineRewards($rewardsLine, $line);

            $rewardsConfig[$lvIdx]['stages'][$spinsIdx]['stages'][$ssIdx]['collect'][$stageIdx] = [
                'stage' => $stageIdx,
                'target' => $target,
                'rewards' =>  urlencode(json_encode($rewardsTemp)),
            ];
        }

        $baseConfig['pinataRewardConfig'] = $rewardsConfig;
//        $this->response(__LINE__, __LINE__, $rewardsConfig);
        $this->hsave($baseConfig);
    }

    /**
     * 各种活动配置导入
     * @param $aType string 活动类型表示
     * @return void
     */
    public function importExcel(string $aType)
    {
        $dataArray = $this->getExcelSheetsArray();
        if (empty($dataArray)) {
            $this->response(-1, "导入的数据为空，请重新上传");
        }

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $rewardTime = date('Y-m-d H:i:s', strtotime($tomorrow) - 3600);
        $baseConfig = [
            "id" => "",
            "name" => "活动导入-{$aType}",
            "abType" => "0",
            "abTest" => "0",
            "taTest" => "0",
            "openPush" => "0",
            "old_type" => "",
            "type" => "{$aType}",
            "cid" => "1",
            "sn_time" => "{$today} - {$tomorrow}",
            "authDays" => "0",
            "reward_time" => "{$rewardTime}",
            "loop_type" => "1",
            "loop_num" => "",
            "client" => "0",
            "user_type" => "0",
            "uc_type" => "0",
            "s_lv" => "",
            "e_lv" => "",
            "s_vip" => "",
            "e_vip" => "",
            "s_score" => "",
            "e_score" => "",
            "isComVersion" => "0",
            "imgName" => "",
            "show_title" => [
                "en" => "",
                "zh" => "",
                "tw" => "",
                "fr" => "",
                "de" => "",
                "es" => "",
                "pt" => "",
                "th" => ""
            ],
            "bname" => [
                "en" => "Join Now!",
                "zh" => "立即参加!",
                "tw" => "立即參加!",
                "fr" => "Adhésion immédiate",
                "de" => "Jetzt beitreten!",
                "es" => "¡Únete ahora!",
                "pt" => "Entrar!",
                "th" => "เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" => "1",
            "bskip" => "0",
            "showDiscountVal" => "0",
            "appointUid" => "",
            "burl" => "",
            "reward" => [],
        ];

        $basicConfArray = $dataArray[0] ?? [];

        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);

        # 解析配置
        if (in_array($aType, ActBaseModel::ACT_LIST)) {
            ActBaseModel::getActModel($aType)->importActData($baseConfig, $dataArray);
        } else {
            ActivityModel::parseOtherConfig($this, $aType, $baseConfig, $basicConfArray, $dataArray);
        }

        $this->hsave($baseConfig);
    }

    //狐狸之锤导入
    public function importFoxHammer()
    {
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $lvAndShushuArray = $dataArray[1] ?? [];
        $stagesConfigArray = $dataArray[2] ?? [];
        $configInfoArray = $dataArray[3] ?? [];
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $priceSkuMap = array_column($this->goodSku, 'sku', 'price');
        //基础配置
        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $rewardTime = date('Y-m-d H:i:s', strtotime($tomorrow) - 3600);
        $baseConfig = [
            "id" => "",
            "name" => "狐狸之锤 - 默认名称",
            "abType" => "0",
            "abTest" => "0",
            "taTest" => "0",
            "openPush" => "0",
            "old_type" => "fox_hammer",
            "type" => "fox_hammer",
            "sn_time" => "{$today} - {$tomorrow}",
            "authDays" => "0",
            "reward_time" => "{$rewardTime}",
            "loop_type" => "1",
            "loop_num" => "",
            "client" => "0",
            "user_type" => "0",
            "uc_type" => "0",
            "s_lv" => "",
            "e_lv" => "",
            "s_vip" => "",
            "e_vip" => "",
            "s_score" => "",
            "e_score" => "",
            "isComVersion" => "0",
            "imgName" => "",
            "show_title" => [
                "en" => "",
                "zh" => "",
                "tw" => "",
                "fr" => "",
                "de" => "",
                "es" => "",
                "pt" => "",
                "th" => ""
            ],
            "bname" => [
                "en" => "Join Now!",
                "zh" => "立即参加!",
                "tw" => "立即參加!",
                "fr" => "Adhésion immédiate",
                "de" => "Jetzt beitreten!",
                "es" => "¡Únete ahora!",
                "pt" => "Entrar!",
                "th" => "เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" => "1",
            "bskip" => "0",
            "burl" => "",
        ];
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        //等级数数分组
        $foxHammerConfig = $foxHammerShuhuConfig = $shushuMapping = $lvMapping = $shushuCnt = [];
        $spinsStageCnt = 0;
        foreach ($lvAndShushuArray as $k => $item) {
            if (empty($k)) continue;
            list($lvMin, $lvMax, $shushuGroups, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            if (empty($lvMapping[$lvKey])) {
                $lvMapping[$lvKey] = ++$spinsStageCnt;
                $shushuCnt[$lvKey] = 0;
                $shushuMapping[$lvKey] = [];
                //数组从0开始所以-1
                $foxHammerShuhuConfig[$lvMapping[$lvKey] - 1] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'data' => [],
                ];

            }
            if (empty($shushuMapping[$lvKey][$shushuGroups])) {
                $shushuMapping[$lvKey][$shushuGroups] = ++$shushuCnt[$lvKey];
                //数组从0开始所以-1
                $foxHammerShuhuConfig[$lvMapping[$lvKey] - 1]['data'][$shushuMapping[$lvKey][$shushuGroups] - 1] = [
                    'shushu' => $this->parseShushuGroups($shushuGroups, $k),
                ];
            }
            //数组从0开始所以-1
            $idxMapping[$idx] = [$lvMapping[$lvKey] - 1, $shushuMapping[$lvKey][$shushuGroups] - 1];
        }
//        echo "<pre>";
//        print_r($foxHammerShuhuConfig);

        $tonArr =$spinsWeightArr=$tonOneIdxs=$spinsWeightOneIdxs= [];
        //ton内容配置
        foreach ($configInfoArray as $k3 => $item3) {
            if(empty($k3))continue;
            list($idx3, $spins, $weight) = $item3;
            $spinsWeightOneIdxs[$idx3]++;
            $spinsWeightArr[$idx3][$spinsWeightOneIdxs[$idx3]] =["spins"=>$spins,"weight"=>$weight];
        }

        //ton价格配置
        foreach ($stagesConfigArray as $k2=>$item2){
            if(empty($k2))continue;
            list($idx, $ton, $price,$discount, $idx2) = $item2;
            $tonOne = ["ton"=>$ton,"price"=>$price,"sku"=> $this->getSkuByPrice($price),"discount"=>$discount,"prize"=>$spinsWeightArr[$idx2]];
            $tonOneIdxs[$idx]++;
            $tonArr[$idx][$tonOneIdxs[$idx]] = $tonOne;
        }
        foreach ($idxMapping as $idx=> $item4){
            $foxHammerConfig[$item4[0]]["data"][$item4[1]]["data"] =  $tonArr[$idx];
        }
//        $this->response(-1, 'test',$foxHammerConfig);
        $baseConfig['foxHammerShuhuConfig'] = $foxHammerShuhuConfig;
        $baseConfig['foxHammerConfig'] = $foxHammerConfig;
//        $this->response(-1, 'test',$baseConfig);
        $this->hsave($baseConfig);
    }
    //随心配导入
    public function importChooseYouWant(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $moneyTypes = [
            '金币' =>1,
            '美元' =>2,
        ];
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $leftAndRightArray = $dataArray[2] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $baseConfig = [
            "id" =>"",
            "name" =>"随心配礼包配置导入 - 默认标题",
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  "choose_you_want" ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $spinsMapping = $shushuMapping = $shushuCnt = $idxMapping = [];
        $spinsStageCnt = 0;
        $chooseYouWantBaseConfig = $chooseYouWantConfig = $chooseYouWantRewardConfig =[];
        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        $chooseYouWantBaseConfig["buyCnt"] = isset($baseConfig["maxNum"])?$baseConfig["maxNum"]:1;
        unset($baseConfig["maxNum"]);
        # 分组配置
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $shushuGroups,$price,$discount, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            if(empty($spinsMapping[$lvKey])){
                $spinsMapping[$lvKey] = ++$spinsStageCnt;
                $shushuCnt[$lvKey] = 0;
                $shushuMapping[$lvKey] = [];
                //数组从0开始所以-1
                $chooseYouWantConfig[$spinsMapping[$lvKey]-1] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'data' => [],
                ];

            }
            if(empty($shushuMapping[$lvKey][$shushuGroups])){
                $shushuMapping[$lvKey][$shushuGroups] = ++$shushuCnt[$lvKey];
                //数组从0开始所以-1
                $chooseYouWantConfig[$spinsMapping[$lvKey]-1]['data'][$shushuMapping[$lvKey][$shushuGroups]-1] = [
                    'shushu' => $this->parseShushuGroups($shushuGroups, $k),
                    'data' => ["price"=>$price,"discount"=>$discount,"sku"=>$this->getSkuByPrice($price)],
                ];
            }
            //数组从0开始所以-1
            $idxMapping[$idx] = [$spinsMapping[$lvKey]-1, $shushuMapping[$lvKey][$shushuGroups]-1];
        }

        # 解析奖励配置
        $rewardArr = $ridArr =  [];
        #左右边关系映射
        foreach ($leftAndRightArray as $k=>$item){
            if(empty($k))continue;
            $line = $k + 1;
            list($idx,$direction,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5,
                $reward6, $isFixNum6, $rewardNum6,
                $reward7, $isFixNum7, $rewardNum7,
                $reward8, $isFixNum8, $rewardNum8,
                $reward9, $isFixNum9, $rewardNum9,
                $reward10, $isFixNum10, $rewardNum10,
                ) = $item;
            $rewardsTemp = [];
            for($i=1;$i<11;$i++){
                $one=[];
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = 1;
                    $one[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                    $rewardsTemp[$idx][$i]['prize'] = urlencode(json_encode($one));
                }
            }
            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空

            $lvshushu = implode('_',$idxMapping[$idx]);
            $chooseYouWantRewardConfig[$direction."_".$lvshushu] = $rewardsTemp[$idx];
        }

        $baseConfig['chooseYouWantBaseConfig'] = $chooseYouWantBaseConfig;
        $baseConfig['chooseYouWantConfig'] = $chooseYouWantConfig;
        $baseConfig['chooseYouWantRewardConfig'] = $chooseYouWantRewardConfig;
//        $this->response(-1, 'test',$chooseYouWantRewardConfig);
        $this->hsave($baseConfig);
    }
    //放弃版本(随心配)
    public function importChooseYouWant2(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $moneyTypes = [
            '金币' =>1,
            '美元' =>2,
        ];
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $leftAndRightArray = $dataArray[2] ?? [];
        $stagesRewardsArray = $dataArray[3] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $baseConfig = [
            "id" =>"",
            "name" =>"随心配礼包配置导入 - 默认标题",
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  "choose_you_want" ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $spinsMapping = $shushuMapping = $shushuCnt = $idxMapping = [];
        $spinsStageCnt = 0;
        $chooseYouWantBaseConfig = $chooseYouWantConfig = $chooseYouWantRewardConfig =[];
        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        $chooseYouWantBaseConfig["buyCnt"] = isset($baseConfig["maxNum"])?$baseConfig["maxNum"]:1;
        unset($baseConfig["maxNum"]);
        # 分组配置
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $shushuGroups,$price,$discount, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            if(empty($spinsMapping[$lvKey])){
                $spinsMapping[$lvKey] = ++$spinsStageCnt;
                $shushuCnt[$lvKey] = 0;
                $shushuMapping[$lvKey] = [];
                //数组从0开始所以-1
                $chooseYouWantConfig[$spinsMapping[$lvKey]-1] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'data' => [],
                ];

            }
            if(empty($shushuMapping[$lvKey][$shushuGroups])){
                $shushuMapping[$lvKey][$shushuGroups] = ++$shushuCnt[$lvKey];
                //数组从0开始所以-1
                $chooseYouWantConfig[$spinsMapping[$lvKey]-1]['data'][$shushuMapping[$lvKey][$shushuGroups]-1] = [
                    'shushu' => $this->parseShushuGroups($shushuGroups, $k),
                    'data' => ["price"=>$price,"discount"=>$discount,"sku"=>$this->getSkuByPrice($price)],
                ];
            }
            //数组从0开始所以-1
            $idxMapping[$idx] = [$spinsMapping[$lvKey]-1, $shushuMapping[$lvKey][$shushuGroups]-1];
        }

        # 解析奖励配置
        $rewardArr = $ridArr =  [];
        foreach ($stagesRewardsArray as $k => $item){
            if(empty($k))continue;
            list($rIdx,$reward, $isFixNum, $rewardNum) = $item;
            $ridArr[$rIdx]++;
            $rewardArr[$rIdx][$ridArr[$rIdx]]['prize'] =urlencode(json_encode($this->getPrizeShowFromTable($k,$reward, $isFixNum, $rewardNum)));
        }
        #左右边关系映射
        foreach ($leftAndRightArray as $k=>$item){
            if(empty($k))continue;
            list($idx,$direction,$rIdx) = $item;
            $lvshushu = implode('_',$idxMapping[$idx]);
            $chooseYouWantRewardConfig[$direction."_".$lvshushu] = $rewardArr[$rIdx];
        }

        $baseConfig['chooseYouWantBaseConfig'] = $chooseYouWantBaseConfig;
        $baseConfig['chooseYouWantConfig'] = $chooseYouWantConfig;
        $baseConfig['chooseYouWantRewardConfig'] = $chooseYouWantRewardConfig;
//        $this->response(-1, 'test',$baseConfig);
        $this->hsave($baseConfig);
    }
    public function importMayaWHeel(){
        $dataArray = $this->getExcelSheetsArray();
        $basicArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $rewardsConfig = $dataArray[2] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $rewardTime = date('Y-m-d H:i:s', strtotime($tomorrow) - 3600);
        $baseConfig = [
            "id"=>"",
            "name"=>"玛雅转盘 - 默认名称",
            "abType"=>"0",
            "abTest"=>"0",
            "taTest"=>"0",
            "openPush"=>"0",
            "old_type"=>"maya_wheel",
            "type"=>"maya_wheel",
            "sn_time"=>"{$today} - {$tomorrow}",
            "authDays"=>"0",
            "reward_time"=>"{$rewardTime}",
            "loop_type"=>"1",
            "loop_num"=>"",
            "client"=>"0",
            "user_type"=>"0",
            "uc_type"=>"0",
            "s_lv"=>"",
            "e_lv"=>"",
            "s_vip"=>"",
            "e_vip"=>"",
            "s_score"=>"",
            "e_score"=>"",
            "isComVersion"=>"0",
            "act_version"=>[
            ],
            "imgName"=>"",
            "show_title"=>[
                "en"=>"Symbol Event",
                "zh"=>"玛雅转盘",
                "tw"=>"玛雅转盘",
                "fr"=>"Évent de Symbole",
                "de"=>"Symbol-Event",
                "es"=>"Evento de Símbolos",
                "pt"=>"Evento de Símbolos",
                "th"=>"Symbol Event"
            ],
            "bname"=>[
                "en"=>"Join Now!",
                "zh"=>"立即参加!",
                "tw"=>"立即參加!",
                "fr"=>"Adhésion immédiate",
                "de"=>"Jetzt beitreten!",
                "es"=>"¡Únete ahora!",
                "pt"=>"Entrar!",
                "th"=>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor"=>"1",
            "bskip"=>"0",
            "burl"=>"",

        ];
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicArray);
        foreach ($basicArray as $k => $item){
            $line = $k +1;
            if($item[0] == '转盘总数'){
                $baseConfig['mayaWheelTotalCnt'] = intval($item[1]);
                if(empty($baseConfig['mayaWheelTotalCnt']))
                    $this->response(-1, $line.'行转盘总数不能为空'. PHP_EOL);
            }
            if($item[0] == '代币消耗配置'){
                for($idx = 1;$idx <= $baseConfig['mayaWheelTotalCnt'];$idx++){
                    $item[$idx] = intval($item[$idx]);
                    if(empty($item[$idx])) $this->response(-1, $line.'行消耗代币不能为空'. PHP_EOL);
                    $baseConfig['mayaWheelSpend'][$idx-1] = $item[$idx];
                }
            }
        }

        # 解析映射关系
        $spinsStageCnt = 0;
        $spinsMapping = $StagesConfig = $lvsMapping = $spinsCnt = [];
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $spinsMin, $spinsMax, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            $spinsKey = "{$spinsMin}-$spinsMax";
            if(empty($lvsMapping[$lvKey])){
                $lvsMapping[$lvKey] = ++$spinsStageCnt;
                $spinsCnt[$lvKey] = 0;
                $spinsMapping[$lvKey] = [];
                $StagesConfig[$lvsMapping[$lvKey]] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'spinStages' => [],
                ];

            }
            if(empty($spinsMapping[$lvKey][$spinsKey])){
                $spinsMapping[$lvKey][$spinsKey] = ++$spinsCnt[$lvKey];
                $StagesConfig[$lvsMapping[$lvKey]]['spinStages'][$spinsMapping[$lvKey][$spinsKey]] = [
                    'start' => $spinsMin,
                    'end' => $spinsMax,
                    'rewards' => [],
                ];
            }
            $idxMapping[$idx] = [$lvsMapping[$lvKey], $spinsMapping[$lvKey][$spinsKey]];
        }

        foreach ($rewardsConfig as $k => $item){
            if(empty($k))continue;
            $line = $k + 1;
            list($idx, $rewardStage, $rewardIdx, $weight, $lastCnt,
                $reward1, $isFixNum1, $rewardNum1) = $item;
            list($lvStage, $spinsStage) =  $idxMapping[$idx] ;
            $prizes = [];
            for($i=1;$i<=1;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $this->multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($prizes)+1;
                    $prizes[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }

            $StagesConfig[$lvStage]['spinStages'][$spinsStage]['rewards'][$rewardStage]['list'][$rewardIdx]= [
                'weight' => $weight,
                'lastCnt' => $lastCnt,
                'prize' => urlencode(json_encode($prizes)),
            ];
        }
        $baseConfig['mayaWheelReward'] = $StagesConfig;
        $this->hsave($baseConfig);
    }
    //安全惊喜导入
    public function importSafeSurprise(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $moneyTypes = [
            '金币' =>1,
            '美元' =>2,
        ];
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $stagesRewardsArray = $dataArray[2] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $baseConfig = [
            "id" =>"",
            "name" =>"安全惊喜礼包配置导入 - 默认标题",
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  "safe_surprise" ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $themeStagesConfig = $spinsMapping = $shushuMapping = $shushuCnt = $idxMapping = [];
        $spinsStageCnt = 0;
        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $shushuGroups, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            if(empty($spinsMapping[$lvKey])){
                $spinsMapping[$lvKey] = ++$spinsStageCnt;
                $shushuCnt[$lvKey] = 0;
                $shushuMapping[$lvKey] = [];
                //数组从0开始所以-1
                $themeStagesConfig[$spinsMapping[$lvKey]-1] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'data' => [],
                ];

            }
            if(empty($shushuMapping[$lvKey][$shushuGroups])){
                $shushuMapping[$lvKey][$shushuGroups] = ++$shushuCnt[$lvKey];
                //数组从0开始所以-1
                $themeStagesConfig[$spinsMapping[$lvKey]-1]['data'][$shushuMapping[$lvKey][$shushuGroups]-1] = [
                    'shushu' => $this->parseShushuGroups($shushuGroups, $k),
                    'data' => [],
                ];
            }
            //数组从0开始所以-1
            $idxMapping[$idx] = [$spinsMapping[$lvKey]-1, $shushuMapping[$lvKey][$shushuGroups]-1];
        }
        # 解析奖励配置
        foreach ($stagesRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $lv, $limit, $price,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5 ) = $item;

            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
            list($spinsStage, $shushuStage) = $idxMapping[$idx];

//            $rewardStage = count($themeStagesConfig[$spinsStage]['data'][$shushuStage]['data']);
//            if($rewardStage != $lv)$this->response(-1, "第{$line}行,层级配置异常");
            $gid = $lv+1838;
            if(!in_array($gid,[1840,1839])){
                $this->response(-1, "第{$line}行,层级配置异常",[$gid]);
            }
            $limit = intval($limit);
            if($limit < 1)$this->response(-1, "第{$line}行,折扣不能为{$limit}");

            $sku = '';
            foreach ($this->goodSku as $skuPrice){
                if($skuPrice['price'] == $price){
                    $sku = $skuPrice['sku'];
                    break;
                }
            }
            if(empty($sku))$this->response(-1, "第{$line}行,购买价格：{$price} 无对应sku");   # 金额无对应sku

            $rewardsTemp = [];
            for($i=1;$i<6;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }

            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $themeStagesConfig[$spinsStage]['data'][$shushuStage]['data'][$lv] = [
                'gprice' =>$price,
                'gid' =>$gid,
                'gsku' =>$sku,
                'gdiscount' =>$limit,
                'prizes' => urlencode(json_encode($rewardsTemp)),
            ];

        }
        $baseConfig['SafeSurpriseConfig'] = $themeStagesConfig;
        $this->hsave($baseConfig);
    }

    //1+1导入
    public function importOnePlus(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $stagesRewardsArray = $dataArray[2] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $baseConfig = [
            "id" =>"",
            "name" =>"1+1配置导入 - 默认标题",
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  "one_plus_gift" ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $stageRewardsConfig = $spinsMapping = $shushuMapping = $shushuCnt = $idxMapping = [];
        $spinsStageCnt = 0;
        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $shushuGroups, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            if(empty($spinsMapping[$lvKey])){
                $spinsMapping[$lvKey] = ++$spinsStageCnt;
                $shushuCnt[$lvKey] = 0;
                $shushuMapping[$lvKey] = [];
                $stageRewardsConfig[$spinsMapping[$lvKey]] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'data' => [],
                ];

            }
            if(empty($shushuMapping[$lvKey][$shushuGroups])){
                $shushuMapping[$lvKey][$shushuGroups] = ++$shushuCnt[$lvKey];
                //数组从0开始所以-1
                $stageRewardsConfig[$spinsMapping[$lvKey]]['data'][$shushuMapping[$lvKey][$shushuGroups]] = [
                    'shushu' => $this->parseShushuGroups($shushuGroups, $k),
                    'data' => [],
                ];
            }
            //数组从0开始所以-1
            $idxMapping[$idx] = [$spinsMapping[$lvKey], $shushuMapping[$lvKey][$shushuGroups]];
        }
        # 解析奖励配置
        foreach ($stagesRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $lv, $price,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5 ) = $item;

            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
            list($spinsStage, $shushuStage) = $idxMapping[$idx];

//            $rewardStage = count($stageRewardsConfig[$spinsStage]['data'][$shushuStage]['data']);
//            if($rewardStage != $lv)$this->response(-1, "第{$line}行,层级配置异常");
            $gid = $lv+1836;
            if(!in_array($gid,[1838,1837])){
                $this->response(-1, "第{$line}行,层级配置异常",[$gid]);
            }

            $sku = $this->getSkuByPrice($price);
            if(empty($sku))$this->response(-1, "第{$line}行,购买价格：{$price} 无对应sku");   # 金额无对应sku

            $rewardsTemp = [];
            for($i=1;$i<6;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }

            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $stageRewardsConfig[$spinsStage]['data'][$shushuStage]['data'][$gid] = [
                'gprice' =>$price,
                'gsku' =>$sku,
                'gdiscount' =>1,
                'gid' => $gid,
                'prizes' => urlencode(json_encode($rewardsTemp)),
            ];

        }
        $baseConfig['onePlusConfig'] = $stageRewardsConfig;
        $this->hsave($baseConfig);
    }
    public function importPickOne(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $stagesRewardsArray = $dataArray[2] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $baseConfig = [
            "id" =>"",
            "name" =>"三选一配置导入 - 默认标题",
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  "pick_one" ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $pickOneStagesConfig = $spinsMapping = $shushuMapping = $shushuCnt = $idxMapping = [];
        $spinsStageCnt = 0;
        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $shushuGroups, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            if(empty($spinsMapping[$lvKey])){
                $spinsMapping[$lvKey] = ++$spinsStageCnt;
                $shushuCnt[$lvKey] = 0;
                $shushuMapping[$lvKey] = [];
                //数组从0开始所以-1
                $pickOneStagesConfig[$spinsMapping[$lvKey]] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'data' => [],
                ];

            }
            if(empty($shushuMapping[$lvKey][$shushuGroups])){
                $shushuMapping[$lvKey][$shushuGroups] = ++$shushuCnt[$lvKey];

                $pickOneStagesConfig[$spinsMapping[$lvKey]]['data'][$shushuMapping[$lvKey][$shushuGroups]] = [
                    'shushu' => $this->parseShushuGroups($shushuGroups, $k),
                    'data' => [[],[],[]],
                ];
            }

            $idxMapping[$idx] = [$spinsMapping[$lvKey], $shushuMapping[$lvKey][$shushuGroups]];
        }
        # 解析奖励配置
        foreach ($stagesRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $lv, $price, $dicsount) = array_slice($item, 0, 4);
            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",[$idxMapping,$item]);    #奖励不能为空
            list($spinsStage, $shushuStage) = $idxMapping[$idx];
            $lv = intval($lv);
            $gid = $lv+130000;
            if(!in_array($gid,[130001,130002,130003,130004])){
                $this->response(-1, "第{$line}行,层级配置异常",[$gid]);
            }

            $sku = $this->getSkuByPrice($price);
            if(empty($sku))$this->response(-1, "第{$line}行,购买价格：{$price} 无对应sku");   # 金额无对应sku


            $rewards = array_slice($item, 4);
            $rewardsTemp = [];
            $i = 0;
            while($i < count($rewards)){
                $reward = $rewards[$i++];
                $isFixNum = $rewards[$i++];
                $rewardNum = $rewards[$i++];
                if(!empty($reward)){
                    if(!in_array($reward, $multiNumTypeReward))$isFixNum = '是';   #非金币奖励，全部固定值奖励
                    $isFixNum = ($isFixNum == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId($reward, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => $rewardNum,
                        "type" => $type,
                        "rtype" => $isFixNum,
                        "skin" => $skin
                    ];
                }
            }


            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $pickOneStagesConfig[$spinsStage]['data'][$shushuStage]['data'][$lv-1] = [
                'price' =>$price,
                'sku' =>$sku,
                'discount' => $lv==4 ? $dicsount : 0,
                'gid' =>$gid,
                'prizes' => urlencode(json_encode($rewardsTemp)),
            ];

        }
        $baseConfig['ChooseOneConfig'] = $pickOneStagesConfig;
        $this->hsave($baseConfig);
    }

    //好友召回导入
    public function importCallbackScore(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $stagesMappingArray = $dataArray[1] ?? [];
        $stagesRewardsArray = $dataArray[2] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $baseConfig = [
            "id" =>"",
            "name" =>"好友召回导入 - 默认标题",
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  "callback_score" ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $stageRewardsConfig = $spinsMapping = $shushuMapping = $shushuCnt = $idxMapping = [];
        $spinsStageCnt = 0;
        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $shushuGroups, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            if(empty($spinsMapping[$lvKey])){
                $spinsMapping[$lvKey] = ++$spinsStageCnt;
                $shushuCnt[$lvKey] = 0;
                $shushuMapping[$lvKey] = [];
                $stageRewardsConfig[$spinsMapping[$lvKey]] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'data' => [],
                ];

            }
            if(empty($shushuMapping[$lvKey][$shushuGroups])){
                $shushuMapping[$lvKey][$shushuGroups] = ++$shushuCnt[$lvKey];
                //数组从0开始所以-1
                $stageRewardsConfig[$spinsMapping[$lvKey]]['data'][$shushuMapping[$lvKey][$shushuGroups]] = [
                    'shushu' => $this->parseShushuGroups($shushuGroups, $k),
                    'data' => [],
                ];
            }
            $idxMapping[$idx] = [$spinsMapping[$lvKey], $shushuMapping[$lvKey][$shushuGroups]];
        }
        # 解析奖励配置
        foreach ($stagesRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5 ) = $item;

            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
            list($spinsStage, $shushuStage) = $idxMapping[$idx];
            $rewardsTemp = [];
            for($i=1;$i<6;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }

            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $stageRewardsConfig[$spinsStage]['data'][$shushuStage]['data'] = urlencode(json_encode($rewardsTemp));
//            $stageRewardsConfig[$spinsStage]['data'][$shushuStage]['data'][1] = [
//                'prizes' => urlencode(json_encode($rewardsTemp)),
//            ];

        }
        $baseConfig['callbackScore'] = $stageRewardsConfig;
        $this->hsave($baseConfig);
    }
    //公会锦标赛导入
    public function importClubTournament(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $basicConfArray2 = $dataArray[1] ?? [];
        $stagesMappingArray = $dataArray[2] ?? [];
        $clubRanksArray = $dataArray[3] ?? [];
        $userRanksArray = $dataArray[4] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        $baseConfig = [
            "id" =>"",
            "name" =>"公会锦标赛导入 - 默认标题",
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  CLUB_TOURNAMENT ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $stageRewardsConfig = $spinsMapping = $shushuMapping = $shushuCnt = $idxMapping = [];
        $starsStageCnt = 0;
        # 解析基础配置
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        # 收集物品解析
        $clubTournamentConfig = [
            'preTimes' => 0,
            'clubMinNum' => 0,
            'userMinNum' => 0,
            'list' => [],
        ];
        $filterPrefixArr = [
            '打',
            '打到盾',
            '偷',
            '完美偷',
            '提前预告时长(小时)',
        ];
        foreach ($basicConfArray2 as $lineKey => $line){
            $lineNum = $lineKey+1;
            if(in_array($line[0], $filterPrefixArr)){
                switch ($line[0]){
                    case '打':$baseConfig['attack_success'] = intval($line[1]);break;
                    case '打到盾':$baseConfig['attack_break'] = intval($line[1]);break;
                    case '偷':$baseConfig['steal_success'] = intval($line[1]);break;
                    case '完美偷':$baseConfig['steal_break'] = intval($line[1]);break;
                    case '提前预告时长(小时)':$clubTournamentConfig['preTimes'] = intval($line[1]);break;
//                    case '俱乐部上榜门槛积分':$clubTournamentConfig['clubMinNum'] = intval($line[1]);break;
//                    case '用户上榜门槛积分':$clubTournamentConfig['userMinNum'] = intval($line[1]);break;
                }
            }
        }
        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($starsMin, $starsMax, $maxClubNum, $clubMinNum, $userMinNum, $idx) = $item;
            $starsKey = "{$starsMin}-$starsMax";
            if(empty($starsMapping[$starsKey])){
                $starsMapping[$starsKey] = $starsStageCnt++;
                $clubTournamentConfig['list'][$starsMapping[$starsKey]] = [
                    'start' => $starsMin,
                    'end' => $starsMax,
                    'clubNum' => $maxClubNum,
                    'clubMinNum' => $clubMinNum,
                    'userMinNum' => $userMinNum,
                    'clubRanks' => [],
                    'userRanks' => [],
                ];

            }
            $idxMapping[$idx] = $starsMapping[$starsKey];
        }

        $rankTitleMap = [
            'clubRanksArray' => 'clubRanks',
            'userRanksArray' => 'userRanks',
        ];
        foreach ($rankTitleMap as $rankTitle => $rank){
            foreach (${$rankTitle} as $k => $item){
                $filterLine = array_filter($item);
                if (empty($filterLine))continue;
                $line = $k + 1;
                if($k == 0)continue;

                list($idx,$rankNum,
                    $reward1, $isFixNum1, $rewardNum1,
                    $reward2, $isFixNum2, $rewardNum2,
                    $reward3, $isFixNum3, $rewardNum3,
                    $reward4, $isFixNum4, $rewardNum4,
                    $reward5, $isFixNum5, $rewardNum5 ) = $item;
                if(!isset($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
                $starsStage = $idxMapping[$idx];
                if(count($clubTournamentConfig['list'][$starsStage][$rank]) != $rankNum-1)$this->response(-1, "第{$line}行,排名配置异常",[$item, $idxMapping]);    #奖励不能为空

                $rewardsTemp = [];
                for($i=1;$i<6;$i++){
                    if(!empty(${'reward'.$i})){
                        if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                        ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                        list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                        $currentId = count($rewardsTemp)+1;
                        $rewardsTemp[] = [
                            'id' => $currentId,
                            "num" => ${'rewardNum'.$i},
                            "type" => $type,
                            "rtype" => ${'isFixNum'.$i},
                            "skin" => $skin
                        ];
                    }
                }

                if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
                $clubTournamentConfig['list'][$starsStage][$rank][] = [
                    'rank' => $rankNum,
                    'prizes' => urlencode(json_encode($rewardsTemp))
                ];
            }
        }

        $baseConfig['clubTournamentConfig'] = $clubTournamentConfig;
        $this->hsave($baseConfig);
    }

    # 公会花园导入
    public function importClubGarden(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $basicConfArray2 = $dataArray[1] ?? [];
        $stagesMappingArray = $dataArray[2] ?? [];
        $stagesRewardsArray = $dataArray[3] ?? [];
        $rankRewardsArray = $dataArray[4] ?? [];

        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        # 解析基础配置
        $baseConfig = [
            "id" =>"",
            "name" =>"import-".CLUB_GARDEN,
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  CLUB_GARDEN ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        $stageRewardsConfig = $spinsMapping = $shushuMapping = $shushuCnt = $idxMapping = [];
        $starsStageCnt = 0;
        # 收集物品解析
        $clubGardenConfig = [
            'preTimes' => 0,
        ];
        $filterPrefixArr = [
            '打',
            '打到盾',
            '偷',
            '完美偷',
            '提前预告时长(小时)',
        ];
        foreach ($basicConfArray2 as $lineKey => $line){
            if(in_array($line[0], $filterPrefixArr)){
                switch ($line[0]){
                    case '打':$baseConfig['attack_success'] = intval($line[1]);break;
                    case '打到盾':$baseConfig['attack_break'] = intval($line[1]);break;
                    case '偷':$baseConfig['steal_success'] = intval($line[1]);break;
                    case '完美偷':$baseConfig['steal_break'] = intval($line[1]);break;
                    case '提前预告时长(小时)':$clubGardenConfig['preTimes'] = $line[1];break;
                }
            }
        }
        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($starsMin, $starsMax, $userMinNum, $idx) = $item;
            $starsKey = "{$starsMin}-$starsMax";
            if(empty($starsMapping[$starsKey])){
                $starsMapping[$starsKey] = $starsStageCnt++;
                $clubGardenConfig['clubStagesList'][$starsMapping[$starsKey]] = [
                    'start' => $starsMin,
                    'end' => $starsMax,
                    'userMinNum' => $userMinNum,
                    'stages' => [],
                ];

            }
            $idxMapping[$idx] = [$starsMapping[$starsKey], intval($userMinNum)];
        }

        # 解析阶段奖励配置
        foreach ($stagesRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $staegIdx, $targetScores,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5 ) = $item;
            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
            list($starsStage, $userMinNum) = $idxMapping[$idx];
            if(count($clubGardenConfig['clubStagesList'][$starsStage]['stages']) != $staegIdx-1)$this->response(-1, "第{$line}行,阶段配置异常",[$item, $idxMapping]);    #奖励不能为空

            $rewardsTemp = [];
            for($i=1;$i<6;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }

            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $clubGardenConfig['clubStagesList'][$starsStage]['stages'][] = [
                'stage' => $staegIdx,
                'target_scores' => $targetScores,
                'prizes' => urlencode(json_encode($rewardsTemp)),
                'user_rank' => [],
            ];
        }

        # 解析阶段排行奖励配置
        foreach ($rankRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $staegIdx, $rank,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5 ) = $item;
            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
            list($starsStage, $userMinNum) = $idxMapping[$idx];
            $staegIdx--;
            if(empty($clubGardenConfig['clubStagesList'][$starsStage]['stages'][$staegIdx]))$this->response(-1, "第{$line}行,阶段配置异常",[$item, $idxMapping]);    #奖励不能为空

            if(count($clubGardenConfig['clubStagesList'][$starsStage]['stages'][$staegIdx]['user_rank']) != $rank-1)$this->response(-1, "第{$line}行,排行配置异常",[$item, $idxMapping]);    #奖励不能为空

            $rewardsTemp = [];
            for($i=1;$i<6;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }

            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $clubGardenConfig['clubStagesList'][$starsStage]['stages'][$staegIdx]['user_rank'][] = [
                'rank' => $rank,
                'prizes' => urlencode(json_encode($rewardsTemp)),
            ];
        }


        $baseConfig['clubGardenConfig'] = $clubGardenConfig;
//        echo json_encode($baseConfig);die;
        $this->hsave($baseConfig);
    }
    public function importGreatMemories(){
        $multiNumTypeReward = $this->multiNumTypeReward; #可以选择 非固定值的奖励类型
        $dataArray = $this->getExcelSheetsArray();
        $basicConfArray = $dataArray[0] ?? [];
        $basicConfArray2 = $dataArray[1] ?? [];
        $stagesMappingArray = $dataArray[2] ?? [];
        $stagesRewardsArray = $dataArray[3] ?? [];

        $baseConfig = $this->getCommonBasicConfig(GREAT_MEMORIES, $basicConfArray);

        $stageRewardsConfig = $lvMapping = $vipMapping = $lostDayMapping = $idxMapping = $extraData = [];
        $starsStageCnt = 0;
        # 收集物品解析
        $clubGardenConfig = [];
        $filterPrefixArr = [
            '奖励1倒计时(分钟)',
            '再次触发活动间隔(天)',
        ];
        foreach ($basicConfArray2 as $lineKey => $line){
            if(in_array($line[0], $filterPrefixArr)){
                switch ($line[0]){
                    case '奖励1倒计时(分钟)':$extraData['reward_end_time'] = $line[1];break;
                    case '再次触发活动间隔(天)':$extraData['act_gap_time'] = $line[1];break;
                }
            }
            $baseConfig['extraData'] = $extraData;
        }

        # 解析映射关系
        foreach ($stagesMappingArray as $k => $item){
            if(empty($k))continue;
            list($lvMin, $lvMax, $vipMin, $vipMax, $lostDayMin, $lostDayMax, $actEndTime, $idx) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            $vipKey = "{$vipMin}-$vipMax";
            $lostDayKey = "{$lostDayMin}-$lostDayMax";

            if(empty($lvMapping[$lvKey])){
                $lvMapping[$lvKey] = ++$starsStageCnt;
                $clubGardenConfig[$lvMapping[$lvKey]]  = [
                    'lvStart' => $lvMin,
                    'lvEnd' => $lvMax,
                    'stages' => [],
                ];
                $vipMapping[$lvKey] = [];
            }

            if(empty($vipMapping[$lvKey][$vipKey])){
                $vipMapping[$lvKey][$vipKey] = count($vipMapping[$lvKey]) + 1;
                $clubGardenConfig[$lvMapping[$lvKey]]['stages'][$vipMapping[$lvKey][$vipKey]] = [
                    'VipStart' => $vipMin,
                    'VipEnd' => $vipMax,
                    'stages' => [],
                ];
                $lostDayMapping[$lvKey.$vipKey] = [];
            }

            if(empty($lostDayMapping[$lvKey.$vipKey][$lostDayKey])){
                $lostDayMapping[$lvKey.$vipKey][$lostDayKey] = count($lostDayMapping[$lvKey.$vipKey]) + 1;
                $clubGardenConfig[$lvMapping[$lvKey]]['stages'][$vipMapping[$lvKey][$vipKey]]['stages'][$lostDayMapping[$lvKey.$vipKey][$lostDayKey]] = [
                    'lostDayStart' => $lostDayMin,
                    'lostDayEnd' => $lostDayMax,
                    'act_end_time' => $actEndTime,
                    'rewards' => [],
                ];
//                $lostDayMapping[$lvKey.$vipKey] = [];
            }
            $idxMapping[$idx] = [$lvMapping[$lvKey], $vipMapping[$lvKey][$vipKey], $lostDayMapping[$lvKey.$vipKey][$lostDayKey], $actEndTime];
        }

        # 解析阶段奖励配置
        foreach ($stagesRewardsArray as $k => $item){
            $filterLine = array_filter($item);
            if (empty($filterLine))continue;
            $line = $k + 1;
            if($k == 0)continue;

            list($idx, $staegIdx, $collDownTime,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,
                $reward4, $isFixNum4, $rewardNum4,
                $reward5, $isFixNum5, $rewardNum5 ) = $item;
            if(empty($idxMapping[$idx]))$this->response(-1, "第{$line}行,唯一id:{$idx} 无对应关系",$idxMapping);    #奖励不能为空
            list($idx1, $idx2, $idx3, $actEndTime) = $idxMapping[$idx];
            if(count($clubGardenConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['rewards']) != $staegIdx-1)$this->response(-1, "第{$line}行,阶段配置异常",[$item, $idxMapping]);    #奖励不能为空
            $rewardsTemp = [];
            for($i=1;$i<6;$i++){
                if(!empty(${'reward'.$i})){
                    if(!in_array(${'reward'.$i}, $multiNumTypeReward))${'isFixNum'.$i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum'.$i} = (${'isFixNum'.$i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $this->parseRewardTypeAndSkinId(${'reward'.$i}, $line);
                    $currentId = count($rewardsTemp)+1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum'.$i},
                        "type" => $type,
                        "rtype" => ${'isFixNum'.$i},
                        "skin" => $skin
                    ];
                }
            }

            if(empty($rewardsTemp))$this->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $clubGardenConfig[$idx1]['stages'][$idx2]['stages'][$idx3]['rewards'][$staegIdx] = [
                'stage' => $staegIdx,
                'cool_down_time' => $collDownTime,
                'prizes' => $rewardsTemp,
            ];
        }

        $baseConfig['greatMemoriesConfig'] = $clubGardenConfig;
//        echo json_encode($baseConfig);die;
        $this->hsave($baseConfig);
    }



    public function getCommonBasicConfig($type, $basicConfArray){
        $time = time();
        $today = date('Y-m-d 00:00:00', $time);
        $tomorrow = date('Y-m-d 00:00:00', $time + 86400);
        # 解析基础配置
        $baseConfig = [
            "id" =>"",
            "name" =>"import-".$type,
            "abType" =>"0",
            "abTest" =>"0",
            "taTest" =>"0",
            "openPush" =>"0",
            "old_type" =>"",
            "type" =>  $type ,
            "cid" =>"1",
            "sn_time" =>"{$today} - {$tomorrow}",
            "authDays" =>"0",
            "reward_time" =>"{$tomorrow}",
            "loop_type" =>"1",
            "loop_num" =>"",
            "client" =>"0",
            "user_type" =>"0",
            "uc_type" =>"0",
            "s_lv" =>"",
            "e_lv" =>"",
            "s_vip" =>"",
            "e_vip" =>"",
            "s_score" =>"",
            "e_score" =>"",
            "isComVersion" =>"0",
            "imgName"=>"",
            "show_title" =>[
                "en" =>"",
                "zh" =>"",
                "tw" =>"",
                "fr" =>"",
                "de" =>"",
                "es" =>"",
                "pt" =>"",
                "th" =>""
            ],
            "bname" =>[
                "en" =>"Join Now!",
                "zh" =>"立即参加!",
                "tw" =>"立即參加!",
                "fr" =>"Adhésion immédiate",
                "de" =>"Jetzt beitreten!",
                "es" =>"¡Únete ahora!",
                "pt" =>"Entrar!",
                "th" =>"เข้าร่วมเดี๋ยวนี้!"
            ],
            "bcolor" =>"1",
            "bskip" =>"0",
            "burl" =>"",
        ];
        $baseConfig = $this->parseBasicConfig($baseConfig, $basicConfArray);
        return $baseConfig;
    }
    public function getCommonBasicConfig2($type, $basicConfArray):array{
        $baseConfig = [];
        $filterPrefixArr = [
            TREASURE => [
                '开放等级' => 'treasureOpenLv',
                '体力存量系数（整数）' => 'spinsRatio',
                '难度系数' => 'difficultyDegree',
                '任务值系数' => 'taskDegree',
            ],
            BUILD_RANK => [
                '上榜门槛积分' => 'buildScoreSettingMinScore',
                '分区类型' => 'setType',
            ],
            RANK => [
                '分区类型' => 'setType',
            ],
        ];
        foreach ($basicConfArray as $lineKey => $line){
            if(!empty($filterPrefixArr[$type][$line[0]])){
                $baseConfig[$filterPrefixArr[$type][$line[0]]] = $line[1];
            }

        }
        return $baseConfig;
    }
    private function parseBasicConfig($basicConfig, &$importData){
        $resourceName = $basicConfig['type'];
        if($basicConfig['type'] == 'super_serial_pack4')$resourceName = 'super_serial_pack3';
        $imgNames = oo::commonOprModel('config')->getActiveImgNameConfig($resourceName);
        $couponImgNames = oo::commonOprModel('config')->getActiveImgNameConfig('couponSkin');
        $bcolors = array_flip(ACT_COLORS);
        $filterPrefixArr = [
            '活动名称',
            '活动类型',
            '参与等级',
            '是否开启版本向下兼容',
            '活动版本',
            '资源文件夹名',
            '按钮/进度条颜色',
            '开始自动创建天数',
            'startTime',
            '是否有spine动画',
            '最大购买次数',
            '活动优先级',
            '活动券皮肤',
            '客户端类型',
            '指定UID参与活动',
        ];
        $platforms = [
            '安卓' => 'Android',
            'IOS' => 'iOS',
        ];
        $clients = [
            '全部' => 0,
            '安卓' => 1,
            'IOS' => 2,
        ];
        $curEnv = $this->config->item('CUR_ENV') ?: "";
        foreach ($importData as $lineKey => $line){
            $lineNum = $lineKey+1;
            if(in_array($line[0], $filterPrefixArr)){
                switch ($line[0]){
                    case 'startTime':
                        $stime = $line[1];
                        $etime = $line[3];
                        $rwtime = $line[5];
                        if($line[2] != 'endTime'
                            ||$line[4] != 'rewardTime'
                            ||empty($stime)
                            ||empty($etime)
                            ||empty($rwtime)
                        )
                            $this->response(-1, $lineNum.'行时间格式错误');
                        $stime = date('Y-m-d H:i:s', strtotime($stime));
                        $etime = date('Y-m-d H:i:s', strtotime($etime));
                        $rwtime = date('Y-m-d H:i:s', strtotime($rwtime));
                        $basicConfig['sn_time'] = "{$stime} - {$etime}";
                        $basicConfig['reward_time'] = $rwtime;
                        break;
                    case '活动名称':
                        $basicConfig['name'] = $line[1];
                        break;
                    case '活动类型':
                        switch ($line[1]){
                            case '常规活动':$basicConfig['uc_type'] = 0;break;
                            case '道具活动':$basicConfig['uc_type'] = 1;break;
                            default:$this->response(-1, '活动类型异常,'.__LINE__);
                        }
                        break;
                    case '参与等级':
                        $basicConfig['s_lv'] = intval($line[1]);
                        $basicConfig['e_lv'] = intval($line[2]);
                        break;
                    case '是否开启版本向下兼容':
                        switch ($line[1]){
                            case '是':$basicConfig['isComVersion'] = 0;break;
                            case '否':$basicConfig['isComVersion'] = 1;break;
                            default:$this->response(-1, '活动版本向下兼容配置异常,'.__LINE__);
                        }
                        break;
                    case '是否有spine动画':
                        switch ($line[1]){
                            case '是':$basicConfig['extraData']['isShowSpine'] = 1;break;
                            case '否':$basicConfig['extraData']['isShowSpine'] = 0;break;
                            default:$this->response(-1, '是否有spine动画,'.__LINE__);
                        }
                        break;
                    case '活动版本':
                        $line[1] = strtr($line[1], ['，'=>',']);
                        $versions = explode(',', $line[1]);
                        $versions = array_filter($versions);
                        if(empty($versions))$this->response(-1, '活动版本配置不能为空,'.__LINE__);
                        foreach ($versions as $version){
                            if(!in_array($version, $this->versions))$this->response(-1, '版本：'.$version.' 不存在,'.__LINE__);
                        }
                        $basicConfig['act_version'] = $versions;
                        break;
                    case '资源文件夹名':
                        if(!empty($line[1])){
                            # 校验资源文件是否配置
                            $match = false;
                            foreach ($imgNames['content'] as $k => $v){
                                if($v['type'] == $line[1]){
                                    $match = true;
                                    $basicConfig['cid'] = $k;
                                    $basicConfig['imgName'] = $v['type'];
                                    break;
                                }
                            }
                            # 校验资源文件 bundle包是否存在
                            if($curEnv == 'exp'){
                                break;
                            }
                            if(!$match)$this->response(-1, "资源文件夹名:{$line[1]} 不存在，".__LINE__);

                            $line[1] = strtolower($line[1]);
                            if(!$this->isValidImgName($line[1], $basicConfig['extraData']['isShowSpine'], $errorMsg))
                                $this->response(-1, $errorMsg);


                        }
                        break;
                    case '活动券皮肤':
                        if(!empty($line[1])){
                            $match = false;
                            foreach ($couponImgNames['content'] as $k => $v){
                                if($v['type'] == $line[1]){
                                    $match = true;
                                    $basicConfig['act_coupon_skin'] = $v['type'];
                                    break;
                                }
                            }
                            if(!$match)$this->response(-1, "活动券皮肤:{$line[1]}不存在，".__LINE__);
                            # 校验资源文件是否配置
                            break;//暂时不校验活动券皮肤
                            if($curEnv == 'exp'){
                                break;
                            }
                            # 校验资源文件 bundle包是否存在
                            $line[1] = strtolower($line[1]);
                            if(!$this->isValidImgName($line[1], 0, $errorMsg))
                                $this->response(-1, $errorMsg);

                        }
                        break;
                    case '按钮/进度条颜色':
                        $basicConfig['bcolor'] = intval($bcolors[$line[1]]);
                        if(empty($basicConfig['bcolor']))$this->response(-1, '颜色配置异常,'.__LINE__);
                        break;
                    case '客户端类型':
                        if(!isset($clients[$line[1]]))$this->response(-1, '客户端类型不存在：'.$line[1]);
                        $basicConfig['client'] = intval($clients[$line[1]]);
                        break;
                    case '开始自动创建天数':
                        $basicConfig['authDays'] = intval($line[1]);
                        break;
                    case '最大购买次数':
                        $basicConfig['maxNum'] = intval($line[1]);
                        break;
                    case '活动优先级':
                        $basicConfig['priority'] = intval($line[1]);
                        break;
                    case '显示折扣数字':
                        $basicConfig['showDiscountVal'] = intval($line[1]);
                        break;
                    case '指定UID参与活动':
                        $basicConfig['appointUid'] = $line[1];
                        break;
                }
                unset($importData[$lineKey]);
            }

        }
        if(empty($basicConfig['s_lv'])|| empty($basicConfig['e_lv']))$this->response(-1, '参与等级异常,'.__LINE__);
        return $basicConfig;
    }
    private function getExcelArray(){
        $file = $this->uploader->getFileInfo();
        $extensionType = $this->getExtensionType($file['originalName']);

        $xlsReader = IOFactory::createReader($extensionType);
        $xlsReader->setReadDataOnly(true);
        $xlsReader->setLoadSheetsOnly(true);
        $Sheets = $xlsReader->load($file['url']);
        $dataArray = $Sheets->getSheet(0)->toArray() ?? [];
        foreach ($dataArray as $k => $item){
            foreach ($item as $k1 => $value){
                $item[$k1] = trim($value);
            }
            $line = array_filter($item);
            if(empty($line))unset($dataArray[$k]);
        }
        return $dataArray;
    }

    /**
     * Notes:限时开关收集活动编辑
     * User: wsc
     * Time: 2020/9/3 20:53
     * @return json
     */
    public function hExitCommonCfg(){
        $data = $this->input->post();
        $postData =$this->postData;
        $postData['mod'] = 'Activitynew';
        $postData['act'] = 'setActCommonCfg';
        $postData['type'] = $data['type'];
        if($data['type']=='collect'){
            $times = explode(" - ",$data['ts_collect_sn_time']);
            $d = [
                "ts_collect_stime"=>strtotime(date('YmdHi',strtotime($times[0]))),
                "ts_collect_etime"=>strtotime(date('YmdHi',strtotime($times[1]))),
                "ts_collect_time"=>intval($data['ts_collect_time']),
                "ts_collect_status"=>intval($data['ts_collect_status'])
            ];
        }
        $postData['config'] = json_encode($d);
        $res = $this->curl->req($this->_url, $postData);

        oo::logs()->adminlog($this->router->fetch_method().'--编辑限时收集：'.json_encode($data));

        $ret = json_decode($res,true);
        if($ret['code']==1){
            $this->response(0, $ret['msg']);
        }else{
            $this->response(1, $ret['msg']);
        }
    }

    public function reward(){
        $sn_time2 = get_cookie('sn_time2');
        if(empty($sn_time2)){
            $sn_time2 = date("Y-m-d 00:00:00")." - ".date("Y-m-d 23:59:59");
        }
        $data = $this->indexData($sn_time2,['chain_gift','super_serial_pack','super_serial_pack2','super_serial_pack3','super_serial_pack4','super_serial_pack7','rank']);
        $data['sn_time2'] = $sn_time2;
        $this->load->view('activity/h5/reward',$data);
    }

    public function iframe($id){
        $data = $this->editData($id);
        $this->load->view('activity/h5/iframe', $data);
    }

    public function js_unescape($str) {
        $ret = '';
        $len = strlen($str);

        for ($i = 0; $i < $len; $i++) {
            if ($str[$i] == '%' && $str[$i+1] == 'u') {
                $val = hexdec(substr($str, $i+2, 4));
                if ($val < 0x7f) $ret .= chr($val);
                else if($val < 0x800) $ret .= chr(0xc0|($val>>6)).chr(0x80|($val&0x3f));
                else $ret .= chr(0xe0|($val>>12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f));
                $i += 5;
            } else if ($str[$i] == '%') {
                $ret .= urldecode(substr($str, $i, 3));
                $i += 2;
            } else $ret .= $str[$i];
        }
        return $ret;
    }

    //收集活动 限时奖励 兼容旧版本时间
    function superCollectTsTime($data = []){
        $out = [];
        foreach($data as $key => $row){
            $out[$key]['s'] = date("Y-m-d H:i:s",strtotime($row['s']));
            $out[$key]['e'] = date("Y-m-d H:i:s",strtotime($row['e']));
        }
        return $out;
    }

    function superCollectPreview($id = 0){
        set_time_limit(0);
        if(empty($id))echo '非法操作!';
        $postData= $this->postData;
        $postData['id'] = $id;
        $postData['mod'] = 'Activitynew';
        $postData['act'] = 'getActivity';
        $res = $this->curl->req($this->_url, $postData);
        $actInfo = json_decode($res, TRUE);
        $extra_reward = json_decode($actInfo['extra_reward'], true);
        $reward_conf = json_decode($actInfo['reward_conf'], true);
        $actInfo['extra_reward'] = $extra_reward;
        $actInfo['reward_conf'] = $reward_conf;

        $tb = otable::slotSpinsReturnRateCfg();
        $sql = "SELECT * FROM {$tb} ";
        $spinReturnCfg = oo::commonOprDb('games')->getAll($sql,1);
        $spinReturnCfg = array_column($spinReturnCfg, 'config', 'type');
        foreach ($spinReturnCfg as $k => $v){
            $spinReturnCfg[$k] = json_decode($v, true);
        }
        $tb = otable::slotFreezePointCfg();
        $sql = "SELECT * FROM {$tb} ";
        $freezePointCfg = oo::commonOprDb('games')->getAll($sql,1);
        $freezePointCfg = array_column($freezePointCfg, 'config', 'type');
        foreach ($freezePointCfg as $k => $v){
            $freezePointCfg[$k] = json_decode($v, true);
        }
//        echo json_encode($extra_reward);die;
        $tb = otable::slotWeightCfg();
        $sql = "select * from {$tb} where levelId=2 limit 1";
        $conf = oo::commonOprDb('games')->getOne($sql, MYSQLI_ASSOC);
        $ret = $conf['slotpro'];
        $lastSlotWeight = json_decode($ret,true);
        $defaultWeight = array_column($lastSlotWeight, 'v', 'id');

        $maxStage = max(array_keys($extra_reward));
        foreach ($extra_reward as $k => $stage){
            $randSpins = intval(($stage['star'] + $stage['end']) / 2);
            if($k == $maxStage){
                $randSpins = $stage['star'] * 2;
            }
            $limit = 600;
            for ($i = 1; $i<= $limit; $i++){
                $uid = ( $k - 1 ) * $limit + $i;
                $configType = 'configA';
                if($uid%2){
                    $configType = 'configB';
                }
                $this->superCollectPreviewUsers[$uid] = [
                    'uid' => $uid,
                    'startSpins' => $randSpins,
                    'currentSpins' => $randSpins,
                    'spendSpins' => 0,
                    'currentStage' => 0,
                    'completeStage' => 0,
                    'getSpins' => 0,
                    'scoreTotal' => 0,
                    'score' => 0,
                    'progress' => 0,
                    'configType' => $configType,
                ];
                while($this->superCollectPreviewUsers[$uid]['currentSpins'] > 0){
                    $slotWeight = $this->getThisSlotWeight(
                        $defaultWeight,
                        $this->superCollectPreviewUsers[$uid],
                        $reward_conf['groupId'],
                        $stage,
                        $spinReturnCfg[$configType],
                        $freezePointCfg[$configType]);
                    $rid = $this->slot($uid, $slotWeight);
                    switch ($rid){
                        case 1:#攻击
                            $this->superCollectPreviewUsers[$uid]['attack'] = empty($this->superCollectPreviewUsers[$uid]['attack']) ? 1 : $this->superCollectPreviewUsers[$uid]['attack']+1;
                            $score = max($actInfo['reward_conf']['attack_success'], $actInfo['reward_conf']['attack_break']);
                            if(!empty($score)){
                                $this->superCollectPreviewUsers[$uid]['scoreTotal']+=$score;
                            }
                            break;
                        case 2:#偷
                            $this->superCollectPreviewUsers[$uid]['steal'] = empty($this->superCollectPreviewUsers[$uid]['steal']) ? 1 : $this->superCollectPreviewUsers[$uid]['steal']+1;
                            $score = max($actInfo['reward_conf']['steal_success'], $actInfo['reward_conf']['steal_break']);
                            if(!empty($score)){
                                $this->superCollectPreviewUsers[$uid]['scoreTotal']+=$score;
                            }
                            break;
                        case 3:#体力
                            $this->superCollectPreviewUsers[$uid]['currentSpins']++;
                            $this->superCollectPreviewUsers[$uid]['getSpins'] = $this->superCollectPreviewUsers[$uid]['getSpins'] ?? 0;
                            $this->superCollectPreviewUsers[$uid]['getSpins']++;
                            $this->superCollectPreviewUsers[$uid]['spins'] = empty($this->superCollectPreviewUsers[$uid]['spins']) ? 1 : $this->superCollectPreviewUsers[$uid]['spins']+1;
                            break;
                        case 4:#护盾
                            $this->superCollectPreviewUsers[$uid]['shief'] = empty($this->superCollectPreviewUsers[$uid]['shief']) ? 1 : $this->superCollectPreviewUsers[$uid]['shief']+1;
                            break;
                        case 5:#1金
                            $this->superCollectPreviewUsers[$uid]['coin1'] = empty($this->superCollectPreviewUsers[$uid]['coin1']) ? 1 : $this->superCollectPreviewUsers[$uid]['coin1']+1;
                            break;
                        case 6:#2金
                            $this->superCollectPreviewUsers[$uid]['coin2'] = empty($this->superCollectPreviewUsers[$uid]['coin2']) ? 1 : $this->superCollectPreviewUsers[$uid]['coin2']+1;
                            break;
                        case 7:#3金
                            $this->superCollectPreviewUsers[$uid]['coin3'] = empty($this->superCollectPreviewUsers[$uid]['coin3']) ? 1 : $this->superCollectPreviewUsers[$uid]['coin3']+1;
                            break;
                        case 8:#4金
                            $this->superCollectPreviewUsers[$uid]['coin4'] = empty($this->superCollectPreviewUsers[$uid]['coin4']) ? 1 : $this->superCollectPreviewUsers[$uid]['coin4']+1;
                            break;
                        case 9:#5金
                            $this->superCollectPreviewUsers[$uid]['coin5'] = empty($this->superCollectPreviewUsers[$uid]['coin5']) ? 1 : $this->superCollectPreviewUsers[$uid]['coin5']+1;
                            break;
                        case 10:#6金
                            $this->superCollectPreviewUsers[$uid]['coin6'] = empty($this->superCollectPreviewUsers[$uid]['coin6']) ? 1 : $this->superCollectPreviewUsers[$uid]['coin6']+1;
                            break;
                        case 11:#空
                            $this->superCollectPreviewUsers[$uid]['empty'] = empty($this->superCollectPreviewUsers[$uid]['empty']) ? 1 : $this->superCollectPreviewUsers[$uid]['empty']+1;
                            break;
                        case 12:#1收集
                            $this->superCollectPreviewUsers[$uid]['hit1'] = empty($this->superCollectPreviewUsers[$uid]['hit1']) ? 1 : $this->superCollectPreviewUsers[$uid]['hit1']+1;
                            if(!empty($actInfo['reward_conf']['one_hit'])){
                                $this->superCollectPreviewUsers[$uid]['scoreTotal']+=$actInfo['reward_conf']['one_hit'];
                            }
                            break;
                        case 13:#2收集
                            $this->superCollectPreviewUsers[$uid]['hit2'] = empty($this->superCollectPreviewUsers[$uid]['hit2']) ? 1 : $this->superCollectPreviewUsers[$uid]['hit2']+1;
                            if(!empty($actInfo['reward_conf']['two_hit'])){
                                $this->superCollectPreviewUsers[$uid]['scoreTotal']+=$actInfo['reward_conf']['two_hit'];
                            }
                            break;
                        case 14:#3收集
                            $this->superCollectPreviewUsers[$uid]['hit3'] = empty($this->superCollectPreviewUsers[$uid]['hit3']) ? 1 : $this->superCollectPreviewUsers[$uid]['hit3']+1;
                            if(!empty($actInfo['reward_conf']['three_hit'])){
                                $this->superCollectPreviewUsers[$uid]['scoreTotal']+=$actInfo['reward_conf']['three_hit'];
                            }
                            break;
                    }
                    $this->parseScoreStage($uid, $stage);
                }
            }
        }
        $headers=[
            "uid" => "uid",
            "configType" => "体力反比配置组",
            'spendSpins' => "体力总消耗",
            'startSpins' =>"进入体力",
            'scoreTotal' => "收集物总数",
            'currentStage' => "达到层",
            'getSpins' => "体力总产出",
            'score' => "当前层收集物数",
            'stepnum' => "当前层预期收集物数",
            'progress' => "卡点进度",
            'attack' => "攻击",
            'steal' => "偷",
            'spins' => "体力",
            'shief' => "盾牌",
            'coin1' => "1金",
            'coin2' => "2金",
            'coin3' => "3金",
            'coin4' => "4金",
            'coin5' => "5金",
            'coin6' => "6金",
            'empty' => "空",
            'hit1' => "收1",
            'hit2' => "收2",
            'hit3' => "收3"
        ];
        $file_name = '收集活动数据预览-'.$id.'-'.date('YmdHis') . '.csv';
        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 ($this->superCollectPreviewUsers as $uid => $user){
            $line = [];
            foreach ($headers as $k => $v){
                $line[] = $user[$k] ?? '-';
            }
            fputcsv($f, $line);
        }
        fclose($f);
    }
    private function parseScoreStage($uid, $stageList){
        $score = $this->superCollectPreviewUsers[$uid]['scoreTotal'];
        foreach ($stageList['list'] as $stage => $items){
            if($score < $items['stepnum'])break;
            if($stage > $this->superCollectPreviewUsers[$uid]['completeStage']){

                #领奖
                foreach ($items['prize'] as $prize){
                    if($prize['type'] == 15){
                        $this->superCollectPreviewUsers[$uid]['currentSpins']+=$prize['num'];
                        $this->superCollectPreviewUsers[$uid]['getSpins']+=$prize['num'];
                    }
                }
                $this->superCollectPreviewUsers[$uid]['completeStage'] = $stage;
            }
            $score -= $items['stepnum'];
        }
        $this->superCollectPreviewUsers[$uid]['score'] = $score;
        $this->superCollectPreviewUsers[$uid]['currentStage'] = $this->superCollectPreviewUsers[$uid]['completeStage'] + 1;
        $this->superCollectPreviewUsers[$uid]['progress'] = number_format($score / $items['stepnum'],2);
        $this->superCollectPreviewUsers[$uid]['stepnum'] =  $items['stepnum'];
    }
    private function getCollectSumNum($stage, $stageList){
        $stepnum = 0;
        $stagePro = 0;
        foreach ($stageList['list'] as $k => $v){
            if($stage < $k)break;
            $stepnum+= $v['stepnum'];
            $stagePro += $v['stageSpins'];
        }
        $getCollectSumNum = [
            'sumExpectSpins' => $stagePro,
            'sumExpectGrade' => $stepnum,
        ];
        return $getCollectSumNum;
    }

    private function slot($uid, $slotWeight){
        $this->superCollectPreviewUsers[$uid]['currentSpins']--;
        $this->superCollectPreviewUsers[$uid]['spendSpins']++;

        $result = '';
        foreach ($slotWeight as $k=>$v){
            $proArr[$k]=intval($v*100);
        }
        //概率数组的总概率精度
        $proSum = array_sum($proArr);
        //概率数组循环
        foreach ($proArr as $key => $proCur) {
            $randNum = mt_rand(1, $proSum);
            if ($randNum <= $proCur) {
                $result = $key;
                break;
            } else {
                $proSum -= $proCur;
            }
        }
        unset ($proArr);
        return $result;
    }
    public function getThisSlotWeight($lastSlotWeight, $userInfo, $actType, $stage, $spinReturnCfg, $freezePointCfg){
        //查询数据库概率
//        $lastSlotWeight = [1=>60,2=>25,3=>10,4=>40,5=>240,6=>130,7=>75,8=>200,9=>130,10=>60,11=>30,12=>120,13=>90,14=>40];

        //老虎机体力返比控制
        $returnRate = 1;
        $config = $spinReturnCfg;
        //[ * 1、累计预设消耗体力 sumExpectSpins, 2、累计预设分数     sumExpectGrade]
        $getCollectActSpins = $userInfo['spendSpins'];//累计消耗体力
        $getCollectActAdd = $userInfo['scoreTotal'];//累计获取

        $getCollectSumNum = $this->getCollectSumNum($userInfo['currentStage'], $stage);
        $a = empty($getCollectSumNum['sumExpectSpins']) ? 0 : $getCollectActSpins / $getCollectSumNum['sumExpectSpins'];
        $b = empty($getCollectSumNum['sumExpectGrade']) ? 0 : $getCollectActAdd / $getCollectSumNum['sumExpectGrade'];

        $getCollectSumNum['currentSpins'] = $getCollectActSpins;
        $getCollectSumNum['currentGrade'] = $getCollectActAdd;
        $getCollectSumNum['a'] = $a;
        $getCollectSumNum['b'] = $b;
        $bArr = [];
        if(!empty($config['config'] ) && is_array($config['config'])){
            krsort($config['config']);
            foreach ($config['config'] as $ak => $values){
                $bArr = $values;
                if($a >= $ak)break;
            }

            $bMap = [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"];
            $bk = 1;
            for($k = 11; $k > 0; $k--){
                $v = $bMap[$k];
                $bk = $k;
                if($b >= $v)break;
            }
            if(isset($bArr[$bk]))$returnRate = $bArr[$bk];
        }


        $hasSpins = false;
        if(!empty($reward['extra_reward']) ){
            $stagePrizes = $stage['list'][$userInfo['currentStage']]['prize'] ?? [];
            foreach ($stagePrizes as $item){#奖励中是否包含体力
                if(!empty($item['type']) && $item['type'] == 15){
                    $hasSpins = true;
                    break;
                }
            }
        }
        #当前层大于10 且有体力奖励
        $freezePointRate = 1;
        $freezePointMinStage = 0;
        if($userInfo['currentStage'] > $freezePointMinStage && $hasSpins){
            #取上一层的累计值
            $getCollectSumNumPreStage = $this->getCollectSumNum($userInfo['currentStage'] - 1, $stage);

            #当前层总分 = 当前层累积预设分数 - 上一层累积预设分数
            $currentStageGrade = $getCollectSumNum['sumExpectGrade'] - $getCollectSumNumPreStage['sumExpectGrade'];

            #当前层预设体力 = 当前层累积预设体力 - 上一层累积预设体力
            $currentStageSpins = $getCollectSumNum['sumExpectSpins'] - $getCollectSumNumPreStage['sumExpectSpins'];

            #当前层获得分数 = 当累积获取 - 上层累积预设分数
            $currentGrade = $getCollectActAdd - $getCollectSumNumPreStage['sumExpectGrade'];

            #收集活动卡点修正
            #A =（当前层总分-当前层获得分数）/ 当前层总分
            $a = empty($currentStageGrade) ? 0 : ($currentStageGrade - $currentGrade ) / $currentStageGrade;

            #B =（ 剩余体力 / 当前收集层预设体力
            $b = empty($currentStageSpins) ? 0 : $userInfo['currentSpins'] / $currentStageSpins;

            #根据用户组获取收集卡点配置
            $config = $freezePointCfg;

            #根据 A、B 获取具体的修正值
            if(!empty($config['config'] ) && is_array($config['config'])){
                ksort($config['config']);
                foreach ($config['config'] as $ak => $values){
                    $bArr = $values;
                    if($a <= $ak)break;
                }
                $bMap = [
                    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",
                    12=>"1.1",
                    13=>"1.2",
                    14=>"1.3",
                    15=>"1.4",
                    16=>"1.5",
                ];
                $bk = 1;
                foreach ($bMap as $k => $v){
                    $bk = $k;
                    if($b <= $v)break;
                }

                #将修正值乘上体力返比修正值
                if(isset($bArr[$bk]))$freezePointRate *= $bArr[$bk];
            }
        }
        $returnRate *= $freezePointRate;

        $groupId = $actType;
        if($groupId==1){//普通收集 (收集物3)
            $actChildType =  1;
        }else if(in_array($groupId,[2,3,4,7])){//特殊收集,特殊收集偷,特殊收集打 (收集物1,2,3)
            $actChildType =  2;
        }else if($groupId==8){//偷收集
            $actChildType =  4;
        }else if($groupId==9){//打收集
            $actChildType =  5;
        }else{//偷,打(无收集物)
            $actChildType =  0;
        }


        $slotWeightBf= $lastSlotWeight;
        unset($lastSlotWeight[12],$lastSlotWeight[13],$lastSlotWeight[14],$lastSlotWeight[15],$lastSlotWeight[16],$lastSlotWeight[17],$lastSlotWeight[18],$lastSlotWeight[19],$lastSlotWeight[20],$lastSlotWeight[21],$lastSlotWeight[22],$lastSlotWeight[23]);
        //收集活动过滤权重
        if($actChildType==1){//普通收集
            $lastSlotWeight[14] = $slotWeightBf[14] * $returnRate;

        }
        if($actChildType==2){//特殊收集,特殊收集偷,特殊收集打 (收集物1,2,3)
            $lastSlotWeight[12] = $slotWeightBf[12] * $returnRate;
            $lastSlotWeight[13] = $slotWeightBf[13] * $returnRate;
            $lastSlotWeight[14] = $slotWeightBf[14] * $returnRate;
        }
        if($actChildType==4){//偷收集
            $lastSlotWeight[18] = $slotWeightBf[18] * $returnRate;
            $lastSlotWeight[19] = $slotWeightBf[19] * $returnRate;
        }
        if($actChildType==5){//打收集
            $lastSlotWeight[20] = $slotWeightBf[20] * $returnRate;
            $lastSlotWeight[21] = $slotWeightBf[21] * $returnRate;
        }


        //收集活动体力返比
        if($returnRate != 1){
            if($actType == 1 || $actType == 7){
                $lastSlotWeight[1] *= $returnRate;//打
                $lastSlotWeight[2] *= $returnRate;//偷
            }else if($actType == 3 || $actType == 5 || $actType == 8){
                $lastSlotWeight[2] *= $returnRate;//偷
            }else if($actType == 4 || $actType == 6 || $actType == 9){
                $lastSlotWeight[1] *= $returnRate;//打
            }
        }
        return $lastSlotWeight;
    }

    public function checkImgName($imgName, $isShowSpine){
        $post = $this->input->post();
        $imgName = $post['imgName'] ?? '';
        $isShowSpine = $post['isSpine'] ?? 0;
        $curEnv = $this->config->item('CUR_ENV') ?: "";
        if($curEnv == 'exp'){
            $this->response(1, '');
        }
        $imgName = strtolower(urldecode($imgName)) ;
        $imgName = trim($imgName,DIRECTORY_SEPARATOR );

        $errorMsg = '';
        if(!$this->isValidImgName($imgName, $isShowSpine, $errorMsg)){
            $this->response(-1, $errorMsg);
        }
        $this->response(1, '');
    }

    private function isValidImgName($imgName, $isShowSpine, &$msg = ''):bool {
        $imgName = strtolower(urldecode($imgName)) ;
        $imgName = trim($imgName,DIRECTORY_SEPARATOR );
        $platforms = [
            '安卓' => 'Android',
            'IOS' => 'iOS',
        ];
        $spinePrefix = '';
        foreach ($platforms as $platform => $platformDir){
            if($isShowSpine > 0){
                $platformDir .= '/collect';
                $spinePrefix = '带spine动画的';
            }
            $sourceDir = __ROOT__ . "/public/game/crazycoin/activity/{$platformDir}/$imgName";
            if(!is_dir($sourceDir)){
                $msg = $platform. $spinePrefix.'资源文件夹不存在：'.$imgName;
                return false;
            }
        }
        return true;
    }

    public function getPrizeShowFromTable($id,$reward, $isFixNum, $rewardNum){
        if(!in_array($reward, $this->multiNumTypeReward))$isFixNum = '是';   #非金币奖励，全部固定值奖励
        $isFixNum = ($isFixNum == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
        list($type, $skin) = $this->parseRewardTypeAndSkinId($reward, $id);
        $rewardsOne[] = [
            'id' => $id,
            "num" => $rewardNum,
            "type" => $type,
            "rtype" => $isFixNum,
            "skin" => $skin
        ];
        return $rewardsOne;
    }

    public function getActStageReward($aid, $stage){
        $stageRewardKey = okeys::activityRewardsStageKeys($aid);
        $reward = oo::commonOprRedis('games')->hGet($stageRewardKey, $stage);
        if(empty($reward)){
            $tbl = otable::actStageRewardsConf();
            $reward = oo::commonOprDb('slavedb')->getOne("select * from {$tbl} where aid = {$aid} and stage = '{$stage}' limit 1");

            if (empty($reward['rewards'])) {
                $stages = explode('_', $stage);
                $stage = "{$stages[1]}_{$stages[2]}";
                $reward = oo::commonOprDb('slavedb')->getOne("select * from {$tbl} where aid = {$aid} and stage = '$stage' limit 1");
            }

            $reward = $reward['rewards'];
        }
        $reward = empty($reward) ? [] : json_decode($reward, true);
        $this->response( 1, 'success', (array)$reward);
    }

    public function getActStageRewardOuterWrap($aid, $stage){
        $actTypeMap = [
            'treasure' => ['extraData', 'yStages']
        ];
        $reward = [];
        $actInfo = oo::commonOprRedis('games')->hGetAll(okeys::activityInfo($aid));
        $actInfo = array_merge((array)$actInfo, (array)oo::commonOprRedis('games')->hGetAll(okeys::activityExtraInfo($aid)));
        if(!empty($actTypeMap[$actInfo['type']]) ){
            $idxKey = 0;
            $typeKeys = $actTypeMap[$actInfo['type']];
            $typeKeys[] = $stage;
            $reward = $actInfo;
            while(!empty($typeKeys[$idxKey])){
                $tmpKey = $typeKeys[$idxKey];
                if(empty($reward[$tmpKey])){
                    break;
                }
                if(!is_array($reward[$tmpKey]))$reward = json_decode($reward[$tmpKey], true);
                else $reward = $reward[$tmpKey];
                $idxKey++;
            }
//            list($key1, $key2) = $actTypeMap[$actInfo['type']];
//            if(!empty($actInfo[$key1])){
//                if(!is_array($actInfo[$key1]))$actInfo[$key1] = json_decode($actInfo[$key1], true);
//                if(!empty($actInfo[$key1][$key2])){
//                    if(!is_array($actInfo[$key1][$key2]))$actInfo[$key1][$key2] = json_decode($actInfo[$key1][$key2], true);
//                    if(!empty($actInfo[$key1][$key2][$stage])){
//                        if(!is_array($actInfo[$key1][$key2][$stage]))$actInfo[$key1][$key2][$stage] = json_decode($actInfo[$key1][$key2][$stage], true);
//                        $reward = $actInfo[$key1][$key2][$stage];
//                    }
//                }
//            }
        }
        $this->response( 1, 'success', (array)$reward);
    }

    # 获取限时卡组主题列表
    public function getTimeLimitedCardsThemes(){
        $themes = oo::commonOprDb('slavedb')->getAll('select * from ' . otable::cardgroup_limit_theme_config() . ' order by id desc');
        $this->response(1, '', ['themes' => $themes]);
    }

    public function coinPushPro(){
        $config = ActivityModel::getCoinPushPro();
        $headers = [
            'bet' => '倍率',
            'spins' => '体力消耗',
            'pro' => '概率（ 0-100）',
        ];
        $data = [
            'title' => '推金币收集物概率配置',
            'headers' => $headers,
            'config' => $config,
            'js' => '',
            'topOperators' => [
                '<input type="file" style="display: none" id="import-file" onchange="commonImport(this)" data-href="/import/coinPushPro">',
                '<button type="button" class="btn btn-outline btn-success" onclick="$(\'#import-file\').click()"  >导入</button>',
                '<a type="button" class="btn btn-outline btn-primary"  href="/export/coinPushPro" target="_blank">导出</a>',
            ],
            'operators' => [],
        ];
        $this->load->view('common/commonTable', $data);
    }

    // 根据活动类型获取基础配置
    public function getActBasicConfig($type){

        $config = ActBaseModel::getActModel($type)->getActBasicConfig();
        $this->response(0, '', $config);
    }
}
