Commit 46373e98 authored by shajiaiming's avatar shajiaiming

优化

parent 3cecfa21
......@@ -10,6 +10,8 @@ class CoinCrossChain extends BaseActiveRecord
const WITHDRAW = 0;
const RECHARGE = 1;
const CROSS_CHAIN_CACHE_FAIL = 'cross_chain_fail';
public static function getDb()
{
return Yii::$app->get('p_sources');
......
......@@ -14,14 +14,15 @@ class CrossChainController extends Controller
*
* @return array
*/
public function actionAutoTransfer()
public function actionAutoTransfer($step, $is_with_draw)
{
$model = CoinCrossChain::find()->where(['send_result' => "0"])->limit(20)->groupBy('transfer_number')->orderBy('id')->asArray()->all();
$model = CoinCrossChain::find()->where(['send_result' => "0", 'step' => (int)$step, 'is_with_draw' => (int)$is_with_draw])->limit(20)->asArray()->all();
if (empty($model)) {
echo date('Y-m-d H:i:s') . '暂无跨链交易计划' . PHP_EOL;
echo date('Y-m-d H:i:s') . ' STEP: ' . $step . '暂无跨链交易计划' . PHP_EOL;
return 0;
}
foreach ($model as $val) {
if( $step > 1) {
$isExist = CoinCrossChain::find()
->where(['transfer_number' => $val['transfer_number']])
->andWhere(['<', 'id', (int)$val['id']])
......@@ -32,9 +33,10 @@ class CrossChainController extends Controller
if ('success' != $isExist['query_result'] && !empty($isExist)) {
continue;
}
}
//go(function () use ($val) {
// \Co::sleep(0.5);
go(function () use ($val) {
\Co::sleep(0.5);
$transfer_url = $val['transfer_url'];
$transfer_url = explode(':', $transfer_url);
......@@ -63,22 +65,22 @@ class CrossChainController extends Controller
$currentModel->send_result = $send_result;
}
$currentModel->save();
//});
});
}
echo date('Y-m-d H:i:s') . '跨链交易成功' . PHP_EOL;
echo date('Y-m-d H:i:s') . ' STEP: ' . $step . '跨链交易成功' . PHP_EOL;
return 0;
}
public function actionQueryTransaction()
{
$redis = Yii::$app->redis;
$model = CoinCrossChain::find()->where(['<>', 'send_result', '0'])->andWhere(['msg' => '0'])->limit(20)->asArray()->all();
if (empty($model)) {
echo date('Y-m-d H:i:s') . '暂无跨链交易计划' . PHP_EOL;
return 0;
}
$current_time = time();
foreach ($model as $val) {
$node_params = $val['transfer_url'];
$node_params = explode(':', $node_params);
......@@ -91,12 +93,18 @@ class CrossChainController extends Controller
$send_result = $val['send_result'];
$result = $service->QueryTransaction($send_result);
if (-1 == $result['code']) {
if('tx not exist' == $result['msg']) continue;
$cache_error_time = $redis->hget(CoinCrossChain::CROSS_CHAIN_CACHE_FAIL, $val['address'] . ':' . $val['is_with_draw']);
if (false == $cache_error_time) {
$redis->hmset(CoinCrossChain::CROSS_CHAIN_CACHE_FAIL, $val['address'] . ':' . $val['is_with_draw'], $current_time);
continue;
}
if (($current_time - $cache_error_time) < 60) {
continue;
}
$msg = $result['msg'];
$query_result = $result['code'];
goto doEnd;
// echo date('Y-m-d H:i:s') . 'ID:' . $val['id'] . '查询错误' . PHP_EOL;
// continue;
}
if (isset($result['result']['actionName']) && 'unknown' == $result['result']['actionName']) {
......@@ -121,7 +129,6 @@ class CrossChainController extends Controller
$count = CoinCrossChain::find()->where(['transfer_number' => $val['transfer_number']])->andWhere(['query_result' => 'success'])->count();
if (3 == $count) {
$redis = Yii::$app->redis;
$key = $val['address'] . '_' . $val['is_with_draw'];
if ($redis->exists($key)) {
$redis->del($key);
......
#!/bin/bash
while true; do php /var/www/html/token_pwallet/yii cross-chain/auto-transfer >> /var/www/html/auto-transfer.log 2>&1; sleep 15; done &
\ No newline at end of file
#!/bin/bash
while true; do php /var/www/html/token_pwallet/yii game-bet/bet-update >> /var/log/bet-update.log 2>&1; sleep 2; done &
\ No newline at end of file
#!/bin/bash
while true; do php /var/www/html/token_pwallet/yii game-bet/game-status >> /var/log/game-status.log 2>&1; sleep 5; done &
\ No newline at end of file
#!/bin/bash
while true; do php /var/www/html/token_pwallet/yii cross-chain/query-transaction >> /var/www/html/query-transaction.log 2>&1; sleep 5; done &
\ 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