Commit b0b5da40 authored by shajiaiming's avatar shajiaiming

fix

parent 8fb05f68
......@@ -23,18 +23,25 @@ class CrossChainController extends BaseController
goto doEnd;
}
$post = $request->post();
if (2 != count($post['txs'])) {
if (3 != count($post['txs'])) {
$msg = '交易笔数错误!';
goto doEnd;
}
$data['is_with_draw'] = $post['isWithdraw'];
$data['is_with_draw'] = (false == $post['isWithdraw']) ? 0 : 1;
$data['address'] = $post['address'];
$data['transfer_number'] = date('YmdHis') . self::getrandnums();
// $redis = Yii::$app->redis;
// if ($redis->exists($post['address'] . '_' . $data['is_with_draw'])) {
// $msg = '存在未完成的交易!';
// goto doEnd;
// }
// $redis->set($post['address'] . '_' . $data['is_with_draw'], $post['address'] . '_' . $data['is_with_draw']);
$isExist = CoinCrossChain::find()
->where(['address' => $post['address'], 'is_with_draw' => $post['isWithdraw']])
->andWhere(['query_result' => '0'])
->where(['address' => $post['address'], 'is_with_draw' => $data['is_with_draw']])
->andWhere(['<>', 'query_result', 'success'])
->asArray()->all();
if ($isExist) {
......@@ -75,7 +82,7 @@ class CrossChainController extends BaseController
goto doEnd;
}
$model = CoinCrossChain::find()->where(['address' => $address, 'is_with_draw' => $is_with_draw])->orderBy("id desc")->limit(2)->asArray()->all();
$model = CoinCrossChain::find()->where(['address' => $address, 'is_with_draw' => $is_with_draw])->orderBy("id desc")->limit(3)->asArray()->all();
if (empty($model)) {
$msg = '数据不存在!';
goto doEnd;
......@@ -84,72 +91,51 @@ class CrossChainController extends BaseController
$step = 0;
foreach ($model as $key => $val) {
if (0 == $key) {
if (false == $val['send_result'] && false == $val['query_result'] && false == $val['msg']) {
$data = [
'step' => $key
];
//未交易
if ('0' == $val['send_result'] && '0' == $val['query_result'] && '0' == $val['msg']) {
$step = $key + 1;
$code = 0;
$msg = '第一笔交易尚未执行';
$msg = '第' . ($key + 1) . '笔交易尚未执行';
goto doEnd;
}
if (true == $val['send_result'] && false == $val['query_result'] && false == $val['msg']) {
$data = [
'step' => $key + 1
];
$code = 0;
$msg = $val['send_result'];
goto doEnd;
}
if (false == $val['send_result'] && false == $val['query_result'] && true == $val['msg']) {
$data = [
'step' => $key + 1
];
//交易报错
if ('0' == $val['send_result'] && '0' == $val['query_result'] && true == $val['msg']) {
$step = $key + 1;
$code = -1;
$msg = $val['msg'];
goto doEnd;
}
if (true == $val['send_result'] && true == $val['query_result'] && false == $val['msg']) {
continue;
}
}
if (1 == $key) {
if (false == $val['send_result'] && false == $val['query_result'] && false == $val['msg']) {
$data = [
'step' => $key + 1
];
$code = 0;
$msg = '第二笔交易尚未执行';
goto doEnd;
}
if (true == $val['send_result'] && false == $val['query_result'] && false == $val['msg']) {
$data = [
'step' => $key + 1
];
//交易成功
if (true == $val['send_result'] && '0' == $val['query_result'] && '0' == $val['msg']) {
$step = $key + 1;
$code = 0;
$msg = $val['send_result'];
goto doEnd;
}
if (false == $val['send_result'] && false == $val['query_result'] && true == $val['msg']) {
$data = [
'step' => $key + 1
];
//交易成功,查询失败
if (true == $val['send_result'] && 'fail' == $val['query_result']) {
$step = $key + 1;
$code = -1;
$msg = $val['msg'];
goto doEnd;
}
if (true == $val['send_result'] && true == $val['query_result'] && false == $val['msg']) {
$data = [
'step' => 3
];
//交易成功,查询成功
if (true == $val['send_result'] && 'success' == $val['query_result'] && 'success' == $val['msg']) {
if (2 == $key){
$step = (2 == $key) ? 4 : ($key + 2);
$code = 0;
$msg = $val['send_result'];
goto doEnd;
}
continue;
}
}
doEnd :
$data = [
'step' => $step
];
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
......
......@@ -23,8 +23,8 @@ class CrossChainController extends Controller
}
foreach ($model as $val) {
// go(function () use ($val) {
// \Co::sleep(0.5);
go(function () use ($val) {
\Co::sleep(0.5);
$node_params = $val['transfer_url'];
$node_params = explode(':', $node_params);
$node_params = [
......@@ -52,20 +52,21 @@ class CrossChainController extends Controller
}
$currentModel->save();
// });
});
}
return 0;
}
public function actionQueryTransaction()
{
$model = CoinCrossChain::find()->where(['<>', 'send_result', '0'])->limit(20)->asArray()->all();
$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;
}
$transfer_number = [];
foreach ($model as $val) {
$node_params = $val['transfer_url'];
$node_params = explode(':', $node_params);
......@@ -78,6 +79,10 @@ class CrossChainController extends Controller
$send_result = $val['send_result'];
$result = $service->QueryTransaction($send_result);
if (-1 == $result['code']) {
echo date('Y-m-d H:i:s') . 'ID:' . $val['id'] . '查询错误' . PHP_EOL;
continue;
}
if (isset($result['result']['actionName']) && 'unknown' == $result['result']['actionName']) {
$query_result = 'success';
......@@ -89,6 +94,7 @@ class CrossChainController extends Controller
$query_result = 'fail';
$msg = $result['result']['receipt']['logs'][0]['log'];
}
$transfer_number[] = $val['transfer_number'];
$currentModel = CoinCrossChain::findOne($val['id']);
$currentModel->query_result = $query_result;
$currentModel->msg = $msg;
......
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