params['lottery']; //获取最新的区块高度 while(true){ $last_header = Chain33Business::getLastHeader(); if ($last_header['code'] != 0) { echo '获取区块高度失败: ' . $last_header['msg'].PHP_EOL; sleep(2); continue; } $last_header = $last_header['result']; //获取最新竞猜期数以及区块高度 $last = CoinLottery::getMaxStage(); if($last && $last->stage == $lottery_config['period_num'] && $last->status == 1){ //达到40期并且开完奖 echo date('Y-m-d H:i:s').': '.'今天彩票期数已达到40期,下期明天10点不见不散'.PHP_EOL; exit; } if ($last) { $start_height = $last->start_height; $end_height = $start_height + $lottery_config['period_total_step']; //某一期结束区块高度 if($last->status == 0){ //未开奖 if($last_header['height'] < $end_height){ //未到开奖区块高度 sleep(2); continue; } if($last_header['height'] >= $end_height){ /*****************************开奖************************************/ echo date('Y-m-d H:i:s').': '.'开奖高度: '.$last_header['height'].PHP_EOL; if(true){ //如果开奖成功 $last->status = 1; $last->lottery_height = $last_header['height']; $last->result = rand(10000,99999); $last->save(); } } }else{ //已开奖 if($last_header['height'] > $end_height){ //到下期参与交易高度 /*****************************开始下期交易****************************/ if(true){ $start_height = $last_header['height']; $end_height = $start_height + $lottery_config['period_total_step']; $stage = $last->stage + 1; CoinLottery::addOneRecord($start_height,$end_height,$stage); } sleep(2); } } } else { //第一期参与交易 $stage = 1; $start_height = $last_header['height']; $end_height = $last_header['height'] + $lottery_config['period_total_step']; /***************************参与交易**********************************/ if(true){ //如果交易成功 CoinLottery::addOneRecord($start_height,$end_height,$stage); } sleep(2); } } exit; } }