Commit f39e20e4 authored by shajiaiming's avatar shajiaiming

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

parent b74973be
......@@ -173,19 +173,30 @@ class Chain33Business
* @param integer $end
* @return array
*/
public static function getBetStatus($start, $end)
public static function getBetStatus($start, $end, $roundArr = [])
{
$node_params = \Yii::$app->params['chain_parallel']['wasm'];
$service = new Chain33Service($node_params);
$execer = 'wasm';
$funcName = 'WasmGetContractTable';
$contractName = 'user.p.tschain.user.wasm.dice';
if (empty($roundArr)) {
for($i = $start + 1; $i <= $end; $i++){
$items[] = [
'tableName' => 'roundinfo',
'key' => 'round:' . $i
];
}
}
if(!empty($roundArr)){
foreach($roundArr as $key => $round){
$items[] = [
'tableName' => 'roundinfo',
'key' => 'round:' . $round
];
}
}
return $service->chain33Query($execer, $funcName, $contractName, $items);
}
......
......@@ -42,6 +42,7 @@ class GameBetController extends Controller
return 0;
}
Yii::$app->redis->set('chain33_game_bet_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;
......@@ -75,12 +76,43 @@ class GameBetController extends Controller
return 0;
}
$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) {
if($model->height + 12 < $height){
$model->valid = 1;
$model->update(false); // skipping validation as no user input is involved
$valid_arr[] = $model->round;
}
$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;
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