<?php
namespace app\index\controller;
use think\facade\Db;

/**
 * 定时任务
 */
class Cron {
    /**
     * 执行手动开奖
     * 依次从1~6开始 1十二星座彩票（500万），2商业之神（1千万），3丰收之神（5千万），4财富之神（1亿），5命运之神（7亿），6永生之神（10亿）
     */
    public function index(){
        echo "<hr>";
        echo "开始执行步骤1";
        echo "<hr>";
        self::zodiac();
    }
    /**
     * 执行步骤1
     */
    public static function zodiac(){//1十二星座
        //获取最新一期信息
        $countNum = Db::name('aadeitycard')->where(["is_finish"=>0])->count();
        if($countNum > 0){
            $rs = Db::name('aadeitycard')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
            $lotteryissue = $rs['lotteryissue'];//期
            $lottery_date = $rs['lottery_date'];//开奖日期
            echo "查询星座神【".$lottery_date." -- ".$lotteryissue."期】<br>";
            $totalAmount = self::CalculateTheTotalNumber(1,$lotteryissue);
            echo '未结算总金额为：'.$totalAmount.'<br>';
            if($totalAmount > 0){
                echo '执行测试虚拟开奖......<br>';
                self::VirtualLotteryDraw(1,$lotteryissue,$lottery_date);
            }else{
                $kjhm = rand(1,365);
                self::ExecuteSaveData(1,$kjhm,$lotteryissue,$lottery_date);
            }
        }else{
            self::hermes();//2、商业之神
        }
    }
    /**
     * 执行开奖数据保存
     */
    public static function ExecuteSaveData($type,$kjhm,$lotteryissue,$lottery_date){//执行开奖数据保存
        if($kjhm > 0 && $kjhm < 366){
            $strnum = sprintf("%03d",$kjhm);
            $hmarr = array_map('intval',str_split((string)$strnum));//转换成数组
            $now = date('Y-m-d H:i:s');
            $kjnow = $lottery_date." 22:00:00";
            echo "号码：".$strnum."；当前时间：".$now."；开奖时间：".$kjnow."<br>";
            if($now >= $kjnow){//执行开奖
                switch($type){
                    case 1:
                        $rs = Db::name('aadeitycard')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
                        $GrandPrize = 5000000;
                        $million = round($rs['million']+rand(1,2));
                        $million_max = 6;
                        $million_min = 1;
                        $jackpot = rand(12345,99999)*10;
                        break;
                    case 2:
                        $rs = Db::name('aahermes')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
                        $GrandPrize = 10000000;
                        $million = round($rs['million']+rand(1,3));
                        $million_max = 13;
                        $million_min = 3;
                        $jackpot = rand(12345,99999)*15;
                        break;
                    case 3:
                        $rs = Db::name('aademeter')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
                        $GrandPrize = 50000000;
                        $million = round($rs['million']+rand(1,4));
                        $million_max = 80;
                        $million_min = 10;
                        $jackpot = rand(12345,99999)*20;
                        break;
                    case 4:
                        $rs = Db::name('aaploutos')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
                        $GrandPrize = 100000000;
                        $million = round($rs['million']+rand(2,7));
                        $million_max = 130;
                        $million_min = 30;
                        $jackpot = rand(12345,99999)*25;
                        break;
                    case 5:
                        $rs = Db::name('aafates')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
                        $GrandPrize = 700000000;
                        $million = round($rs['million']+rand(3,9));
                        $million_max = 800;
                        $million_min = 100;
                        $jackpot = rand(12345,99999)*30;
                        break;
                    case 6:
                        $rs = Db::name('aaimmortality')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
                        $GrandPrize = 1000000000;
                        $million = round($rs['million']+rand(5,15));
                        $million_max = 1300;
                        $million_min = 300;
                        $jackpot = rand(12345,99999)*35;
                        break;
                }
                $is_finish = $rs['is_finish'];
                if($is_finish==0){//未完结  未开奖
                    $lottery_id = $rs['lottery_id'];
                    $areaid = rand(6,201);//头奖得主区域ID
                    if($million >= $million_max){
                        $million = $million_min;
                        $jackpot = $GrandPrize;
                        self::addTopprize(1,$lottery_date,$lotteryissue,$GrandPrize,$areaid);
                    }
                    $data = [];
                    $data['number_a'] = $hmarr[0];
                    $data['number_b'] = $hmarr[1];
                    $data['number_c'] = $hmarr[2];
                    $data['jackpot'] = $jackpot;
                    $data['is_finish'] = 1;//是否完结 0未完结  1已经完结
                    $data['areaid'] = $areaid;
                    $data['total_winners'] = rand(12345,59999);//中奖人数
                    //新增一期
                    $date = $rs['lottery_date'];
                    $xdate = date('Y-m-d',strtotime($date.' +1 days'));//下一天
                    $year = date('Y',strtotime($xdate));
                    $order = sprintf("%03d",date('z',strtotime($xdate))+1);
                    $xdata = [];
                    $xdata['lottery_date'] = $xdate;
                    $xdata['lotteryissue'] = $year.$order;
                    $xdata['million'] = $million;
                    $xdata['data_flag'] = 1;
                    $xdata['add_time'] = strtotime($kjnow);
                    //修改数据
                    switch($type){
                        case 1:
                            $data['asian_a'] = rand(21234,199999);//参与人数
                            $data['asian_b'] = round($data['asian_a']*1.23456);//投注单
                            $data['asian_c'] = rand(12345,99999)*10;//随机数
                            $data['asian_d'] = round($data['asian_a']*rand(1,100)/1000);//随机数
                            $data['america_a'] = rand(31234,299999);//参与人数
                            $data['america_b'] = round($data['america_a']*1.23456);//投注单
                            $data['america_c'] = rand(12345,99999)*10;//随机数
                            $data['america_d'] = round($data['america_a']*rand(1,100)/1000);//随机数
                            $data['europe_a'] = rand(31234,299999);//参与人数
                            $data['europe_b'] = round($data['europe_a']*1.23456);//投注单
                            $data['europe_c'] = rand(12345,99999)*10;//随机数
                            $data['europe_d'] = round($data['europe_a']*rand(1,100)/1000);//随机数
                            $data['africa_a'] = rand(11234,109999);//参与人数
                            $data['africa_b'] = round($data['africa_a']*1.23456);//投注单
                            $data['africa_c'] = rand(12345,99999)*10;//随机数
                            $data['africa_d'] = round($data['africa_a']*rand(1,100)/1000);//随机数
                            $data['oceania_a'] = rand(9234,99999);//参与人数
                            $data['oceania_b'] = round($data['oceania_a']*1.23456);//投注单
                            $data['oceania_c'] = rand(12345,99999)*10;//随机数
                            $data['oceania_d'] = round($data['oceania_a']*rand(1,100)/1000);//随机数
                            Db::name('aadeitycard')->where(['lottery_id'=>$lottery_id])->update($data);
                            Db::name('aadeitycard')->insert($xdata);
                            self::ClaimingThePrize(1,$lotteryissue,$kjhm);//执行兑奖
                            break;
                        case 2:
                            $data['grouping'] = self::RandLetter(1);
                            Db::name('aahermes')->where(['lottery_id'=>$lottery_id])->update($data);
                            Db::name('aahermes')->insert($xdata);
                            self::ClaimingThePrize(2,$lotteryissue,$kjhm);//执行兑奖
                            break;
                        case 3:
                            $data['number_d'] = rand(1,9);
                            $data['grouping'] = self::RandLetter(1);
                            Db::name('aademeter')->where(['lottery_id'=>$lottery_id])->update($data);
                            Db::name('aademeter')->insert($xdata);
                            self::ClaimingThePrize(3,$lotteryissue,$kjhm);//执行兑奖
                            break;
                        case 4:
                            $data['number_d'] = self::RandLetter(1);
                            $data['grouping'] = self::RandLetter(1);
                            Db::name('aaploutos')->where(['lottery_id'=>$lottery_id])->update($data);
                            Db::name('aaploutos')->insert($xdata);
                            self::ClaimingThePrize(4,$lotteryissue,$kjhm);//执行兑奖
                            break;
                        case 5:
                            $data['number_e'] = self::RandLetter(1);
                            $data['number_d'] = self::RandLetter(1);
                            $data['grouping'] = self::RandLetter(1);
                            Db::name('aafates')->where(['lottery_id'=>$lottery_id])->update($data);
                            Db::name('aafates')->insert($xdata);
                            self::ClaimingThePrize(5,$lotteryissue,$kjhm);//执行兑奖
                            break;
                        case 6:
                            $data['number_i'] = rand(1,9);
                            $data['number_h'] = rand(1,9);
                            $data['number_g'] = rand(1,9);
                            $data['number_f'] = rand(1,9);
                            $data['number_e'] = rand(1,9);
                            $data['number_d'] = rand(1,9);
                            Db::name('aaimmortality')->where(['lottery_id'=>$lottery_id])->update($data);
                            Db::name('aaimmortality')->insert($xdata);
                            self::ClaimingThePrize(6,$lotteryissue,$kjhm);//执行兑奖
                            break;
                    }
                    echo "插入第".$year.$order."期完毕！<br>";
                }
            }
        }
        switch($type){
            case 1:
                self::hermes();//2、商业之神
                break;
            case 2:
                self::demeter();//3丰收之神
                break;
            case 3:
                self::ploutos();//4财富之神
                break;
            case 4:
                self::fates();//5命运之神
                break;
            case 5:
                self::immortality();//6永生之神
                break;
            case 6:
                self::getStatisticalwinning_rate();//7统计竞猜胜率
                break;
            case 7:
                self::getUpdateTheProxyReport();//8统计代理提成
                break;
            case 8: break;
            case 9: break;
            case 10: break;
            case 11: break;
            case 12: break;
        }
    }
    /**
     * 执行步骤2
     */
    public static function hermes(){//2商业之神
        echo "<hr>";
        echo "开始执行步骤2、";
        echo "<hr>";
        //获取最新一期信息
        $countNum = Db::name('aahermes')->where(["is_finish"=>0])->count();
        if($countNum > 0){
            $rs = Db::name('aahermes')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
            $lotteryissue = $rs['lotteryissue'];//期
            $lottery_date = $rs['lottery_date'];//开奖日期
            echo "查询商业之神【".$lottery_date." -- ".$lotteryissue."期】<br>";
            $totalAmount = self::CalculateTheTotalNumber(2,$lotteryissue);
            echo '未结算总金额为：'.$totalAmount.'<br>';
            if($totalAmount > 0){
                echo '执行测试虚拟开奖......<br>';
                self::VirtualLotteryDraw(2,$lotteryissue,$lottery_date);
            }else{
                $kjhm = rand(1,365);
                self::ExecuteSaveData(2,$kjhm,$lotteryissue,$lottery_date);
            }
        }else{
            self::demeter();//3丰收之神
        }       
    }
    /**
     * 执行步骤3
     */
    public static function demeter(){//3丰收之神
        echo "<hr>";
        echo "开始执行步骤3、";
        echo "<hr>";
        //获取最新一期信息
        $countNum = Db::name('aademeter')->where(["is_finish"=>0])->count();
        if($countNum > 0){
            $rs = Db::name('aademeter')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
            $lotteryissue = $rs['lotteryissue'];//期
            $lottery_date = $rs['lottery_date'];//开奖日期
            echo "查询丰收之神【".$lottery_date." -- ".$lotteryissue."期】<br>";
            $totalAmount = self::CalculateTheTotalNumber(3,$lotteryissue);
            echo '未结算总金额为：'.$totalAmount.'<br>';
            if($totalAmount > 0){
                echo '执行测试虚拟开奖......<br>';
                self::VirtualLotteryDraw(3,$lotteryissue,$lottery_date);
            }else{
                $kjhm = rand(1,365);
                self::ExecuteSaveData(3,$kjhm,$lotteryissue,$lottery_date);
            }
        }else{
            self::ploutos();//4财富之神
        }
    }
    /**
     * 执行步骤4
     */
    public static function ploutos(){//4财富之神
        echo "<hr>";
        echo "开始执行步骤4、财富之神";
        echo "<hr>";
        //获取最新一期信息
        $countNum = Db::name('aaploutos')->where(["is_finish"=>0])->count();
        if($countNum > 0){
            $rs = Db::name('aaploutos')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
            $lotteryissue = $rs['lotteryissue'];//期
            $lottery_date = $rs['lottery_date'];//开奖日期
            echo "查询财富之神【".$lottery_date." -- ".$lotteryissue."期】<br>";
            $totalAmount = self::CalculateTheTotalNumber(4,$lotteryissue);
            echo '未结算总金额为：'.$totalAmount.'<br>';
            if($totalAmount > 0){
                echo '执行测试虚拟开奖......<br>';
                self::VirtualLotteryDraw(4,$lotteryissue,$lottery_date);
            }else{
                $kjhm = rand(1,365);
                self::ExecuteSaveData(4,$kjhm,$lotteryissue,$lottery_date);
            }
        }else{
            self::fates();//5命运之神
        }
    }
    /**
     * 执行步骤5
     */
    public static function fates(){//5命运之神
        echo "<hr>";
        echo "开始执行步骤5、命运之神";
        echo "<hr>";
        //获取最新一期信息
        $countNum = Db::name('aafates')->where(["is_finish"=>0])->count();
        if($countNum > 0){
            $rs = Db::name('aafates')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
            $lotteryissue = $rs['lotteryissue'];//期
            $lottery_date = $rs['lottery_date'];//开奖日期
            echo "查询命运之神【".$lottery_date." -- ".$lotteryissue."期】<br>";
            $totalAmount = self::CalculateTheTotalNumber(5,$lotteryissue);
            echo '未结算总金额为：'.$totalAmount.'<br>';
            if($totalAmount > 0){
                echo '执行测试虚拟开奖......<br>';
                self::VirtualLotteryDraw(5,$lotteryissue,$lottery_date);
            }else{
                $kjhm = rand(1,365);
                self::ExecuteSaveData(5,$kjhm,$lotteryissue,$lottery_date);
            }
        }else{
            self::immortality();//6永生之神
        }
    }
    /**
     * 执行步骤6
     */
    public static function immortality(){//6永生之神
        echo "<hr>";
        echo "开始执行步骤6、永生之神";
        echo "<hr>";
        //获取最新一期信息
        $countNum = Db::name('aaimmortality')->where(["is_finish"=>0])->count();
        if($countNum > 0){
            $rs = Db::name('aaimmortality')->where(["is_finish"=>0])->order('lottery_id DESC LIMIT 1')->find();
            $lotteryissue = $rs['lotteryissue'];//期
            $lottery_date = $rs['lottery_date'];//开奖日期
            echo "查询命运之神【".$lottery_date." -- ".$lotteryissue."期】<br>";
            $totalAmount = self::CalculateTheTotalNumber(6,$lotteryissue);
            echo '未结算总金额为：'.$totalAmount.'<br>';
            if($totalAmount > 0){
                echo '执行测试虚拟开奖......<br>';
                self::VirtualLotteryDraw(6,$lotteryissue,$lottery_date);
            }else{
                $kjhm = rand(1,365);
                self::ExecuteSaveData(6,$kjhm,$lotteryissue,$lottery_date);
            }
        }else{
            self::getStatisticalwinning_rate();//7统计竞猜胜率
        }
    }
    /**
     * 执行步骤7统计竞猜胜率
     */
    public static function getStatisticalwinning_rate(){
        echo "<hr>";
        echo "开始执行步骤7、统计竞猜胜率";
        echo "<hr>";
        $lista = Db::name("aadeitycard")->where(['is_finish'=>1,'data_flag'=>1])->order('lotteryissue desc')->limit(1)->find();
        $akjrq = $lista['lotteryissue'];
        $adata = Db::name('aadeitycard_orders')
                    ->where(['lotteryissue'=>$akjrq,'is_guess'=>1,'data_flag'=>1])
                    ->group('userid,lotteryissue,order_type')
                    ->field('userid,lotteryissue,order_type')
                    ->order('userid asc,lotteryissue desc')
                    ->select();
        foreach ($adata as $key => $v) {
            $userid = $v['userid'];
            $lotteryissue = $v['lotteryissue'];
            $order_type = $v['order_type'];
            $updateArr = [];
            $rsu = Db::name('users')->where(['id'=>$userid])->field('winning_rate,predicted_total,winning')->find();
            $updateArr['predicted_total'] = round($rsu['predicted_total']+1);
            $winNum = Db::name('aadeitycard_orders')->where(['lotteryissue'=>$akjrq,'userid'=>$userid,'is_guess'=>1,'is_win'=>1])->count();
            $updateArr['winning'] = round($rsu['winning']+$winNum);
            if($updateArr['winning'] > 0){
                $updateArr['winning_rate'] = round($updateArr['winning'] / $updateArr['predicted_total'] * 100);
            }else{
                $updateArr['winning_rate'] = $rsu['winning_rate'];
            }
            if($updateArr['winning_rate'] > 100) $updateArr['winning_rate'] = 100;
            Db::name('users')->where('id',$userid)->update($updateArr);
            // echo $v['userid'].'、'.$v['lotteryissue'].'期、'.$v['order_type'].'<br>';
        }
        $listb = Db::name("aahermes")->where(['is_finish'=>1,'data_flag'=>1])->order('lotteryissue desc')->limit(1)->find();
        $bkjrq = $listb['lotteryissue'];
        $bdata = Db::name('aahermes_orders')
                    ->where(['lotteryissue'=>$bkjrq,'is_guess'=>1,'data_flag'=>1])
                    ->group('userid,lotteryissue,order_type')
                    ->field('userid,lotteryissue,order_type')
                    ->order('userid asc,lotteryissue desc')
                    ->select();
        foreach ($bdata as $key => $v) {
            $userid = $v['userid'];
            $lotteryissue = $v['lotteryissue'];
            $order_type = $v['order_type'];
            $updateArr = [];
            $rsu = Db::name('users')->where(['id'=>$userid])->field('winning_rate,predicted_total,winning')->find();
            $updateArr['predicted_total'] = round($rsu['predicted_total']+1);
            $winNum = Db::name('aahermes_orders')->where(['lotteryissue'=>$bkjrq,'userid'=>$userid,'is_guess'=>1,'is_win'=>1])->count();
            $updateArr['winning'] = round($rsu['winning']+$winNum);
            if($updateArr['winning'] > 0){
                $updateArr['winning_rate'] = round($updateArr['winning'] / $updateArr['predicted_total'] * 100);
            }else{
                $updateArr['winning_rate'] = $rsu['winning_rate'];
            }
            if($updateArr['winning_rate'] > 100) $updateArr['winning_rate'] = 100;
            Db::name('users')->where('id',$userid)->update($updateArr);
            // echo $v['userid'].'、'.$v['lotteryissue'].'期、'.$v['order_type'].'<br>';
        }
        $listc = Db::name("aademeter")->where(['is_finish'=>1,'data_flag'=>1])->order('lotteryissue desc')->limit(1)->find();
        $ckjrq = $listc['lotteryissue'];
        $cdata = Db::name('aademeter_orders')
                    ->where(['lotteryissue'=>$ckjrq,'is_guess'=>1,'data_flag'=>1])
                    ->group('userid,lotteryissue,order_type')
                    ->field('userid,lotteryissue,order_type')
                    ->order('userid asc,lotteryissue desc')
                    ->select();
        foreach ($cdata as $key => $v) {
            $userid = $v['userid'];
            $lotteryissue = $v['lotteryissue'];
            $order_type = $v['order_type'];
            $updateArr = [];
            $rsu = Db::name('users')->where(['id'=>$userid])->field('winning_rate,predicted_total,winning')->find();
            $updateArr['predicted_total'] = round($rsu['predicted_total']+1);
            $winNum = Db::name('aademeter_orders')->where(['lotteryissue'=>$ckjrq,'userid'=>$userid,'is_guess'=>1,'is_win'=>1])->count();
            $updateArr['winning'] = round($rsu['winning']+$winNum);
            if($updateArr['winning'] > 0){
                $updateArr['winning_rate'] = round($updateArr['winning'] / $updateArr['predicted_total'] * 100);
            }else{
                $updateArr['winning_rate'] = $rsu['winning_rate'];
            }
            if($updateArr['winning_rate'] > 100) $updateArr['winning_rate'] = 100;
            Db::name('users')->where('id',$userid)->update($updateArr);
            // echo $v['userid'].'、'.$v['lotteryissue'].'期、'.$v['order_type'].'<br>';
        }
        $listd = Db::name("aaploutos")->where(['is_finish'=>1,'data_flag'=>1])->order('lotteryissue desc')->limit(1)->find();
        $dkjrq = $listd['lotteryissue'];
        $ddata = Db::name('aaploutos_orders')
                    ->where(['lotteryissue'=>$dkjrq,'is_guess'=>1,'data_flag'=>1])
                    ->group('userid,lotteryissue,order_type')
                    ->field('userid,lotteryissue,order_type')
                    ->order('userid asc,lotteryissue desc')
                    ->select();
        foreach ($ddata as $key => $v) {
            $userid = $v['userid'];
            $lotteryissue = $v['lotteryissue'];
            $order_type = $v['order_type'];
            $updateArr = [];
            $rsu = Db::name('users')->where(['id'=>$userid])->field('winning_rate,predicted_total,winning')->find();
            $updateArr['predicted_total'] = round($rsu['predicted_total']+1);
            $winNum = Db::name('aaploutos_orders')->where(['lotteryissue'=>$dkjrq,'userid'=>$userid,'is_guess'=>1,'is_win'=>1])->count();
            $updateArr['winning'] = round($rsu['winning']+$winNum);
            if($updateArr['winning'] > 0){
                $updateArr['winning_rate'] = round($updateArr['winning'] / $updateArr['predicted_total'] * 100);
            }else{
                $updateArr['winning_rate'] = $rsu['winning_rate'];
            }
            if($updateArr['winning_rate'] > 100) $updateArr['winning_rate'] = 100;
            Db::name('users')->where('id',$userid)->update($updateArr);
            // echo $v['userid'].'、'.$v['lotteryissue'].'期、'.$v['order_type'].'<br>';
        }
        $liste = Db::name("aafates")->where(['is_finish'=>1,'data_flag'=>1])->order('lotteryissue desc')->limit(1)->find();
        $ekjrq = $liste['lotteryissue'];
        $edata = Db::name('aafates_orders')
                    ->where(['lotteryissue'=>$ekjrq,'is_guess'=>1,'data_flag'=>1])
                    ->group('userid,lotteryissue,order_type')
                    ->field('userid,lotteryissue,order_type')
                    ->order('userid asc,lotteryissue desc')
                    ->select();
        foreach ($edata as $key => $v) {
            $userid = $v['userid'];
            $lotteryissue = $v['lotteryissue'];
            $order_type = $v['order_type'];
            $updateArr = [];
            $rsu = Db::name('users')->where(['id'=>$userid])->field('winning_rate,predicted_total,winning')->find();
            $updateArr['predicted_total'] = round($rsu['predicted_total']+1);
            $winNum = Db::name('aafates_orders')->where(['lotteryissue'=>$ekjrq,'userid'=>$userid,'is_guess'=>1,'is_win'=>1])->count();
            $updateArr['winning'] = round($rsu['winning']+$winNum);
            if($updateArr['winning'] > 0){
                $updateArr['winning_rate'] = round($updateArr['winning'] / $updateArr['predicted_total'] * 100);
            }else{
                $updateArr['winning_rate'] = $rsu['winning_rate'];
            }
            if($updateArr['winning_rate'] > 100) $updateArr['winning_rate'] = 100;
            Db::name('users')->where('id',$userid)->update($updateArr);
            // echo $v['userid'].'、'.$v['lotteryissue'].'期、'.$v['order_type'].'<br>';
        }
        $listf = Db::name("aaimmortality")->where(['is_finish'=>1,'data_flag'=>1])->order('lotteryissue desc')->limit(1)->find();
        $fkjrq = $listf['lotteryissue'];
        $fdata = Db::name('aaimmortality_orders')
                    ->where(['lotteryissue'=>$fkjrq,'is_guess'=>1,'data_flag'=>1])
                    ->group('userid,lotteryissue,order_type')
                    ->field('userid,lotteryissue,order_type')
                    ->order('userid asc,lotteryissue desc')
                    ->select();
        foreach ($fdata as $key => $v) {
            $userid = $v['userid'];
            $lotteryissue = $v['lotteryissue'];
            $order_type = $v['order_type'];
            $updateArr = [];
            $rsu = Db::name('users')->where(['id'=>$userid])->field('winning_rate,predicted_total,winning')->find();
            $updateArr['predicted_total'] = round($rsu['predicted_total']+1);
            $winNum = Db::name('aaimmortality_orders')->where(['lotteryissue'=>$fkjrq,'userid'=>$userid,'is_guess'=>1,'is_win'=>1])->count();
            $updateArr['winning'] = round($rsu['winning']+$winNum);
            if($updateArr['winning'] > 0){
                $updateArr['winning_rate'] = round($updateArr['winning'] / $updateArr['predicted_total'] * 100);
            }else{
                $updateArr['winning_rate'] = $rsu['winning_rate'];
            }
            if($updateArr['winning_rate'] > 100) $updateArr['winning_rate'] = 100;
            Db::name('users')->where('id',$userid)->update($updateArr);
            // echo $v['userid'].'、'.$v['lotteryissue'].'期、'.$v['order_type'].'<br>';
        }        
        echo "执行统计竞猜完毕！<br>";
        self::getUpdateTheProxyReport();//8统计代理提成
    }
    /**
     * 执行步骤8统计代理提成
     */
    public static function getUpdateTheProxyReport(){
        echo "<hr>";
        echo "开始执行步骤8、统计代理提成";
        echo "<hr>";
        $webNum = 1;
        for($i=1;$i<=$webNum;$i++){
            $webid = $i;
            $where = [];
            $where[] = ['data_flag',"=",1];
            $where[] = ['is_finish',"=",1];
            $alist = Db::name("aadeitycard")->where($where)->order('lotteryissue desc')->limit(1)->find();
            $lottery_date = $alist['lottery_date'];
            $lotteryissue = $alist['lotteryissue'];
            $awhere = [];
            $awhere[] = ['data_flag',"=",1];
            $awhere[] = ['lotteryissue',"=",$lotteryissue];
            $awhere[] = ['webid',"=",$webid];
            $awhere[] = ['is_finish',"=",1];
            $aMoney = Db::name('aadeitycard_orders')->where($awhere)->sum("order_money*blowup");
            $bMoney = Db::name('aahermes_orders')->where($awhere)->sum("order_money*blowup");
            $cMoney = Db::name('aademeter_orders')->where($awhere)->sum("order_money*blowup");
            $dMoney = Db::name('aaploutos_orders')->where($awhere)->sum("order_money*blowup");
            $eMoney = Db::name('aafates_orders')->where($awhere)->sum("order_money*blowup");
            $fMoney = Db::name('aaimmortality_orders')->where($awhere)->sum("order_money*blowup");
            $totalAmount = round($aMoney+$bMoney+$cMoney+$dMoney+$eMoney+$fMoney,2);
            $bwhere = [];
            $bwhere[] = ['data_flag',"=",1];
            $bwhere[] = ['lotteryissue',"=",$lotteryissue];
            $bwhere[] = ['webid',"=",$webid];
            $bwhere[] = ['is_finish',"=",1];
            $bwhere[] = ['is_win',"=",1];
            $aPrize = Db::name('aadeitycard_orders')->where($bwhere)->sum("bonuses");
            $bPrize = Db::name('aahermes_orders')->where($bwhere)->sum("bonuses");
            $cPrize = Db::name('aademeter_orders')->where($bwhere)->sum("bonuses");
            $dPrize = Db::name('aaploutos_orders')->where($bwhere)->sum("bonuses");
            $ePrize = Db::name('aafates_orders')->where($bwhere)->sum("bonuses");
            $fPrize = Db::name('aaimmortality_orders')->where($bwhere)->sum("bonuses");
            $totalPrizeMoney = round($aPrize+$bPrize+$cPrize+$dPrize+$ePrize+$fPrize,2);
            $rs = Db::name('users')->where(['user_webid'=>$webid])->field('id,user_bonus,bonus_type')->find();
            $userid = $rs['id'];
            $user_bonus = $rs['user_bonus'];
            $bonus_type = (int)$rs['bonus_type'];
            if($bonus_type == 1){//流水提成
                $agencyCommission = round($totalAmount*$user_bonus/100,2);
            }elseif($bonus_type == 2){//盈亏提成
                $agencyCommission = round(($totalAmount-$totalPrizeMoney)*$user_bonus/100,2);
            }
            $data = [];
            $data['webid'] = $webid;
            $data['userid'] = $userid;
            $data['user_bonus'] = $user_bonus;
            $data['lottery_date'] = $lottery_date;
            $data['lotteryissue'] = $lotteryissue;
            $data['total_amount'] = $totalAmount;
            $data['total_prize_money'] = $totalPrizeMoney;
            $data['agency_commission'] = $agencyCommission;
            $data['add_time'] = strtotime(date('Y-m-d H:i:s'));
            $num = Db::name('aaproxy_report')->where(['webid'=>$webid,'userid'=>$userid,'lottery_date'=>$lottery_date,'lotteryissue'=>$lotteryissue])->count();
            if($num <= 0){
                Db::name('users')->where(['id'=>$userid])->inc('due_payment',$agencyCommission)->update();//待结算佣金
                Db::name('aaproxy_report')->insert($data);
            } 
        }
        echo "执行统计代理提成完毕！<br>";
    }
    /**
     * 执行竞猜统计
     */
    public static function getExecuteBettingStatistics(){
        $lotteryissue = (int)input("id");//执行第几期结算
        if($lotteryissue <= 0){
            $lotteryissue = Db::name('aadeitycard')->where(['data_flag'=>1,'is_finish'=>1])->order('lotteryissue desc')->limit(1)->value('lotteryissue');
        }
        $date = date('Y-m-d');
        $start = date('Y-m-d 22:00:00',strtotime("-1 day"));
        $end = date('Y-m-d 22:00:00',strtotime(date('Y-m-d H:i:s')));
		var_dump($date);
		echo '<br>';
		var_dump($start);
		echo '<br>';
		var_dump($end);
		echo '<br>';

        $prefix = config('database.prefix');

        $hydata = [];
        $report = [];
        $where = [];
		$where[] = ['data_flag',"=",1];
        $where[] = ['is_finish',"=",1];
        $where[] = ['is_guess',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
        $zodiac = Db::name('aadeitycard_orders')->where($where)->field('userid,order_type,is_win,sum(is_guess) orderNum')->group('userid,order_type,is_win')->select();
        $hermes = Db::name('aahermes_orders')->where($where)->field('userid,order_type,is_win,sum(is_guess) orderNum')->group('userid,order_type,is_win')->select();
        $demeter = Db::name('aademeter_orders')->where($where)->field('userid,order_type,is_win,sum(is_guess) orderNum')->group('userid,order_type,is_win')->select();
        $ploutos = Db::name('aaploutos_orders')->where($where)->field('userid,order_type,is_win,sum(is_guess) orderNum')->group('userid,order_type,is_win')->select();
        $fates = Db::name('aafates_orders')->where($where)->field('userid,order_type,is_win,sum(is_guess) orderNum')->group('userid,order_type,is_win')->select();
        $undying = Db::name('aaimmortality_orders')->where($where)->field('userid,order_type,is_win,sum(is_guess) orderNum')->group('userid,order_type,is_win')->select();
        foreach($zodiac as $key => $v){
            if(!in_array($v['userid'],$hydata))$hydata[] = $v['userid'];
            if(empty($report[$v['userid']])){
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = 1;
                    $report[$v['userid']]['S_'.$v['userid']] = 0;
                }else{
                    $report[$v['userid']]['Y_'.$v['userid']] = 0;
                    $report[$v['userid']]['S_'.$v['userid']] = 1;
                }
            }else{
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = round($report[$v['userid']]['Y_'.$v['userid']]+1);
                }else{
                    $report[$v['userid']]['S_'.$v['userid']] = round($report[$v['userid']]['S_'.$v['userid']]+1);
                }
            }
        }
        echo '统计第 '.$lotteryissue.' 期；<br>';
        echo 'zodiac数据：'.count($zodiac).'条<br>';
        unset($zodiac);
        foreach($hermes as $key => $v){
            if(!in_array($v['userid'],$hydata))$hydata[] = $v['userid'];
            if(empty($report[$v['userid']])){
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = 1;
                    $report[$v['userid']]['S_'.$v['userid']] = 0;
                }else{
                    $report[$v['userid']]['Y_'.$v['userid']] = 0;
                    $report[$v['userid']]['S_'.$v['userid']] = 1;
                }
            }else{
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = round($report[$v['userid']]['Y_'.$v['userid']]+1);
                }else{
                    $report[$v['userid']]['S_'.$v['userid']] = round($report[$v['userid']]['S_'.$v['userid']]+1);
                }
            }
        }
        echo 'hermes数据：'.count($hermes).'条<br>';
        unset($hermes);
        foreach($demeter as $key => $v){
            if(!in_array($v['userid'],$hydata))$hydata[] = $v['userid'];
            if(empty($report[$v['userid']])){
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = 1;
                    $report[$v['userid']]['S_'.$v['userid']] = 0;
                }else{
                    $report[$v['userid']]['Y_'.$v['userid']] = 0;
                    $report[$v['userid']]['S_'.$v['userid']] = 1;
                }
            }else{
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = round($report[$v['userid']]['Y_'.$v['userid']]+1);
                }else{
                    $report[$v['userid']]['S_'.$v['userid']] = round($report[$v['userid']]['S_'.$v['userid']]+1);
                }
            }
        }
        echo 'demeter数据：'.count($demeter).'条<br>';
        unset($demeter);
        foreach($ploutos as $key => $v){
            if(!in_array($v['userid'],$hydata))$hydata[] = $v['userid'];
            if(empty($report[$v['userid']])){
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = 1;
                    $report[$v['userid']]['S_'.$v['userid']] = 0;
                }else{
                    $report[$v['userid']]['Y_'.$v['userid']] = 0;
                    $report[$v['userid']]['S_'.$v['userid']] = 1;
                }
            }else{
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = round($report[$v['userid']]['Y_'.$v['userid']]+1);
                }else{
                    $report[$v['userid']]['S_'.$v['userid']] = round($report[$v['userid']]['S_'.$v['userid']]+1);
                }
            }
        }
        echo 'ploutos数据：'.count($ploutos).'条<br>';
        unset($ploutos);
        foreach($fates as $key => $v){
            if(!in_array($v['userid'],$hydata))$hydata[] = $v['userid'];
            if(empty($report[$v['userid']])){
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = 1;
                    $report[$v['userid']]['S_'.$v['userid']] = 0;
                }else{
                    $report[$v['userid']]['Y_'.$v['userid']] = 0;
                    $report[$v['userid']]['S_'.$v['userid']] = 1;
                }
            }else{
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = round($report[$v['userid']]['Y_'.$v['userid']]+1);
                }else{
                    $report[$v['userid']]['S_'.$v['userid']] = round($report[$v['userid']]['S_'.$v['userid']]+1);
                }
            }
        }
        echo 'fates数据：'.count($fates).'条<br>';
        unset($fates);
        foreach($undying as $key => $v){
            if(!in_array($v['userid'],$hydata))$hydata[] = $v['userid'];
            if(empty($report[$v['userid']])){
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = 1;
                    $report[$v['userid']]['S_'.$v['userid']] = 0;
                }else{
                    $report[$v['userid']]['Y_'.$v['userid']] = 0;
                    $report[$v['userid']]['S_'.$v['userid']] = 1;
                }
            }else{
                if($v['is_win']==1){
                    $report[$v['userid']]['Y_'.$v['userid']] = round($report[$v['userid']]['Y_'.$v['userid']]+1);
                }else{
                    $report[$v['userid']]['S_'.$v['userid']] = round($report[$v['userid']]['S_'.$v['userid']]+1);
                }
            }
        }
        echo 'undying数据：'.count($undying).'条<br>';
        unset($undying);
		$now_day = strtotime(date('Y-m-d'));
        echo '数据：'.count($hydata).'条<br>';
        foreach($hydata as $v){
            $userid = $v;
            $rsu = Db::name('users')->where(['id'=>$userid])->field('winning_rate,predicted_total,winning,ranking_time')->find();
            if(empty($rsu['ranking_time']) || $rsu['ranking_time'] < $now_day){
                $data = [];
                $data['predicted_total'] = round($rsu['predicted_total']+$report[$v]['Y_'.$v]+$report[$v]['S_'.$v]);
                $data['winning'] = round($rsu['winning']+$report[$v]['Y_'.$v]);
                $data['winning_rate'] = round($data['winning']/$data['predicted_total']*100);
                $data['ranking_time'] = $now_day;
                Db::name('users')->where(['id'=>$userid])->update($data);
                echo '更新ID:'.$userid.'；总=='.$data['predicted_total'].'；赢=='.$data['winning'].'；胜率：'.$data['winning_rate'].'%<br>';
                unset($data);
            }else{
                echo '存在ID:'.$v.'；Y=='.$report[$v]['Y_'.$v].'；S=='.$report[$v]['S_'.$v].'<br>';
            }
        }
        $xdata = Db::name('users')->where([['data_flag',"=",1],['predicted_total',">=",100]])->order('winning_rate desc')->select();
        foreach($xdata as $key => $v){
            $px = $key+1;
            $userId = $v['id'];
            $updata = [];
            if($v['winning_rate'] > 85 && $userId <= 2008){
                $updata['winning_rate'] = 80;
                $updata['winning'] = round($v['predicted_total']*0.8);
            }
            if($v['winning_rate'] < 30 && $userId <= 2008){
                $updata['winning_rate'] = 30;
                $updata['winning'] = round($v['predicted_total']*0.3);
            }
            $updata['guess_ranking'] = $px;
            Db::name('users')->where([['id','=',$userId]])->update($updata);
            unset($updata);
        }
        echo "执行统计竞猜胜率完毕！<br>";
    }
    /**
     * 指定期号结算
     */
    public static function getDesignatedSettlement(){
        $lotteryissue = (int)input("id");//执行第几期结算
        echo '指定第 '.$lotteryissue.' 期<br>';
        $where = [];
        $where[] = ['is_finish',"=",1];
        $where[] = ['data_flag',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
        //获取开奖信息
        $rsa = Db::name('aadeitycard')->where($where)->find();
        if(!empty($rsa)){
            $kjhm = round($rsa['number_a'].$rsa['number_b'].$rsa['number_c']*1);
            $kjhmxz = self::chkZodiacSigns($kjhm);
            $kjhmsj = self::chkFourSeasons($kjhm);
            $kjhmys = self::chkFourElement($kjhm);
            $kjhmyy = self::chkYinYang($kjhm);
            if($kjhm % 2==0){
                $kjhmds = 2;
            }else{
                $kjhmds = 1;
            }
            if($kjhm >= 183){
                $kjhmdx = 2;
            }else{
                $kjhmdx = 1;
            }
            $lista = Db::name("aadeitycard_orders")->where([['lotteryissue','=',$lotteryissue]])->select();
            foreach($lista as $key => $v){
                $orderid = $v['orderid'];
                $data = [];
                switch($v['order_type']){
                    case 1:
                        if($v['order_number'] == $kjhm){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }
                        break;
                    case 2:
                        if($v['order_number'] == $kjhmxz){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 3:
                        if($v['order_number'] == $kjhmsj){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 4:
                        if($v['order_number'] == $kjhmys){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 5:
                        if($v['order_number'] == $kjhmyy){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 6:
                        if($v['order_number'] == $kjhmds){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 7:
                        if($v['order_number'] == $kjhmdx){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                }
                $data['is_finish'] = 1;
                Db::name("aadeitycard_orders")->where(['orderid'=>$orderid])->update($data);
            }
            echo '星座第 '.$lotteryissue.' 期，重置完毕！<br>';
        }
        $rsb = Db::name('aahermes')->where($where)->find();
        if(!empty($rsb)){
            $kjhm = round($rsb['number_a'].$rsb['number_b'].$rsb['number_c']*1);
            $kjhmxz = self::chkZodiacSigns($kjhm);
            $kjhmsj = self::chkFourSeasons($kjhm);
            $kjhmys = self::chkFourElement($kjhm);
            $kjhmyy = self::chkYinYang($kjhm);
            if($kjhm % 2==0){
                $kjhmds = 2;
            }else{
                $kjhmds = 1;
            }
            if($kjhm >= 183){
                $kjhmdx = 2;
            }else{
                $kjhmdx = 1;
            }
            $listb = Db::name("aahermes_orders")->where([['lotteryissue','=',$lotteryissue]])->select();
            foreach($listb as $key => $v){
                $orderid = $v['orderid'];
                $data = [];
                switch($v['order_type']){
                    case 1:
                        if($v['order_number'] == $kjhm){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }
                        break;
                    case 2:
                        if($v['order_number'] == $kjhmxz){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 3:
                        if($v['order_number'] == $kjhmsj){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 4:
                        if($v['order_number'] == $kjhmys){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 5:
                        if($v['order_number'] == $kjhmyy){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 6:
                        if($v['order_number'] == $kjhmds){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 7:
                        if($v['order_number'] == $kjhmdx){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                }
                $data['is_finish'] = 1;
                Db::name("aahermes_orders")->where(['orderid'=>$orderid])->update($data);
            }
            echo '商业第 '.$lotteryissue.' 期，重置完毕！<br>';
        }
        $rsc = Db::name('aademeter')->where($where)->find();
        if(!empty($rsc)){
            $kjhm = round($rsc['number_a'].$rsc['number_b'].$rsc['number_c']*1);
            $kjhmxz = self::chkZodiacSigns($kjhm);
            $kjhmsj = self::chkFourSeasons($kjhm);
            $kjhmys = self::chkFourElement($kjhm);
            $kjhmyy = self::chkYinYang($kjhm);
            if($kjhm % 2==0){
                $kjhmds = 2;
            }else{
                $kjhmds = 1;
            }
            if($kjhm >= 183){
                $kjhmdx = 2;
            }else{
                $kjhmdx = 1;
            }
            $listc = Db::name("aademeter_orders")->where([['lotteryissue','=',$lotteryissue]])->select();
            foreach($listc as $key => $v){
                $orderid = $v['orderid'];
                $data = [];
                switch($v['order_type']){
                    case 1:
                        if($v['order_number'] == $kjhm){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }
                        break;
                    case 2:
                        if($v['order_number'] == $kjhmxz){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 3:
                        if($v['order_number'] == $kjhmsj){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 4:
                        if($v['order_number'] == $kjhmys){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 5:
                        if($v['order_number'] == $kjhmyy){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 6:
                        if($v['order_number'] == $kjhmds){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 7:
                        if($v['order_number'] == $kjhmdx){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                }
                $data['is_finish'] = 1;
                Db::name("aademeter_orders")->where(['orderid'=>$orderid])->update($data);
            }
            echo '丰收第 '.$lotteryissue.' 期，重置完毕！<br>';
        }
        $rsd = Db::name('aaploutos')->where($where)->find();
        if(!empty($rsd)){
            $kjhm = round($rsd['number_a'].$rsd['number_b'].$rsd['number_c']*1);
            $kjhmxz = self::chkZodiacSigns($kjhm);
            $kjhmsj = self::chkFourSeasons($kjhm);
            $kjhmys = self::chkFourElement($kjhm);
            $kjhmyy = self::chkYinYang($kjhm);
            if($kjhm % 2==0){
                $kjhmds = 2;
            }else{
                $kjhmds = 1;
            }
            if($kjhm >= 183){
                $kjhmdx = 2;
            }else{
                $kjhmdx = 1;
            }
            $listd = Db::name("aaploutos_orders")->where([['lotteryissue','=',$lotteryissue]])->select();
            foreach($listd as $key => $v){
                $orderid = $v['orderid'];
                $data = [];
                switch($v['order_type']){
                    case 1:
                        if($v['order_number'] == $kjhm){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }
                        break;
                    case 2:
                        if($v['order_number'] == $kjhmxz){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 3:
                        if($v['order_number'] == $kjhmsj){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 4:
                        if($v['order_number'] == $kjhmys){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 5:
                        if($v['order_number'] == $kjhmyy){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 6:
                        if($v['order_number'] == $kjhmds){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 7:
                        if($v['order_number'] == $kjhmdx){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                }
                $data['is_finish'] = 1;
                Db::name("aaploutos_orders")->where(['orderid'=>$orderid])->update($data);
            }
            echo '财富第 '.$lotteryissue.' 期，重置完毕！<br>';
        }        
        $rse = Db::name('aafates')->where($where)->find();
        if(!empty($rse)){
            $kjhm = round($rse['number_a'].$rse['number_b'].$rse['number_c']*1);
            $kjhmxz = self::chkZodiacSigns($kjhm);
            $kjhmsj = self::chkFourSeasons($kjhm);
            $kjhmys = self::chkFourElement($kjhm);
            $kjhmyy = self::chkYinYang($kjhm);
            if($kjhm % 2==0){
                $kjhmds = 2;
            }else{
                $kjhmds = 1;
            }
            if($kjhm >= 183){
                $kjhmdx = 2;
            }else{
                $kjhmdx = 1;
            }
            $liste = Db::name("aafates_orders")->where([['lotteryissue','=',$lotteryissue]])->select();
            foreach($liste as $key => $v){
                $orderid = $v['orderid'];
                $data = [];
                switch($v['order_type']){
                    case 1:
                        if($v['order_number'] == $kjhm){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }
                        break;
                    case 2:
                        if($v['order_number'] == $kjhmxz){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 3:
                        if($v['order_number'] == $kjhmsj){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 4:
                        if($v['order_number'] == $kjhmys){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 5:
                        if($v['order_number'] == $kjhmyy){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 6:
                        if($v['order_number'] == $kjhmds){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 7:
                        if($v['order_number'] == $kjhmdx){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                }
                $data['is_finish'] = 1;
                Db::name("aafates_orders")->where(['orderid'=>$orderid])->update($data);
            }
            echo '命运第 '.$lotteryissue.' 期，重置完毕！<br>';
        }
        $rsf = Db::name('aaimmortality')->where($where)->find();
        if(!empty($rsf)){
            $kjhm = round($rsf['number_a'].$rsf['number_b'].$rsf['number_c']*1);
            $kjhmxz = self::chkZodiacSigns($kjhm);
            $kjhmsj = self::chkFourSeasons($kjhm);
            $kjhmys = self::chkFourElement($kjhm);
            $kjhmyy = self::chkYinYang($kjhm);
            if($kjhm % 2==0){
                $kjhmds = 2;
            }else{
                $kjhmds = 1;
            }
            if($kjhm >= 183){
                $kjhmdx = 2;
            }else{
                $kjhmdx = 1;
            }
            $listf = Db::name("aaimmortality_orders")->where([['lotteryissue','=',$lotteryissue]])->select();
            foreach($listf as $key => $v){
                $orderid = $v['orderid'];
                $data = [];
                switch($v['order_type']){
                    case 1:
                        if($v['order_number'] == $kjhm){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }
                        break;
                    case 2:
                        if($v['order_number'] == $kjhmxz){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 3:
                        if($v['order_number'] == $kjhmsj){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 4:
                        if($v['order_number'] == $kjhmys){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                    case 5:
                        if($v['order_number'] == $kjhmyy){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 6:
                        if($v['order_number'] == $kjhmds){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                       
                        break;
                    case 7:
                        if($v['order_number'] == $kjhmdx){
                            $data['is_guess'] = 1;
                            $data['bonuses'] = round($v['order_money']*$v['blowup']*$v['payout_ratio'],2);
                            $data['is_win'] = 1;
                        }else{
                            $data['is_win'] = -1;
                        }                        
                        break;
                }
                $data['is_finish'] = 1;
                Db::name("aaimmortality_orders")->where(['orderid'=>$orderid])->update($data);
            }
            echo '永生第 '.$lotteryissue.' 期，重置完毕！<br>';
        }
    }
    /**
     * 执行竞猜胜率提升
     */
    public static function getPerformModifications(){
        $lotteryissue = (int)input("id");//执行第几期结算
        $type = (int)input("tid");
        $where = [];
        $where[] = ['data_flag',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
        $where[] = ['is_guess',"=",1];
        switch($type){
            case 1:
                $listsa = Db::name("aadeitycard_orders")->where($where)->field('userid,order_type,sum(is_guess) orderNum')->group('userid,order_type')->select();
                $rs = Db::name('aadeitycard')->where([['lotteryissue',"=",$lotteryissue],["is_finish",'=',1]])->field('number_a,number_b,number_c')->find();
                $kjhm = round($rs['number_a'].$rs['number_b'].$rs['number_c']*1);
                $kjhmxz = self::chkZodiacSigns($kjhm);
                $kjhmsj = self::chkFourSeasons($kjhm);
                $kjhmys = self::chkFourElement($kjhm);
                $kjhmyy = self::chkYinYang($kjhm);
                if($kjhm % 2==0){
                    $kjhmds = 2;
                }else{
                    $kjhmds = 1;
                }
                if($kjhm >= 183){
                    $kjhmdx = 2;
                }else{
                    $kjhmdx = 1;
                }
                $winNum1 = Db::name("aadeitycard_orders")->where([["is_win",'=',1],['order_type',"=",1],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum2 = Db::name("aadeitycard_orders")->where([["is_win",'=',1],['order_type',"=",2],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum3 = Db::name("aadeitycard_orders")->where([["is_win",'=',1],['order_type',"=",3],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum4 = Db::name("aadeitycard_orders")->where([["is_win",'=',1],['order_type',"=",4],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum5 = Db::name("aadeitycard_orders")->where([["is_win",'=',1],['order_type',"=",5],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum6 = Db::name("aadeitycard_orders")->where([["is_win",'=',1],['order_type',"=",6],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum7 = Db::name("aadeitycard_orders")->where([["is_win",'=',1],['order_type',"=",7],['lotteryissue',"=",$lotteryissue]])->count();
                break;
            case 2:
                $listsa = Db::name("aahermes_orders")->where($where)->field('userid,order_type,sum(is_guess) orderNum')->group('userid,order_type')->select();
                $rs = Db::name('aahermes')->where([['lotteryissue',"=",$lotteryissue],["is_finish",'=',1]])->field('number_a,number_b,number_c')->find();
                $kjhm = round($rs['number_a'].$rs['number_b'].$rs['number_c']*1);
                $kjhmxz = self::chkZodiacSigns($kjhm);
                $kjhmsj = self::chkFourSeasons($kjhm);
                $kjhmys = self::chkFourElement($kjhm);
                $kjhmyy = self::chkYinYang($kjhm);
                if($kjhm % 2==0){
                    $kjhmds = 2;
                }else{
                    $kjhmds = 1;
                }
                if($kjhm >= 183){
                    $kjhmdx = 2;
                }else{
                    $kjhmdx = 1;
                }
                $winNum1 = Db::name("aahermes_orders")->where([["is_win",'=',1],['order_type',"=",1],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum2 = Db::name("aahermes_orders")->where([["is_win",'=',1],['order_type',"=",2],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum3 = Db::name("aahermes_orders")->where([["is_win",'=',1],['order_type',"=",3],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum4 = Db::name("aahermes_orders")->where([["is_win",'=',1],['order_type',"=",4],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum5 = Db::name("aahermes_orders")->where([["is_win",'=',1],['order_type',"=",5],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum6 = Db::name("aahermes_orders")->where([["is_win",'=',1],['order_type',"=",6],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum7 = Db::name("aahermes_orders")->where([["is_win",'=',1],['order_type',"=",7],['lotteryissue',"=",$lotteryissue]])->count();                
                break;
            case 3:
                $listsa = Db::name("aademeter_orders")->where($where)->field('userid,order_type,sum(is_guess) orderNum')->group('userid,order_type')->select();
                $rs = Db::name('aademeter')->where([['lotteryissue',"=",$lotteryissue],["is_finish",'=',1]])->field('number_a,number_b,number_c')->find();
                $kjhm = round($rs['number_a'].$rs['number_b'].$rs['number_c']*1);
                $kjhmxz = self::chkZodiacSigns($kjhm);
                $kjhmsj = self::chkFourSeasons($kjhm);
                $kjhmys = self::chkFourElement($kjhm);
                $kjhmyy = self::chkYinYang($kjhm);
                if($kjhm % 2==0){
                    $kjhmds = 2;
                }else{
                    $kjhmds = 1;
                }
                if($kjhm >= 183){
                    $kjhmdx = 2;
                }else{
                    $kjhmdx = 1;
                }
                $winNum1 = Db::name("aademeter_orders")->where([["is_win",'=',1],['order_type',"=",1],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum2 = Db::name("aademeter_orders")->where([["is_win",'=',1],['order_type',"=",2],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum3 = Db::name("aademeter_orders")->where([["is_win",'=',1],['order_type',"=",3],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum4 = Db::name("aademeter_orders")->where([["is_win",'=',1],['order_type',"=",4],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum5 = Db::name("aademeter_orders")->where([["is_win",'=',1],['order_type',"=",5],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum6 = Db::name("aademeter_orders")->where([["is_win",'=',1],['order_type',"=",6],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum7 = Db::name("aademeter_orders")->where([["is_win",'=',1],['order_type',"=",7],['lotteryissue',"=",$lotteryissue]])->count();                
                break;
            case 4:
                $listsa = Db::name("aaploutos_orders")->where($where)->field('userid,order_type,sum(is_guess) orderNum')->group('userid,order_type')->select();
                $rs = Db::name('aaploutos')->where([['lotteryissue',"=",$lotteryissue],["is_finish",'=',1]])->field('number_a,number_b,number_c')->find();
                $kjhm = round($rs['number_a'].$rs['number_b'].$rs['number_c']*1);
                $kjhmxz = self::chkZodiacSigns($kjhm);
                $kjhmsj = self::chkFourSeasons($kjhm);
                $kjhmys = self::chkFourElement($kjhm);
                $kjhmyy = self::chkYinYang($kjhm);
                if($kjhm % 2==0){
                    $kjhmds = 2;
                }else{
                    $kjhmds = 1;
                }
                if($kjhm >= 183){
                    $kjhmdx = 2;
                }else{
                    $kjhmdx = 1;
                }
                $winNum1 = Db::name("aaploutos_orders")->where([["is_win",'=',1],['order_type',"=",1],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum2 = Db::name("aaploutos_orders")->where([["is_win",'=',1],['order_type',"=",2],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum3 = Db::name("aaploutos_orders")->where([["is_win",'=',1],['order_type',"=",3],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum4 = Db::name("aaploutos_orders")->where([["is_win",'=',1],['order_type',"=",4],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum5 = Db::name("aaploutos_orders")->where([["is_win",'=',1],['order_type',"=",5],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum6 = Db::name("aaploutos_orders")->where([["is_win",'=',1],['order_type',"=",6],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum7 = Db::name("aaploutos_orders")->where([["is_win",'=',1],['order_type',"=",7],['lotteryissue',"=",$lotteryissue]])->count();                
                break;
            case 5:
                $listsa = Db::name("aafates_orders")->where($where)->field('userid,order_type,sum(is_guess) orderNum')->group('userid,order_type')->select();
                $rs = Db::name('aafates')->where([['lotteryissue',"=",$lotteryissue],["is_finish",'=',1]])->field('number_a,number_b,number_c')->find();
                $kjhm = round($rs['number_a'].$rs['number_b'].$rs['number_c']*1);
                $kjhmxz = self::chkZodiacSigns($kjhm);
                $kjhmsj = self::chkFourSeasons($kjhm);
                $kjhmys = self::chkFourElement($kjhm);
                $kjhmyy = self::chkYinYang($kjhm);
                if($kjhm % 2==0){
                    $kjhmds = 2;
                }else{
                    $kjhmds = 1;
                }
                if($kjhm >= 183){
                    $kjhmdx = 2;
                }else{
                    $kjhmdx = 1;
                }
                $winNum1 = Db::name("aafates_orders")->where([["is_win",'=',1],['order_type',"=",1],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum2 = Db::name("aafates_orders")->where([["is_win",'=',1],['order_type',"=",2],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum3 = Db::name("aafates_orders")->where([["is_win",'=',1],['order_type',"=",3],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum4 = Db::name("aafates_orders")->where([["is_win",'=',1],['order_type',"=",4],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum5 = Db::name("aafates_orders")->where([["is_win",'=',1],['order_type',"=",5],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum6 = Db::name("aafates_orders")->where([["is_win",'=',1],['order_type',"=",6],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum7 = Db::name("aafates_orders")->where([["is_win",'=',1],['order_type',"=",7],['lotteryissue',"=",$lotteryissue]])->count();                
                break;
            case 6:
                $listsa = Db::name("aaimmortality_orders")->where($where)->field('userid,order_type,sum(is_guess) orderNum')->group('userid,order_type')->select();
                $rs = Db::name('aaimmortality')->where([['lotteryissue',"=",$lotteryissue],["is_finish",'=',1]])->field('number_a,number_b,number_c')->find();
                $kjhm = round($rs['number_a'].$rs['number_b'].$rs['number_c']*1);
                $kjhmxz = self::chkZodiacSigns($kjhm);
                $kjhmsj = self::chkFourSeasons($kjhm);
                $kjhmys = self::chkFourElement($kjhm);
                $kjhmyy = self::chkYinYang($kjhm);
                if($kjhm % 2==0){
                    $kjhmds = 2;
                }else{
                    $kjhmds = 1;
                }
                if($kjhm >= 183){
                    $kjhmdx = 2;
                }else{
                    $kjhmdx = 1;
                }
                $winNum1 = Db::name("aaimmortality_orders")->where([["is_win",'=',1],['order_type',"=",1],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum2 = Db::name("aaimmortality_orders")->where([["is_win",'=',1],['order_type',"=",2],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum3 = Db::name("aaimmortality_orders")->where([["is_win",'=',1],['order_type',"=",3],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum4 = Db::name("aaimmortality_orders")->where([["is_win",'=',1],['order_type',"=",4],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum5 = Db::name("aaimmortality_orders")->where([["is_win",'=',1],['order_type',"=",5],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum6 = Db::name("aaimmortality_orders")->where([["is_win",'=',1],['order_type',"=",6],['lotteryissue',"=",$lotteryissue]])->count();
                $winNum7 = Db::name("aaimmortality_orders")->where([["is_win",'=',1],['order_type',"=",7],['lotteryissue',"=",$lotteryissue]])->count();                
                break;
        }
        $type1 = $type2 = $type3 = $type4 = $type5 = $type6 = $type7 = 0;
        $hyId1 = $hyId2 = $hyId3 = $hyId4 = $hyId5 = $hyId6 = $hyId7 = [];
		if(empty($listsa)){
			echo 'id：第几期；tid：1~6';
			die();
		}
        foreach ($listsa as $key => $v){
            if($v['order_type']==1){
                $type1 = $type1+1;
                if(!in_array($v['userid'],$hyId1))$hyId1[] = $v['userid'];
            }
            if($v['order_type']==2){
                $type2 = $type2+1;
                if(!in_array($v['userid'],$hyId2))$hyId2[] = $v['userid'];
            }
            if($v['order_type']==3){
                $type3 = $type3+1;
                if(!in_array($v['userid'],$hyId3))$hyId3[] = $v['userid'];
            }
            if($v['order_type']==4){
                $type4 = $type4+1;
                if(!in_array($v['userid'],$hyId4))$hyId4[] = $v['userid'];
            }
            if($v['order_type']==5){
                $type5 = $type5+1;
                if(!in_array($v['userid'],$hyId5))$hyId5[] = $v['userid'];
            }
            if($v['order_type']==6){
                $type6 = $type6+1;
                if(!in_array($v['userid'],$hyId6))$hyId6[] = $v['userid'];
            }
            if($v['order_type']==7){
                $type7 = $type7+1;
                if(!in_array($v['userid'],$hyId7))$hyId7[] = $v['userid'];
            }
        }
        if(count($hyId1)>0){//直选
            echo $lotteryissue.'期竞猜直选：'.$type1.' 人；';
            $winrate = 0;
            if($winNum1 > 0){
                $winrate = round($winNum1/$type1*100);
            }
            echo '1胜='.$winNum1.'；胜率='.$winrate.' % ；';
            if($winrate < 50){
                $modNum = round(($type1*50/100)-$winNum1);
                echo '需要修改 '.$modNum.' 条数据；<br>';
                shuffle($hyId1);// 打乱数组
                for($i=0;$i<$modNum;$i++){
                    $userid = $hyId1[$i];
                    self::toOperateAndModify($type,$lotteryissue,$order_type=1,$userid,$kjhm);
                }
            }
            echo '<br>';
        }
        if(count($hyId2)>0){//星座
            echo $lotteryissue.'期竞猜星座：'.$type2.' 人；';
            $winrate = 0;
            if($winNum2 > 0){
                $winrate = round($winNum2/$type2*100);
            }
            echo '2胜='.$winNum2.'；胜率='.$winrate.' % ；';
            if($winrate < 50){
                $modNum = round(($type2*50/100)-$winNum2);
                echo '需要修改 '.$modNum.' 条数据；<br>';
                shuffle($hyId2);// 打乱数组
                for($i=0;$i<$modNum;$i++){
                    $userid = $hyId2[$i];
                    self::toOperateAndModify($type,$lotteryissue,$order_type=2,$userid,$kjhmxz);
                }
            }
            echo '<br>';
        }
        if(count($hyId3)>0){//四季
            echo $lotteryissue.'期竞猜四季：'.$type3.' 人；';
            $winrate = 0;
            if($winNum3 > 0){
                $winrate = round($winNum3/$type3*100);
            }
            echo '3胜='.$winNum3.'；胜率='.$winrate.' % ；';
            if($winrate < 50){
                $modNum = round(($type3*50/100)-$winNum3);
                echo '需要修改 '.$modNum.' 条数据；<br>';
                shuffle($hyId3);// 打乱数组
                for($i=0;$i<$modNum;$i++){
                    $userid = $hyId3[$i];
                    self::toOperateAndModify($type,$lotteryissue,$order_type=3,$userid,$kjhmsj);
                }
            }
            echo '<br>';
        }        
        if(count($hyId4)>0){//元素
            echo $lotteryissue.'期竞猜元素：'.$type4.' 人；';
            $winrate = 0;
            if($winNum4 > 0){
                $winrate = round($winNum4/$type4*100);
            }
            echo '4胜='.$winNum4.'；胜率='.$winrate.' % ；';
            if($winrate < 50){
                $modNum = round(($type4*50/100)-$winNum4);
                echo '需要修改 '.$modNum.' 条数据；<br>';
                shuffle($hyId4);// 打乱数组
                for($i=0;$i<$modNum;$i++){
                    $userid = $hyId4[$i];
                    self::toOperateAndModify($type,$lotteryissue,$order_type=4,$userid,$kjhmys);
                }
            }
            echo '<br>';
        }        
        if(count($hyId5)>0){//阴阳
            echo $lotteryissue.'期竞猜阴阳：'.$type5.' 人；';
            $winrate = 0;
            if($winNum5 > 0){
                $winrate = round($winNum5/$type5*100);
            }
            echo '5胜='.$winNum5.'；胜率='.$winrate.' % ；';
            if($winrate < 50){
                $modNum = round(($type5*50/100)-$winNum5);
                echo '需要修改 '.$modNum.' 条数据；<br>';
                shuffle($hyId5);// 打乱数组
                for($i=0;$i<$modNum;$i++){
                    $userid = $hyId5[$i];
                    self::toOperateAndModify($type,$lotteryissue,$order_type=5,$userid,$kjhmyy);
                }
            }
            echo '<br>';
        }        
        if(count($hyId6)>0){//单双
            echo $lotteryissue.'期竞猜单双：'.$type6.' 人；';
            $winrate = 0;
            if($winNum6 > 0){
                $winrate = round($winNum6/$type6*100);
            }
            echo '6胜='.$winNum6.'；胜率='.$winrate.' % ；';
            if($winrate < 50){
                $modNum = round(($type6*50/100)-$winNum6);
                echo '需要修改 '.$modNum.' 条数据；<br>';
                shuffle($hyId6);// 打乱数组
                for($i=0;$i<$modNum;$i++){
                    $userid = $hyId6[$i];
                    self::toOperateAndModify($type,$lotteryissue,$order_type=6,$userid,$kjhmds);
                }
            }
            echo '<br>';
        }  
        if(count($hyId7)>0){//大小
            echo $lotteryissue.'期竞猜大小：'.$type7.' 人；';
            $winrate = 0;
            if($winNum7 > 0){
                $winrate = round($winNum7/$type7*100);
            }
            echo '7胜='.$winNum7.'；胜率='.$winrate.' % ；';
            if($winrate < 50){
                $modNum = round(($type7*50/100)-$winNum7);
                echo '需要修改 '.$modNum.' 条数据；<br>';
                shuffle($hyId7);// 打乱数组
                for($i=0;$i<$modNum;$i++){
                    $userid = $hyId7[$i];
                    self::toOperateAndModify($type,$lotteryissue,$order_type=7,$userid,$kjhmdx);
                }
            }
            echo '<br>';
        }
    }
    /**
     * 去执行操作修改
     * type         数据表分类
     * lotteryissue 第几期
     * order_type    玩法分类
     * userid       会员ID
     * kjhm         修改内容
     */
    public static function toOperateAndModify($type,$lotteryissue,$order_type,$userid,$kjhm){
        switch($type){
            case 1:
                $rsu = Db::name("aadeitycard_orders")->where([['userid','=',$userid],["is_win",'=',-1],['order_type',"=",$order_type],['lotteryissue',"=",$lotteryissue]])->orderRaw('rand()')->limit(1)->find();
                $orderid = $rsu['orderid'];
                $data = [];
                $data['order_number'] = $kjhm;
                $data['is_win'] = 1;
                $data['bonuses'] = round($rsu['order_money']*$rsu['blowup']*$rsu['payout_ratio'],2);
                $data['is_finish'] = 1;
                Db::name("aadeitycard_orders")->where(['orderid'=>$orderid])->update($data);
                echo $userid.'：玩法：'.$order_type.'；ID：'.$orderid.'；重置为胜出！<br>';             
                break;
            case 2:
                $rsu = Db::name("aahermes_orders")->where([['userid','=',$userid],["is_win",'=',-1],['order_type',"=",$order_type],['lotteryissue',"=",$lotteryissue]])->orderRaw('rand()')->limit(1)->find();
                $orderid = $rsu['orderid'];
                $data = [];
                $data['order_number'] = $kjhm;
                $data['is_win'] = 1;
                $data['bonuses'] = round($rsu['order_money']*$rsu['blowup']*$rsu['payout_ratio'],2);
                $data['is_finish'] = 1;
                Db::name("aahermes_orders")->where(['orderid'=>$orderid])->update($data);
                echo $userid.'：玩法：'.$order_type.'；ID：'.$orderid.'；重置为胜出！<br>';                
                break;
            case 3:
                $rsu = Db::name("aademeter_orders")->where([['userid','=',$userid],["is_win",'=',-1],['order_type',"=",$order_type],['lotteryissue',"=",$lotteryissue]])->orderRaw('rand()')->limit(1)->find();
                $orderid = $rsu['orderid'];
                $data = [];
                $data['order_number'] = $kjhm;
                $data['is_win'] = 1;
                $data['bonuses'] = round($rsu['order_money']*$rsu['blowup']*$rsu['payout_ratio'],2);
                $data['is_finish'] = 1;
                Db::name("aademeter_orders")->where(['orderid'=>$orderid])->update($data);
                echo $userid.'：玩法：'.$order_type.'；ID：'.$orderid.'；重置为胜出！<br>';                
                break;
            case 4:
                $rsu = Db::name("aaploutos_orders")->where([['userid','=',$userid],["is_win",'=',-1],['order_type',"=",$order_type],['lotteryissue',"=",$lotteryissue]])->orderRaw('rand()')->limit(1)->find();
                $orderid = $rsu['orderid'];
                $data = [];
                $data['order_number'] = $kjhm;
                $data['is_win'] = 1;
                $data['bonuses'] = round($rsu['order_money']*$rsu['blowup']*$rsu['payout_ratio'],2);
                $data['is_finish'] = 1;
                Db::name("aaploutos_orders")->where(['orderid'=>$orderid])->update($data);
                echo $userid.'：玩法：'.$order_type.'；ID：'.$orderid.'；重置为胜出！<br>';                                
                break;
            case 5:
                $rsu = Db::name("aafates_orders")->where([['userid','=',$userid],["is_win",'=',-1],['order_type',"=",$order_type],['lotteryissue',"=",$lotteryissue]])->orderRaw('rand()')->limit(1)->find();
                $orderid = $rsu['orderid'];
                $data = [];
                $data['order_number'] = $kjhm;
                $data['is_win'] = 1;
                $data['bonuses'] = round($rsu['order_money']*$rsu['blowup']*$rsu['payout_ratio'],2);
                $data['is_finish'] = 1;
                Db::name("aafates_orders")->where(['orderid'=>$orderid])->update($data);
                echo $userid.'：玩法：'.$order_type.'；ID：'.$orderid.'；重置为胜出！<br>';                                
                break;
            case 6:
                $rsu = Db::name("aaimmortality_orders")->where([['userid','=',$userid],["is_win",'=',-1],['order_type',"=",$order_type],['lotteryissue',"=",$lotteryissue]])->orderRaw('rand()')->limit(1)->find();
                $orderid = $rsu['orderid'];
                $data = [];
                $data['order_number'] = $kjhm;
                $data['is_win'] = 1;
                $data['bonuses'] = round($rsu['order_money']*$rsu['blowup']*$rsu['payout_ratio'],2);
                $data['is_finish'] = 1;
                Db::name("aaimmortality_orders")->where(['orderid'=>$orderid])->update($data);
                echo $userid.'：玩法：'.$order_type.'；ID：'.$orderid.'；重置为胜出！<br>';                
                break;
        }





    }





    /**
     * 中奖备注
     */
    public static function toWinningRemark($lottery_type,$orderid){
		switch($lottery_type){
			case 1:
                $rs = Db::name("aadeitycard_orders")->where(["orderid"=>$orderid])->field('webid,order_type,order_number')->find();
                break;
			case 2:
                $rs = Db::name("aahermes_orders")->where(["orderid"=>$orderid])->field('webid,order_type,order_number')->find();
                break;
			case 3:
                $rs = Db::name("aademeter_orders")->where(["orderid"=>$orderid])->field('webid,order_type,order_number')->find();
                break;
			case 4:
                $rs = Db::name("aaploutos_orders")->where(["orderid"=>$orderid])->field('webid,order_type,order_number')->find();
                break;
			case 5:
                $rs = Db::name("aafates_orders")->where(["orderid"=>$orderid])->field('webid,order_type,order_number')->find();
                break;
			case 6:
                $rs = Db::name("aaimmortality_orders")->where(["orderid"=>$orderid])->field('webid,order_type,order_number')->find();
                break;
		}
        $webid = (int)$rs['webid'];
        $order_type = (int)$rs['order_type'];
        $order_number = $rs['order_number'];
        switch($webid){
            case 1://中文站，中文备注
                switch($lottery_type){
                    case 1: $remark = '十二星座|';
                    case 2: $remark = '商业之神|';
                    case 3: $remark = '丰收之神|';
                    case 4: $remark = '财富之神|';
                    case 5: $remark = '命运之神|';
                    case 6: $remark = '永生之神|';
                }
                switch($order_type){
                    case 1: $remark .= '直选：'.$order_number; break;
                    case 2: 
                        $xz = self::toNameZodiac($order_number,0);
                        $remark .= '星座：'.$xz;
                        break;
                    case 3:
                        $sj = self::tonameFour($order_number,0);
                        $remark .= '四季：'.$sj; 
                        break;
                    case 4: 
                        $ys = self::tonameFourElement($order_number,0);
                        $remark .= '元素：'.$ys; 
                        break;
                    case 5:
                        $yy = self::tonameYinYang($order_number,0);
                        $remark .= '阴阳：'.$yy;
                        break;
                    case 6:
                        if($order_number % 2==0){
                            $ds = '双';
                        }else{
                            $ds = '单';
                        }
                        $remark .= '单双：'.$ds; 
                        break;
                    case 7:
                        if($order_number <= 182){
                            $dx = '小';
                        }else{
                            $dx = '大';
                        }
                        $remark .= '大小：'.$dx;
                        break;
                }
                break;
            default://英文站，英文备注
                switch($lottery_type){
                    case 1: $remark = 'Zodiac|';
                    case 2: $remark = 'Hermes|';
                    case 3: $remark = 'Demeter|';
                    case 4: $remark = 'Ploutos|';
                    case 5: $remark = 'Fates|';
                    case 6: $remark = 'Immortality|';
                }
                switch($order_type){
                    case 1: $remark .= 'Direct election：'.$order_number; break;
                    case 2: 
                        $xz = self::toNameZodiac($order_number,1);
                        $remark .= 'Constellation：'.$xz; 
                        break;
                    case 3:
                        $sj = self::tonameFour($order_number,1);
                        $remark .= 'Four Seasons：'.$sj;
                        break;
                    case 4:
                        $ys = self::tonameFourElement($order_number,1);
                        $remark .= 'Element：'.$ys;
                        break;
                    case 5:
                        $yy = self::tonameYinYang($order_number,1);
                        $remark .= 'Yin and Yang：'.$yy; 
                        break;
                    case 6:
                        if($order_number % 2==0){
                            $ds = 'Even';
                        }else{
                            $ds = 'Odd';
                        }                        
                        $remark .= 'Odd or Even：'.$ds; 
                        break;
                    case 7:
                        if($order_number <= 182){
                            $dx = 'small';
                        }else{
                            $dx = 'big';
                        }                        
                        $remark .= 'big or small：'.$dx;
                        break;
                }
                break;
        }
        return $remark;
    }
	/**
	 * 会员自动兑奖
	 */
	public static function AutomaticPrizeRedemption($lottery_type,$orderid,$userid,$bonuses){
		if($bonuses > 0){
            $redShare = MyConst('common_redEnvelopePercentage');//系统设置的分享提成比例
            $share_money = round($bonuses*$redShare/100);//分享彩金
            $bonuses = round($bonuses-$share_money,2);
            $webid = Db::name('users')->where(["id"=>$userid])->value('webid');//获取代理ID
            $dlNum = Db::name('users')->where(["user_webid"=>$webid])->count();
            $remark = self::toWinningRemark($lottery_type,$orderid);
            if($webid>0 && $dlNum>0){
                Db::name('users')->where(["user_webid"=>$webid])->inc('red_envelope_pool',$share_money)->update();//分享彩金加入代理的红包池
                //创建红包池流水记录
                $wlm = [];
                $wlm['webid'] = $webid;//网站编号ID
	      	    $wlm['target_type'] = 14;//红包池流水
	      	    $wlm['target_id'] = $userid;
	      	    $wlm['data_id'] = $orderid;
	      	    $wlm['data_src'] = 15;//会员分享彩金
	      	    $wlm['remark'] = $remark.'|'.$bonuses;//备注中奖类型+奖金
	      	    $wlm['money_type'] = 1;//收入
	      	    $wlm['money'] = $share_money;
	      	    $wlm['give_money'] = 0;
	      	    $wlm['pay_type'] = 15;//会员分享彩金
	      	    $wlm['trade_no'] = $lottery_type;//彩票类型
	      	    $wlm['add_time'] = strtotime(date('Y-m-d H:i:s'));
	      	    Db::name('log_moneys')->insert($wlm);
            }
            Db::name('users')->where(["id"=>$userid])->inc('user_money',$bonuses)->update();//加入会员金币
            Db::name('users')->where(["id"=>$userid])->inc('share_money',$share_money)->update();//加入分享彩金总额
			//创建流水记录
			$lm = [];
            $lm['webid'] = $webid;//网站编号ID
			$lm['target_type'] = 9;//来源9兑奖收入
			$lm['target_id'] = $userid;//会员ID
			$lm['data_id'] = $orderid;//数据表流水ID
			$lm['data_src'] = 9;//来源9兑奖收入
			$lm['remark'] = $remark.'|'.$bonuses;//备注中奖类型+奖金
			$lm['money_type'] = 1;//收入
			$lm['money'] = (float)$bonuses;//金币
            $lm['trade_no'] = $lottery_type;//外部流水号,数据表ID
			$lm['pay_type'] = 'Lottery Center';
			$lm['data_flag'] = 1;
			$lm['add_time'] = strtotime(date('Y-m-d H:i:s'));
			Db::name('log_moneys')->insert($lm);
		}
	}    
    /**
     * 执行兑奖
     * $lottery_type 数据表ID
     * $lotteryissue  第几期
     * $kjhm     开奖号码
     */
    public static function ClaimingThePrize($lottery_type,$lotteryissue,$kjhm){
        $where = [];
        $where[] = ['is_finish',"=",0];
        $where[] = ['data_flag',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
        switch($lottery_type){
            case 1:
				$lista = Db::name("aadeitycard_orders")->where($where)->where(["order_type"=>1])->select();//查询1直选记录
				$listb = Db::name("aadeitycard_orders")->where($where)->where(["order_type"=>2])->select();//查询2星座记录
				$listc = Db::name("aadeitycard_orders")->where($where)->where(["order_type"=>3])->select();//查询3四季记录
				$listd = Db::name("aadeitycard_orders")->where($where)->where(["order_type"=>4])->select();//查询4四元素记录
				$liste = Db::name("aadeitycard_orders")->where($where)->where(["order_type"=>5])->select();//查询5阴阳记录
				$listf = Db::name("aadeitycard_orders")->where($where)->where(["order_type"=>6])->select();//查询6单双记录
				$listg = Db::name("aadeitycard_orders")->where($where)->where(["order_type"=>7])->select();//查询7大小记录
				break;
            case 2:
				$lista = Db::name("aahermes_orders")->where($where)->where(["order_type"=>1])->select();//查询1直选记录
				$listb = Db::name("aahermes_orders")->where($where)->where(["order_type"=>2])->select();//查询2星座记录
				$listc = Db::name("aahermes_orders")->where($where)->where(["order_type"=>3])->select();//查询3四季记录
				$listd = Db::name("aahermes_orders")->where($where)->where(["order_type"=>4])->select();//查询4四元素记录
				$liste = Db::name("aahermes_orders")->where($where)->where(["order_type"=>5])->select();//查询5阴阳记录
				$listf = Db::name("aahermes_orders")->where($where)->where(["order_type"=>6])->select();//查询6单双记录
				$listg = Db::name("aahermes_orders")->where($where)->where(["order_type"=>7])->select();//查询7大小记录
				break;
            case 3:
				$lista = Db::name("aademeter_orders")->where($where)->where(["order_type"=>1])->select();//查询1直选记录
				$listb = Db::name("aademeter_orders")->where($where)->where(["order_type"=>2])->select();//查询2星座记录
				$listc = Db::name("aademeter_orders")->where($where)->where(["order_type"=>3])->select();//查询3四季记录
				$listd = Db::name("aademeter_orders")->where($where)->where(["order_type"=>4])->select();//查询4四元素记录
				$liste = Db::name("aademeter_orders")->where($where)->where(["order_type"=>5])->select();//查询5阴阳记录
				$listf = Db::name("aademeter_orders")->where($where)->where(["order_type"=>6])->select();//查询6单双记录
				$listg = Db::name("aademeter_orders")->where($where)->where(["order_type"=>7])->select();//查询7大小记录
				break;
			case 4:
				$lista = Db::name("aaploutos_orders")->where($where)->where(["order_type"=>1])->select();//查询1直选记录
				$listb = Db::name("aaploutos_orders")->where($where)->where(["order_type"=>2])->select();//查询2星座记录
				$listc = Db::name("aaploutos_orders")->where($where)->where(["order_type"=>3])->select();//查询3四季记录
				$listd = Db::name("aaploutos_orders")->where($where)->where(["order_type"=>4])->select();//查询4四元素记录
				$liste = Db::name("aaploutos_orders")->where($where)->where(["order_type"=>5])->select();//查询5阴阳记录
				$listf = Db::name("aaploutos_orders")->where($where)->where(["order_type"=>6])->select();//查询6单双记录
				$listg = Db::name("aaploutos_orders")->where($where)->where(["order_type"=>7])->select();//查询7大小记录
				break;
			case 5:
				$lista = Db::name("aafates_orders")->where($where)->where(["order_type"=>1])->select();//查询1直选记录
				$listb = Db::name("aafates_orders")->where($where)->where(["order_type"=>2])->select();//查询2星座记录
				$listc = Db::name("aafates_orders")->where($where)->where(["order_type"=>3])->select();//查询3四季记录
				$listd = Db::name("aafates_orders")->where($where)->where(["order_type"=>4])->select();//查询4四元素记录
				$liste = Db::name("aafates_orders")->where($where)->where(["order_type"=>5])->select();//查询5阴阳记录
				$listf = Db::name("aafates_orders")->where($where)->where(["order_type"=>6])->select();//查询6单双记录
				$listg = Db::name("aafates_orders")->where($where)->where(["order_type"=>7])->select();//查询7大小记录
				break;
			case 6:
				$lista = Db::name("aaimmortality_orders")->where($where)->where(["order_type"=>1])->select();//查询1直选记录
				$listb = Db::name("aaimmortality_orders")->where($where)->where(["order_type"=>2])->select();//查询2星座记录
				$listc = Db::name("aaimmortality_orders")->where($where)->where(["order_type"=>3])->select();//查询3四季记录
				$listd = Db::name("aaimmortality_orders")->where($where)->where(["order_type"=>4])->select();//查询4四元素记录
				$liste = Db::name("aaimmortality_orders")->where($where)->where(["order_type"=>5])->select();//查询5阴阳记录
				$listf = Db::name("aaimmortality_orders")->where($where)->where(["order_type"=>6])->select();//查询6单双记录
				$listg = Db::name("aaimmortality_orders")->where($where)->where(["order_type"=>7])->select();//查询7大小记录
				break;
        }
        foreach($lista as $key => $v){
            $orderid = $v['orderid'];
			$userid = $v['userid'];
            $data = [];
            if($v['order_number']==$kjhm){
                $data['is_win'] = 1;//1中奖
                if($userid<=2005){
                    $data['is_guess'] = 1;//1自动竞猜
                }
                $bonuses = round($v['order_money']*$v['payout_ratio']*$v['blowup']);//彩金
				$data['bonuses'] = $bonuses;
				self::AutomaticPrizeRedemption($lottery_type,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lottery_type){
				case 1:
					Db::name("aadeitycard_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 2:
					Db::name("aahermes_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 3:
					Db::name("aademeter_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 4:
					Db::name("aaploutos_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 5:
					Db::name("aafates_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 6:
					Db::name("aaimmortality_orders")->where(["orderid"=>$orderid])->update($data);
					break;
            }
        }
		unset($lista);
        foreach($listb as $key => $v){
            $orderid = $v['orderid'];
			$userid = $v['userid'];
            $data = [];
			$xz = self::chkZodiacSigns($kjhm);
            if($v['order_number']==$xz){
                $data['is_win'] = 1;//1中奖
                if($userid<=20005){
                    $data['is_guess'] = 1;//1自动竞猜
                }
                $bonuses = round($v['order_money']*$v['payout_ratio']*$v['blowup']);//彩金
				$data['bonuses'] = $bonuses;
				self::AutomaticPrizeRedemption($lottery_type,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lottery_type){
				case 1:
					Db::name("aadeitycard_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 2:
					Db::name("aahermes_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 3:
					Db::name("aademeter_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 4:
					Db::name("aaploutos_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 5:
					Db::name("aafates_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 6:
					Db::name("aaimmortality_orders")->where(["orderid"=>$orderid])->update($data);
					break;
            }
        }
		unset($listb);
        foreach($listc as $key => $v){
            $orderid = $v['orderid'];
			$userid = $v['userid'];
            $data = [];
            $sj = self::chkFourSeasons($kjhm);
            if($v['order_number']==$sj){
                $data['is_win'] = 1;//1中奖
                if($userid<=2005){
                    $data['is_guess'] = 1;//1自动竞猜
                }
                $bonuses = round($v['order_money']*$v['payout_ratio']*$v['blowup']);//彩金
				$data['bonuses'] = $bonuses;
				self::AutomaticPrizeRedemption($lottery_type,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lottery_type){
				case 1:
					Db::name("aadeitycard_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 2:
					Db::name("aahermes_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 3:
					Db::name("aademeter_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 4:
					Db::name("aaploutos_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 5:
					Db::name("aafates_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 6:
					Db::name("aaimmortality_orders")->where(["orderid"=>$orderid])->update($data);
					break;
            }
        }
		unset($listc);
        foreach($listd as $key => $v){
            $orderid = $v['orderid'];
			$userid = $v['userid'];
            $data = [];
            $sys = self::chkFourElement($kjhm);
            if($v['order_number']==$sys){
                $data['is_win'] = 1;//1中奖
                if($userid<=2005){
                    $data['is_guess'] = 1;//1自动竞猜
                }
                $bonuses = round($v['order_money']*$v['payout_ratio']*$v['blowup']);//彩金
				$data['bonuses'] = $bonuses;
				self::AutomaticPrizeRedemption($lottery_type,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lottery_type){
				case 1:
					Db::name("aadeitycard_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 2:
					Db::name("aahermes_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 3:
					Db::name("aademeter_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 4:
					Db::name("aaploutos_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 5:
					Db::name("aafates_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 6:
					Db::name("aaimmortality_orders")->where(["orderid"=>$orderid])->update($data);
					break;
            }			
        }
		unset($listd);
        foreach($liste as $key => $v){
            $orderid = $v['orderid'];
			$userid = $v['userid'];
            $data = [];
            $yy = self::chkYinYang($kjhm);
            if($v['order_number']==$yy){
                $data['is_win'] = 1;//1中奖
                if($userid<=2005){
                    $data['is_guess'] = 1;//1自动竞猜
                }
                $bonuses = round($v['order_money']*$v['payout_ratio']*$v['blowup']);//彩金
				$data['bonuses'] = $bonuses;
				self::AutomaticPrizeRedemption($lottery_type,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lottery_type){
				case 1:
					Db::name("aadeitycard_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 2:
					Db::name("aahermes_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 3:
					Db::name("aademeter_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 4:
					Db::name("aaploutos_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 5:
					Db::name("aafates_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 6:
					Db::name("aaimmortality_orders")->where(["orderid"=>$orderid])->update($data);
					break;
            }			
        }
		unset($liste);
        foreach($listf as $key => $v){
            $orderid = $v['orderid'];
			$userid = $v['userid'];
            $data = [];
            $ds = 0;
            if($kjhm % 2==0){
                $ds = 2;
            }else{
                $ds = 1;
            }
            if($v['order_number']==$ds){
                $data['is_win'] = 1;//1中奖
                if($userid<=2005){
                    $data['is_guess'] = 1;//1自动竞猜
                }
                $bonuses = round($v['order_money']*$v['payout_ratio']*$v['blowup']);//彩金
				$data['bonuses'] = $bonuses;
				self::AutomaticPrizeRedemption($lottery_type,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lottery_type){
				case 1:
					Db::name("aadeitycard_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 2:
					Db::name("aahermes_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 3:
					Db::name("aademeter_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 4:
					Db::name("aaploutos_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 5:
					Db::name("aafates_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 6:
					Db::name("aaimmortality_orders")->where(["orderid"=>$orderid])->update($data);
					break;
            }			
        }
		unset($listf);
        foreach($listg as $key => $v){
            $orderid = $v['orderid'];
			$userid = $v['userid'];
            $data = [];
            $dx = 0;
            if($kjhm  >= 183){
                $dx = 2;
            }else{
                $dx = 1;
            }
            if($v['order_number']==$dx){
                $data['is_win'] = 1;//1中奖
                if($userid<=2005){
                    $data['is_guess'] = 1;//1自动竞猜
                }
                $bonuses = round($v['order_money']*$v['payout_ratio']*$v['blowup']);//彩金
				$data['bonuses'] = $bonuses;
				self::AutomaticPrizeRedemption($lottery_type,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lottery_type){
				case 1:
					Db::name("aadeitycard_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 2:
					Db::name("aahermes_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 3:
					Db::name("aademeter_orders")->where(["orderid"=>$orderid])->update($data);
					break;
                case 4:
					Db::name("aaploutos_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 5:
					Db::name("aafates_orders")->where(["orderid"=>$orderid])->update($data);
					break;
			    case 6:
					Db::name("aaimmortality_orders")->where(["orderid"=>$orderid])->update($data);
					break;
            }			
        }
		unset($listg);
    }
    /**
     * 执行测试虚拟开奖
     * $type          数据表ID
     * $lotteryissue  第几期
     * $lottery_date   日期
     */
    public static function VirtualLotteryDraw($type,$lotteryissue,$lottery_date){
        $where = [];
        $where[] = ['is_finish',"=",0];
        $where[] = ['data_flag',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
        $totalAmount = 0;
        switch($type){
            case 1://1十二星座
                $totalAmount = Db::name("aadeitycard_orders")->where($where)->sum("order_money*blowup");//总金额
                break;
            case 2://2商业彩票
                $totalAmount = Db::name("aahermes_orders")->where($where)->sum("order_money*blowup");//总金额
                break;
            case 3://3丰收彩票
                $totalAmount = Db::name("aademeter_orders")->where($where)->sum("order_money*blowup");//总金额
                break;
            case 4://4财富彩票
                $totalAmount = Db::name("aaploutos_orders")->where($where)->sum("order_money*blowup");//总金额
                break;
            case 5://5命运彩票
                $totalAmount = Db::name("aafates_orders")->where($where)->sum("order_money*blowup");//总金额
                break;
            case 6://6永生彩票
                $totalAmount = Db::name("aaimmortality_orders")->where($where)->sum("order_money*blowup");//总金额
                break;
        }
        $ylAmount = round($totalAmount*0.15);//15%盈利范围
        echo $lotteryissue."期订单总金额：$".$totalAmount."，15%盈利值约：$".$ylAmount."<br>";
        $number_arr = [];//创建虚拟开奖数组，统计1~365的开出盈亏。
        for($i=1;$i<366;$i++){
            $cjnum = self::StatisticalBonus($type,$lotteryissue,$i);
            $ykNum = round($totalAmount-$cjnum);
            $Arr['haoma'] = $i;
            $Arr['cjnum'] = $cjnum;
            $Arr['ykNum'] = $ykNum;
            if($ykNum >= $ylAmount){
                $number_arr[] = $Arr;
                // echo $i."号奖金总额：$".$cjnum."，盈利：".$ykNum."，加入开奖数组。<br>";
            }else{
                // echo "<span style='color:#f00'>".$i."号奖金总额：$".$cjnum."，亏损：".$ykNum."。</span><br>";
            }
        }
        echo '还有'.count($number_arr).'个号码。<br>';
        $ykNum = array_column($number_arr,'ykNum');
        //对 $number_arr 按照 $ykNum 升序排列
        array_multisort($ykNum, SORT_ASC, $number_arr);
        echo "按照升序排列......<br>";
        $kjhm = $number_arr[0]['haoma'];
        echo "<span>号码：".$kjhm."，盈亏：".$number_arr[0]['ykNum']."<br>";
        self::ExecuteSaveData($type,$kjhm,$lotteryissue,$lottery_date);
    }
    /**
     * 统计奖金
     * $type          数据表ID
     * $lotteryissue  第几期
     * $num   号码
     */
    public static function StatisticalBonus($type,$lotteryissue,$num){
        $where = [];
        $where[] = ['is_finish',"=",0];
        $where[] = ['data_flag',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
        $cjTotal = 0;
        switch($type){
            case 1:
                $order_money = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',1],['order_number','=',$num]])->sum("order_money*blowup");//1直选金额
                $cjTotal = round($order_money*360,2);//直选彩金
                $xznum = self::chkZodiacSigns($num);
                $order_money2 = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = self::FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = self::chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = self::FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = self::chkFourElement($num);
                $order_money4 = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = self::FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = self::chkYinYang($num);
                $order_money5 = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = self::FormatTheOdds(5,$yynum);
                $yycj = round($order_money5*$yypl,2);//阴阳彩金
                $cjTotal = round($cjTotal+$yycj,2);//加入总金额
                if($num % 2==0){
                    $dsnum = 2;
                }else{
                    $dsnum = 1;
                }
                $order_money6 = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',6],['order_number','=',$dsnum]])->sum("order_money*blowup");//6单双金额
                $dspl = self::FormatTheOdds(6,$dsnum);
                $dscj = round($order_money6*$dspl,2);//单双彩金
                $cjTotal = round($cjTotal+$dscj,2);//加入总金额
                if($num <= 182){
                    $dxnum = 1;
                }else{
                    $dxnum = 2;
                }
                $order_money7 = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',7],['order_number','=',$dxnum]])->sum("order_money*blowup");//7大小金额
                $dxpl = self::FormatTheOdds(7,$dxnum);
                $dxcj = round($order_money7*$dxpl,2);//大小彩金
                $cjTotal = round($cjTotal+$dxcj,2);//加入总金额
                break;
            case 2:
                $order_money = Db::name("aahermes_orders")->where($where)->where([['order_type','=',1],['order_number','=',$num]])->sum("order_money*blowup");//1直选金额
                $cjTotal = round($order_money*360,2);//直选彩金
                $xznum = self::chkZodiacSigns($num);
                $order_money2 = Db::name("aahermes_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = self::FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = self::chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aahermes_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = self::FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = self::chkFourElement($num);
                $order_money4 = Db::name("aahermes_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = self::FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = self::chkYinYang($num);
                $order_money5 = Db::name("aahermes_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = self::FormatTheOdds(5,$yynum);
                $yycj = round($order_money5*$yypl,2);//阴阳彩金
                $cjTotal = round($cjTotal+$yycj,2);//加入总金额
                if($num % 2==0){
                    $dsnum = 2;
                }else{
                    $dsnum = 1;
                }
                $order_money6 = Db::name("aahermes_orders")->where($where)->where([['order_type','=',6],['order_number','=',$dsnum]])->sum("order_money*blowup");//6单双金额
                $dspl = self::FormatTheOdds(6,$dsnum);
                $dscj = round($order_money6*$dspl,2);//单双彩金
                $cjTotal = round($cjTotal+$dscj,2);//加入总金额
                if($num <= 182){
                    $dxnum = 1;
                }else{
                    $dxnum = 2;
                }
                $order_money7 = Db::name("aahermes_orders")->where($where)->where([['order_type','=',7],['order_number','=',$dxnum]])->sum("order_money*blowup");//7大小金额
                $dxpl = self::FormatTheOdds(7,$dxnum);
                $dxcj = round($order_money7*$dxpl,2);//大小彩金
                $cjTotal = round($cjTotal+$dxcj,2);//加入总金额                
                break;
            case 3:
                $order_money = Db::name("aademeter_orders")->where($where)->where([['order_type','=',1],['order_number','=',$num]])->sum("order_money*blowup");//1直选金额
                $cjTotal = round($order_money*360,2);//直选彩金
                $xznum = self::chkZodiacSigns($num);
                $order_money2 = Db::name("aademeter_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = self::FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = self::chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aademeter_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = self::FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = self::chkFourElement($num);
                $order_money4 = Db::name("aademeter_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = self::FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = self::chkYinYang($num);
                $order_money5 = Db::name("aademeter_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = self::FormatTheOdds(5,$yynum);
                $yycj = round($order_money5*$yypl,2);//阴阳彩金
                $cjTotal = round($cjTotal+$yycj,2);//加入总金额
                if($num % 2==0){
                    $dsnum = 2;
                }else{
                    $dsnum = 1;
                }
                $order_money6 = Db::name("aademeter_orders")->where($where)->where([['order_type','=',6],['order_number','=',$dsnum]])->sum("order_money*blowup");//6单双金额
                $dspl = self::FormatTheOdds(6,$dsnum);
                $dscj = round($order_money6*$dspl,2);//单双彩金
                $cjTotal = round($cjTotal+$dscj,2);//加入总金额
                if($num <= 182){
                    $dxnum = 1;
                }else{
                    $dxnum = 2;
                }
                $order_money7 = Db::name("aademeter_orders")->where($where)->where([['order_type','=',7],['order_number','=',$dxnum]])->sum("order_money*blowup");//7大小金额
                $dxpl = self::FormatTheOdds(7,$dxnum);
                $dxcj = round($order_money7*$dxpl,2);//大小彩金
                $cjTotal = round($cjTotal+$dxcj,2);//加入总金额                
                break;
            case 4:
                $order_money = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',1],['order_number','=',$num]])->sum("order_money*blowup");//1直选金额
                $cjTotal = round($order_money*360,2);//直选彩金
                $xznum = self::chkZodiacSigns($num);
                $order_money2 = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = self::FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = self::chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = self::FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = self::chkFourElement($num);
                $order_money4 = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = self::FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = self::chkYinYang($num);
                $order_money5 = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = self::FormatTheOdds(5,$yynum);
                $yycj = round($order_money5*$yypl,2);//阴阳彩金
                $cjTotal = round($cjTotal+$yycj,2);//加入总金额
                if($num % 2==0){
                    $dsnum = 2;
                }else{
                    $dsnum = 1;
                }
                $order_money6 = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',6],['order_number','=',$dsnum]])->sum("order_money*blowup");//6单双金额
                $dspl = self::FormatTheOdds(6,$dsnum);
                $dscj = round($order_money6*$dspl,2);//单双彩金
                $cjTotal = round($cjTotal+$dscj,2);//加入总金额
                if($num <= 182){
                    $dxnum = 1;
                }else{
                    $dxnum = 2;
                }
                $order_money7 = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',7],['order_number','=',$dxnum]])->sum("order_money*blowup");//7大小金额
                $dxpl = self::FormatTheOdds(7,$dxnum);
                $dxcj = round($order_money7*$dxpl,2);//大小彩金
                $cjTotal = round($cjTotal+$dxcj,2);//加入总金额                
                break;
            case 5:
                $order_money = Db::name("aafates_orders")->where($where)->where([['order_type','=',1],['order_number','=',$num]])->sum("order_money*blowup");//1直选金额
                $cjTotal = round($order_money*360,2);//直选彩金
                $xznum = self::chkZodiacSigns($num);
                $order_money2 = Db::name("aafates_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = self::FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = self::chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aafates_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = self::FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = self::chkFourElement($num);
                $order_money4 = Db::name("aafates_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = self::FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = self::chkYinYang($num);
                $order_money5 = Db::name("aafates_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = self::FormatTheOdds(5,$yynum);
                $yycj = round($order_money5*$yypl,2);//阴阳彩金
                $cjTotal = round($cjTotal+$yycj,2);//加入总金额
                if($num % 2==0){
                    $dsnum = 2;
                }else{
                    $dsnum = 1;
                }
                $order_money6 = Db::name("aafates_orders")->where($where)->where([['order_type','=',6],['order_number','=',$dsnum]])->sum("order_money*blowup");//6单双金额
                $dspl = self::FormatTheOdds(6,$dsnum);
                $dscj = round($order_money6*$dspl,2);//单双彩金
                $cjTotal = round($cjTotal+$dscj,2);//加入总金额
                if($num <= 182){
                    $dxnum = 1;
                }else{
                    $dxnum = 2;
                }
                $order_money7 = Db::name("aafates_orders")->where($where)->where([['order_type','=',7],['order_number','=',$dxnum]])->sum("order_money*blowup");//7大小金额
                $dxpl = self::FormatTheOdds(7,$dxnum);
                $dxcj = round($order_money7*$dxpl,2);//大小彩金
                $cjTotal = round($cjTotal+$dxcj,2);//加入总金额                
                break;
            case 6:
                $order_money = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',1],['order_number','=',$num]])->sum("order_money*blowup");//1直选金额
                $cjTotal = round($order_money*360,2);//直选彩金
                $xznum = self::chkZodiacSigns($num);
                $order_money2 = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = self::FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = self::chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = self::FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = self::chkFourElement($num);
                $order_money4 = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = self::FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = self::chkYinYang($num);
                $order_money5 = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = self::FormatTheOdds(5,$yynum);
                $yycj = round($order_money5*$yypl,2);//阴阳彩金
                $cjTotal = round($cjTotal+$yycj,2);//加入总金额
                if($num % 2==0){
                    $dsnum = 2;
                }else{
                    $dsnum = 1;
                }
                $order_money6 = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',6],['order_number','=',$dsnum]])->sum("order_money*blowup");//6单双金额
                $dspl = self::FormatTheOdds(6,$dsnum);
                $dscj = round($order_money6*$dspl,2);//单双彩金
                $cjTotal = round($cjTotal+$dscj,2);//加入总金额
                if($num <= 182){
                    $dxnum = 1;
                }else{
                    $dxnum = 2;
                }
                $order_money7 = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',7],['order_number','=',$dxnum]])->sum("order_money*blowup");//7大小金额
                $dxpl = self::FormatTheOdds(7,$dxnum);
                $dxcj = round($order_money7*$dxpl,2);//大小彩金
                $cjTotal = round($cjTotal+$dxcj,2);//加入总金额
                break;
        }
        return $cjTotal;
    }

    /**
     * 随机是否竞猜
     */
    public static function getRandomGuessing(){
        $num = rand(0,5);//随机数
        if($num == 1){
            $num = 1;
        }else{
            $num = 0;
        }
        return $num;
    }
    /**
     * 格式化赔率
     */
    public static function FormatTheOdds($type,$num){
        $pl = 0;
        switch($type){
            case 1: $pl = 360; break;//直选赔率 360
            case 2:
                if($num==1 || $num==3 || $num==10 || $num==12){
                    $pl=12;
                }elseif($num==4 || $num==6 || $num==7 || $num==8 || $num==9){
                    $pl=11.5;
                }elseif($num==2 || $num==11){
                    $pl=12.5;
                }elseif($num==5){
                    $pl=11;
                }
                break;
            case 3:
                if($num==1 || $num==2 ){
                    $pl=3.8;
                }elseif($num==3 || $num==4){
                    $pl=4;
                }                
                break;
            case 4:
                if($num==1 || $num==4 ){
                    $pl=3.8;
                }elseif($num==2 || $num==3){
                    $pl=4;
                }                
                break;
            case 5: $pl = 1.96; break;
            case 6: $pl = 1.96; break;
            case 7: $pl = 1.96; break;
        }
        return $pl;
    }
    /**
     * 统计未结算注单总金额
     * $lottery_type 数据表ID
     * $lotteryissue  第几期
     */
    public static function CalculateTheTotalNumber($lottery_type,$lotteryissue){
        $where = [];
        $where[] = ['is_finish',"=",0];
        $where[] = ['data_flag',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
		$totalAmount = 0;
        switch($lottery_type){
            case 1:
				$totalAmount = Db::name("aadeitycard_orders")->where($where)->sum("order_money*blowup");//1星座彩票总金额
				break;
            case 2:
				$totalAmount = Db::name("aahermes_orders")->where($where)->sum("order_money*blowup");//2商业彩票总金额
				break;
            case 3:
				$totalAmount = Db::name("aademeter_orders")->where($where)->sum("order_money*blowup");//3丰收彩票总金额
				break;
			case 4:
				$totalAmount = Db::name("aaploutos_orders")->where($where)->sum("order_money*blowup");//4财富彩票总金额
				break;
			case 5:
				$totalAmount = Db::name("aafates_orders")->where($where)->sum("order_money*blowup");//5命运彩票总金额
				break;
			case 6:
				$totalAmount = Db::name("aaimmortality_orders")->where($where)->sum("order_money*blowup");//6永生彩票总金额
				break;
        }
        return  (float)$totalAmount;
    }
    /**
     * 十二星座验证
     */
    public static function chkZodiacSigns($num){
        $xz=0;
        $xz1Arr = ['20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49'];
        $xz2Arr = ['50','51','52','53','54','55','56','57','58','59','60','61','62','63','64','65','66','67','68','69','70','71','72','73','74','75','76','77','78'];
        $xz3Arr = ['79','80','81','82','83','84','85','86','87','88','89','90','91','92','93','94','95','96','97','98','99','100','101','102','103','104','105','106','107','108'];
        $xz4Arr = ['109','110','111','112','113','114','115','116','117','118','119','120','121','122','123','124','125','126','127','128','129','130','131','132','133','134','135','136','137','138','139'];
        $xz5Arr = ['140','141','142','143','144','145','146','147','148','149','150','151','152','153','154','155','156','157','158','159','160','161','162','163','164','165','166','167','168','169','170','171'];
        $xz6Arr = ['172','173','174','175','176','177','178','179','180','181','182','183','184','185','186','187','188','189','190','191','192','193','194','195','196','197','198','199','200','201','202'];
        $xz7Arr = ['203','204','205','206','207','208','209','210','211','212','213','214','215','216','217','218','219','220','221','222','223','224','225','226','227','228','229','230','231','232','233'];
        $xz8Arr = ['234','235','236','237','238','239','240','241','242','243','244','245','246','247','248','249','250','251','252','253','254','255','256','257','258','259','260','261','262','263','264'];
        $xz9Arr = ['265','266','267','268','269','270','271','272','273','274','275','276','277','278','279','280','281','282','283','284','285','286','287','288','289','290','291','292','293','294','295'];
        $xz10Arr = ['296','297','298','299','300','301','302','303','304','305','306','307','308','309','310','311','312','313','314','315','316','317','318','319','320','321','322','323','324','325'];
        $xz11Arr = ['326','327','328','329','330','331','332','333','334','335','336','337','338','339','340','341','342','343','344','345','346','347','348','349','350','351','352','353','354'];
        $xz12Arr = ['355','356','357','358','359','360','361','362','363','364','365','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19'];
        if(in_array($num,$xz1Arr)){
            $xz=1;
        }elseif(in_array($num,$xz2Arr)){
            $xz=2;
        }elseif(in_array($num,$xz3Arr)){
            $xz=3;
        }elseif(in_array($num,$xz4Arr)){
            $xz=4;
        }elseif(in_array($num,$xz5Arr)){
            $xz=5;
        }elseif(in_array($num,$xz6Arr)){
            $xz=6;
        }elseif(in_array($num,$xz7Arr)){
            $xz=7;
        }elseif(in_array($num,$xz8Arr)){
            $xz=8;
        }elseif(in_array($num,$xz9Arr)){
            $xz=9;
        }elseif(in_array($num,$xz10Arr)){
            $xz=10;
        }elseif(in_array($num,$xz11Arr)){
            $xz=11;
        }elseif(in_array($num,$xz12Arr)){
            $xz=12;
        }
        return $xz;
    }
    /**
     * 四季验证
     */
    public static function chkFourSeasons($num){
        $sj = 0;
        if($num>=1 && $num<=78){
            $sj = 4;
        }elseif($num>=79 && $num<=171){
            $sj = 1;
        }elseif($num>=172 && $num<=264){
            $sj = 2;
        }elseif($num>=265 && $num<=354){
            $sj = 3;
        }elseif($num>=355 && $num<=365){
            $sj = 4;
        }
        return $sj;
    }  
    /**
     * 四元素验证
     */
    public static function chkFourElement($num){
        $sys = 0;
        if($num>=1 && $num<=19){
            $sys = 4;
        }elseif(($num>=20 && $num<=49) || ($num>=140 && $num<=171) || ($num>=265 && $num<=295)){
            $sys = 1;
        }elseif(($num>=50 && $num<=78) || ($num>=172 && $num<=202) || ($num>=296 && $num<=325)){
            $sys = 2;
        }elseif(($num>=79 && $num<=108) || ($num>=203 && $num<=233) || ($num>=326 && $num<=354)){
            $sys = 3;
        }elseif(($num>=109 && $num<=139) || ($num>=234 && $num<=264) || ($num>=355 && $num<=365)){
            $sys = 4;
        }
        return $sys;
    }
    /**
     * 阴阳验证
     */
    public static function chkYinYang($num){
        $yy = 0;
        if($num>=1 && $num<=19){
            $yy = 2;
        }elseif(($num>=20 && $num<=49) || ($num>=79 && $num<=108) || ($num>=140 && $num<=171) || ($num>=203 && $num<=233) || ($num>=265 && $num<=295) || ($num>=326 && $num<=354)){
            $yy = 1;
        }elseif(($num>=50 && $num<=78) || ($num>=109 && $num<=139) || ($num>=172 && $num<=202) || ($num>=234 && $num<=264) || ($num>=296 && $num<=325) || ($num>=355 && $num<=365)){
            $yy = 2;
        }
        return $yy;
    }
    /**
     * 添加百万大奖记录
     */
    public static function addTopprize($type,$date,$qi,$jackpot,$areaid){
        //echo '开始添加最大头奖新闻记录<br>';
        $data = [];
        $data['lottery_type'] = $type;
        $data['lottery_date'] = $date;
        $data['lotteryissue'] = $qi;
        $data['jackpot'] = $jackpot;
        $data['areaid'] = $areaid;
        //echo '添加：'.$qi.' 期头奖；<br>';
        //var_dump($data);
        Db::name('aatopprize')->insert($data);
        $jackpot = '$'.number_format($jackpot);
        for($i=1;$i<5;$i++){//1英文 2中文 3印地语 4西班牙语
            $lottery_type = self::lottery_type($type,$i);  //彩票名称
            $areaName = self::ToAreas($areaid,$i);         //区域名称
            $cpNumber = self::TocpNumbers($type,$date,$qi);//开奖号码
            $shopNum = rand(15678,99999);                  //随机销售网点
            $title = self::ToTitle($type,$areaid,$qi,$i);  //新闻标题
            switch($i){//模版
                case 1:
                    $tpl = Db::name('Article')->where([['data_flag','=',1],['is_enable','=',1],['id','=',1657]])->value('content');
                    $isEn = 'en';
                    break;
                case 2:
                    $tpl = Db::name('Article')->where([['data_flag','=',1],['is_enable','=',1],['id','=',1656]])->value('content');
                    $isEn = 'zh';
                    break;
                case 3:
                    $tpl = Db::name('Article')->where([['data_flag','=',1],['is_enable','=',1],['id','=',1659]])->value('content');
                    $isEn = 'hi';           
                    break;
                case 4:
                    $tpl = Db::name('Article')->where([['data_flag','=',1],['is_enable','=',1],['id','=',1658]])->value('content');
                    $isEn = 'spa';                
                    break;
            }
            $tplContent = str_replace('${LOTTERY_NAME}',$lottery_type,$tpl);
            $tplContent = str_replace('${LOTTERY_JACKPOT}',$jackpot,$tplContent);
            $tplContent = str_replace('${LOTTERY_DATE}',$date,$tplContent);
            $tplContent = str_replace('${LOTTERY_AREAID}',$areaName,$tplContent);
            $tplContent = str_replace('${LOTTERY_ISSUE}',$qi,$tplContent);
            $tplContent = str_replace('${LOTTERY_NUMBER}',$cpNumber,$tplContent);
            $tplContent = str_replace('${SHOP_NUMBER}',$shopNum,$tplContent);
            self::addArticles($title,$isEn,$tplContent,$date,$qi);//12大奖新闻
        }
    }
    public static function lottery_type($type,$lang){//文章模版彩票名称替换词
        $name = '';
        if($lang==1){
            switch($type){
                case 1: $name = 'Gods of the Zodiac'; break;
                case 2: $name = 'Hermes'; break;
                case 3: $name = 'Demeter'; break;
                case 4: $name = 'Ploutos'; break;
		        case 5: $name = 'Fates'; break;
		        case 6: $name = 'Immortality'; break;
            }
        }elseif($lang==2){
            switch($type){
                case 1: $name = '星座之神'; break;
                case 2: $name = '商业之神'; break;
                case 3: $name = '丰收之神'; break;
                case 4: $name = '财富之神'; break;
		        case 5: $name = '命运之神'; break;
		        case 6: $name = '永生之神'; break;
            }
        }elseif($lang==3){
            switch($type){
                case 1: $name = 'नक्षत्र देवता'; break;
                case 2: $name = 'व्यापार के देवता'; break;
                case 3: $name = 'फसल के देवता'; break;
                case 4: $name = 'धन के देवता'; break;
		        case 5: $name = 'भाग्य के देवता'; break;
		        case 6: $name = 'अमर देवता'; break;
            }
        }elseif($lang==4){
            switch($type){
                case 1: $name = 'Dioses del zodiaco'; break;
                case 2: $name = 'El Dios de los negocios'; break;
                case 3: $name = 'El Dios de la cosecha'; break;
                case 4: $name = 'El Dios de la riqueza'; break;
		        case 5: $name = 'El Dios del destino'; break;
		        case 6: $name = 'El Dios de la vida eterna'; break;
            }
        }
        return $name;
    }
    public static function ToAreas($areaid,$lang){//文章模版区域替换词
        $name = '';
        $rs = Db::name('areas')->where(["areaid"=>$areaid])->find();
        switch($lang){
            case 1: $name = $rs['area_nameen']; break;//英文
            case 2: $name = $rs['area_name']; break;//中文
            case 3: $name = $rs['area_namehi']; break;//印地语
            case 4: $name = $rs['area_namees']; break;//西班牙语
        }
        return $name;
    }
    public static function TocpNumbers($type,$lottery_date,$lotteryissue){//文章模版开奖号码替换
        $cpNumber = '';
        if($type==1){//十二星座
            $rscp = Db::name('aadeitycard')->where(["lottery_date"=>$lottery_date,"lotteryissue"=>$lotteryissue])->find();
            $cpNumber = $rscp['number_a'].$rscp['number_b'].$rscp['number_c'];
        }elseif($type==2){//商业之神
            $rscp = Db::name('aahermes')->where(["lottery_date"=>$lottery_date,"lotteryissue"=>$lotteryissue])->find();
            $cpNumber = $rscp['grouping'].$rscp['number_a'].$rscp['number_b'].$rscp['number_c'];
        }elseif($type==3){//丰收之神
            $rscp = Db::name('aademeter')->where(["lottery_date"=>$lottery_date,"lotteryissue"=>$lotteryissue])->find();
            $cpNumber = $rscp['numberD'].$rscp['grouping'].$rscp['number_a'].$rscp['number_b'].$rscp['number_c'];
        }elseif($type==4){//财富之神
            $rscp = Db::name('aaploutos')->where(["lottery_date"=>$lottery_date,"lotteryissue"=>$lotteryissue])->find();
            $cpNumber = $rscp['numberD'].$rscp['grouping'].$rscp['number_a'].$rscp['number_b'].$rscp['number_c'];
        }elseif($type==5){//命运之神
            $rscp = Db::name('aafates')->where(["lottery_date"=>$lottery_date,"lotteryissue"=>$lotteryissue])->find();
            $cpNumber = $rscp['numberE'].$rscp['numberD'].$rscp['grouping'].$rscp['number_a'].$rscp['number_b'].$rscp['number_c'];
        }elseif($type==6){//永生之神
            $rscp = Db::name('aaimmortality')->where(["lottery_date"=>$lottery_date,"lotteryissue"=>$lotteryissue])->find();
            $cpNumber = $rscp['numberD'].$rscp['numberE'].$rscp['numberF'].$rscp['numberG'].$rscp['numberH'].$rscp['numberI'].$rscp['number_a'].$rscp['number_b'].$rscp['number_c'];
        }
        return $cpNumber;
    }
    public static function ToTitle($type,$areaid,$qi,$lang){//文章模版标题替换
        $name = '';
        if($lang==1){
            $areaName = self::ToAreas($areaid,1);
            switch($type){
                case 1: $name = 'In the '.$qi.'th installment of '.$areaName.', a player won the jackpot of 5 million yuan in the God of Constellations lottery'; break;
                case 2: $name = '['.$areaName.'] Player Wins $10 Million Jackpot in Commercial God [Issue '.$qi.']'; break;
                case 3: $name = 'The winner of the 50 million prize in the God of Harvest ['.$qi.'th issue] comes from '.$areaName; break;
                case 4: $name = 'The God of Wealth [No. '.$qi.'] has revealed a billionaire from ['.$areaName.']'; break;
		        case 5: $name = 'The God of Destiny descends [Issue '.$qi.'] and the lucky winner from ['.$areaName.'] wins $700 million'; break;
		        case 6: $name = 'Eternal God [Issue '.$qi.'] selects a billionaire from ['.$areaName.']'; break;
            }
        }elseif($lang==2){
            $areaName = self::ToAreas($areaid,2);
            switch($type){
                case 1: $name = $qi.'期'.$areaName.'玩家喜中星座之神500万大奖'; break;
                case 2: $name = $areaName."玩家喜中商业之神'.$qi.'千万美元大奖"; break;
                case 3: $name = '丰收之神'.$qi.'期5千万得主来自'.$areaName; break;
                case 4: $name = '财富之神'.$qi.'期再爆一位'.$areaName.'的亿万富豪'; break;
		        case 5: $name = '命运之神降临'.$qi.'期'.$areaName.'的幸运者获奖7亿美元'; break;
		        case 6: $name = '永生之神'.$qi.'期选出'.$areaName.'10亿美元大富豪'; break;
            }
        }elseif($lang==3){
            $areaName = self::ToAreas($areaid,3);
            switch($type){
                case 1: $name = $qi.' अंक '.$areaName.' खिलाड़ी ने राशि देवता से 500 लाख का पुरस्कार जीता'; break;
                case 2: $name = '['.$areaName.'] खिलाड़ी ने व्यापार देवता को जीता ['.$qi.'] करोड़ों डॉलर का पुरस्कार'; break;
                case 3: $name = 'फसल के देवता [अंक '.$qi.'] 5 करोड़ के जीतने वाला व्यक्ति ['.$areaName.'] से था'; break;
                case 4: $name = 'धन के देवता ['.$qi.'] ने एक ['.$areaName.'] के अरबपति का खुलासा किया'; break;
		        case 5: $name = 'किस्मत का देवता आया [एपिसोड '.$qi.'] ['.$areaName.'] के भाग्यशाली ने 7 अरब डॉलर जीते'; break;
		        case 6: $name = 'अमरता का देवता [अंक '.$qi.'] ने [ '.$areaName.' ] के 1 अरब डॉलर के धनी का चयन किया'; break;
            }
        }elseif($lang==4){
            $areaName = self::ToAreas($areaid,4);
            switch($type){
                case 1: $name = 'Edición '.$qi.' ['.$areaName.'] Jugador feliz por ganar el premio de 5 millones de Dioses del Zodiaco'; break;
                case 2: $name = '['.$areaName.'] Jugador gana el premio del Dios de la Comercio [Sorteo '.$qi.'] Millones de dólares'; break;
                case 3: $name = 'Dios de la cosecha [Edición '.$qi.'] El ganador de 50 millones es de ['.$areaName.']'; break;
                case 4: $name = 'El dios de la riqueza ['.$qi.'] reveló a un multimillonario de ['.$areaName.']'; break;
		        case 5: $name = 'El dios del destino desciende [Edición '.$qi.'] La afortunada de ['.$areaName.'] gana 700 millones de dólares'; break;
		        case 6: $name = 'Dios de la inmortalidad [Episodio '.$qi.'] selecciona a un millonario de 1.000 millones de dólares en ['.$areaName.']'; break;
            }
        }
        return $name;
    }
    public static function addArticles($title,$isEn,$tplcontent,$lottery_date,$lotteryissue){
        $cidArr = [11,12,13,15];//11行业动态，12大奖新闻，13热点新闻，15系统公告
        $randtime = rand(80000,85200);
        $catId = $cidArr[rand(0,3)];
        $data = [];
        $data['article_category_id'] = $catId;
        $data['title'] = $title;
        $data['is_enable'] = 1;
        $data['lang_name'] = $isEn;
        $data['content'] = $tplcontent;
        $data['seo_keywords'] = $title;
        $data['staffid'] = 1;
        $data['data_flag'] = 1;
        $data['seo_title'] = $title;
        $data['add_time'] = strtotime($lottery_date)+$randtime;
        $data['solve'] = $lotteryissue;
		$data["access_count"] = (int)round(rand(1,23)*3);
        $data['seo_desc'] = $title;
        Db::name('article')->insert($data);
        unset($data);
    }
    /**
     * 生成随机字母
     */
    public static function RandLetter($len){
        $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $tmp = '';
        for($i=0;$i<$len;$i++){
            $tmp.=$str[rand(0,25)];
        }
        return $tmp;
    }
    /** 辅助查询函数End */
    /**
     * 十二星座名称
     */
    public static function toNameZodiac($num,$key=0){
        $name = '';
		if($key==1){//英文
			switch($num){
				case 1: $name = 'Aquarius'; break;
				case 2: $name = 'Pisces'; break;
				case 3: $name = 'Aries'; break;
				case 4: $name = 'Taurus'; break;
				case 5: $name = 'Gemini'; break;
				case 6: $name = 'Cancerians'; break;
				case 7: $name = 'Leo'; break;
				case 8: $name = 'Virgo'; break;
				case 9: $name = 'Libra'; break;
				case 10: $name = 'Scorpio'; break;
				case 11: $name = 'Sagittarius'; break;
				case 12: $name = 'Capricorn'; break;
			}
		}else{
			switch($num){
				case 1: $name = '水瓶座'; break;
				case 2: $name = '双鱼座'; break;
				case 3: $name = '白羊座'; break;
				case 4: $name = '金牛座'; break;
				case 5: $name = '双子座'; break;
				case 6: $name = '巨蟹座'; break;
				case 7: $name = '狮子座'; break;
				case 8: $name = '处女座'; break;
				case 9: $name = '天秤座'; break;
				case 10: $name = '天蝎座'; break;
				case 11: $name = '射手座'; break;
				case 12: $name = '摩羯座'; break;
			}
		}
        return $name;
    }
    /**
     * 四季名称
     */
    public static function tonameFour($num,$key=0){
        $name = '';
		if($key==1){
			switch($num){
				case 1: $name = 'spring'; break;
				case 2: $name = 'summer'; break;
				case 3: $name = 'autumn'; break;
				case 4: $name = 'winter'; break;
			}
		}else{
			switch($num){
				case 1: $name = '春天'; break;
				case 2: $name = '夏天'; break;
				case 3: $name = '秋天'; break;
				case 4: $name = '冬天'; break;
			}
		}
        return $name;
    } 
    /**
     * 四元素名称
     */
    public static function tonameFourElement($num,$key=0){
        $name = '';
		if($key==1){
			switch($num){
				case 1: $name = 'Wind Element'; break;
				case 2: $name = 'Water Element'; break;
				case 3: $name = 'Fire Element'; break;
				case 4: $name = 'Earth element'; break;
			}
		}else{
			switch($num){
				case 1: $name = '风元素'; break;
				case 2: $name = '水元素'; break;
				case 3: $name = '火元素'; break;
				case 4: $name = '土元素'; break;
			}
		}
        return $name;
    }   
    /**
     * 阴阳名称
     */
    public static function tonameYinYang($num,$key=0){
        $name = '';
		if($key==1){
			switch($num){
				case 1: $name = 'Yang'; break;
				case 2: $name = 'Yin'; break;
			}
		}else{
			switch($num){
				case 1: $name = '阳'; break;
				case 2: $name = '阴'; break;
			}
		}
        return $name;	
    }


}

?>