Commit f39e20e4 authored by shajiaiming's avatar shajiaiming

投注信息增加区块高度判断 fix

parent b74973be
...@@ -173,19 +173,30 @@ class Chain33Business ...@@ -173,19 +173,30 @@ class Chain33Business
* @param integer $end * @param integer $end
* @return array * @return array
*/ */
public static function getBetStatus($start, $end) public static function getBetStatus($start, $end, $roundArr = [])
{ {
$node_params = \Yii::$app->params['chain_parallel']['wasm']; $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 = 'user.p.tschain.user.wasm.dice';
if (empty($roundArr)) {
for($i = $start + 1; $i <= $end; $i++){ for($i = $start + 1; $i <= $end; $i++){
$items[] = [ $items[] = [
'tableName' => 'roundinfo', 'tableName' => 'roundinfo',
'key' => 'round:' . $i 'key' => 'round:' . $i
]; ];
} }
}
if(!empty($roundArr)){
foreach($roundArr as $key => $round){
$items[] = [
'tableName' => 'roundinfo',
'key' => 'round:' . $round
];
}
}
return $service->chain33Query($execer, $funcName, $contractName, $items); return $service->chain33Query($execer, $funcName, $contractName, $items);
} }
......
...@@ -42,6 +42,7 @@ class GameBetController extends Controller ...@@ -42,6 +42,7 @@ class GameBetController extends Controller
return 0; return 0;
} }
Yii::$app->redis->set('chain33_game_bet_status',$current_round,'EX',300); Yii::$app->redis->set('chain33_game_bet_status',$current_round,'EX',300);
$result = $service->getBetStatus($cache_current_round, $current_round); $result = $service->getBetStatus($cache_current_round, $current_round);
if( 0 !== $result['code']){ if( 0 !== $result['code']){
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL; echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
...@@ -75,12 +76,43 @@ class GameBetController extends Controller ...@@ -75,12 +76,43 @@ class GameBetController extends Controller
return 0; return 0;
} }
$height = $result['height']; $height = $result['height'];
$models = CoinGameBet::find()->where(['valid' => CoinGameBet::VAILD_FALSE])->all(); $models = CoinGameBet::find()->select('round')->where([
'and',
['valid' => CoinGameBet::VAILD_FALSE],
['<', 'height', $height - 12]
])->all();
if(empty($models)){
echo date('Y-m-d H:i:s') . '无需更新的数据'.PHP_EOL;
return 0;
}
$valid_arr = [];
foreach ($models as $model) { foreach ($models as $model) {
if($model->height + 12 < $height){ $valid_arr[] = $model->round;
$model->valid = 1; }
$model->update(false); // skipping validation as no user input is involved $result = $service->getBetStatus('', '', $valid_arr);
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);
CoinGameBet::updateAll([
'amount' => $resultArr['amount'],
'height' => $resultArr['height'],
'guess_num' => $resultArr['guess_num'],
'rand_num' => $resultArr['rand_num'],
'player_win' => $resultArr['player_win'],
'valid' => CoinGameBet::VAILD_TRUE
],[
'round' => $resultArr['round']
]);
} }
echo date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL; echo date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL;
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