<?php
namespace app\index\controller;
use think\facade\Db;
/**
 * 开奖控制器
 */
class Lotterydraw {
    /**
     * 执行手动开奖
     */
    public function index(){
        //依次从1~6开始 1十二星座彩票（500万），2商业之神（1千万），3丰收之神（5千万），4财富之神（1亿），5命运之神（7亿），6永生之神（10亿）
        $step = (int)input("step");//执行步骤
        $key = input("key");
        $map = input("map");
        switch($step){
            case 2:
                $this->hermes($key,$map);//2商业之神
                break;
            case 3:
                $this->demeter($key,$map);//3丰收之神
                break;
            case 4:
                $this->ploutos($key,$map);//4财富之神
                break;
            case 5:
                $this->fates($key,$map);//5命运之神
                break;
            case 6:
                $this->immortality($key,$map);//6永生之神
                break;
            case 7:
                $this->getStatisticalWinningRate();//统计竞猜胜率
                break;
            case 8:
                $this->getUpdateTheProxyReport();//统计代理提成
                break;
            default://默认从1开始
                $this->zodiac($key,$map);//1十二星座
                break;
        }
    }
    /**
     * 执行步骤1
     */
    public function zodiac($key,$map){//1十二星座
        echo "<hr>";
        echo "开始执行手动操作：步骤1、星座神邸";
        echo "<hr>";
        //获取最新一期信息
        $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 = $this->CalculateTheTotalNumber(1,$lotteryissue);
        echo '未结算总金额为：'.$totalAmount.'<br>';
        echo '是否生成测试流水单：<a href="http://localhost/12xz/index.php?s=Lotterydraw/index.html?key=1">是</a>、否。<br>';
        if($key==1){
            echo '执行生成测试流水单......<br>';
            $this->GenerateTestProcess(1,$lotteryissue,$lottery_date);
        }
        echo '是否统计虚拟测试开奖：<a href="http://localhost/12xz/index.php?s=Lotterydraw/index.html?key=2">是</a>、否。<br>';
        $this->toNavigationMenu();//导航菜单
        if($key==2){
            echo '执行测试虚拟开奖......<br>';
            $this->VirtualLotteryDraw(1,$lotteryissue,$lottery_date);
        }
        if($key==3){
            $num = WSTBase64urlDecode($map);
            $strnum = sprintf("%03d",$num);
            $hmarr = array_map('intval',str_split((string)$strnum));//转换成数组
            $now = date('Y-m-d H:i:s');
            $kjnow = $lottery_date." 22:00:00";
            $jztime = $lottery_date." 23:00:00";
            echo "号码：".$strnum."；当前时间：".$now."；开奖时间：".$kjnow."<br>";
            if($now >= $kjnow ){//执行开奖
                $is_finish = $rs['is_finish'];
                if($is_finish==0){//未完结  未开奖
                    $lottery_id = $rs['lottery_id'];
                    $areaid = rand(6,201);//头奖得主区域ID
                    $million = round($rs['million']+rand(1,2));
                    $jackpot = rand(12345,99999)*10;//随机数
                    if($million>=5){
                        $million = 1;
                        $this->addTopprize(1,$lottery_date,$lotteryissue,5000000,$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);//中奖人数
                    $data['asian_a'] = rand(21234,199999);//参与人数
                    $data['asian_b'] = round($data['asian_a']*1.23456);//投注单
                    $data['asian_c'] = rand(12345,99999)*10;//随机数
                    $data['america_a'] = rand(31234,299999);//参与人数
                    $data['america_b'] = round($data['america_a']*1.23456);//投注单
                    $data['america_c'] = rand(12345,99999)*10;//随机数
                    $data['europe_a'] = rand(31234,299999);//参与人数
                    $data['europe_b'] = round($data['europe_a']*1.23456);//投注单
                    $data['europe_c'] = rand(12345,99999)*10;//随机数
                    $data['africa_a'] = rand(11234,109999);//参与人数
                    $data['africa_b'] = round($data['africa_a']*1.23456);//投注单
                    $data['africa_c'] = rand(12345,99999)*10;//随机数
                    $data['oceania_a'] = rand(9234,99999);//参与人数
                    $data['oceania_b'] = round($data['oceania_a']*1.23456);//投注单
                    $data['oceania_c'] = rand(12345,99999)*10;//随机数
                   // Db::name('aadeitycard')->where(['lottery_id'=>$lottery_id])->update($data);
                   // $this->ClaimingThePrize(1,$lotteryissue,$num);//执行兑奖
                    //新增一期
                    $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['create_time'] = $xdate;
                  //  Db::name('aadeitycard')->insert($xdata);
                    echo "插入第".$year.$order."期完毕！<br>";
                }
            }else{
                echo "等待开奖....";
                echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=2'>进入2商业之神</a><br>";
            }
        }
    } 
    /**
     * 执行步骤2
     */
    public function hermes($key,$map){//2商业之神
        echo "<hr>";
        echo "开始执行手动操作：步骤2、商业之神";
        echo "<hr>";
        //获取最新一期信息
        $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 = $this->CalculateTheTotalNumber(2,$lotteryissue);
        echo '未结算总金额为：'.$totalAmount.'<br>';
        echo '是否生成测试流水单：<a href="http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=2&key=4">是</a>、否。<br>';
        if($key==4){
            echo '执行生成测试流水单......<br>';
            $this->GenerateTestProcess(2,$lotteryissue,$lottery_date);
        }
        echo '是否统计虚拟测试开奖：<a href="http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=2&key=5">是</a>、否。<br>';
        $this->toNavigationMenu();//导航菜单
        if($key==5){
            echo '执行测试虚拟开奖......<br>';
            $this->VirtualLotteryDraw(2,$lotteryissue,$lottery_date);
        }
        if($key==6){
            $num = WSTBase64urlDecode($map);
            $strnum = sprintf("%03d",$num);
            $hmarr = array_map('intval',str_split((string)$strnum));//转换成数组
            $now = date('Y-m-d H:i:s');
            $kjnow = $lottery_date." 22:00:00";
            $jztime = $lottery_date." 23:00:00";
            echo "号码：".$strnum."；当前时间：".$now."；开奖时间：".$kjnow."<br>";
            if($now >= $kjnow ){//执行开奖
                $is_finish = $rs['is_finish'];
                if($is_finish==0){//未完结  未开奖
                    $lottery_id = $rs['lottery_id'];
                    $areaid = rand(6,201);//头奖得主区域ID
                    $million = round($rs['million']+rand(1,3));
                    $jackpot = rand(12345,99999)*10;//随机数
                    if($million>=15){
                        $million = 3;
                        $this->addTopprize(2,$lottery_date,$lotteryissue,10000000,$areaid);
                    }
                    $data = [];
                    $data['grouping'] = $this->RandLetter(1);
                    $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;//头奖得主区域ID
                    $data['total_winners'] = rand(11234,59999);//中奖人数
                    Db::name('aahermes')->where(['lottery_id'=>$lottery_id])->update($data);
                    $this->ClaimingThePrize(2,$lotteryissue,$num);//执行兑奖
                    //新增一期
                    $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['create_time'] = $xdate;
                    Db::name('aahermes')->insert($xdata);
                    echo "插入第".$year.$order."期完毕！<br>";
                }
            }else{
                echo "等待开奖....";
                echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=3'>进入3丰收之神</a><br>";
            }
        }        
    }
    /**
     * 执行步骤3
     */
    public function demeter($key,$map){//3丰收之神
        echo "<hr>";
        echo "开始执行手动操作：步骤3、丰收之神";
        echo "<hr>";
        //获取最新一期信息
        $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 = $this->CalculateTheTotalNumber(3,$lotteryissue);
        echo '未结算总金额为：'.$totalAmount.'<br>';
        echo '是否生成测试流水单：<a href="http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=3&key=7">是</a>、否。<br>';
        if($key==7){
            echo '执行生成测试流水单......<br>';
            $this->GenerateTestProcess(3,$lotteryissue,$lottery_date);
        }
        echo '是否统计虚拟测试开奖：<a href="http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=3&key=8">是</a>、否。<br>';
        $this->toNavigationMenu();//导航菜单
        if($key==8){
            echo '执行测试虚拟开奖......<br>';
            $this->VirtualLotteryDraw(3,$lotteryissue,$lottery_date);
        }
        if($key==9){
            $num = WSTBase64urlDecode($map);
            $strnum = sprintf("%03d",$num);
            $hmarr = array_map('intval',str_split((string)$strnum));//转换成数组
            $now = date('Y-m-d H:i:s');
            $kjnow = $lottery_date." 22:00:00";
            $jztime = $lottery_date." 23:00:00";
            echo "号码：".$strnum."；当前时间：".$now."；开奖时间：".$kjnow."<br>";
            if($now >= $kjnow ){//执行开奖
                $is_finish = $rs['is_finish'];
                if($is_finish==0){//未完结  未开奖
                    $lottery_id = $rs['lottery_id'];
                    $areaid = rand(6,201);//头奖得主区域ID
                    $million = round($rs['million']+rand(1,5));
                    $jackpot = rand(12345,99999)*10;//随机数
                    if($million>=60){
                        $million = 10;
                        $this->addTopprize(3,$lottery_date,$lotteryissue,50000000,$areaid);
                    }
                    $data = [];
                    $data['numberD'] = rand(1,9);
                    $data['grouping'] = $this->RandLetter(1);
                    $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;//头奖得主区域ID
                    $data['total_winners'] = rand(11234,59999);//中奖人数
                    Db::name('aademeter')->where(['lottery_id'=>$lottery_id])->update($data);
                    $this->ClaimingThePrize(3,$lotteryissue,$num);//执行兑奖
                    //新增一期
                    $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['create_time'] = $xdate;
                    Db::name('aademeter')->insert($xdata);
                    echo "插入第".$year.$order."期完毕！<br>";
                }
            }else{
                echo "等待开奖....";
                echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=4'>进入4财富之神</a><br>";
            }
        }
    }
    /**
     * 执行步骤4
     */
    public function ploutos($key,$map){//4财富之神
        echo "<hr>";
        echo "开始执行手动操作：步骤4、财富之神";
        echo "<hr>";
        //获取最新一期信息
        $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 = $this->CalculateTheTotalNumber(4,$lotteryissue);
        echo '未结算总金额为：'.$totalAmount.'<br>';
        echo '是否生成测试流水单：<a href="http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=4&key=10">是</a>、否。<br>';
        if($key==10){
            echo '执行生成测试流水单......<br>';
            $this->GenerateTestProcess(4,$lotteryissue,$lottery_date);
        }
        echo '是否统计虚拟测试开奖：<a href="http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=4&key=11">是</a>、否。<br>';
        $this->toNavigationMenu();//导航菜单
        if($key==11){
            echo '执行测试虚拟开奖......<br>';
            $this->VirtualLotteryDraw(4,$lotteryissue,$lottery_date);
        }
        if($key==12){
            $num = WSTBase64urlDecode($map);
            $strnum = sprintf("%03d",$num);
            $hmarr = array_map('intval',str_split((string)$strnum));//转换成数组
            $now = date('Y-m-d H:i:s');
            $kjnow = $lottery_date." 22:00:00";
            $jztime = $lottery_date." 23:00:00";
            echo "号码：".$strnum."；当前时间：".$now."；开奖时间：".$kjnow."<br>";
            if($now >= $kjnow ){//执行开奖
                $is_finish = $rs['is_finish'];
                if($is_finish==0){//未完结  未开奖
                    $lottery_id = $rs['lottery_id'];
                    $areaid = rand(6,201);//头奖得主区域ID
                    $million = round($rs['million']+rand(1,6));
                    $jackpot = rand(12345,99999)*10;//随机数
                    if($million>=110){
                        $million = 30;
                        $this->addTopprize(4,$lottery_date,$lotteryissue,100000000,$areaid);
                    }
                    $data = [];
                    $data['numberD'] = $this->RandLetter(1);
                    $data['grouping'] = $this->RandLetter(1);
                    $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;//头奖得主区域ID
                    $data['total_winners'] = rand(12345,69999);//中奖人数
                    Db::name('aaploutos')->where(['lottery_id'=>$lottery_id])->update($data);
                    $this->ClaimingThePrize(4,$lotteryissue,$num);//执行兑奖
                    //新增一期
                    $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['create_time'] = $xdate;
                    Db::name('aaploutos')->insert($xdata);
                    echo "插入第".$year.$order."期完毕！<br>";
                }
            }else{
                echo "等待开奖....";
                echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=5'>进入5命运之神</a><br>";
            }
        }
    }
    /**
     * 执行步骤5
     */
    public function fates($key,$map){//5命运之神
        echo "<hr>";
        echo "开始执行手动操作：步骤5、命运之神";
        echo "<hr>";
        //获取最新一期信息
        $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 = $this->CalculateTheTotalNumber(5,$lotteryissue);
        echo '未结算总金额为：'.$totalAmount.'<br>';
        echo '是否生成测试流水单：<a href="http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=5&key=13">是</a>、否。<br>';
        if($key==13){
            echo '执行生成测试流水单......<br>';
            $this->GenerateTestProcess(5,$lotteryissue,$lottery_date);
        }
        echo '是否统计虚拟测试开奖：<a href="http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=5&key=14">是</a>、否。<br>';
        $this->toNavigationMenu();//导航菜单
        if($key==14){
            echo '执行测试虚拟开奖......<br>';
            $this->VirtualLotteryDraw(5,$lotteryissue,$lottery_date);
        }
        if($key==15){
            $num = WSTBase64urlDecode($map);
            $strnum = sprintf("%03d",$num);
            $hmarr = array_map('intval',str_split((string)$strnum));//转换成数组
            $now = date('Y-m-d H:i:s');
            $kjnow = $lottery_date." 22:00:00";
            $jztime = $lottery_date." 23:00:00";
            echo "号码：".$strnum."；当前时间：".$now."；开奖时间：".$kjnow."<br>";
            if($now >= $kjnow ){//执行开奖
                $is_finish = $rs['is_finish'];
                if($is_finish==0){//未完结  未开奖
                    $lottery_id = $rs['lottery_id'];
                    $areaid = rand(6,201);//头奖得主区域ID
                    $million = round($rs['million']+rand(1,7));
                    $jackpot = rand(12345,99999)*10;//随机数
                    if($million>=700){
                        $million = 100;
                        $this->addTopprize(5,$lottery_date,$lotteryissue,700000000,$areaid);
                    }
                    $data = [];
                    $data['numberE'] = $this->RandLetter(1);
                    $data['numberD'] = $this->RandLetter(1);
                    $data['grouping'] = $this->RandLetter(1);
                    $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;//头奖得主区域ID
                    $data['total_winners'] = rand(12345,69999);//中奖人数
                    Db::name('aafates')->where(['lottery_id'=>$lottery_id])->update($data);
                    $this->ClaimingThePrize(5,$lotteryissue,$num);//执行兑奖
                    //新增一期
                    $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['create_time'] = $xdate;
                    Db::name('aafates')->insert($xdata);
                    echo "插入第".$year.$order."期完毕！<br>";
                }
            }else{
                echo "等待开奖....";
                echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=6'>进入6永生之神</a><br>";
            }
        }
    }
    /**
     * 执行步骤6
     */
    public function immortality($key,$map){//6永生之神
        echo "<hr>";
        echo "开始执行手动操作：步骤6、永生之神";
        echo "<hr>";
        //获取最新一期信息
        $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 = $this->CalculateTheTotalNumber(6,$lotteryissue);
        echo '未结算总金额为：'.$totalAmount.'<br>';
        echo '是否生成测试流水单：<a href="http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=6&key=16">是</a>、否。<br>';
        if($key==16){
            echo '执行生成测试流水单......<br>';
            $this->GenerateTestProcess(6,$lotteryissue,$lottery_date);
        }
        echo '是否统计虚拟测试开奖：<a href="http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=6&key=17">是</a>、否。<br>';
        $this->toNavigationMenu();//导航菜单
        if($key==17){
            echo '执行测试虚拟开奖......<br>';
            $this->VirtualLotteryDraw(6,$lotteryissue,$lottery_date);
        }
        if($key==18){
            $num = WSTBase64urlDecode($map);
            $strnum = sprintf("%03d",$num);
            $hmarr = array_map('intval',str_split((string)$strnum));//转换成数组
            $now = date('Y-m-d H:i:s');
            $kjnow = $lottery_date." 22:00:00";
            $jztime = $lottery_date." 23:00:00";
            echo "号码：".$strnum."；当前时间：".$now."；开奖时间：".$kjnow."<br>";
            if($now >= $kjnow ){//执行开奖
                $is_finish = $rs['is_finish'];
                if($is_finish==0){//未完结  未开奖
                    $lottery_id = $rs['lottery_id'];
                    $areaid = rand(6,201);//头奖得主区域ID
                    $million = round($rs['million']+rand(5,19));
                    $jackpot = rand(102345,999999)*10;//随机数
                    if($million>=1000){
                        $million = 300;
                        $this->addTopprize(6,$lottery_date,$lotteryissue,1000000000,$areaid);
                    }
                    $data = [];
                    $data['numberI'] = rand(1,9);//随机数
                    $data['numberH'] = rand(1,9);//随机数
                    $data['numberG'] = rand(1,9);//随机数
                    $data['numberF'] = rand(1,9);//随机数
                    $data['numberE'] = rand(1,9);//随机数
                    $data['numberD'] = rand(1,9);//随机数
                    $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;//头奖得主区域ID
                    $data['total_winners'] = rand(123456,999999);//中奖人数
                    Db::name('aaimmortality')->where(['lottery_id'=>$lottery_id])->update($data);
                    $this->ClaimingThePrize(6,$lotteryissue,$num);//执行兑奖
                    //新增一期
                    $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['create_time'] = $xdate;
                    Db::name('aaimmortality')->insert($xdata);
                    echo "插入第".$year.$order."期完毕！<br>";
                }
            }else{
                echo "等待开奖....";
                echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html'>回到1星座神邸</a><br>";
            }
        }
    }
    /**
     * 执行步骤7统计竞猜胜率
     */
    public function getStatisticalWinningRate(){
        $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(['userid'=>$userid])->field('winningRate,predictedTotal,winning')->find();
            $updateArr['predictedTotal'] = round($rsu['predictedTotal']+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['winningRate'] = round($updateArr['winning'] / $updateArr['predictedTotal'] * 100);
            }else{
                $updateArr['winningRate'] = $rsu['winningRate'];
            }
            if($updateArr['winningRate'] > 100) $updateArr['winningRate'] = 100;
            Db::name('users')->where('userid',$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(['userid'=>$userid])->field('winningRate,predictedTotal,winning')->find();
            $updateArr['predictedTotal'] = round($rsu['predictedTotal']+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['winningRate'] = round($updateArr['winning'] / $updateArr['predictedTotal'] * 100);
            }else{
                $updateArr['winningRate'] = $rsu['winningRate'];
            }
            if($updateArr['winningRate'] > 100) $updateArr['winningRate'] = 100;
            Db::name('users')->where('userid',$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(['userid'=>$userid])->field('winningRate,predictedTotal,winning')->find();
            $updateArr['predictedTotal'] = round($rsu['predictedTotal']+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['winningRate'] = round($updateArr['winning'] / $updateArr['predictedTotal'] * 100);
            }else{
                $updateArr['winningRate'] = $rsu['winningRate'];
            }
            if($updateArr['winningRate'] > 100) $updateArr['winningRate'] = 100;
            Db::name('users')->where('userid',$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(['userid'=>$userid])->field('winningRate,predictedTotal,winning')->find();
            $updateArr['predictedTotal'] = round($rsu['predictedTotal']+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['winningRate'] = round($updateArr['winning'] / $updateArr['predictedTotal'] * 100);
            }else{
                $updateArr['winningRate'] = $rsu['winningRate'];
            }
            if($updateArr['winningRate'] > 100) $updateArr['winningRate'] = 100;
            Db::name('users')->where('userid',$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(['userid'=>$userid])->field('winningRate,predictedTotal,winning')->find();
            $updateArr['predictedTotal'] = round($rsu['predictedTotal']+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['winningRate'] = round($updateArr['winning'] / $updateArr['predictedTotal'] * 100);
            }else{
                $updateArr['winningRate'] = $rsu['winningRate'];
            }
            if($updateArr['winningRate'] > 100) $updateArr['winningRate'] = 100;
            Db::name('users')->where('userid',$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(['userid'=>$userid])->field('winningRate,predictedTotal,winning')->find();
            $updateArr['predictedTotal'] = round($rsu['predictedTotal']+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['winningRate'] = round($updateArr['winning'] / $updateArr['predictedTotal'] * 100);
            }else{
                $updateArr['winningRate'] = $rsu['winningRate'];
            }
            if($updateArr['winningRate'] > 100) $updateArr['winningRate'] = 100;
            Db::name('users')->where('userid',$userid)->update($updateArr);
            // echo $v['userid'].'、'.$v['lotteryissue'].'期、'.$v['order_type'].'<br>';
        }        
        echo "执行统计竞猜胜率完毕！<br>";
        $this->toNavigationMenu();//导航菜单
    }
    /**
     * 执行步骤8统计代理提成
     */
    public function getUpdateTheProxyReport(){
        $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(['userwebid'=>$webid])->field('userid,userBonus,bonusType')->find();
            $userid = $rs['userid'];
            $userBonus = $rs['userBonus'];
            $bonusType = (int)$rs['bonusType'];
            if($bonusType == 1){//流水提成
                $agencyCommission = round($totalAmount*$userBonus/100,2);
            }elseif($bonusType == 2){//盈亏提成
                $agencyCommission = round(($totalAmount-$totalPrizeMoney)*$userBonus/100,2);
            }
            $data = [];
            $data['webid'] = $webid;
            $data['userid'] = $userid;
            $data['userBonus'] = $userBonus;
            $data['lottery_date'] = $lottery_date;
            $data['lotteryissue'] = $lotteryissue;
            $data['totalAmount'] = $totalAmount;
            $data['totalPrizeMoney'] = $totalPrizeMoney;
            $data['agencyCommission'] = $agencyCommission;
            $data['create_time'] = 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(['userid'=>$userid])->setInc('duePayment',$agencyCommission);//待结算佣金
                Db::name('aaproxy_report')->insert($data);
            } 
        }
        echo "执行统计代理提成完毕！<br>";
        $this->toNavigationMenu();//导航菜单
    }
    /**
     * 执行竞猜统计
     */
    public 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')));
        $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);
        echo '数据：'.count($hydata).'条<br>';
        foreach($hydata as $v){
            $userid = $v;
            $rsu = Db::name('users')->where(['userid'=>$userid])->field('winningRate,predictedTotal,winning,rankingTime')->find();
            if(empty($rsu['rankingTime']) || $rsu['rankingTime'] < $date){
                $data = [];
                $data['predictedTotal'] = round($rsu['predictedTotal']+$report[$v]['Y_'.$v]+$report[$v]['S_'.$v]);
                $data['winning'] = round($rsu['winning']+$report[$v]['Y_'.$v]);
                $data['winningRate'] = round($data['winning']/$data['predictedTotal']*100);
                $data['rankingTime'] = $date;
                Db::name('users')->where(['userid'=>$userid])->update($data);
                echo '更新ID:'.$userid.'；总=='.$data['predictedTotal'].'；赢=='.$data['winning'].'；胜率：'.$data['winningRate'].'%<br>';
                unset($data);
            }else{
                echo '存在ID:'.$v.'；Y=='.$report[$v]['Y_'.$v].'；S=='.$report[$v]['S_'.$v].'<br>';
            }
        }
        echo "执行统计竞猜胜率完毕！<br>";
        $this->toNavigationMenu();//导航菜单
    }
    /**
     * 指定期号结算
     */
    public 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 = WSTchkZodiacSigns($kjhm);
            $kjhmsj = WSTchkFourSeasons($kjhm);
            $kjhmys = WSTchkFourElement($kjhm);
            $kjhmyy = WSTchkYinYang($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 = WSTchkZodiacSigns($kjhm);
            $kjhmsj = WSTchkFourSeasons($kjhm);
            $kjhmys = WSTchkFourElement($kjhm);
            $kjhmyy = WSTchkYinYang($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 = WSTchkZodiacSigns($kjhm);
            $kjhmsj = WSTchkFourSeasons($kjhm);
            $kjhmys = WSTchkFourElement($kjhm);
            $kjhmyy = WSTchkYinYang($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 = WSTchkZodiacSigns($kjhm);
            $kjhmsj = WSTchkFourSeasons($kjhm);
            $kjhmys = WSTchkFourElement($kjhm);
            $kjhmyy = WSTchkYinYang($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 = WSTchkZodiacSigns($kjhm);
            $kjhmsj = WSTchkFourSeasons($kjhm);
            $kjhmys = WSTchkFourElement($kjhm);
            $kjhmyy = WSTchkYinYang($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 = WSTchkZodiacSigns($kjhm);
            $kjhmsj = WSTchkFourSeasons($kjhm);
            $kjhmys = WSTchkFourElement($kjhm);
            $kjhmyy = WSTchkYinYang($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>';
        }
        $this->toNavigationMenu();//导航菜单
    }
    /**
     * 执行竞猜胜率提升
     */
    public 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 = WSTchkZodiacSigns($kjhm);
                $kjhmsj = WSTchkFourSeasons($kjhm);
                $kjhmys = WSTchkFourElement($kjhm);
                $kjhmyy = WSTchkYinYang($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 = WSTchkZodiacSigns($kjhm);
                $kjhmsj = WSTchkFourSeasons($kjhm);
                $kjhmys = WSTchkFourElement($kjhm);
                $kjhmyy = WSTchkYinYang($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 = WSTchkZodiacSigns($kjhm);
                $kjhmsj = WSTchkFourSeasons($kjhm);
                $kjhmys = WSTchkFourElement($kjhm);
                $kjhmyy = WSTchkYinYang($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 = WSTchkZodiacSigns($kjhm);
                $kjhmsj = WSTchkFourSeasons($kjhm);
                $kjhmys = WSTchkFourElement($kjhm);
                $kjhmyy = WSTchkYinYang($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 = WSTchkZodiacSigns($kjhm);
                $kjhmsj = WSTchkFourSeasons($kjhm);
                $kjhmys = WSTchkFourElement($kjhm);
                $kjhmyy = WSTchkYinYang($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 = WSTchkZodiacSigns($kjhm);
                $kjhmsj = WSTchkFourSeasons($kjhm);
                $kjhmys = WSTchkFourElement($kjhm);
                $kjhmyy = WSTchkYinYang($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 = [];
        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];
                    $this->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];
                    $this->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];
                    $this->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];
                    $this->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];
                    $this->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];
                    $this->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];
                    $this->toOperateAndModify($type,$lotteryissue,$order_type=7,$userid,$kjhmdx);
                }
            }
            echo '<br>';
        }
        $this->toNavigationMenu();//导航菜单          
    }
    /**
     * 去执行操作修改
     * type         数据表分类
     * lotteryissue 第几期
     * order_type    玩法分类
     * userid       会员ID
     * kjhm         修改内容
     */
    public 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 function toNavigationMenu(){
        echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=1'>进入1星座神邸</a><br>";
        echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=2'>进入2商业之神</a><br>";
        echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=3'>进入3丰收之神</a><br>";
        echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=4'>进入4财富之神</a><br>";
        echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=5'>进入5命运之神</a><br>";
        echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=6'>进入6永生之神</a><br>";
        echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/getExecuteBettingStatistics?id=0'>进入7统计竞猜胜率</a><br>";
        echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=8'>进入8统计代理佣金</a><br>";
        echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/getDesignatedSettlement?id=9'>指定期重置订单</a><br>";
        echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/getPerformModifications?id=9&tid=9'>竞猜胜率提升</a><br>";
    }
    /**
     * 中奖备注
     */
    function toWinningRemark($lotteryType,$orderid){
		switch($lotteryType){
			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($lotteryType){
                    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 = $this->toNameZodiac($order_number,0);
                        $remark .= '星座：'.$xz;
                        break;
                    case 3:
                        $sj = $this->tonameFour($order_number,0);
                        $remark .= '四季：'.$sj; 
                        break;
                    case 4: 
                        $ys = $this->tonameFourElement($order_number,0);
                        $remark .= '元素：'.$ys; 
                        break;
                    case 5:
                        $yy = $this->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($lotteryType){
                    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 = $this->toNameZodiac($order_number,1);
                        $remark .= 'Constellation：'.$xz; 
                        break;
                    case 3:
                        $sj = $this->tonameFour($order_number,1);
                        $remark .= 'Four Seasons：'.$sj;
                        break;
                    case 4:
                        $ys = $this->tonameFourElement($order_number,1);
                        $remark .= 'Element：'.$ys;
                        break;
                    case 5:
                        $yy = $this->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;
    }
	/**
	 * 会员自动兑奖
	 */
	function AutomaticPrizeRedemption($lotteryType,$orderid,$userid,$bonuses){

		if($bonuses > 0){
            $redShare = WSTConf('CONF.redEnvelopePercentage');//系统设置的分享提成比例
            $shareMoney = round($bonuses*$redShare/100);//分享彩金
            $bonuses = round($bonuses-$shareMoney,2);
            $webid = Db::name('users')->where(["userid"=>$userid])->value('webid');//获取代理ID
            $dlNum = Db::name('users')->where(["userwebid"=>$webid])->count();
            $remark = $this->toWinningRemark($lotteryType,$orderid);
            if($webid>0 && $dlNum>0){
                Db::name('users')->where(["userwebid"=>$webid])->setInc('redEnvelopePool',$shareMoney);//分享彩金加入代理的红包池
                //创建红包池流水记录
                $wlm = [];
                $wlm['webid'] = $webid;//网站编号ID
	      	    $wlm['targetType'] = 14;//红包池流水
	      	    $wlm['targetId'] = $userid;
	      	    $wlm['dataId'] = $orderid;
	      	    $wlm['dataSrc'] = 15;//会员分享彩金
	      	    $wlm['remark'] = $remark.'|'.$bonuses;//备注中奖类型+奖金
	      	    $wlm['moneyType'] = 1;//收入
	      	    $wlm['money'] = $shareMoney;
	      	    $wlm['giveMoney'] = 0;
	      	    $wlm['payType'] = 15;//会员分享彩金
	      	    $wlm['tradeNo'] = $lotteryType;//彩票类型
	      	    $wlm['create_time'] = date('Y-m-d H:i:s');
	      	    Db::name('log_moneys')->insert($wlm);
            }
            Db::name('users')->where(["userid"=>$userid])->setInc('userMoney',$bonuses);//加入会员金币
            Db::name('users')->where(["userid"=>$userid])->setInc('shareMoney',$shareMoney);//加入分享彩金总额
			//创建流水记录
			$lm = [];
            $lm['webid'] = $webid;//网站编号ID
			$lm['targetType'] = 9;//来源9兑奖收入
			$lm['targetId'] = $userid;//会员ID
			$lm['dataId'] = $orderid;//数据表流水ID
			$lm['dataSrc'] = 9;//来源9兑奖收入
			$lm['remark'] = $remark.'|'.$bonuses;//备注中奖类型+奖金
			$lm['moneyType'] = 1;//收入
			$lm['money'] = (float)$bonuses;//金币
            $lm['tradeNo'] = $lotteryType;//外部流水号,数据表ID
			$lm['payType'] = 'Lottery Center';
			$lm['data_flag'] = 1;
			$lm['create_time'] = date('Y-m-d H:i:s');
			Db::name('log_moneys')->insert($lm);
		}
	}    
    /**
     * 执行兑奖
     * $lotteryType 数据表ID
     * $lotteryissue  第几期
     * $kjhm     开奖号码
     */
    public function ClaimingThePrize($lotteryType,$lotteryissue,$kjhm){
        $where = [];
        $where[] = ['is_finish',"=",0];
        $where[] = ['data_flag',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
        switch($lotteryType){
            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;
				$this->AutomaticPrizeRedemption($lotteryType,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lotteryType){
				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 = $this->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;
				$this->AutomaticPrizeRedemption($lotteryType,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lotteryType){
				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 = [];
            $sjArr = $this->chkFourSeasons($kjhm);
			$sj = $sjArr[0];
            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;
				$this->AutomaticPrizeRedemption($lotteryType,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lotteryType){
				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 = $this->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;
				$this->AutomaticPrizeRedemption($lotteryType,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lotteryType){
				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 = $this->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;
				$this->AutomaticPrizeRedemption($lotteryType,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lotteryType){
				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;
				$this->AutomaticPrizeRedemption($lotteryType,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lotteryType){
				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;
				$this->AutomaticPrizeRedemption($lotteryType,$orderid,$userid,$bonuses);//操作会员自动兑奖
            }else{
                $data['is_win'] = -1;//-1未中奖
            }
            $data['is_finish'] = 1;//1已经完结
            switch($lotteryType){
				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);
    }
    /**
     * 执行测试虚拟开奖
     * $lotteryType 数据表ID
     * $lotteryissue  第几期
     * $lottery_date   日期
     */
    public function VirtualLotteryDraw($lotteryType,$lotteryissue,$lottery_date){
        $where = [];
        $where[] = ['is_finish',"=",0];
        $where[] = ['data_flag',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
        $totalAmount = 0;
        switch($lotteryType){
            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 = $this->StatisticalBonus($lotteryType,$lotteryissue,$i);
            $ykNum = round($totalAmount-$cjnum);
            $Arr['haoma'] = $i;
            $Arr['cjnum'] = $cjnum;
            $Arr['ykNum'] = $ykNum;
            $number_arr[] = $Arr;
            if($ykNum >= $ylAmount){
                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>";
        foreach($number_arr as $key => $v){
            $pwd = WSTBase64urlEncode($v['haoma']);
            $xzname = $this->chkZodiacSigns($v['haoma']);
            $xzname = $this->toNameZodiac($xzname);
            $sjname = $this->chkFourSeasons($v['haoma']);
            $sjname = $this->tonameFour($sjname);
            $sysname = $this->chkFourElement($v['haoma']);
            $sysname = $this->tonameFourElement($sysname);
            $yyname = $this->chkYinYang($v['haoma']);
            $yyname = $this->tonameYinYang($yyname);
            if($v['ykNum'] >= $ylAmount){
                echo "<span>号码：".$v['haoma']."，盈亏：".$v['ykNum']."。".$xzname."；".$sjname."；".$sysname."；".$yyname;
            }else{
                echo "<span style='color:#f00'>号码：".$v['haoma']."，盈亏：".$v['ykNum']."。".$xzname."；".$sjname."；".$sysname."；".$yyname;
            }
            switch($lotteryType){
                case 1://1十二星座
                    echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?key=3&map=".$pwd."'>==选择请点击</a></span><br>";
                    break;
                case 2://2商业彩票
                    echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=2&key=6&map=".$pwd."'>==选择请点击</a></span><br>";
                    break;
                case 3://3丰收彩票
                    echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=3&key=9&map=".$pwd."'>==选择请点击</a></span><br>";
                    break;
                case 4://4财富彩票
                    echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=4&key=12&map=".$pwd."'>==选择请点击</a></span><br>";
                    break;
                case 5://5命运彩票
                    echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=5&key=15&map=".$pwd."'>==选择请点击</a></span><br>";
                    break;
                case 6://6永生彩票
                    echo "<a href='http://localhost/12xz/CN/admin/Lotterydraw/index.html?step=6&key=18&map=".$pwd."'>==选择请点击</a></span><br>";
                    break;
            }
        }
    }
    /**
     * 统计奖金
     * $lotteryType 数据表ID
     * $lotteryissue  第几期
     * $num   号码
     */
    public function StatisticalBonus($lotteryType,$lotteryissue,$num){
        $where = [];
        $where[] = ['is_finish',"=",0];
        $where[] = ['data_flag',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
        $cjTotal = 0;
        switch($lotteryType){
            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 = $this->chkZodiacSigns($num);
                $order_money2 = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = $this->FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = $this->chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = $this->FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = $this->chkFourElement($num);
                $order_money4 = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = $this->FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = $this->chkYinYang($num);
                $order_money5 = Db::name("aadeitycard_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = $this->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 = $this->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 = $this->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 = $this->chkZodiacSigns($num);
                $order_money2 = Db::name("aahermes_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = $this->FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = $this->chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aahermes_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = $this->FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = $this->chkFourElement($num);
                $order_money4 = Db::name("aahermes_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = $this->FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = $this->chkYinYang($num);
                $order_money5 = Db::name("aahermes_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = $this->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 = $this->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 = $this->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 = $this->chkZodiacSigns($num);
                $order_money2 = Db::name("aademeter_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = $this->FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = $this->chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aademeter_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = $this->FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = $this->chkFourElement($num);
                $order_money4 = Db::name("aademeter_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = $this->FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = $this->chkYinYang($num);
                $order_money5 = Db::name("aademeter_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = $this->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 = $this->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 = $this->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 = $this->chkZodiacSigns($num);
                $order_money2 = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = $this->FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = $this->chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = $this->FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = $this->chkFourElement($num);
                $order_money4 = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = $this->FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = $this->chkYinYang($num);
                $order_money5 = Db::name("aaploutos_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = $this->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 = $this->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 = $this->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 = $this->chkZodiacSigns($num);
                $order_money2 = Db::name("aafates_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = $this->FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = $this->chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aafates_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = $this->FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = $this->chkFourElement($num);
                $order_money4 = Db::name("aafates_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = $this->FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = $this->chkYinYang($num);
                $order_money5 = Db::name("aafates_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = $this->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 = $this->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 = $this->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 = $this->chkZodiacSigns($num);
                $order_money2 = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',2],['order_number','=',$xznum]])->sum("order_money*blowup");//2星座金额
                $xzpl = $this->FormatTheOdds(2,$xznum);
                $xzcj = round($order_money2*$xzpl,2);//星座彩金
                $cjTotal = round($cjTotal+$xzcj,2);//加入总金额
                $sjnum = $this->chkFourSeasons($num);//四季转换
                $order_money3 = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',3],['order_number','=',$sjnum]])->sum("order_money*blowup");//3四季金额
                $sjpl = $this->FormatTheOdds(3,$sjnum);
                $sjcj = round($order_money3*$sjpl,2);//四季彩金
                $cjTotal = round($cjTotal+$sjcj,2);//加入总金额
                $ysnum = $this->chkFourElement($num);
                $order_money4 = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',4],['order_number','=',$ysnum]])->sum("order_money*blowup");//4元素金额
                $yspl = $this->FormatTheOdds(4,$ysnum);
                $yscj = round($order_money4*$yspl,2);//元素彩金
                $cjTotal = round($cjTotal+$yscj,2);//加入总金额
                $yynum = $this->chkYinYang($num);
                $order_money5 = Db::name("aaimmortality_orders")->where($where)->where([['order_type','=',5],['order_number','=',$yynum]])->sum("order_money*blowup");//5阴阳金额
                $yypl = $this->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 = $this->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 = $this->FormatTheOdds(7,$dxnum);
                $dxcj = round($order_money7*$dxpl,2);//大小彩金
                $cjTotal = round($cjTotal+$dxcj,2);//加入总金额
                break;
        }
        return $cjTotal;
    }
    /**
     * 生成测试流水
     * $lotteryType 数据表ID
     * $lotteryissue  第几期
     * $lottery_date   日期
     */
    public function GenerateTestProcess($lotteryType,$lotteryissue,$lottery_date){
        $where = [];
        $where[] = ['lotteryissue',"=",$lotteryissue];
        $where[] = ['is_finish',"=",0];
        switch($lotteryType){
            case 1:
				$num = Db::name("aadeitycard_orders")->where($where)->count();//1星座彩票总金额
				break;
            case 2:
				$num = Db::name("aahermes_orders")->where($where)->count();//2商业彩票总金额
				break;
            case 3:
				$num = Db::name("aademeter_orders")->where($where)->count();//3丰收彩票总金额
				break;
			case 4:
				$num = Db::name("aaploutos_orders")->where($where)->count();//4财富彩票总金额
				break;
			case 5:
				$num = Db::name("aafates_orders")->where($where)->count();//5命运彩票总金额
				break;
			case 6:
				$num = Db::name("aaimmortality_orders")->where($where)->count();//6永生彩票总金额
				break;
        }        
        if($num<365){
            $orderData = [];
            for($i=1;$i<366;$i++){//直选
                $data = [];
                $data['userid'] = rand(1,2005);//随机数
                $data['lottery_date'] = $lottery_date;//开奖日期
                $data['lotteryissue'] = $lotteryissue;//期
                $data['order_type'] = 1;//直选
                $data['order_number'] = $i;
                $data['order_money'] = rand(1,100);//随机数
                $data['blowup'] = rand(1,5);//随机数
                $data['is_guess'] = $this->getRandomGuessing();//随机数,是否加入竞猜 1加入 0不加入
                $data['payout_ratio'] = $this->FormatTheOdds(1,$i);//赔率
                $data['data_flag'] = 1;//
                $data['create_time'] = date('Y-m-d H:i:s');
                $orderData[] = $data;
            }
            for($i=1;$i<13;$i++){//星座
                $adata = [];
                $adata['userid'] = rand(1,2005);//随机数
                $adata['lottery_date'] = $lottery_date;//开奖日期
                $adata['lotteryissue'] = $lotteryissue;//期
                $adata['order_type'] = 2;//星座
                $adata['order_number'] = $i;
                $adata['order_money'] = rand(1,100);//随机数
                $adata['blowup'] = rand(1,5);//随机数
                $adata['is_guess'] = $this->getRandomGuessing();//随机数,是否加入竞猜 1加入 0不加入
                $adata['payout_ratio'] = $this->FormatTheOdds(2,$i);//赔率
                $adata['data_flag'] = 1;
                $adata['create_time'] = date('Y-m-d H:i:s');
                $orderData[]  = $adata;
            }
            for($i=1;$i<5;$i++){//四季
                $bdata = [];
                $bdata['userid'] = rand(1,2005);//随机数
                $bdata['lottery_date'] = $lottery_date;//开奖日期
                $bdata['lotteryissue'] = $lotteryissue;//期
                $bdata['order_type'] = 3;//四季
                $bdata['order_number'] = $i;
                $bdata['order_money'] = rand(1,100);//随机数
                $bdata['blowup'] = rand(1,5);//随机数
                $bdata['is_guess'] = $this->getRandomGuessing();//随机数,是否加入竞猜 1加入 0不加入
                $bdata['payout_ratio'] = $this->FormatTheOdds(3,$i);//赔率
                $bdata['data_flag'] = 1;//
                $bdata['create_time'] = date('Y-m-d H:i:s');
                $orderData[]  = $bdata;
            }
            for($i=1;$i<5;$i++){//四元素
                $cdata = [];
                $cdata['userid'] = rand(1,2005);//随机数
                $cdata['lottery_date'] = $lottery_date;//开奖日期
                $cdata['lotteryissue'] = $lotteryissue;//期
                $cdata['order_type'] = 4;//四元素
                $cdata['order_number'] = $i;
                $cdata['order_money'] = rand(1,100);//随机数
                $cdata['blowup'] = rand(1,5);//随机数
                $cdata['is_guess'] = $this->getRandomGuessing();//随机数,是否加入竞猜 1加入 0不加入
                $cdata['payout_ratio'] = $this->FormatTheOdds(4,$i);//赔率
                $cdata['data_flag'] = 1;
                $cdata['create_time'] = date('Y-m-d H:i:s');
                $orderData[]  = $cdata;
            }
            for($i=1;$i<7;$i++){//阴阳
                $ddata = [];
                $ddata['userid'] = rand(1,2005);//随机数
                $ddata['lottery_date'] = $lottery_date;//开奖日期
                $ddata['lotteryissue'] = $lotteryissue;//期
                $ddata['order_type'] = 5;//阴阳
                $ddata['order_number'] = rand(1,2);
                $ddata['order_money'] = rand(1,100);//随机数
                $ddata['blowup'] = rand(1,5);//随机数
                $ddata['is_guess'] = $this->getRandomGuessing();//随机数,是否加入竞猜 1加入 0不加入
                $ddata['payout_ratio'] = $this->FormatTheOdds(5,$i);//赔率
                $ddata['data_flag'] = 1;//
                $ddata['create_time'] = date('Y-m-d H:i:s');
                $orderData[]  = $ddata;
            }
            for($i=1;$i<9;$i++){//单双
                $edata = [];
                $edata['userid'] = rand(1,2005);//随机数
                $edata['lottery_date'] = $lottery_date;//开奖日期
                $edata['lotteryissue'] = $lotteryissue;//期
                $edata['order_type'] = 6;//单双
                $edata['order_number'] = rand(1,2);
                $edata['order_money'] = rand(1,100);//随机数
                $edata['blowup'] = rand(1,5);//随机数
                $edata['is_guess'] = $this->getRandomGuessing();//随机数,是否加入竞猜 1加入 0不加入
                $edata['payout_ratio'] = $this->FormatTheOdds(6,$i);//赔率
                $edata['data_flag'] = 1;
                $edata['create_time'] = date('Y-m-d H:i:s');
                $orderData[]  = $edata;
            }
            for($i=1;$i<16;$i++){//大小
                $fdata = [];
                $fdata['userid'] = rand(1,2005);//随机数
                $fdata['lottery_date'] = $lottery_date;//开奖日期
                $fdata['lotteryissue'] = $lotteryissue;//期
                $fdata['order_type'] = 7;//大小
                $fdata['order_number'] = rand(1,2);
                $fdata['order_money'] = rand(1,100);//随机数
                $fdata['blowup'] = rand(1,5);//随机数
                $fdata['is_guess'] = $this->getRandomGuessing();//随机数,是否加入竞猜 1加入 0不加入
                $fdata['payout_ratio'] = $this->FormatTheOdds(7,$i);//赔率
                $fdata['data_flag'] = 1;//
                $fdata['create_time'] = date('Y-m-d H:i:s');
                $orderData[]  = $fdata;
            }
            switch($lotteryType){
                case 1:
                    Db::name('aadeitycard_orders')->insertAll($orderData);
                    break;
                case 2:
                    Db::name('aahermes_orders')->insertAll($orderData);
                    break;
                case 3:
                    Db::name('aademeter_orders')->insertAll($orderData);
                    break;
			    case 4:
                    Db::name('aaploutos_orders')->insertAll($orderData);
                    break;
			    case 5:
                    Db::name('aafates_orders')->insertAll($orderData);
                    break;
			    case 6:
                    Db::name('aaimmortality_orders')->insertAll($orderData);
                    break;
            }
            echo "测试订单生成完毕。<br>";
        }else{
            echo "订单数据：".$num." 条。<br>";
        }
    }
    /**
     * 随机是否竞猜
     */
    public function getRandomGuessing(){
        $num = rand(0,5);//随机数
        if($num == 1){
            $num = 1;
        }else{
            $num = 0;
        }
        return $num;
    }
    /**
     * 格式化赔率
     */
    public 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;
    }
    /**
     * 统计未结算注单总金额
     * $lotteryType 数据表ID
     * $lotteryissue  第几期
     */
    public function CalculateTheTotalNumber($lotteryType,$lotteryissue){
        $where = [];
        $where[] = ['is_finish',"=",0];
        $where[] = ['data_flag',"=",1];
        $where[] = ['lotteryissue',"=",$lotteryissue];
		$totalAmount = 0;
        switch($lotteryType){
            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 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 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 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 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 function addTopprize($type,$date,$qi,$jackpot,$areaid){
        $str = 0;
        $data = [];
        $data['lotteryType'] = $type;
        $data['lottery_date'] = $date;
        $data['lotteryissue'] = $qi;
        $data['jackpot'] = $jackpot;
        $data['areaid'] = $areaid;
        $sqi = Db::name('aatopprize')->where(['lotteryType'=>$type])->order('topId desc')->value('lotteryissue');
        $num = round((int)$qi-(int)$sqi);
        $randNum = rand(30,99);//随机数
        if($num >= $randNum){
            Db::name('aatopprize')->insert($data);
            $str = 1;
            $lotteryType = $this->LotteryType($type,2);//2中文
            $areaName = $this->ToAreas($areaid,2);//2中文
            $cpNumber = $this->TocpNumbers($type,$date,$qi);//开奖号码
            $shopNum = rand(15678,99999);//随机数
            $title = $this->ToTitle($type,$areaid,2);//2中文
            $tpl = WSTMsgTemplates('GREEK_DEITIES_NEWS');//中文模版
            if($tpl['tplContent']!='' && $tpl['status']=='1'){
                $tplContent = str_replace('${LOTTERY_NAME}',$lotteryType,$tpl['tplContent']);
                $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);
                $tplContent = str_replace('《BR》',"<br>",$tplContent);
                $isEn = 2;//中文
                $addnews = $this->addArticles($title,$isEn,$tplContent,$date,$qi);//12大奖新闻
            }
            $enlotteryType = $this->LotteryType($type,1);//1英文
            $enareaName = $this->ToAreas($areaid,1);//1英文
            $entitle = $this->ToTitle($type,$areaid,1);//1英文
            $entpl = WSTMsgTemplates('GREEK_DEITIES_NEWS_EN');//英文模版
            if($entpl['tplContent']!='' && $entpl['status']=='1'){
                $entplContent = str_replace('${LOTTERY_NAME}',$enlotteryType,$entpl['tplContent']);
                $entplContent = str_replace('${LOTTERY_JACKPOT}',$jackpot,$entplContent);
                $entplContent = str_replace('${LOTTERY_DATE}',$date,$entplContent);
                $entplContent = str_replace('${LOTTERY_areaid}',$enareaName,$entplContent);
                $entplContent = str_replace('${LOTTERY_ISSUE}',$qi,$entplContent);
                $entplContent = str_replace('${LOTTERY_NUMBER}',$cpNumber,$entplContent);
                $entplContent = str_replace('${SHOP_NUMBER}',$shopNum,$entplContent);
                $entplContent = str_replace('《BR》',"<br>",$entplContent);
                $isEn = 1;//英文
                $addnews = $this->addArticles($entitle,$isEn,$entplContent,$date,$qi);
            }
            $hilotteryType = $this->LotteryType($type,3);//3印地语
            $hiareaName = $this->ToAreas($areaid,3);//3印地语
            $hititle = $this->ToTitle($type,$areaid,3);//3印地语
            $hitpl = WSTMsgTemplates('GREEK_DEITIES_NEWS_HI');//印地语模版
            if($hitpl['tplContent']!='' && $hitpl['status']=='1'){
                $hitplContent = str_replace('${LOTTERY_NAME}',$hilotteryType,$hitpl['tplContent']);
                $hitplContent = str_replace('${LOTTERY_JACKPOT}',$jackpot,$hitplContent);
                $hitplContent = str_replace('${LOTTERY_DATE}',$date,$hitplContent);
                $hitplContent = str_replace('${LOTTERY_areaid}',$hiareaName,$hitplContent);
                $hitplContent = str_replace('${LOTTERY_ISSUE}',$qi,$hitplContent);
                $hitplContent = str_replace('${LOTTERY_NUMBER}',$cpNumber,$hitplContent);
                $hitplContent = str_replace('${SHOP_NUMBER}',$shopNum,$hitplContent);
                $hitplContent = str_replace('《BR》',"<br>",$hitplContent);
                $isEn = 3;//英文
                $addnews = $this->addArticles($hititle,$isEn,$hitplContent,$date,$qi);
            }                      
            $eslotteryType = $this->LotteryType($type,4);//4西班牙语
            $esareaName = $this->ToAreas($areaid,4);//4西班牙语
            $estitle = $this->ToTitle($type,$areaid,4);//4西班牙语
            $estpl = WSTMsgTemplates('GREEK_DEITIES_NEWS_ES');//西班牙语模版
            if($estpl['tplContent']!='' && $estpl['status']=='1'){
                $estplContent = str_replace('${LOTTERY_NAME}',$eslotteryType,$estpl['tplContent']);
                $estplContent = str_replace('${LOTTERY_JACKPOT}',$jackpot,$estplContent);
                $estplContent = str_replace('${LOTTERY_DATE}',$date,$estplContent);
                $estplContent = str_replace('${LOTTERY_areaid}',$esareaName,$estplContent);
                $estplContent = str_replace('${LOTTERY_ISSUE}',$qi,$estplContent);
                $estplContent = str_replace('${LOTTERY_NUMBER}',$cpNumber,$estplContent);
                $estplContent = str_replace('${SHOP_NUMBER}',$shopNum,$estplContent);
                $estplContent = str_replace('《BR》',"<br>",$estplContent);
                $isEn = 4;//西班牙语
                $addnews = $this->addArticles($estitle,$isEn,$estplContent,$date,$qi);
            }
        }
        return $str;
    }
    public function LotteryType($type,$lang){//文章模版彩票名称替换词
        $name = '';
        if($lang==1){
            switch($type){
                case 1: $name = 'Zodiac Lottery'; 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 = 'Doce constelaciones'; 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 function ToAreas($areaid,$lang){//文章模版区域替换词
        $name = '';
        $rs = Db::name('areas')->where(["areaid"=>$areaid])->find();
        switch($lang){
            case 1: $name = $rs['areaNameen']; break;//英文
            case 2: $name = $rs['areaName']; break;//中文
            case 3: $name = $rs['areaNamehi']; break;//印地语
            case 4: $name = $rs['areaNamees']; break;//西班牙语
        }
        return $name;
    }
    public 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 function ToTitle($type,$areaid,$lang){//文章模版标题替换
        $name = '';
        if($lang==1){
            $areaName = $this->ToAreas($areaid,1);
            switch($type){
                case 1: $name = 'Twelve zodiac sign lottery draws another 5 million prize!'; break;
                case 2: $name = $areaName.' lottery players are thrilled to have won the multi-million-dollar prize awarded by the "God of Business"!'; break;
                case 3: $name = 'The God of Harvest has added another 50 million winner!'; break;
                case 4: $name = 'The god of wealth has once again chosen a billionaire!'; break;
		        case 5: $name = 'The god of fate descended and bestowed seven hundred million dollars upon a lucky person!'; break;
		        case 6: $name = 'The God of Immortality has once again selected a billionaire worth 1 billion dollars!'; break;
            }
        }elseif($lang==2){
            $areaName = $this->ToAreas($areaid,2);
            switch($type){
                case 1: $name = '十二星座彩票再出500万大奖'; break;
                case 2: $name = $areaName."彩票玩家喜中商业之神千万美元神旨大奖！"; break;
                case 3: $name = '丰收之神又新增一位5千万得主！'; break;
                case 4: $name = '财富之神再次选出一位亿万富豪！'; break;
		        case 5: $name = '命运之神降临赋予一位幸运者获得7亿美元！'; break;
		        case 6: $name = '永生之神再次选出10亿美元大富豪！'; break;
            }
        }elseif($lang==3){
            $areaName = $this->ToAreas($areaid,3);
            switch($type){
                case 1: $name = 'बारह राशि लॉटरी में फिर से 50 लाख का जीतने का पुरस्कार'; break;
                case 2: $name = $areaName.' लॉटरी खिलाड़ी को व्यापार के देवता का लाखों डॉलर का भाग्यशाली पुरस्कार मिला!'; break;
                case 3: $name = 'फील्ड गॉड के पास एक और 50 मिलियन का मालिक हो गया है!'; break;
                case 4: $name = 'धन के देवता ने एक बार फिर एक अरबपति को चुना है!'; break;
		        case 5: $name = 'भाग्य के देवता ने एक सौभाग्यशाली को 700 मिलियन डॉलर प्रदान किए!'; break;
		        case 6: $name = 'अमर देवता ने एक बार फिर 10 अरब डॉलर के बहुमूल्य व्यक्ति को चुना!'; break;
            }
        }elseif($lang==4){
            $areaName = $this->ToAreas($areaid,4);
            switch($type){
                case 1: $name = 'La lotería de los doce signos zodiacales vuelve con un premio máximo de 5 millones'; break;
                case 2: $name = 'Un jugador de lotería '.$areaName.' gana el premio milionario del Dios de la Comerciación'; break;
                case 3: $name = 'El Dios de la Cosecha tiene un nuevo dueño de 50 millones'; break;
                case 4: $name = 'El dios de la riqueza ha elegido nuevamente a un multimillonario'; break;
		        case 5: $name = 'El dios del destino ha descendido y otorgado a un afortunado 700 millones de dólares!'; break;
		        case 6: $name = 'De nuevo, el Dios de la eternidad selecciona a un multimillonario de 10 mil millones de dólares!'; break;
            }
        }
        return $name;
    }
    public function addArticles($title,$isEn,$tplcontent,$lottery_date,$lotteryissue){
        $cidArr = [11,12,13,15];//11行业动态，12大奖新闻，13热点新闻，15系统公告
        $catId = $cidArr[rand(0,3)];
        $hour = rand(22,23);//随机数
        $minute = rand(1,59);//随机数
        $xztime = strtotime(date('Y-m-d H:i:s'));
        $create_time = $lottery_date." ".$hour.":".$minute;
        $wbtime = strtotime($create_time);
        $sjc = floor(round($xztime-$wbtime)/86400);
        $data = [];
        $data['catId'] = $catId;
        $data['articleTitle'] = $title;
        $data['isShow'] = 1;
        $data['isEn'] = $isEn;
        $data['articleContent'] = $tplcontent;
        $data['articleKey'] = $title;
        $data['staffId'] = 1;
        $data['data_flag'] = 1;
        $data['create_time'] = $create_time;
        $data['solve'] = $lotteryissue;
		$data["visitorNum"] = (int)round($sjc*3);
        $data['articleDesc'] = $title;
        $wzNum = Db::name('articles')->where(["catId"=>$catId,"isEn"=>$isEn,"solve"=>$lotteryissue])->count();
        if($wzNum<=0){
            //Db::name('articles')->insert($data);
        }
    }
    /**
     * 生成随机字母
     */
    function RandLetter($len){
        $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $tmp = '';
        for($i=0;$i<$len;$i++){
            $tmp.=$str[rand(0,25)];
        }
        return $tmp;
    }
    /** 辅助查询函数End */
    /**
     * 十二星座名称
     */
    function toNameZodiac($num,$key){
        $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;
    }
    /**
     * 四季名称
     */
    function tonameFour($num,$key){
        $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;
    } 
    /**
     * 四元素名称
     */
    function tonameFourElement($num,$key){
        $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;
    }   
    /**
     * 阴阳名称
     */
    function tonameYinYang($num,$key){
        $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;	
    }


}

