Commit 2135ea03 authored by shajiaiming's avatar shajiaiming

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

parent 1e858c3a
...@@ -74,6 +74,7 @@ class GameBetController extends BaseController ...@@ -74,6 +74,7 @@ class GameBetController extends BaseController
$query = CoinGameBet::find() $query = CoinGameBet::find()
->select('round, player, amount, height, guess_num, guess_num, rand_num, player_win') ->select('round, player, amount, height, guess_num, guess_num, rand_num, player_win')
->where('player= :player',[':player' => $player]) ->where('player= :player',[':player' => $player])
->andWhere(['valid' => CoinGameBet::VAILD_TRUE])
->orderBy('update_time desc'); ->orderBy('update_time desc');
$count = $query->count(); $count = $query->count();
......
...@@ -120,16 +120,6 @@ class Chain33Business ...@@ -120,16 +120,6 @@ class Chain33Business
} }
/** /**
* 获取最新的区块
*/
public static function getLastHeader()
{
$service = new Chain33Service();
$result = $service->getLastHeader();
return $result;
}
/**
* 获取区块hash * 获取区块hash
* *
* @param integer $height * @param integer $height
...@@ -199,6 +189,18 @@ class Chain33Business ...@@ -199,6 +189,18 @@ class Chain33Business
return $service->chain33Query($execer, $funcName, $contractName, $items); return $service->chain33Query($execer, $funcName, $contractName, $items);
} }
/*
* 获取最新的区块头
* @param null
* @return array
*/
public static function getLastHeader()
{
$node_params = \Yii::$app->params['chain_parallel']['wasm'];
$service = new Chain33Service($node_params);
return $service->getLastHeader();
}
/** /**
* 获取地址下的所有交易记录 * 获取地址下的所有交易记录
* *
......
...@@ -18,6 +18,9 @@ class CoinGameBet extends BaseActiveRecord ...@@ -18,6 +18,9 @@ class CoinGameBet extends BaseActiveRecord
const SCENARIOS_ADD = 'add'; const SCENARIOS_ADD = 'add';
const SCENARIOS_UPDATE = 'update'; const SCENARIOS_UPDATE = 'update';
const VAILD_TRUE = 1;
const VAILD_FALSE = 0;
public static function getDb() public static function getDb()
{ {
return Yii::$app->get('p_sources'); return Yii::$app->get('p_sources');
...@@ -44,7 +47,7 @@ class CoinGameBet extends BaseActiveRecord ...@@ -44,7 +47,7 @@ class CoinGameBet extends BaseActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['round', 'amount', 'height', 'guess_num', 'rand_num', 'player_win'], 'int'], [['round', 'amount', 'height', 'guess_num', 'rand_num', 'player_win', 'vaild'], 'int'],
[['player'], 'string'] [['player'], 'string']
]; ];
} }
...@@ -52,8 +55,8 @@ class CoinGameBet extends BaseActiveRecord ...@@ -52,8 +55,8 @@ class CoinGameBet extends BaseActiveRecord
public function sercians() public function sercians()
{ {
return [ return [
self::SCENARIOS_ADD => ['round', 'amount', 'height', 'guess_num', 'rand_num', 'player_win', 'player'], self::SCENARIOS_ADD => ['round', 'amount', 'height', 'guess_num', 'rand_num', 'player_win', 'player', 'vaild'],
self::SCENARIOS_UPDATE => ['round', 'amount', 'height', 'guess_num', 'rand_num', 'player_win', 'player'], self::SCENARIOS_UPDATE => ['round', 'amount', 'height', 'guess_num', 'rand_num', 'player_win', 'player', 'vaild'],
]; ];
} }
......
...@@ -31,17 +31,18 @@ class GameBetController extends Controller ...@@ -31,17 +31,18 @@ class GameBetController extends Controller
$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');
if(empty($cache_current_round)){ // if(empty($cache_current_round)){
$cache_current_round = CoinGameBet::find()->max('round'); // $cache_current_round = CoinGameBet::find()->max('round');
Yii::$app->redis->set('chain33_game_bet_status',$cache_current_round,'EX',300); // Yii::$app->redis->set('chain33_game_bet_status',$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 date('Y-m-d H:i:s') . '数据已为最新'.PHP_EOL;
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);
$cache_current_round = 55470;
$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;
...@@ -64,4 +65,25 @@ class GameBetController extends Controller ...@@ -64,4 +65,25 @@ class GameBetController extends Controller
echo date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL; echo date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL;
return 0; return 0;
} }
public function actionBetUpdate()
{
$service = new Chain33Business();
$result = $service->getLastHeader();
$result = $result['result'] ?? [];
if(empty($result)){
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
return 0;
}
$height = $result['height'];
$models = CoinGameBet::find()->where(['valid' => CoinGameBet::VAILD_FALSE])->all();
foreach ($models as $model) {
if($model->height + 12 < $height){
$model->valid = 1;
$model->update(false); // skipping validation as no user input is involved
}
}
echo date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL;
return 0;
}
} }
\ No newline at end of file
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