Commit ceca8b1a authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/bet' into 'master'

Feature/bet See merge request !40
parents 1e858c3a b74973be
......@@ -74,6 +74,7 @@ class GameBetController extends BaseController
$query = CoinGameBet::find()
->select('round, player, amount, height, guess_num, guess_num, rand_num, player_win')
->where('player= :player',[':player' => $player])
->andWhere(['valid' => CoinGameBet::VAILD_TRUE])
->orderBy('update_time desc');
$count = $query->count();
......
......@@ -120,16 +120,6 @@ class Chain33Business
}
/**
* 获取最新的区块
*/
public static function getLastHeader()
{
$service = new Chain33Service();
$result = $service->getLastHeader();
return $result;
}
/**
* 获取区块hash
*
* @param integer $height
......@@ -199,6 +189,18 @@ class Chain33Business
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
const SCENARIOS_ADD = 'add';
const SCENARIOS_UPDATE = 'update';
const VAILD_TRUE = 1;
const VAILD_FALSE = 0;
public static function getDb()
{
return Yii::$app->get('p_sources');
......@@ -44,7 +47,7 @@ class CoinGameBet extends BaseActiveRecord
public function rules()
{
return [
[['round', 'amount', 'height', 'guess_num', 'rand_num', 'player_win'], 'int'],
[['round', 'amount', 'height', 'guess_num', 'rand_num', 'player_win', 'vaild'], 'int'],
[['player'], 'string']
];
}
......@@ -52,8 +55,8 @@ class CoinGameBet extends BaseActiveRecord
public function sercians()
{
return [
self::SCENARIOS_ADD => ['round', 'amount', 'height', 'guess_num', 'rand_num', 'player_win', 'player'],
self::SCENARIOS_UPDATE => ['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', 'vaild'],
];
}
......
......@@ -64,4 +64,25 @@ class GameBetController extends Controller
echo date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL;
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