<?php

class ActivityModel extends CI_Model
{

    // 构建活动公共配置
    public static function buildCommonConf(array &$data): array
    {
        $commonConf = [];
        $commonConf['showDiscountVal'] = $data['showDiscountVal'] ?? 0;
        $commonConf['appointUid'] = rtrim(str_replace("，", ",", $data['appointUid']), ', ');
        unset($data['showDiscountVal'], $data['appointUid']);

        return $commonConf;
    }

    // 获取活动公共配置
    public static function getCommonConf(int $aid): array
    {
        $tb = otable::activityCommonConf();
        $info = oo::commonOprDb('slavedb')->getOne("SELECT * FROM {$tb} WHERE `aid`={$aid}");

        return json_decode($info['config'] ?? '{}', true);
    }

    // 更新活动公共配置
    public static function setCommonConf(int $aid, array $config)
    {
        $tb = otable::activityCommonConf();
        $info = oo::commonOprDb('slavedb')->getOne("SELECT * FROM {$tb} WHERE `aid`={$aid}");

        $configStr = json_encode($config, JSON_NUMERIC_CHECK);
        if (empty($info)) {
            $sql = "INSERT INTO {$tb} (`aid`, `config`) VALUES('$aid', '$configStr') ";
        } else {
            $sql = "UPDATE {$tb} SET `config` = '{$configStr}' WHERE `aid` = {$aid}";
        }

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

        // 清空缓存
        $cacheKey = okeys::actCommonConf($aid);
        oo::commonOprRedis('games')->delete($cacheKey);
    }

    //二维化幸运狐狸的配置数据
    public static function formatLuckyFoxConf(&$luckyFoxConf): bool
    {
        foreach ($luckyFoxConf as &$oneLvStage) {
            foreach ($oneLvStage['stages'] as &$oneSpinsStage) {
                $flag = self::gridLayerFormat($oneSpinsStage['list']);
                if (!$flag) {
                    return false;
                }
            }
        }

        $luckyFoxConf = json_encode($luckyFoxConf, JSON_NUMERIC_CHECK);
        return true;
    }

    private static function gridLayerFormat(&$list): bool
    {
        $formatConf = [];
        foreach ($list as $oneConf) {
            if (empty($oneConf['grid']) || empty($oneConf['layer']) || empty($oneConf['weight']) || empty($oneConf['prize'])) {
                return false;
            }
            $formatConf[$oneConf['grid'] - 1][$oneConf['layer'] - 1] = $oneConf;
        }
        $list = $formatConf;

        return true;
    }

    //一维化幸运狐狸的配置数据
    public static function serializeLuckyFoxConf($luckyFoxConf)
    {
        $luckyFoxConf = json_decode($luckyFoxConf, true);
        foreach ($luckyFoxConf as &$oneLvStage) {
            foreach ($oneLvStage['stages'] as &$oneSpinsStage) {
                $oneSpinsStage['list'] = self::gridLayerSerialize($oneSpinsStage['list']);
            }
        }

        return json_encode($luckyFoxConf, JSON_NUMERIC_CHECK);
    }

    private static function gridLayerSerialize($list): array
    {
        $formatConf = [];
        $count = 0;
        foreach ($list as $oneGrid) {
            foreach ($oneGrid as $oneLayer) {
                $formatConf[++$count] = $oneLayer;
            }
        }

        return $formatConf;
    }

    //格式化收集活动的奖励配置
    public static function formatSuperCollectConf(string $rewardString)
    {
        $rewardInfo = json_decode($rewardString, true);
        if (isset($rewardInfo[1]['start']) && isset($rewardInfo[1]['end'])) {
            // 旧活动的体力区间字段替换
            $rewardString = str_replace("start", "spinsStart", $rewardString);
            $rewardString = str_replace("end", "spinsEnd", $rewardString);
            $rewardInfo = json_decode($rewardString, true);

            // 塞进一个大的等级区间
            $rewardInfo = [
                1 => [
                    'lvStart' => 0,
                    'lvEnd' => 999999999,
                    'stages' => $rewardInfo
                ]
            ];
        }

        // unset 每个区间的奖励配置 用ajax异步加载
        foreach ($rewardInfo as &$lvItem) {
            foreach ($lvItem['stages'] as &$spinsItem) {
                foreach ($spinsItem['stages'] as &$ssItem) {
                    $ssItem['list'] = [];
                }
            }
        }

        return json_encode($rewardInfo);
    }

