Commit 6f7903ac authored by shajiaiming's avatar shajiaiming

游戏链区分

parent 7d8ac310
......@@ -153,13 +153,12 @@ class Chain33Business
* 获取游戏状态
* @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);
$execer = 'wasm';
$funcName = 'WasmGetContractTable';
$contractName = 'user.p.tschain.user.wasm.dice';
$contractName = $node_params['contractName'];
$items[] = [
'tableName' => 'gamestatus',
'key' => 'dice_statics'
......
......@@ -63,7 +63,7 @@ class CoinGameBet extends BaseActiveRecord
public static function loadArray(array $data)
{
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();
}
}
......@@ -16,53 +16,62 @@ class GameBetController extends Controller
*/
public function actionGameStatus()
{
$service = new Chain33Business();
$result = $service->getGameStatus();
if( 0 !== $result['code']){
echo date('Y-m-d H:i:s') . $result['msg'].PHP_EOL;
$nodes = \Yii::$app->params['chain_parallel']['wasm'];
if(empty($nodes)){
echo date('Y-m-d H:i:s') . '无节点'.PHP_EOL;
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'] ?? [];
if(empty($queryResultItems)){
echo date('Y-m-d H:i:s') . 'error'.PHP_EOL;
return 0;
if (empty($queryResultItems)) {
echo $key.':'.date('Y-m-d H:i:s') . 'error'.PHP_EOL;
continue;
}
$resultJSON = json_decode($queryResultItems['queryResultItems'][0]['resultJSON'],true);
$resultJSON = json_decode($queryResultItems['queryResultItems'][0]['resultJSON'], true);
$current_round = $resultJSON['current_round'];
$cache_current_round = Yii::$app->redis->get('chain33_game_bet_status');
if(empty($cache_current_round)){
$cache_current_round = CoinGameBet::find()->max('round');
Yii::$app->redis->set('chain33_game_bet_status',$cache_current_round,'EX',300);
$cache_current_round = Yii::$app->redis->get('chain33_game_bet_status_'.$key);
if (empty($cache_current_round)) {
$cache_current_round = CoinGameBet::find()->where(['platform' => $key])->max('round');
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);
if($cache_current_round >= $current_round){
echo date('Y-m-d H:i:s') . '数据已为最新'.PHP_EOL;
return 0;
if ($cache_current_round >= $current_round) {
echo $key.':'.date('Y-m-d H:i:s') . '数据已为最新' . PHP_EOL;
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);
if( 0 !== $result['code']){
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
return 0;
$result = $service->getBetStatus($cache_current_round, $current_round, '', $node);
if (0 !== $result['code']) {
echo $key.':'.date('Y-m-d H:i:s') . '数据错误' . PHP_EOL;
continue;
}
$queryResultItems = $result['result'] ?? [];
if(empty($queryResultItems)){
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
return 0;
if (empty($queryResultItems)) {
echo $key.':'.date('Y-m-d H:i:s') . '数据错误' . PHP_EOL;
continue;
}
foreach ($queryResultItems['queryResultItems'] as $key => $val){
if( false == $val['found'] ) continue;
$resultArr = json_decode($val['resultJSON'],true);
$platform = $key;
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']
$resultArr['round'], $resultArr['player'], $resultArr['amount'], $resultArr['height'], $resultArr['guess_num'], $resultArr['rand_num'], $resultArr['player_win'], $platform
];
}
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;
}
......
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