Commit b0b5da40 authored by shajiaiming's avatar shajiaiming

fix

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