    //格式化体力大师的奖励配置
    public static function formatSpinsMasterConf(string $rewardString)
    {
        $rewardInfo = json_decode($rewardString, true);
        if (isset($rewardInfo[1]['start']) && isset($rewardInfo[1]['end'])) {
            // 旧活动的体力区间字段替换
            $rewardString = str_replace("start", "spinsStart", $rewardString);
            $rewardString = str_replace("end", "spinsEnd", $rewardString);
            $rewardInfo = json_decode($rewardString, true);

            // 塞进一个大的等级区间
            $rewardInfo = [
                1 => [
                    'lvStart' => 0,
                    'lvEnd' => 999999999,
                    'stages' => $rewardInfo
                ]
            ];
        }

        // unset 每个区间的奖励配置 用ajax异步加载
        foreach ($rewardInfo as &$lvItem) {
            foreach ($lvItem['stages'] as &$spinsItem) {
                foreach ($spinsItem['stages'] as &$ssItem) {
                    $ssItem['reward'] = [];
                }
            }
        }

        return json_encode($rewardInfo);
    }

    //去除奖励配置项(三层分组)
    public static function unsetThirdRewardConf(string $rewardString)
    {
        $rewardInfo = json_decode($rewardString, true);
        // unset 每个区间的奖励配置 用ajax异步加载
        foreach ($rewardInfo as &$lvItem) {
            foreach ($lvItem['stages'] as &$spinsItem) {
                foreach ($spinsItem['stages'] as &$ssItem) {
                    $ssItem['reward'] = [];
                }
            }
        }

        return json_encode($rewardInfo);
    }

    //去除奖励配置项(二层分组)
    public static function unsetSecondRewardConf(string $rewardString)
    {
        $rewardInfo = json_decode($rewardString, true);
        // unset 每个区间的奖励配置 用ajax异步加载
        foreach ($rewardInfo as &$lvItem) {
            foreach ($lvItem['stages'] as &$spinsItem) {
                $spinsItem['reward'] = [];
            }
        }

        return json_encode($rewardInfo);
    }

    //兼容收集活动的奖励配置
    public static function formatCollectJigsawConf(string $rewardString)
    {
        $rewardInfo = json_decode($rewardString, true);
        if (isset($rewardInfo[1]['start']) && isset($rewardInfo[1]['end'])) {
            // 旧活动的体力区间字段替换
            $rewardString = str_replace("start", "spinsStart", $rewardString);
            $rewardString = str_replace("end", "spinsEnd", $rewardString);
            $rewardInfo = json_decode($rewardString, true);

            // 塞进一个大的等级区间
            $rewardInfo = [
                1 => [
                    'lvStart' => 0,
                    'lvEnd' => 999999999,
                    'stages' => $rewardInfo
                ]
            ];
        }

        // unset 每个区间的奖励配置 用ajax异步加载
        foreach ($rewardInfo as &$lvItem) {
            foreach ($lvItem['stages'] as &$spinsItem) {
                foreach ($spinsItem['stages'] as &$ssItem) {
                    $ssItem['reward'] = [];
                }
            }
        }

        return json_encode($rewardInfo);
    }

    //兼容锦标赛的房间分区配置
    public static function formatRankRoomAllotConf(string $rewardString)
    {
        $rewardInfo = json_decode($rewardString, true);
        if (isset($rewardInfo['roomAllotConf'])) {
            return $rewardString;
        }

        $spinsSet = $rewardInfo['spinsSet'];
        $spinsSetSpins = $rewardInfo['spinsSetSpins'];

        $lvRangeConf = [];
        for ($i = 0; $i < count($spinsSet) - 1; $i++) {
            $lvRangeConf[] = [
                'spinsStart' => $spinsSet[$i],
                'spinsEnd' => $spinsSet[$i + 1] - 1,
                'robotStop' => $spinsSetSpins[$i]
            ];
        }

        // 塞进一个大的等级区间
        $rewardInfo['roomAllotConf'] = [
            [
                'lvStart' => 0,
                'lvEnd' => 999999999,
                'stages' => $lvRangeConf
            ]
        ];

        return json_encode($rewardInfo);
    }

    //兼容四选一活动的奖励配置
    public static function formatEasterEggConf(string $rewardString)
    {
        $rewardInfo = json_decode($rewardString, true);
        foreach ($rewardInfo['protect'] as &$oneProtect) {
            if (isset($oneProtect['lv'])) {
                $oneProtect['lvMin'] = $oneProtect['lvMax'] = $oneProtect['lv'];
                unset($oneProtect['lv']);
            }
        }

        return json_encode($rewardInfo, JSON_NUMERIC_CHECK);
    }

