getGameStatus(); if( 0 !== $result['code']){ echo date('Y-m-d H:i:s') . $result['msg'].PHP_EOL; return 0; } $queryResultItems = $result['result'] ?? []; if(empty($queryResultItems)){ echo date('Y-m-d H:i:s') . 'error'.PHP_EOL; return 0; } $resultJSON = json_decode($queryResultItems['queryResultItems'][0]['resultJSON'],true); $current_round = $resultJSON['current_round']; $cache_current_round = Yii::$app->redis->get('chain33_game_status'); if(empty($cache_current_round)){ $cache_current_round = CoinGameBet::find()->max('round'); Yii::$app->redis->set('chain33_game_status',$cache_current_round,'EX',300); } $cache_current_round = (false == $cache_current_round ? 0 : $cache_current_round); if($cache_current_round >= $current_round){ echo date('Y-m-d H:i:s') . '数据已为最新'.PHP_EOL; return 0; } Yii::$app->redis->set('chain33_game_status',$current_round,'EX',300); $result = $service->getBetStatus($cache_current_round, $current_round); if( 0 !== $result['code']){ echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL; return 0; } $queryResultItems = $result['result'] ?? []; if(empty($queryResultItems)){ echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL; return 0; } foreach ($queryResultItems['queryResultItems'] as $key => $val){ if( false == $val['found'] ) continue; $resultArr = json_decode($val['resultJSON'],true); $datas[] = [ $resultArr['round'], $resultArr['player'], $resultArr['amount'], $resultArr['height'], $resultArr['guess_num'], $resultArr['rand_num'], $resultArr['player_win'] ]; } CoinGameBet::loadArray($datas); echo date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL; return 0; } }