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
d6f42d10
Commit
d6f42d10
authored
Nov 01, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/issue_coin' into develop
parents
9a78b64e
60f0b8c2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
449 additions
and
53 deletions
+449
-53
IssueCoinController.php
api/controllers/IssueCoinController.php
+177
-8
CoinIssueChainRecord.php
common/models/psources/CoinIssueChainRecord.php
+15
-11
CoinIssueCoin.php
common/models/psources/CoinIssueCoin.php
+9
-3
CrossChainController.php
console/controllers/CrossChainController.php
+0
-31
IssueChainTransferController.php
console/controllers/IssueChainTransferController.php
+248
-0
No files found.
api/controllers/IssueCoinController.php
View file @
d6f42d10
...
...
@@ -2,12 +2,12 @@
namespace
api\controllers
;
use
common\models\psources\CoinIssueRecord
;
use
common\models\psources\CoinPlatform
;
use
Yii
;
use
yii\data\Pagination
;
use
api\base\BaseController
;
use
common\models\psources\CoinPlatform
;
use
common\models\psources\CoinIssueCoin
;
use
common\models\psources\CoinIssueChainRecord
;
class
IssueCoinController
extends
BaseController
{
...
...
@@ -49,6 +49,7 @@ class IssueCoinController extends BaseController
$code
=
-
1
;
goto
doEnd
;
}
$result
=
[
'name'
=>
isset
(
$result
[
'name'
])
?
$result
[
'name'
]
:
''
,
'symbol'
=>
isset
(
$result
[
'symbol'
])
?
strtoupper
(
$result
[
'symbol'
])
:
''
,
...
...
@@ -60,8 +61,6 @@ class IssueCoinController extends BaseController
'chain_id'
=>
$chain_id
,
'charge_unit_id'
=>
isset
(
$result
[
'charge_unit_id'
])
?
$result
[
'charge_unit_id'
]
:
''
,
'charge'
=>
$coin_platform
->
issue_charge
,
'step_one_tx'
=>
isset
(
$result
[
'step_one_tx'
])
?
$result
[
'step_one_tx'
]
:
''
,
'step_one_result'
=>
0
];
$model
->
load
(
$result
,
''
);
if
(
!
$model
->
save
())
{
...
...
@@ -154,14 +153,69 @@ class IssueCoinController extends BaseController
}
/**
* 撤消申请
* 申请撤消/确认
* @param integer id
* @param string pre_create_tx
* @param string pre_send_transaction
* @return array
*/
public
function
actionSendTransfer
()
{
$params
=
Yii
::
$app
->
request
->
post
();
$id
=
isset
(
$params
[
'id'
])
?
(
int
)
$params
[
'id'
]
:
0
;
$pre_create_tx
=
isset
(
$params
[
'pre_create_tx'
])
?
$params
[
'pre_create_tx'
]
:
''
;
$pre_send_transaction
=
isset
(
$params
[
'pre_send_transaction'
])
?
$params
[
'pre_send_transaction'
]
:
''
;
if
(
false
==
$id
||
false
==
$pre_create_tx
||
false
==
$pre_send_transaction
)
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$model
=
CoinIssueChainRecord
::
find
()
->
where
([
'issue_coin_id'
=>
$id
])
->
one
();
if
(
true
==
$model
)
{
$msg
=
'交易记录已存在'
;
$code
=
-
1
;
goto
doEnd
;
}
$params
=
[
'pre_create_tx'
=>
$pre_create_tx
,
'pre_send_transaction'
=>
$pre_send_transaction
,
'pre_query_transaction'
=>
'standby'
,
'finish_tx'
=>
'standby'
,
'finish_send_transaction'
=>
'standby'
,
'finish_query_transaction'
=>
'standby'
,
'issue_coin_id'
=>
$id
,
];
$transfer_model
=
new
CoinIssueChainRecord
();
$transfer_model
->
setScenario
(
CoinIssueChainRecord
::
SCENARIOS_PRE_CREATE
);
$transfer_model
->
load
(
$params
,
''
);
if
(
!
$transfer_model
->
save
())
{
$msg
=
current
(
$transfer_model
->
firstErrors
);
$code
=
-
1
;
goto
doEnd
;
}
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
/**
* 申请撤消/确认
* @param integer id
* @param integer status
* @return array
*/
public
function
actionVerify
()
{
$id
=
Yii
::
$app
->
request
->
post
(
'id'
,
''
);
if
(
false
==
$id
)
{
$params
=
Yii
::
$app
->
request
->
post
();
$id
=
isset
(
$params
[
'id'
])
?
(
int
)
$params
[
'id'
]
:
0
;
$status
=
isset
(
$params
[
'status'
])
?
(
int
)
$params
[
'status'
]
:
0
;
if
(
false
==
$id
||
false
==
$status
)
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
...
...
@@ -174,6 +228,13 @@ class IssueCoinController extends BaseController
goto
doEnd
;
}
$record_model
=
CoinIssueChainRecord
::
find
()
->
where
([
'issue_coin_id'
=>
$id
])
->
one
();
if
(
false
==
$record_model
)
{
$msg
=
'交易记录不存在'
;
$code
=
-
1
;
goto
doEnd
;
}
if
(
$model
->
status
>
CoinIssueCoin
::
UN_AUDIT
)
{
$msg
=
'不允许取消的发行'
;
$code
=
-
1
;
...
...
@@ -181,7 +242,7 @@ class IssueCoinController extends BaseController
}
$data
=
[
'status'
=>
CoinIssueCoin
::
CANCEL_ISSUE
,
'status'
=>
$status
,
];
$model
->
setScenario
(
CoinIssueCoin
::
SCENARIOS_CANCEL
);
$model
->
load
(
$data
,
''
);
...
...
@@ -191,10 +252,117 @@ class IssueCoinController extends BaseController
goto
doEnd
;
}
if
(
$status
==
CoinIssueCoin
::
ALLOWED_ISSUE
)
{
$record_model
->
pre_query_transaction
=
'success'
;
$record_model
->
update
();
}
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
/**
* 手续费划转
* @return
*/
public
function
actionPayCharge
()
{
$issue_coin_model
=
CoinIssueCoin
::
find
()
->
select
(
'id'
)
->
where
([
'charge_pay'
=>
CoinIssueCoin
::
ALLOW_PAY
])
->
asArray
()
->
all
();
if
(
false
==
$issue_coin_model
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无手续费划转任务'
.
PHP_EOL
;
return
0
;
}
$issue_transfer
=
CoinIssueTransfer
::
find
()
->
where
([
'unissue'
=>
1
])
->
andWhere
([
'in'
,
'issue_coin_id'
,
ArrayHelper
::
getColumn
(
$issue_coin_model
,
'id'
)])
->
asArray
()
->
all
();
if
(
false
==
$issue_transfer
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无手续费划转任务'
.
PHP_EOL
;
return
0
;
}
$node
=
Yii
::
$app
->
params
[
'chain_nodes'
][
'STO'
];
$service
=
new
Chain33Service
(
$node
);
foreach
(
$issue_transfer
as
$val
)
{
$result
=
$service
->
sendTransaction
(
$val
[
'txhex'
]);
if
(
0
==
$result
[
'code'
])
{
$send_result
=
$result
[
'result'
];
$currentModel
=
CoinIssueTransfer
::
findOne
(
$val
[
'id'
]);
$currentModel
->
send_result
=
$send_result
;
$currentModel
->
msg
=
0
;
$currentModel
->
save
();
}
else
{
$currentModel
=
CoinIssueTransfer
::
findOne
(
$val
[
'id'
]);
$currentModel
->
msg
=
$result
[
'msg'
];
$currentModel
->
save
();
}
}
echo
date
(
'Y-m-d H:i:s'
)
.
'手续费划转任务完成'
.
PHP_EOL
;
return
0
;
}
/**
* 手续费划转状态确认
* @return
*/
public
function
actionPayChargeStatus
()
{
$unissue
=
-
1
;
$model
=
CoinIssueTransfer
::
find
()
->
where
([
'<>'
,
'send_result'
,
'0'
])
->
andWhere
([
'msg'
=>
'0'
])
->
asArray
()
->
all
();
if
(
empty
(
$model
))
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无需要确认的手续费划转状态'
.
PHP_EOL
;
return
0
;
}
$node
=
\Yii
::
$app
->
params
[
'chain_parallel'
][
'primary'
];
$service
=
new
Chain33Service
(
$node
);
foreach
(
$model
as
$val
)
{
$send_result
=
$val
[
'send_result'
];
$result
=
$service
->
QueryTransaction
(
$send_result
);
if
(
isset
(
$result
[
'result'
][
'actionName'
])
&&
'unknown'
==
$result
[
'result'
][
'actionName'
])
{
$query_result
=
'success'
;
$msg
=
'success'
;
goto
doEnd
;
}
else
if
(
isset
(
$result
[
'result'
][
'receipt'
][
'ty'
])
&&
2
==
$result
[
'result'
][
'receipt'
][
'ty'
])
{
$query_result
=
'success'
;
$msg
=
'success'
;
goto
doEnd
;
}
else
{
if
(
isset
(
$result
[
'result'
][
'receipt'
][
'logs'
]))
{
foreach
(
$result
[
'result'
][
'receipt'
][
'logs'
]
as
$log
)
{
if
(
isset
(
$log
[
'tyName'
])
&&
'LogErr'
==
$log
[
'tyName'
])
{
$msg
=
$log
[
'tyName'
];
break
;
}
}
}
else
{
$msg
=
$result
[
'msg'
];
}
$query_result
=
$result
[
'code'
];
goto
doEnd
;
}
doEnd
:
if
(
'success'
==
$msg
)
{
$unissue
=
0
;
$coin_issue_coin
=
CoinIssueCoin
::
find
()
->
where
([
'id'
=>
$val
[
'issue_coin_id'
]])
->
one
();
$coin_issue_coin
->
charge_pay
=
CoinIssueCoin
::
SUCCESS_PAY
;
$coin_issue_coin
->
save
();
}
$currentModel
=
CoinIssueTransfer
::
findOne
(
$val
[
'id'
]);
$currentModel
->
query_result
=
$query_result
;
if
(
$unissue
>
-
1
)
{
$currentModel
->
unissue
=
$unissue
;
}
$currentModel
->
msg
=
$msg
;
$currentModel
->
save
();
}
}
}
\ No newline at end of file
common/models/psources/CoinIssue
Transfer
.php
→
common/models/psources/CoinIssue
ChainRecord
.php
View file @
d6f42d10
...
...
@@ -3,10 +3,11 @@
namespace
common\models\psources
;
use
Yii
;
use
common\core\BaseActiveRecord
;
class
CoinIssue
Transfer
extends
Base
ActiveRecord
class
CoinIssue
ChainRecord
extends
Common
ActiveRecord
{
//定义场景
const
SCENARIOS_PRE_CREATE
=
'create'
;
public
static
function
getDb
()
{
...
...
@@ -15,26 +16,28 @@ class CoinIssueTransfer extends BaseActiveRecord
public
static
function
tableName
()
{
return
'{{%coin_issue_
transfer
}}'
;
return
'{{%coin_issue_
chain_record
}}'
;
}
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
public
function
rules
()
{
return
[
[[
'txhex'
,
'issue_coin_id'
],
'required'
],
[[
'send_result'
,
'query_result'
,
'msg'
],
'safe'
]
[[
'pre_create_tx'
,
'pre_send_transaction'
,
'pre_query_transaction'
,
'finish_tx'
,
'finish_send_transaction'
,
'finish_query_transaction'
,
'issue_coin_id'
],
'required'
],
[[
'issue_coin_id'
],
'integer'
],
[[
'finish_tx'
],
'safe'
]
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_
CREATE
=>
[
'txhex'
,
'issue_coin_id'
,
'send_result'
,
'query_result'
,
'msg
'
],
self
::
SCENARIOS_
PRE_CREATE
=>
[
'pre_create_tx'
,
'pre_send_transaction'
,
'pre_query_transaction'
,
'finish_tx'
,
'finish_send_transaction'
,
'finish_query_transaction'
,
'issue_coin_id
'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
}
public
function
getCoin
()
{
return
$this
->
hasOne
(
CoinIssueCoin
::
className
(),
[
'id'
=>
'issue_coin_id'
]);
}
}
\ No newline at end of file
common/models/psources/CoinIssueCoin.php
View file @
d6f42d10
...
...
@@ -20,6 +20,7 @@ class CoinIssueCoin extends CommonActiveRecord
const
SUCCESS_ISSUE
=
3
;
const
FAIL_ISSUE
=
4
;
const
CANCEL_ISSUE
=
5
;
const
ALLOWED_ISSUE
=
6
;
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
...
...
@@ -39,7 +40,7 @@ class CoinIssueCoin extends CommonActiveRecord
public
function
rules
()
{
return
[
[[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
,
'charge'
,
'step_one_tx'
],
'required'
],
[[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
,
'charge'
],
'required'
],
[[
'total'
,
'category'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
],
'integer'
],
[
'introduction'
,
'string'
,
'length'
=>
[
1
,
20
]],
[
'symbol'
,
'string'
,
'length'
=>
[
1
,
6
]],
...
...
@@ -89,7 +90,7 @@ class CoinIssueCoin extends CommonActiveRecord
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
,
'charge'
,
'step_one_tx'
,
'step_one_result'
],
self
::
SCENARIOS_CREATE
=>
[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
,
'charge'
],
self
::
SCENARIOS_UPDATE
=>
[
'status'
,
'msg'
],
self
::
SCENARIOS_CANCEL
=>
[
'status'
],
];
...
...
@@ -109,7 +110,6 @@ class CoinIssueCoin extends CommonActiveRecord
'msg'
=>
'失败原因'
,
'status'
=>
'状态'
,
'charge_unit_id'
=>
'手续费'
,
'step_one_tx'
=>
'签名'
,
];
}
...
...
@@ -144,4 +144,9 @@ class CoinIssueCoin extends CommonActiveRecord
{
return
$this
->
hasOne
(
CoinSupportedCoin
::
className
(),
[
'id'
=>
'charge_unit_id'
]);
}
public
function
getTransfer
()
{
return
$this
->
hasOne
(
CoinIssueChainRecord
::
className
(),
[
'issue_coin_id'
=>
'id'
]);
}
}
\ No newline at end of file
console/controllers/CrossChainController.php
View file @
d6f42d10
...
...
@@ -207,36 +207,5 @@ class CrossChainController extends Controller
$this
->
queryTransaction
(
$node_params
,
$result
[
'result'
][
'tx'
][
'next'
]);
}
return
$result
;
// if (isset($result['result']['actionName']) && 'unknown' == $result['result']['actionName']) {
// if (isset($result['result']['tx']['next'])) {
// $this->queryTransaction($node_params, $result['result']['tx']['next']);
// }
// }
//
// if (isset($result['result']['receipt']['ty']) && 2 == $result['result']['receipt']['ty']){
// if (isset($result['result']['tx']['next'])) {
// $this->queryTransaction($node_params, $result['result']['tx']['next']);
// }
// }
//
// return $result;
// if (isset($result['result']['receipt']) && is_array($result['result']['receipt']['logs'])){
// foreach ($result['result']['receipt']['logs'] as $log) {
// if (isset($log['tyName']) && 'logerr' == strtolower($log['tyName'])){
// return $result;
// }
// }
// }
// static $result = [];
// $service = new Chain33Service($node_params);
// $result = $service->QueryTransaction($send_result);
// echo json_encode($result) . PHP_EOL;
// if (isset($result['result']['tx']['next'])) {
// $this->queryTransaction($node_params, $result['result']['tx']['next']);
// }
// return $result;
}
}
console/controllers/IssueChainTransferController.php
0 → 100644
View file @
d6f42d10
<?php
namespace
console\controllers
;
use
Yii
;
use
yii\console\Controller
;
use
yii\helpers\ArrayHelper
;
use
common\models\psources\Coin
;
use
common\models\psources\CoinIssueChainRecord
;
use
common\models\psources\CoinIssueCoin
;
use
common\models\psources\CoinIssueRecord
;
use
common\models\psources\CoinIssueTransfer
;
use
common\service\chain33\Chain33Service
;
class
IssueChainTransferController
extends
Controller
{
/**
* 自动发币
* @param $step 1 生成预创建token 的交易 2 生成完成创建token 的交易
* @param $type 0 自动发布 1 人工发布
* @return
*/
public
function
actionSendTransaction
(
$step
,
$type
)
{
if
(
0
==
$type
)
{
$status
=
CoinIssueCoin
::
UN_AUDIT
;
$manual_review
=
Yii
::
$app
->
redis
->
get
(
'issue_chain_manual_review'
);
if
(
'close'
==
$manual_review
)
{
return
0
;
}
}
if
(
1
==
$type
)
{
$status
=
CoinIssueCoin
::
ALLOW_ISSUE
;
}
$issue_coin_model
=
CoinIssueCoin
::
find
()
->
select
(
'id'
)
->
where
([
'status'
=>
$status
])
->
asArray
()
->
all
();
if
(
false
==
$issue_coin_model
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无执行任务'
.
PHP_EOL
;
return
0
;
}
$issue_coin_ids
=
ArrayHelper
::
getColumn
(
$issue_coin_model
,
'id'
);
if
(
1
==
$step
)
{
$columns
=
[
'id'
,
'pre_create_tx'
,
'issue_coin_id'
];
$condition
=
[
'pre_send_transaction'
=>
'standby'
,
'pre_query_transaction'
=>
'standby'
];
}
if
(
2
==
$step
)
{
$columns
=
[
'id'
,
'finish_tx'
,
'issue_coin_id'
];
$condition
=
[
'pre_query_transaction'
=>
'success'
,
'finish_tx'
=>
'standby'
,
'finish_send_transaction'
=>
'standby'
,
'finish_query_transaction'
=>
'standby'
];
}
$model
=
CoinIssueChainRecord
::
find
()
->
select
(
$columns
)
->
where
(
$condition
)
->
andWhere
([
'in'
,
'issue_coin_id'
,
$issue_coin_ids
])
->
all
();
if
(
false
==
$model
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
' STEP: '
.
$step
.
'暂无交易计划'
.
PHP_EOL
;
return
0
;
}
$node
=
Yii
::
$app
->
params
[
'chain_nodes'
][
'STO'
];
$chain_service
=
new
Chain33Service
(
$node
);
foreach
(
$model
as
$val
)
{
//执行1.2构造
$result
=
$chain_service
->
createRawTokenFinishTx
(
$val
->
coin
->
symbol
,
$val
->
coin
->
owner
);
if
(
null
!=
$result
[
'error'
])
{
$status
=
CoinIssueCoin
::
FAIL_ISSUE
;
$data
=
[
'status'
=>
CoinIssueCoin
::
FAIL_ISSUE
,
'finish_query_transaction'
=>
$result
[
'msg'
]
];
goto
doEnd
;
}
$txHex
=
$result
[
'result'
];
$privkey
=
'72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e21'
;
#$privkey = $val->coin->chain->private_key;
$expire
=
'1m'
;
//执行1.2签名
$signRawTx
=
$chain_service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
$status
=
CoinIssueCoin
::
FAIL_ISSUE
;
$data
=
[
'finish_query_transaction'
=>
$signRawTx
[
'msg'
]
];
goto
doEnd
;
}
//执行1.2交易
$result
=
$chain_service
->
sendTransaction
(
$signRawTx
[
'result'
]);
if
(
0
!=
$result
[
'code'
])
{
$status
=
CoinIssueCoin
::
FAIL_ISSUE
;
$data
=
[
'finish_tx'
=>
$signRawTx
[
'result'
],
'finish_query_transaction'
=>
$result
[
'msg'
]
];
goto
doEnd
;
}
$status
=
CoinIssueCoin
::
SUCCESS_ISSUE
;
$data
=
[
'finish_tx'
=>
$signRawTx
[
'result'
],
'finish_send_transaction'
=>
$result
[
'result'
]
];
doEnd
:
CoinIssueChainRecord
::
updateAll
(
$data
,
[
'id'
=>
$val
->
id
,
]);
//交易失败
if
(
$status
==
CoinIssueCoin
::
FAIL_ISSUE
)
{
CoinIssueCoin
::
updateAll
([
'status'
=>
$status
],
[
'id'
=>
$val
->
coin
->
id
,
]);
}
}
echo
date
(
'Y-m-d H:i:s'
)
.
'执行完成'
.
PHP_EOL
;
return
0
;
}
public
function
actionQueryTransaction
(
$step
)
{
if
(
1
==
$step
)
{
$model
=
CoinIssueChainRecord
::
find
()
->
where
([
'<>'
,
'pre_send_transaction'
,
'standby'
])
->
all
();
}
if
(
2
==
$step
)
{
$model
=
CoinIssueChainRecord
::
find
()
->
where
([
'pre_send_transaction'
=>
'success'
])
->
andWhere
([
'<>'
,
'finish_send_transaction'
,
'standby'
])
->
all
();
}
if
(
false
==
$model
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
' STEP: '
.
$step
.
'暂无完成的发送交易'
.
PHP_EOL
;
return
0
;
}
$node
=
\Yii
::
$app
->
params
[
'chain_parallel'
][
'primary'
];
$service
=
new
Chain33Service
(
$node
);
foreach
(
$model
as
$val
)
{
if
(
1
==
$step
)
{
$result
=
$service
->
QueryTransaction
(
$val
->
pre_send_transaction
);
}
if
(
2
==
$step
)
{
$result
=
$service
->
QueryTransaction
(
$val
->
finish_send_transaction
);
}
if
(
isset
(
$result
[
'result'
][
'actionName'
])
&&
'unknown'
==
$result
[
'result'
][
'actionName'
])
{
$status
=
CoinIssueCoin
::
SUCCESS_ISSUE
;
$data
=
[
'finish_query_transaction'
=>
'success'
];
goto
doEnd
;
}
else
if
(
isset
(
$result
[
'result'
][
'receipt'
][
'ty'
])
&&
2
==
$result
[
'result'
][
'receipt'
][
'ty'
])
{
$status
=
CoinIssueCoin
::
SUCCESS_ISSUE
;
$data
=
[
'finish_query_transaction'
=>
'success'
];
goto
doEnd
;
}
else
{
$status
=
CoinIssueCoin
::
FAIL_ISSUE
;
if
(
isset
(
$result
[
'result'
][
'receipt'
][
'logs'
]))
{
foreach
(
$result
[
'result'
][
'receipt'
][
'logs'
]
as
$log
)
{
if
(
isset
(
$log
[
'tyName'
])
&&
'LogErr'
==
$log
[
'tyName'
])
{
$data
=
[
'finish_query_transaction'
=>
$log
[
'tyName'
]
];
break
;
}
}
}
else
{
$data
=
[
'finish_query_transaction'
=>
$result
[
'msg'
]
];
}
goto
doEnd
;
}
doEnd
:
CoinIssueChainRecord
::
updateAll
(
$data
,
[
'id'
=>
$val
->
id
,
]);
//查询后,交易失败
if
(
$status
==
CoinIssueCoin
::
FAIL_ISSUE
)
{
CoinIssueCoin
::
updateAll
([
'status'
=>
$status
],
[
'id'
=>
$val
->
coin
->
id
,
]);
}
//查询后,交易成功
if
(
$status
=
CoinIssueCoin
::
SUCCESS_ISSUE
)
{
CoinIssueCoin
::
updateAll
([
'status'
=>
$status
,
'charge_pay'
=>
CoinIssueCoin
::
SUCCESS_PAY
],
[
'id'
=>
$val
->
coin
->
id
,
]);
$params
=
[
'name'
=>
$val
->
coin
->
name
,
'symbol'
=>
$val
->
coin
->
symbol
,
'introduction'
=>
$val
->
coin
->
introduction
,
'total'
=>
(
int
)
$val
->
coin
->
total
,
'price'
=>
isset
(
$val
->
coin
->
platform
->
issue_charge
)
?
(
int
)
$val
->
coin
->
platform
->
issue_charge
:
0
,
'category'
=>
(
int
)
$val
->
coin
->
category
,
'owner'
=>
$val
->
coin
->
owner
,
'platform_id'
=>
$val
->
coin
->
platform_id
,
'platform'
=>
$val
->
coin
->
chain
->
platform
];
$this
->
syncRecord
(
$params
);
$this
->
syncCoin
(
$params
);
}
}
echo
date
(
'Y-m-d H:i:s'
)
.
'查询完成,同步完成'
.
PHP_EOL
;
return
0
;
}
public
function
syncCoin
(
$params
=
[])
{
$model_coin
=
Coin
::
find
()
->
where
([
'name'
=>
$params
[
'name'
],
'platform'
=>
$params
[
'platform'
]])
->
one
();
if
(
false
==
$model_coin
)
{
$model
=
new
Coin
();
$model
->
name
=
$params
[
'symbol'
];
$model
->
sid
=
$params
[
'name'
];
$model
->
platform
=
$params
[
'platform'
];
$model
->
chain
=
'BTY'
;
$model
->
treaty
=
1
;
$model
->
save
();
}
}
public
function
syncRecord
(
$params
=
[])
{
$coin_issue_record
=
new
CoinIssueRecord
();
$coin_issue_record
->
platform_id
=
$params
[
'platform_id'
];
$coin_issue_record
->
total
=
$params
[
'total'
];
$coin_issue_record
->
save
();
}
public
function
syncTransfer
(
$id
)
{
$issue_transfer
=
CoinIssueTransfer
::
find
()
->
where
([
'id'
=>
$id
])
->
one
();
$issue_transfer
->
unissue
=
0
;
$issue_transfer
->
save
();
}
}
\ No newline at end of file
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