    // 解析活动奖励配置
    public static function parseOtherConfig(Activity $activity, string $aType, array &$baseConfig, array $basicConfArray, array $dataArray)
    {
        $stagesMappingArray = $dataArray[1] ?? [];
        $stagesRewardsArray = $dataArray[2] ?? [];
        $stagesRewardsMoreArray = $dataArray[3] ?? [];

        # 解析映射关系
        list($activityConf, $idxMapping) = ActivityModel::analysisConfMap($activity, $aType, $stagesMappingArray);

        # 解析奖励
        switch ($aType) {
            case DRIFT_TREASURE:    // 漂流的宝藏
            case TRAVEL_DIARY:      // 旅行日记
                $baseConfig['driftTreasureConfig'] = ActivityModel::driftTreasureReward($activity, $baseConfig, $basicConfArray, $stagesRewardsArray, $activityConf, $idxMapping);
                break;
            case SPINS_MASTER:  //体力大师
                $baseConfig['spinsMasterConfig'] = ActivityModel::spinsMasterReward($activity, $stagesRewardsArray, $activityConf, $idxMapping);
                break;
            case JIGSAW:  // 拼图活动
                $baseConfig['jigsawConfig'] = ActivityModel::jigsawReward($activity, $stagesRewardsArray, $activityConf, $idxMapping);
                break;
            case LUCKY_FOX:  // 幸运狐狸
                $baseConfig['luckyFoxConfig'] = ActivityModel::luckyFoxReward($activity, $stagesRewardsArray, $activityConf, $idxMapping);
                break;
            case SUPER_GASHAPON:  // 超级扭蛋
                $baseConfig['superGashaponConfig'] = ActivityModel::superGashaponReward($activity, $stagesRewardsArray, $activityConf, $idxMapping);
                break;
            case SUPER_BOMB:  // 超级炸弹
                $baseConfig['superBombConfig'] = ActivityModel::superBombConfig($basicConfArray);
                break;
            case CRAZY_BUILD:  // 疯狂建造
                $baseConfig['crazyBuildConfig'] = ActivityModel::crazyBuildConfig($activity, $baseConfig, $basicConfArray, $stagesRewardsArray, $activityConf, $idxMapping);
                break;
            case SPECIAL_NOTICE:  // 特殊公告
                $baseConfig['specialNoticeConfig'] = ActivityModel::specialNoticeConfig($activity, $basicConfArray, $stagesMappingArray);
                break;
            case SUPER_SERIAL_PACK5:  // 有进度六格连环礼包
            case SUPER_SERIAL_PACK6:  // 有进度连环礼包1
            case SUPER_SERIAL_PACK7:  // 有进度连环礼包2
                $baseConfig['superSerialProgressConfig'] = ActivityModel::superSerialProgressConfig($activity, $stagesRewardsArray, $stagesRewardsMoreArray, $activityConf, $idxMapping);
                break;
            case TIME_LIMITED_CARD:  // 限时卡组
                $baseConfig['timeLimitedCards'] = ActivityModel::timeLimitedCards($activity, $basicConfArray, $dataArray[1] ?? []);
                break;
            default:
                $activity->response(-1, "活动类型错误:" . $aType);
        }
    }

    // 解析映射关系
    public static function analysisConfMap(Activity $activity, string $aType, array $stagesMappingArray): array
    {
        switch ($aType) {
            // 等级 => 体力 => 数数分组 3层嵌套
            case DRIFT_TREASURE:  // 漂流的宝藏
            case TRAVEL_DIARY:    //旅行日记
            case SPINS_MASTER:
            case JIGSAW:
                return ActivityModel::threeLayerConfMap($activity, $stagesMappingArray);
            // 等级 => 体力 2层嵌套
            case LUCKY_FOX:
                return ActivityModel::twoLayerLvSpinsConfMap($stagesMappingArray, 'list');
            case SUPER_GASHAPON:
                return ActivityModel::twoLayerLvSpinsConfMap($stagesMappingArray);
            // 等级 => 数数分组 2层嵌套
            case SUPER_SERIAL_PACK5:
            case SUPER_SERIAL_PACK6:
            case SUPER_SERIAL_PACK7:
                return ActivityModel::twoLayerLvSSConfMap($activity, $stagesMappingArray);
            // 数数分组 1层嵌套
            case CRAZY_BUILD:
                return ActivityModel::crazyBuildLayerConfMap($activity, $stagesMappingArray);
            // 无奖励配置
            case SUPER_BOMB:
            case TIME_LIMITED_CARD:
            case SPECIAL_NOTICE:
                return [];
            default:
                $activity->response(-1, "活动类型错误");
                return [];
        }
    }

    // 解析三层映射关系 等级 => 体力 => 数数分组 3层嵌套
    public static function threeLayerConfMap(Activity $activity, array $stagesMappingArray): array
    {
        $lvStageCnt = 0;
        $activityConf = $lvMapping = $spinsMapping = $shushuMapping = $spinsCnt = $shushuCnt = $idxMapping = [];
        for ($i = 1; $i < count($stagesMappingArray); $i++) {
            $item = $stagesMappingArray[$i];
            if (empty(array_filter($item))) 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] = [];

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

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

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

                $activityConf[$lvMapping[$lvKey]]['stages'][$spinsMapping[$lvKey][$spinsKey]]['stages'][$curSSStage] = [
                    'shushu' => $activity->parseShushuGroups($ssGroup, $i + 1),
                    'reward' => [],
                ];

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

        return [$activityConf, $idxMapping];
    }

