Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
b0b5da40
Commit
b0b5da40
authored
Aug 29, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
8fb05f68
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
90 deletions
+82
-90
CrossChainController.php
api/controllers/CrossChainController.php
+48
-62
CrossChainController.php
console/controllers/CrossChainController.php
+34
-28
No files found.
api/controllers/CrossChainController.php
View file @
b0b5da40
...
...
@@ -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
[
'isWith
draw'
]])
->
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
];
$code
=
0
;
$msg
=
'第一笔交易尚未执行'
;
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
];
$code
=
-
1
;
$msg
=
$val
[
'msg'
];
goto
doEnd
;
}
if
(
true
==
$val
[
'send_result'
]
&&
true
==
$val
[
'query_result'
]
&&
false
==
$val
[
'msg'
])
{
continue
;
}
//未交易
if
(
'0'
==
$val
[
'send_result'
]
&&
'0'
==
$val
[
'query_result'
]
&&
'0'
==
$val
[
'msg'
])
{
$step
=
$key
+
1
;
$code
=
0
;
$msg
=
'第'
.
(
$key
+
1
)
.
'笔交易尚未执行'
;
goto
doEnd
;
}
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
;
$msg
=
$val
[
'send_result'
];
goto
doEnd
;
}
if
(
false
==
$val
[
'send_result'
]
&&
false
==
$val
[
'query_result'
]
&&
true
==
$val
[
'msg'
])
{
$data
=
[
'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
(
'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'
]
&&
'0'
==
$val
[
'query_result'
]
&&
'0'
==
$val
[
'msg'
])
{
$step
=
$key
+
1
;
$code
=
0
;
$msg
=
$val
[
'send_result'
];
goto
doEnd
;
}
//交易成功,查询失败
if
(
true
==
$val
[
'send_result'
]
&&
'fail'
==
$val
[
'query_result'
])
{
$step
=
$key
+
1
;
$code
=
-
1
;
$msg
=
$val
[
'msg'
];
goto
doEnd
;
}
//交易成功,查询成功
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
];
}
...
...
console/controllers/CrossChainController.php
View file @
b0b5da40
...
...
@@ -23,49 +23,50 @@ class CrossChainController extends Controller
}
foreach
(
$model
as
$val
)
{
//
go(function () use ($val) {
//
\Co::sleep(0.5);
$node_params
=
$val
[
'transfer_url'
];
$node_params
=
explode
(
':'
,
$node_params
);
$node_params
=
[
'scheme'
=>
$node_params
[
0
],
'host'
=>
str_replace
(
'//'
,
''
,
$node_params
[
1
]),
'port'
=>
$node_params
[
2
]
];
$service
=
new
Chain33Service
(
$node_params
);
$sign_str
=
$val
[
'txhex'
];
$result
=
$service
->
sendTransaction
(
$sign_str
);
go
(
function
()
use
(
$val
)
{
\Co
::
sleep
(
0.5
);
$node_params
=
$val
[
'transfer_url'
];
$node_params
=
explode
(
':'
,
$node_params
);
$node_params
=
[
'scheme'
=>
$node_params
[
0
],
'host'
=>
str_replace
(
'//'
,
''
,
$node_params
[
1
]),
'port'
=>
$node_params
[
2
]
];
$service
=
new
Chain33Service
(
$node_params
);
$sign_str
=
$val
[
'txhex'
];
$result
=
$service
->
sendTransaction
(
$sign_str
);
if
(
0
!=
$result
[
'code'
])
{
$msg
=
$result
[
'msg'
];
goto
doEnd
;
}
$send_result
=
$result
[
'result'
];
if
(
0
!=
$result
[
'code'
])
{
$msg
=
$result
[
'msg'
];
goto
doEnd
;
}
$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
->
save
();
doEnd
:
$currentModel
=
CoinCrossChain
::
findOne
(
$val
[
'id'
]);
if
(
isset
(
$msg
))
{
$currentModel
->
msg
=
$msg
;
}
if
(
isset
(
$send_result
))
{
$currentModel
->
send_result
=
$send_result
;
}
$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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment