Commit 339caf98 authored by shajiaiming's avatar shajiaiming

fix

parent 0ef821ef
......@@ -298,6 +298,15 @@ class Chain33Service
return $this->send($params, 'Chain33.SignRawTx');
}
public function getBlock2MainInfo($start, $end)
{
$params = [
"Start" => $start,
"End" => $end,
];
return $this->send($params, 'paracross.GetBlock2MainInfo');
}
public function sendTrade($data)
{
$params = [
......
......@@ -4,6 +4,7 @@ namespace console\controllers;
use common\business\Chain33Business;
use common\models\psources\CoinGameBet;
use common\service\chain33\Chain33Service;
use yii\console\Controller;
use Yii;
......@@ -76,32 +77,38 @@ class GameBetController extends Controller
public function actionBetUpdate()
{
$service = new Chain33Business();
$node_params = [
'scheme' => 'https',
'host' => 'jiedian1.bityuan.com',
'port' => 8801
];
$result = $service->getLastHeader($node_params);
$main_height = isset($result['result']['height']) ? $result['result']['height'] : 0;
$safe_main_height = $main_height - 14;
$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;
$service = new Chain33Service($node);
$result = $service->getLastHeader();
$height = $result['result']['height'];
$main_info = $service->getBlock2MainInfo($height - 14, $height);
$items = $main_info['result']['items'];
$items = $this->arraySort($items, 'mainHeight');
foreach ($items as $item) {
if ($safe_main_height > $item['mainHeight']) {
$safe_height = $item['height'];
break;
}
}
$queryResultItems = $result['result'] ?? [];
if (empty($queryResultItems)) {
echo $key . ':' . date('Y-m-d H:i:s') . 'error' . PHP_EOL;
continue;
}
$resultJSON = json_decode($queryResultItems['queryResultItems'][0]['resultJSON'], true);
$current_height = $resultJSON['height'];
echo $key . ':' . date('Y-m-d H:i:s') . '当前高度为:' . $current_height . PHP_EOL;
echo $key . ':' . date('Y-m-d H:i:s') . '当前主链高度为:' . $main_height . ';当前平行链高度为:' . $height . ';当前安全高度为:' . $safe_height . PHP_EOL;
$models = CoinGameBet::find()->select('round')->where([
'and',
['valid' => CoinGameBet::VAILD_FALSE],
['<', 'height', $current_height - 14],
['<', 'height', $safe_height],
['platform' => $key]
])->all();
if (empty($models)) {
......@@ -112,7 +119,8 @@ class GameBetController extends Controller
foreach ($models as $model) {
$valid_arr[] = $model->round;
}
$result = $service->getBetStatus('', '', $valid_arr, $node);
$business = new Chain33Business();
$result = $business->getBetStatus('', '', $valid_arr, $node);
if (0 !== $result['code']) {
echo $key . ':' . date('Y-m-d H:i:s') . '数据错误' . PHP_EOL;
continue;
......@@ -145,4 +153,14 @@ class GameBetController extends Controller
return 0;
}
protected function arraySort($array, $keys, $sort = SORT_DESC)
{
$keysValue = [];
foreach ($array as $k => $v) {
$keysValue[$k] = $v[$keys];
}
array_multisort($keysValue, $sort, $array);
return $array;
}
}
\ 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