    // 解析两层映射关系 等级 => 体力 2层嵌套
    public static function twoLayerLvSpinsConfMap(array $stagesMappingArray, $rewardFieldName = 'reward'): array
    {
        $activityConf = $lvMapping = $spinsMapping = $spinsCnt = $idxMapping = [];
        $spinsStageCnt = 0;

        for ($i = 1; $i < count($stagesMappingArray); $i++) {
            $item = $stagesMappingArray[$i];
            if (empty(array_filter($item))) continue;

            list($idx, $lvMin, $lvMax, $spinsMin, $spinsMax) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            $spinsKey = "{$spinsMin}-$spinsMax";
            if (empty($lvMapping[$lvKey])) {
                $lvMapping[$lvKey] = ++$spinsStageCnt;
                $spinsCnt[$lvKey] = 0;
                $spinsMapping[$lvKey] = [];

                $activityConf[$lvMapping[$lvKey]] = [
                    'lvStart' => $lvMin,
                    'lvEnd' => $lvMax,
                    'stages' => [],
                ];
            }
            if (empty($spinsMapping[$lvKey][$spinsKey])) {
                $spinsMapping[$lvKey][$spinsKey] = ++$spinsCnt[$lvKey];

                $activityConf[$lvMapping[$lvKey]]['stages'][$spinsMapping[$lvKey][$spinsKey]] = [
                    'spinsStart' => $spinsMin,
                    'spinsEnd' => $spinsMax,
                    $rewardFieldName => [],
                ];

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

        return [$activityConf, $idxMapping];
    }

    // 解析两层映射关系 等级 => 数数分组 2层嵌套
    public static function twoLayerLvSSConfMap(Activity $activity, array $stagesMappingArray): array
    {
        $activityConf = $lvMapping = $ssMapping = $ssCnt = $idxMapping = [];
        $ssStageCnt = 0;

        for ($i = 1; $i < count($stagesMappingArray); $i++) {
            $item = $stagesMappingArray[$i];
            if (empty(array_filter($item))) continue;

            list($idx, $lvMin, $lvMax, $ssGroup) = $item;
            $lvKey = "{$lvMin}-$lvMax";
            if (empty($lvMapping[$lvKey])) {
                $lvMapping[$lvKey] = ++$ssStageCnt;
                $ssCnt[$lvKey] = 0;
                $ssMapping[$lvKey] = [];

                $activityConf[$lvMapping[$lvKey]] = [
                    'start' => $lvMin,
                    'end' => $lvMax,
                    'stages' => [],
                ];
            }
            if (empty($ssMapping[$lvKey][$ssGroup])) {
                $ssMapping[$lvKey][$ssGroup] = ++$ssCnt[$lvKey];

                $activityConf[$lvMapping[$lvKey]]['stages'][$ssMapping[$lvKey][$ssGroup]] = [
                    'shushu' => $activity->parseShushuGroups($ssGroup, $i + 1),
                    'list' => [],
                ];

            }
            $idxMapping[$idx] = [$lvMapping[$lvKey], $ssMapping[$lvKey][$ssGroup]];
        }

        return [$activityConf, $idxMapping];
    }

    public static function crazyBuildLayerConfMap(Activity $activity, array $stagesMappingArray): array
    {
        $shushuCnt = 0;
        $activityConf = $shushuMapping = $idxMapping = [];
        for ($i = 1; $i < count($stagesMappingArray); $i++) {
            $item = $stagesMappingArray[$i];
            if (empty(array_filter($item))) continue;

            list($idx, $ssGroup) = $item;

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

                $activityConf[$curSSStage] = [
                    'shushu' => $activity->parseShushuGroups($ssGroup, $i + 1),
                    'reward' => [],
                ];
            }
            $idxMapping[$idx] = [$shushuMapping[$ssGroup]];
        }

        return [$activityConf, $idxMapping];
    }

    public static function spinsMasterReward(Activity $activity, $stagesRewardsArray, $activityConfig, $idxMapping): array
    {
        foreach ($stagesRewardsArray as $k => $item) {
            if ($k == 0 || empty(array_filter($item))) {
                continue;
            }
            $line = $k + 1;

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

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

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

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

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

        return $activityConfig;
    }

    // 数数分组
    public static function jigsawReward(Activity $activity, $stagesRewardsArray, $activityConfig, $idxMapping): array
    {
        foreach ($stagesRewardsArray as $k => $item) {
            if ($k == 0 || empty(array_filter($item))) {
                continue;
            }

            $line = $k + 1;

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

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

            list($lvStage, $spinsStage, $ssStage) = $idxMapping[$idx];

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

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

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

            $blockimg = strtolower($blockimg);
            foreach (PLAT_ALL as $onePlat) {
                $sourceDir = __ROOT__ . "/public/game/crazycoin/activity/{$onePlat}/{$blockimg}";
                if (!is_dir($sourceDir)) {
                    $activity->response(-1, "第{$line}行,所配置的资源不存在: {$blockimg}");
                }
            }

            $activityConfig[$lvStage]['stages'][$spinsStage]['stages'][$ssStage]['reward'][$rewardStage] = [
                'stage' => $rewardStage,
                'stepnum' => $stepnum,
                'blockimg' => $blockimg,
                'prize' => $rewardsTemp,
            ];
        }

        return $activityConfig;
    }

    // 解析其他配置
    public static function luckyFoxReward(Activity $activity, $stagesRewardsArray, $activityConfig, $idxMapping): array
    {
        foreach ($stagesRewardsArray as $k => $item) {
            $filterLine = array_filter($item);
            if (empty($filterLine)) continue;
            $line = $k + 1;
            if ($k == 0) continue;

            list($idx, $grid, $layer, $weight,
                $reward1, $isFixNum1, $rewardNum1,
                $reward2, $isFixNum2, $rewardNum2,
                $reward3, $isFixNum3, $rewardNum3,) = $item;


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

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

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

            if (empty($rewardsTemp)) $activity->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $activityConfig[$lvStage]['stages'][$spinsStage]['list'][$rewardStage] = [
                'grid' => $grid,
                'layer' => $layer,
                'weight' => $weight,
                'prize' => $rewardsTemp,
            ];
        }

        return $activityConfig;
    }

    // 超级扭蛋奖励解析
    public static function superGashaponReward(Activity $activity, $stagesRewardsArray, $activityConfig, $idxMapping): array
    {
        $gashTypeMap = ["普通" => 0, "大奖" => 1, "幸运蛋" => 2];
        foreach ($stagesRewardsArray as $k => $item) {
            $filterLine = array_filter($item);
            if (empty($filterLine)) continue;
            $line = $k + 1;
            if ($k == 0) continue;

            list($idx, $layer, $gashType, $weight, $needCoins, $reward, $isFixNum, $rewardNum,) = $item;

            $gashType = $gashTypeMap[$gashType] ?? null;
            if ($gashType === null) {
                $activity->response(-1, "第{$line}行,唯一id:{$idx} 未配置奖励类型");
            }

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

            $rewardStage = count($activityConfig[$lvStage]['stages'][$spinsStage]['reward']) + 1;

            // 非幸运蛋有奖励
            $rewardsTemp = [];
            if ($gashType != 2) {
                if (empty($reward)) {
                    $activity->response(-1, "第{$line}行,唯一id:{$idx} 无奖励配置");
                }
                #非金币奖励，全部固定值奖励
                if (!in_array($reward, $activity->multiNumTypeReward)) {
                    $isFixNum = '是';
                }
                $isFixNum = ($isFixNum == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2

                list($type, $skin) = $activity->parseRewardTypeAndSkinId($reward, $line);

                $rewardsTemp[] = [
                    'id' => 1,
                    "num" => $rewardNum,
                    "type" => $type,
                    "rtype" => $isFixNum,
                    "skin" => $skin
                ];
            }

            $activityConfig[$lvStage]['stages'][$spinsStage]['reward'][$rewardStage] = [
                'layer' => $layer,
                'gashType' => $gashType,
                'weight' => $weight,
                'needCoins' => $needCoins,
                'prize' => $rewardsTemp,
            ];
        }

        return $activityConfig;
    }

    // 超级炸弹额外配置解析
    private static function superBombConfig(array $basicConfArray): array
    {
        $superBombConfig = [
            'attackNums' => 0,  // 超级攻击机会数量
            'shootRate' => 0,   // 每个超级攻击里包含的攻击次数
            'robotConf' => [    // 机器人配置
                'useShieldPet' => [0, 0, 0, 0, 0],   // 盾宠物使用次数
                'shieldNums' => [0, 0, 0, 0, 0],   // 盾牌数量
            ]
        ];
        foreach ($basicConfArray as $index => $oneLineInfo) {
            switch ($oneLineInfo[0]) {
                case "超级攻击机会数量":
                    $superBombConfig['attackNums'] = $oneLineInfo[1];
                    break;
                case "每个超级攻击里包含的攻击次数":
                    $superBombConfig['shootRate'] = $oneLineInfo[1];
                    break;
                case "保底触发次数范围":
                    $superBombConfig['minFloorAttack'] = $oneLineInfo[1];
                    $superBombConfig['maxFloorAttack'] = $oneLineInfo[2];
                    break;
                case "盾宠物使用次数":
                    $nextLine = $basicConfArray[$index + 1];
                    $superBombConfig['robotConf']['useShieldPet'] = [$nextLine[1], $nextLine[2], $nextLine[3], $nextLine[4], $nextLine[5]];
                    break;
                case "盾牌数量":
                    $nextLine = $basicConfArray[$index + 1];
                    $superBombConfig['robotConf']['shieldNums'] = [$nextLine[1], $nextLine[2], $nextLine[3], $nextLine[4], $nextLine[5]];
                    break;
            }
        }

        return $superBombConfig;
    }

    // 特殊公告解析语言配置
    private static function specialNoticeConfig(Activity $activity, array $basicConfArray, array $dataArray): array
    {
        $DevMap = ['全部' => 'all', '安卓' => 'android', '苹果' => 'ios'];

        $data = ['device' => 0, 'conf' => []];

        // 解析基础配置
        foreach ($basicConfArray as $oneLineInfo) {
            switch ($oneLineInfo[0]) {
                case "生效平台":
                    $data['device'] = $DevMap[$oneLineInfo[1]];
                    break;
                default:
                    break;
            }
        }

        unset($dataArray[0]);
        foreach ($dataArray as $row) {
            list($ignore, $lang, $title, $salutation, $content, $sign) = $row;
            $data['conf'][$lang] = [
                'title' => $title,
                'salutation' => $salutation,
                'content' => $content,
                'sign' => $sign,
            ];

            if (empty($title) || empty($content)) {
                $activity->response(-1, "{$lang}语言, 配置不能为空");
            }
        }

        if (empty($data['conf'])) {
            $activity->response(-1, "未配置语言配置");
        }

        return $data;
    }

    // 有进度六格连环礼包解析语言配置
    private static function superSerialProgressConfig(Activity $activity, array $stagesRewardsArray, array $stagesRewardsMoreArray, array $activityConf, array $idxMapping): array
    {
        $moneyTypes = ['金币' => 1, '美元' => 2];
        foreach ($stagesRewardsArray as $k => $item) {
            $filterLine = array_filter($item);
            if (empty($filterLine)) continue;
            $line = $k + 1;
            if ($k == 0) continue;

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

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

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

            $limit = intval($limit);
            if ($limit < 1) $activity->response(-1, "第{$line}行,限量不能为{$limit}");
            if (empty($moneyTypes[$mType])) $activity->response(-1, "第{$line}行,购买货币：{$mType}不存在");
            if ($moneyTypes[$mType] == 2) {   # 美元时，判断金额与 sku 是否匹配
                $bet = 0;
                $skuTemp = '';
                foreach ($activity->goodSku as $skuPrice) {
                    if ($skuPrice['price'] == $price) {
                        $skuTemp = $skuPrice['sku'];
                        break;
                    }
                }
                if (empty($skuTemp)) $activity->response(-1, "第{$line}行,购买价格：{$price} 无对应sku");   # 金额无对应sku
                if ($skuTemp != $sku) $activity->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}, $activity->multiNumTypeReward)) ${'isFixNum' . $i} = '是';   #非金币奖励，全部固定值奖励
                    ${'isFixNum' . $i} = (${'isFixNum' . $i} == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
                    list($type, $skin) = $activity->parseRewardTypeAndSkinId(${'reward' . $i}, $line);
                    $currentId = count($rewardsTemp) + 1;
                    $rewardsTemp[] = [
                        'id' => $currentId,
                        "num" => ${'rewardNum' . $i},
                        "type" => $type,
                        "rtype" => ${'isFixNum' . $i},
                        "skin" => $skin
                    ];
                }
            }

            if (empty($rewardsTemp)) $activity->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $activityConf[$lvStage]['stages'][$ssStage]['list']['stages'][$rewardStage] = [
                'stage' => $rewardStage,
                'name' => 'serialPack-' . $rewardStage,
                'gMax' => $limit,
                'collect' => $collect,
                'mtype' => $moneyTypes[$mType],
                'coin' => 'coins01',
                'bet' => $bet,
                'sku' => $sku,
                'price' => $price,
                'prize' => urlencode(json_encode($rewardsTemp)),
            ];
        }

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

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

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

            $rewardStage = count($activityConf[$lvStage]['stages'][$ssStage]['list']['progress'] ?? []) + 1;
            if ($rewardStage != $id) $activity->response(-1, "第{$line}行,层级配置异常不能为空");

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

            if (empty($rewardsTemp)) $activity->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $activityConf[$lvStage]['stages'][$ssStage]['list']['progress'][$rewardStage] = [
                'progressBarId' => $id,
                'stepNum' => $stepNum,
                'prize' => urlencode(json_encode($rewardsTemp)),
            ];
        }

