<?php

define('IN_WEB', true);

class ConfigNew {
    public function start($aRequest) {
        $startTime = intval(microtime(TRUE) * 1000);
        if(empty($aRequest['version'])){
            $aRequest['version'] = '1.0.0.0';
        }
        $sid = isset($aRequest['sid'])?$aRequest['sid']:1;
        //include (dirname(__FILE__)."/../com.php");
        //header('Access-Control-Allow-Origin:*');//允许跨域(临时)

        $ret = oo::commonOprModel('readconfig')->getStaticConfigPath("",$sid);

        $ret['Lang'] = oo::commonOprModel('readconfig')->getLangStaticConfigPath();

        $md5 = oo::commonOprModel('readconfig')->getStaticMd5ConfigPath();
        foreach ($md5 as $key=>$row){
            $ret[ucfirst($key)."Md5"] = $row;
        }

        oo::commonOprRedis('common')->incr(okeys::getVersionCount());//登陆成功率统计

        if(!oo::compareVersion(funs::changeVersionLength($aRequest['version']),oo::commonOprRedis('common')->get(okeys::CurForeVersion($sid)))){
            $ret['Version'] = str_replace('Version','VersionForce',$ret['Version']);
        }

        if(!oo::compareVersion($aRequest['version'],'1.7.4')){
            $ret['VipConfig'] = 'VipConfig1599446560.json';
        }elseif(!oo::compareVersion($aRequest['version'], '1.8.5')){
            //1.8.5版本vip功能修改
            $ret['VipConfig'] = 'VipConfig1612259276.json';
        }

        if(!oo::compareVersion($aRequest['version'],'1.7.3')){
            $ret['LuckyDraw'] = 'LuckyDraw1585289352.json';
        }

        //签到进度 版本区分
        if(!oo::compareVersion($aRequest['version'],'1.7.0')){
            $ret['Signin'] = 'Signin1600949611.json';
        }

        //分享配置 版本区分
        if(!oo::compareVersion($aRequest['version'],'1.7.4')){
            $ret['Share'] = 'ShareConfig1584067106.json';
            $ret['LDE'] = "LDE.json";
            $ret['LEN'] = "LEN.json";
            $ret['LES'] = "LES.json";
            $ret['LFR'] = "LFR.json";
            $ret['LID'] = "LID.json";
            $ret['LNO'] = "LNO.json";
            $ret['LPT'] = "LPT.json";
            $ret['LTH'] = "LTH.json";
            $ret['LTW'] = "LTW.json";
            $ret['LVI'] = "LVI.json";
            $ret['LZH'] = "LZH.json";
        }

        if(!oo::compareVersion($aRequest['version'],'1.7.3')){
            $ret['MiningGameConfig'] = 'MiningGameConfig1598514140.json';
        }

        if(!oo::compareVersion($aRequest['version'],'1.7.8')){
            if(IS_DEBUF){
                $ret['RemoteAssets'] = 'RemoteAssets_1770.json';
                $ret['MainBgConfig'] = 'MainBgConfig1598320209.json';
            }else{
                $ret['RemoteAssets'] = 'RemoteAssets_1770.json';
                $ret['MainBgConfig'] = 'MainBgConfig1601470837.json';
            }
        }else{
            if(!oo::compareVersion($aRequest['version'],'1.8.3')){
                if(IS_DEBUF){
                    $ret['RemoteAssets'] = 'RemoteAssets1615770897.json';
                }else{
                    $ret['RemoteAssets'] = 'RemoteAssets1615607975.json';
                }
            }
        }

        if(!oo::compareVersion($aRequest['version'],'1.8.4')){
            if(IS_DEBUF){
                $ret['RecommendConfig'] = "RecommendConfig1615557861.json";
            }else{
                $ret['RecommendConfig'] = "RecommendConfig1614071352.json";
            }
        }
        if(!oo::compareVersion($aRequest['version'],'1.10')){
            if(IS_DEBUF){

            }else{
                $ret['Share'] = "ShareConfig1618415073.json";
            }
        }
        $ret["hotupdate"] = oo::commonOprModel('Gameupdate')->getGameUpdateHotfix($sid,funs::changeVersionLength($aRequest['version'],3));
        $endTime = intval(microtime(TRUE) * 1000);
        $runTime = $endTime - $startTime;
        if(IS_DEBUF){
            oo::logs()->debug3(['startTime'=>$startTime,'endTime'=>$endTime,'runTime'=> $runTime], 'configRuntimeDetail');
        }else{
            $runTime >= 500 && oo::logs()->debug3(['startTime'=>$startTime,'endTime'=>$endTime,'runTime'=> $runTime], 'configRuntimeDetail');
        }
        return json_encode($ret,JSON_NUMERIC_CHECK);
    }
}
