Commit 176cbc54 authored by shajiaiming's avatar shajiaiming

筛选交易数据

parent a735b982
......@@ -10,6 +10,7 @@ class CoinCrossChain extends BaseActiveRecord
const WITHDRAW = 0;
const RECHARGE = 1;
const CROSS_CHAIN_TRANSFERING = 'cross_chain_transfering';
const CROSS_CHAIN_CACHE_FAIL = 'cross_chain_fail';
public static function getDb()
......
......@@ -16,11 +16,13 @@ class CrossChainController extends Controller
*/
public function actionAutoTransfer($step, $is_with_draw)
{
$redis = Yii::$app->redis;
$model = CoinCrossChain::find()->where(['send_result' => "0", 'step' => (int)$step, 'is_with_draw' => (int)$is_with_draw])->asArray()->all();
if (empty($model)) {
echo date('Y-m-d H:i:s') . ' STEP: ' . $step . '暂无跨链交易计划' . PHP_EOL;
return 0;
}
$current_time = time();
foreach ($model as $val) {
if ($step > 1) {
$isExist = CoinCrossChain::find()
......@@ -34,8 +36,13 @@ class CrossChainController extends Controller
continue;
}
}
$cache_transfering_time = $redis->hget(CoinCrossChain::CROSS_CHAIN_TRANSFERING, $val['address'] . ':' . $val['is_with_draw']);
if (true == $cache_transfering_time) {
continue;
}
$redis->hmset(CoinCrossChain::CROSS_CHAIN_TRANSFERING, $val['address'] . ':' . $val['is_with_draw'], $current_time);
go(function () use ($val) {
go(function () use ($val, $redis) {
\Co::sleep(0.5);
$transfer_url = $val['transfer_url'];
$transfer_url = explode(':', $transfer_url);
......@@ -43,29 +50,26 @@ class CrossChainController extends Controller
$node_params = [
'scheme' => $transfer_url[0],
'host' => str_replace('//', '', $transfer_url[1]),
'port' => isset($transfer_url[2]) ? $transfer_url[2] : ''
'port' => isset($transfer_url[2]) ? $transfer_url[2] : '',
'timeout' => 100
];
$service = new Chain33Service($node_params);
$sign_str = $val['txhex'];
$result = $service->sendTransaction($sign_str);
if (0 != $result['code']) {
$msg = $result['msg'];
goto doEnd;
}
if (0 == $result['code']) {
$send_result = $result['result'];
doEnd :
$currentModel = CoinCrossChain::findOne($val['id']);
if (isset($msg)) {
$currentModel->msg = $msg;
}
if (isset($send_result)) {
$currentModel->send_result = $send_result;
$currentModel->msg = 0;
}
$currentModel->save();
$redis->hdel(CoinCrossChain::CROSS_CHAIN_TRANSFERING, $val['address'] . ':' . $val['is_with_draw']);
}
if (0 != $result && (false == strstr($result['msg'], 'ErrDupTx'))) {
$redis->hdel(CoinCrossChain::CROSS_CHAIN_TRANSFERING, $val['address'] . ':' . $val['is_with_draw']);
}
});
}
echo date('Y-m-d H:i:s') . ' STEP: ' . $step . '跨链交易成功' . PHP_EOL;
......
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