        return $activityConf;
    }

    // 超级炸弹额外配置解析
    private static function crazyBuildConfig(Activity $activity, &$baseConfig, array $basicConfArray, $stagesRewardsArray, $activityConf, $idxMapping): array
    {
        // 解析基础配置
        foreach ($basicConfArray as $index => $oneLineInfo) {
            switch ($oneLineInfo[0]) {
                case "活动层数":
                    $baseConfig['extraData'] = ["layer" => $oneLineInfo[1]];
                    break;
                default:
                    break;
            }
        }

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

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


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


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

            if (empty($basicRewardsTemp) || empty($finalRewardsTemp)) $activity->response(-1, "第{$line}行,奖励不能为空");    #奖励不能为空
            $activityConf[$ssStage]["reward"]["basicReward"][$lv] = [
                'userLevel' => $lv,
                'prize' => $basicRewardsTemp,
            ];
            $activityConf[$ssStage]["reward"]["finalReward"][$lv] = [
                'userLevel' => $lv,
                'prize' => $finalRewardsTemp,
            ];
        }

        return $activityConf;
    }

    // 漂流的宝藏额外配置解析
    private static function driftTreasureReward(Activity $activity, &$baseConfig, array $basicConfArray, $stagesRewardsArray, $activityConf, $idxMapping): array
    {
        // 解析基础配置
        foreach ($basicConfArray as $index => $oneLineInfo) {
            switch (trim($oneLineInfo[0])) {
                case "基础积分值":
                    $baseConfig['reward_conf'] = [
                        "steal_break" => $oneLineInfo[1],
                        "steal_success" => $oneLineInfo[2],
                        "attack_success" => $oneLineInfo[3],
                        "attack_break" => $oneLineInfo[4],
                    ];
                    break;
                default:
                    break;
            }
        }

        return ActivityModel::spinsMasterReward($activity, $stagesRewardsArray, $activityConf, $idxMapping);
    }

    // 限时卡组
    private static function timeLimitedCards(Activity $actObj, $basicConfArray, array $stagesRewardsArray): array
    {
        $themes = oo::commonOprDb('slavedb')->getAll('select * from ' . otable::cardgroup_limit_theme_config() . ' order by id desc');
        $themes = array_column($themes, 'id', 'theme_res');
        $themesName = array_keys($themes);
        $conf = [
            'progress' => []
        ];
        // 解析基础配置
        foreach ($basicConfArray as $index => $oneLineInfo) {
            switch (trim($oneLineInfo[0])) {
                case "开放卡组":
                    if (!in_array($oneLineInfo[1], $themesName)) $actObj->response(__LINE__, '卡组资源不存在：' . $oneLineInfo[1]);
                    $conf['themeId'] = $themes[$oneLineInfo[1]];
                    break;
                default:
                    break;
            }
        }

        foreach ($stagesRewardsArray as $k => $item) {
            if (empty($k)) continue;
            $filterLine = array_filter($item);
            if (empty($filterLine)) continue;
            $line = $k + 1;
            $rewardBasic = array_slice($item, 0, 2);
            $rewardsLine = array_slice($item, 2);
            list($stageIdx, $target) = $rewardBasic;
            $rewardsTemp = $actObj->parseLineRewards($rewardsLine, $line);
            $conf['progress'][$stageIdx] = [
                'stage' => $stageIdx,
                'target' => $target,
                'rewards' => urlencode(json_encode($rewardsTemp)),
            ];
        }
        return $conf;
    }

    public static function formatCrazyBuildConf(Activity $activity, $crazyBuildConfig): string
    {
        foreach ($crazyBuildConfig as $ssStage => &$oneSsStage) {
            foreach ($oneSsStage['reward'] as &$oneRewardStage) {
                foreach ($oneRewardStage as $lv => &$oneReward) {
                    $onePrize = json_decode(urldecode($oneReward['prize']), true);
                    if (empty($onePrize) || !is_array($onePrize)) {
                        $activity->response(-1, "数数层级：{$ssStage} 等级：{$lv} 奖励格式错误");
                    }

                    $oneReward['userLevel'] = $lv;
                    $oneReward['prize'] = $onePrize;
                }
            }
        }

        return json_encode($crazyBuildConfig, JSON_NUMERIC_CHECK);
    }

    public static function writeCrazyBuildConfCache($data)
    {
        $conditionKeys = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $extraReward = json_decode($data['reward_info'], true);
        foreach ($extraReward as $idx1 => $item1) {
            $stageKey = $idx1;
            $stageConditions = [
                [
                    "start" => 0,
                    "end" => 0,
                    'shushu' => $item1['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($item1['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));
    }

    public static function writeDriftTreasureConfCache($data)
    {
        $conditionKeys = okeys::activityConditionKeys($data['aid']);
        $stageRewardKeys = okeys::activityRewardsStageKeys($data['aid']);
        $rewardInfo = json_decode($data['reward_info'], true);
        foreach ($rewardInfo 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));
    }

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

                ];
                oo::commonOprRedis('games')->hset($conditionKeys, $stageKey, json_encode($stageConditions, JSON_NUMERIC_CHECK));
                oo::commonOprRedis('games')->hset($stageRewardKeys, $stageKey, json_encode($item2['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));
    }

    public static function emptyCrazyBuildConf(string $reward_info): string
    {
        $extraReward = json_decode($reward_info, true);
        foreach ($extraReward as &$oneReward) {
            $oneReward['reward'] = [];
        }

        return json_encode($extraReward, JSON_NUMERIC_CHECK);
    }

    // 获取宝箱区间值
    public static function getSectionNum($lv, $pro)
    {
        if (empty($pro)) {
            return [0, 0];
        }
        $arr = array_column($pro, 'weight', 'lv');
        $thisLvWeight = [];
        foreach ($arr as $lev => $weight) {
            if ($lev <= $lv) {
                $thisLvWeight = $weight;
            } else {
                break;
            }
        }
        return [$thisLvWeight[0]['num'], $thisLvWeight[count($thisLvWeight) - 1]['num']];
    }

    // 获取皮肤宝箱奖励结构
    public static function getChestProp($skin, $lv = 3)
    {
        if ($lv < 3) {
            $lv = 3;
        }
        $chestProp = [
            "skin" => $skin,
            "cardNum" => 0,
            "jokerCardNum" => 0,
            "coinsNum" => [0, 0],
            "spinsNum" => [0, 0],
            "petExp" => [0, 0],
            "petFood" => 0,
            "skinResourceId" => 0
        ];
        $conf = oo::commonOprModel('config')->getChestSkinConfig($skin);

        foreach ($conf['info'] as $k => $item) {
            if ($item['propsId'] == 17) {//卡片数
                $chestProp["cardNum"] = $item["num"];
            }
            if ($item['propsId'] == 18) {//小丑卡保底
                $chestProp["jokerCardNum"] = $item["num"];
            }
            if ($item['propsId'] == 14) {//金币
                $chestProp["coinsNum"] = self::getSectionNum($lv, $item["pro"]);
            }
            if ($item['propsId'] == 15) {//体力
                $chestProp["spinsNum"] = self::getSectionNum($lv, $item["pro"]);
            }
            if ($item['propsId'] == 8) {//宠物经验
                $chestProp["petExp"] = self::getSectionNum($lv, $item["pro"]);
            }
            if ($item['propsId'] == 9) {//宠物粮食
                $chestProp["petFood"] = $item["num"];
            }
        }
        $chestProp['skinResourceId'] = $conf['skinResourceId'];
        return $chestProp;
    }

    public static function getPropsShow($data, $lv)
    {
        if (empty($data)) {
            return [];
        }
        $chestProp = [];
        // todo 金币处理
        $baseCoin = 1;

        $skin = intval($data['skin']);
        $retData = [
            "propsId" => $data['type'],
            "num" => $data['num'],
            "skin" => $skin,
            "jokerCardExpireTime" => 0,
            "cards" => [],
            "chestProps" => $chestProp,
            "skinResourceId" => $skin
        ];
        switch (intval($data['type'])) {
            case 13:
            case 48:
            case 49:
            case 50:   // 金卡// 固定黑金卡// 固定限时金卡// 固定限时黑金卡
                if ($data['rtype'] == 1) {
                    $retData['cards'] = [];
                }
                break;
            case 14: // 金币
                if ($data['rtype'] == 2) {
                    $retData["num"] = $baseCoin * $data['num'];
                }
                break;
            case 18: //小丑卡
                $retData['jokerCardExpireTime'] = time() + 86400;
                break;
            case 19: //皮肤宝箱
                $chestProp = self::getChestProp($skin, $lv);
                //皮肤
                $retData['skin'] = $skin;
                //todo 皮肤资源
                $skinResourceId = $chestProp['skinResourceId'] > 0 ? $chestProp['skinResourceId'] : $skin;
                $chestProp['skinResourceId'] = $retData['skinResourceId'] = $skinResourceId;

                $retData['chestProps'] = $chestProp;
                break;
            default: //道具活动
                $retData['skin'] = $skin;
                break;
        }
        return $retData;
    }

    public static function getPropsShowArr($data, $lv)
    {
        $arr = [];
        foreach ($data as $item) {
            $arr[] = self::getPropsShow($item, $lv);
        }
        return $arr;
    }

    public static function getCoinPushPro(): array
    {
        $tb = otable::coinPushPro();
        $sql = 'select * from '.$tb;
        return oo::commonOprDb('slavedb')->getAll($sql);
    }
}


