Commit 6f7903ac authored by shajiaiming's avatar shajiaiming

游戏链区分

parent 7d8ac310
...@@ -153,13 +153,12 @@ class Chain33Business ...@@ -153,13 +153,12 @@ class Chain33Business
* 获取游戏状态 * 获取游戏状态
* @return array * @return array
*/ */
public static function getGameStatus() public static function getGameStatus($node_params = [])
{ {
$node_params = \Yii::$app->params['chain_parallel']['wasm'];
$service = new Chain33Service($node_params); $service = new Chain33Service($node_params);
$execer = 'wasm'; $execer = 'wasm';
$funcName = 'WasmGetContractTable'; $funcName = 'WasmGetContractTable';
$contractName = 'user.p.tschain.user.wasm.dice'; $contractName = $node_params['contractName'];
$items[] = [ $items[] = [
'tableName' => 'gamestatus', 'tableName' => 'gamestatus',
'key' => 'dice_statics' 'key' => 'dice_statics'
......
...@@ -63,7 +63,7 @@ class CoinGameBet extends BaseActiveRecord ...@@ -63,7 +63,7 @@ class CoinGameBet extends BaseActiveRecord
public static function loadArray(array $data) public static function loadArray(array $data)
{ {
return self::getDb()->createCommand()->batchInsert(self::tableName(), return self::getDb()->createCommand()->batchInsert(self::tableName(),
['round', 'player', 'amount', 'height', 'guess_num', 'rand_num', 'player_win'], ['round', 'player', 'amount', 'height', 'guess_num', 'rand_num', 'player_win', 'platform'],
$data)->execute(); $data)->execute();
} }
} }
...@@ -16,53 +16,62 @@ class GameBetController extends Controller ...@@ -16,53 +16,62 @@ class GameBetController extends Controller
*/ */
public function actionGameStatus() public function actionGameStatus()
{ {
$service = new Chain33Business(); $nodes = \Yii::$app->params['chain_parallel']['wasm'];
$result = $service->getGameStatus(); if(empty($nodes)){
if( 0 !== $result['code']){ echo date('Y-m-d H:i:s') . '无节点'.PHP_EOL;
echo date('Y-m-d H:i:s') . $result['msg'].PHP_EOL;
return 0; return 0;
} }
foreach ($nodes as $key => $node) {
$service = new Chain33Business();
$result = $service->getGameStatus($node);
if (0 !== $result['code']) {
echo $key.':'.date('Y-m-d H:i:s') . $result['msg'].PHP_EOL;
continue;
}
$queryResultItems = $result['result'] ?? []; $queryResultItems = $result['result'] ?? [];
if(empty($queryResultItems)){ if (empty($queryResultItems)) {
echo date('Y-m-d H:i:s') . 'error'.PHP_EOL; echo $key.':'.date('Y-m-d H:i:s') . 'error'.PHP_EOL;
return 0; continue;
} }
$resultJSON = json_decode($queryResultItems['queryResultItems'][0]['resultJSON'],true); $resultJSON = json_decode($queryResultItems['queryResultItems'][0]['resultJSON'], true);
$current_round = $resultJSON['current_round']; $current_round = $resultJSON['current_round'];
$cache_current_round = Yii::$app->redis->get('chain33_game_bet_status'); $cache_current_round = Yii::$app->redis->get('chain33_game_bet_status_'.$key);
if(empty($cache_current_round)){ if (empty($cache_current_round)) {
$cache_current_round = CoinGameBet::find()->max('round'); $cache_current_round = CoinGameBet::find()->where(['platform' => $key])->max('round');
Yii::$app->redis->set('chain33_game_bet_status',$cache_current_round,'EX',300); Yii::$app->redis->set('chain33_game_bet_status_'.$key, $cache_current_round, 'EX', 300);
} }
$cache_current_round = (false == $cache_current_round ? 0 : $cache_current_round); $cache_current_round = (false == $cache_current_round ? 0 : $cache_current_round);
if($cache_current_round >= $current_round){ if ($cache_current_round >= $current_round) {
echo date('Y-m-d H:i:s') . '数据已为最新'.PHP_EOL; echo $key.':'.date('Y-m-d H:i:s') . '数据已为最新' . PHP_EOL;
return 0; continue;
} }
Yii::$app->redis->set('chain33_game_bet_status',$current_round,'EX',300); Yii::$app->redis->set('chain33_game_bet_status_'.$key, $current_round, 'EX', 300);
$result = $service->getBetStatus($cache_current_round, $current_round); $result = $service->getBetStatus($cache_current_round, $current_round, '', $node);
if( 0 !== $result['code']){ if (0 !== $result['code']) {
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL; echo $key.':'.date('Y-m-d H:i:s') . '数据错误' . PHP_EOL;
return 0; continue;
} }
$queryResultItems = $result['result'] ?? []; $queryResultItems = $result['result'] ?? [];
if(empty($queryResultItems)){ if (empty($queryResultItems)) {
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL; echo $key.':'.date('Y-m-d H:i:s') . '数据错误' . PHP_EOL;
return 0; continue;
} }
foreach ($queryResultItems['queryResultItems'] as $key => $val){ $platform = $key;
if( false == $val['found'] ) continue; foreach ($queryResultItems['queryResultItems'] as $key => $val) {
$resultArr = json_decode($val['resultJSON'],true); if (false == $val['found']) continue;
$resultArr = json_decode($val['resultJSON'], true);
$datas[] = [ $datas[] = [
$resultArr['round'], $resultArr['player'], $resultArr['amount'], $resultArr['height'], $resultArr['guess_num'], $resultArr['rand_num'], $resultArr['player_win'] $resultArr['round'], $resultArr['player'], $resultArr['amount'], $resultArr['height'], $resultArr['guess_num'], $resultArr['rand_num'], $resultArr['player_win'], $platform
]; ];
} }
CoinGameBet::loadArray($datas); CoinGameBet::loadArray($datas);
echo date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL; echo $platform.':'.date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL;
continue;
}
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment