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
30f735a0
Commit
30f735a0
authored
Nov 19, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/issue_coin' into 'master'
Feature/issue coin See merge request
!203
parents
f837e880
70bb9c95
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
2841 additions
and
67 deletions
+2841
-67
IssueChainController.php
api/controllers/IssueChainController.php
+72
-0
IssueCoinController.php
api/controllers/IssueCoinController.php
+466
-0
WalletController.php
api/controllers/WalletController.php
+61
-23
IndexAsset.php
backend/assets/coinSupportedCoin/IndexAsset.php
+17
-0
CoinSupportedCoinController.php
backend/controllers/CoinSupportedCoinController.php
+71
-0
WalletController.php
backend/controllers/WalletController.php
+6
-2
CoinPlatformForm.php
backend/models/coin/CoinPlatformForm.php
+9
-0
add.php
backend/views/coin-supported-coin/add.php
+12
-0
index.php
backend/views/coin-supported-coin/index.php
+34
-0
add.php
backend/views/wallet/add.php
+15
-0
edit.php
backend/views/wallet/edit.php
+12
-0
index.php
backend/views/wallet/index.php
+3
-6
index.js
backend/web/js/coin-supported-coin/index.js
+72
-0
LoginStatusAuthInterceptor.php
common/behaviors/LoginStatusAuthInterceptor.php
+2
-2
ErrorMessage.php
common/components/ErrorMessage.php
+39
-0
Tools.php
common/models/Tools.php
+334
-0
CoinIssueChainRecord.php
common/models/psources/CoinIssueChainRecord.php
+54
-0
CoinIssueCoin.php
common/models/psources/CoinIssueCoin.php
+197
-0
CoinIssueRecord.php
common/models/psources/CoinIssueRecord.php
+42
-0
CoinIssueRevokeRecord.php
common/models/psources/CoinIssueRevokeRecord.php
+43
-0
CoinPlatform.php
common/models/psources/CoinPlatform.php
+19
-3
CoinSupportedCoin.php
common/models/psources/CoinSupportedCoin.php
+78
-0
CommonActiveRecord.php
common/models/psources/CommonActiveRecord.php
+146
-0
Chain33Service.php
common/service/chain33/Chain33Service.php
+33
-0
CrossChainController.php
console/controllers/CrossChainController.php
+0
-31
IssueChainTransferController.php
console/controllers/IssueChainTransferController.php
+370
-0
IssueCoinController.php
console/controllers/IssueCoinController.php
+299
-0
TickerController.php
console/controllers/TickerController.php
+2
-0
IssueChainController.php
wallet/controllers/IssueChainController.php
+168
-0
IssueCoinController.php
wallet/controllers/IssueCoinController.php
+165
-0
No files found.
api/controllers/IssueChainController.php
0 → 100644
View file @
30f735a0
<?php
namespace
api\controllers
;
use
Yii
;
use
api\base\BaseController
;
use
common\models\psources\CoinPlatform
;
class
IssueChainController
extends
BaseController
{
/**
* 可发行链列表
* @return array
*/
public
function
actionIndex
()
{
$data
=
null
;
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
if
(
empty
(
$platform_id
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
if
(
1
==
$platform_id
)
{
$chain_model
=
CoinPlatform
::
find
()
->
all
();
}
else
{
$chain_model
=
CoinPlatform
::
find
()
->
where
([
'id'
=>
$platform_id
])
->
all
();
}
if
(
false
==
$chain_model
)
{
$msg
=
'不存在的链'
;
$code
=
-
1
;
goto
doEnd
;
}
foreach
(
$chain_model
as
&
$val
)
{
$val
->
chain_name
=
isset
(
$val
->
chain
->
platform
)
?
$val
->
chain
->
platform
:
''
;
$val
->
issue_charge
=
(
float
)
sprintf
(
"%0.3f"
,
$val
->
issue_charge
);
$val
->
charge_unit
=
isset
(
$val
->
gas
->
coin_name
)
?
$val
->
gas
->
coin_name
:
''
;
unset
(
$val
->
download_url
);
unset
(
$val
->
introduce
);
unset
(
$val
->
create_time
);
unset
(
$val
->
update_time
);
}
$msg
=
'ok'
;
$code
=
0
;
$data
=
is_array
(
$chain_model
)
?
$chain_model
:
[
$chain_model
];
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
/**
* 人工审核状态
* @return array
*/
public
function
actionManualReviewStatus
()
{
$status
=
0
;
$manual_review
=
Yii
::
$app
->
redis
->
get
(
'issue_chain_manual_review'
);
if
(
false
==
$manual_review
||
'open'
==
$manual_review
)
{
$status
=
1
;
}
return
[
'code'
=>
0
,
'data'
=>
$status
];
}
}
\ No newline at end of file
api/controllers/IssueCoinController.php
0 → 100644
View file @
30f735a0
<?php
namespace
api\controllers
;
use
common\components\ErrorMessage
;
use
common\models\psources\CoinIssueRevokeRecord
;
use
common\service\chain33\Chain33Service
;
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
{
public
function
actionValidate
()
{
$data
=
null
;
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
if
(
empty
(
$platform_id
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$coin_platform
=
CoinPlatform
::
findOne
(
$platform_id
);
if
(
false
==
$coin_platform
)
{
$msg
=
'参数错误'
;
$code
=
-
1
;
goto
doEnd
;
}
$result
=
Yii
::
$app
->
request
->
post
();
$chain_id
=
isset
(
$result
[
'chain_id'
])
?
$result
[
'chain_id'
]
:
0
;
if
(
false
==
$chain_id
)
{
$msg
=
'不存在的链'
;
$code
=
-
1
;
goto
doEnd
;
}
$result
=
[
'name'
=>
isset
(
$result
[
'name'
])
?
$result
[
'name'
]
:
''
,
'symbol'
=>
isset
(
$result
[
'symbol'
])
?
$result
[
'symbol'
]
:
''
,
'total'
=>
isset
(
$result
[
'total'
])
?
$result
[
'total'
]
:
''
,
'owner'
=>
isset
(
$result
[
'owner'
])
?
$result
[
'owner'
]
:
''
,
'introduction'
=>
isset
(
$result
[
'introduction'
])
?
$result
[
'introduction'
]
:
''
,
'category'
=>
isset
(
$result
[
'category'
])
?
$result
[
'category'
]
:
0
,
'type'
=>
isset
(
$result
[
'type'
])
?
$result
[
'type'
]
:
0
,
'platform_id'
=>
$platform_id
,
'chain_id'
=>
$chain_id
,
'charge_unit_id'
=>
isset
(
$result
[
'charge_unit_id'
])
?
$result
[
'charge_unit_id'
]
:
''
,
'charge'
=>
$coin_platform
->
issue_charge
,
];
$model
=
new
CoinIssueCoin
();
$model
->
setScenario
(
CoinIssueCoin
::
SCENARIOS_CREATE
);
$model
->
load
(
$result
,
''
);
if
(
!
$model
->
validate
())
{
$msg
=
$model
->
errors
;
$code
=
-
1
;
goto
doEnd
;
}
$msg
=
'ok'
;
$code
=
0
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
/**
* 发行申请
* @return array
*/
public
function
actionApply
()
{
$data
=
null
;
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
if
(
empty
(
$platform_id
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$coin_platform
=
CoinPlatform
::
findOne
(
$platform_id
);
if
(
false
==
$coin_platform
)
{
$msg
=
'参数错误'
;
$code
=
-
1
;
goto
doEnd
;
}
$model
=
new
CoinIssueCoin
();
$model
->
setScenario
(
CoinIssueCoin
::
SCENARIOS_CREATE
);
if
(
!
Yii
::
$app
->
request
->
isPost
)
{
$msg
=
'错误的请求方式'
;
$code
=
-
1
;
goto
doEnd
;
}
$result
=
Yii
::
$app
->
request
->
post
();
$chain_id
=
isset
(
$result
[
'chain_id'
])
?
$result
[
'chain_id'
]
:
0
;
if
(
false
==
$chain_id
)
{
$msg
=
'不存在的链'
;
$code
=
-
1
;
goto
doEnd
;
}
$pre_create_tx
=
isset
(
$result
[
'pre_create_tx'
])
?
$result
[
'pre_create_tx'
]
:
''
;
$pre_send_transaction
=
isset
(
$result
[
'pre_send_transaction'
])
?
$result
[
'pre_send_transaction'
]
:
''
;
if
(
false
==
$pre_create_tx
||
false
==
$pre_send_transaction
)
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$result
=
[
'name'
=>
isset
(
$result
[
'name'
])
?
$result
[
'name'
]
:
''
,
'symbol'
=>
isset
(
$result
[
'symbol'
])
?
strtoupper
(
$result
[
'symbol'
])
:
''
,
'total'
=>
isset
(
$result
[
'total'
])
?
$result
[
'total'
]
:
''
,
'owner'
=>
isset
(
$result
[
'owner'
])
?
$result
[
'owner'
]
:
''
,
'introduction'
=>
isset
(
$result
[
'introduction'
])
?
$result
[
'introduction'
]
:
''
,
'category'
=>
isset
(
$result
[
'category'
])
?
$result
[
'category'
]
:
0
,
'type'
=>
isset
(
$result
[
'type'
])
?
$result
[
'type'
]
:
0
,
'platform_id'
=>
$platform_id
,
'chain_id'
=>
$chain_id
,
'charge_unit_id'
=>
isset
(
$result
[
'charge_unit_id'
])
?
$result
[
'charge_unit_id'
]
:
''
,
'charge'
=>
$coin_platform
->
issue_charge
,
];
$model
->
load
(
$result
,
''
);
if
(
!
$model
->
save
())
{
$msg
=
$model
->
errors
;
$code
=
-
1
;
goto
doEnd
;
}
$msg
=
'ok'
;
$code
=
0
;
$data
=
$model
->
getPrimaryKey
();
$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'
=>
$data
,
];
$transfer_model
=
new
CoinIssueChainRecord
();
$transfer_model
->
setScenario
(
CoinIssueChainRecord
::
SCENARIOS_PRE_CREATE
);
$transfer_model
->
load
(
$params
,
''
);
$transfer_model
->
save
();
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
/**
* 申请列表
* @param integer page
* @param integer size
* @return array
*/
public
function
actionApplyList
()
{
$data
=
null
;
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
$address
=
Yii
::
$app
->
request
->
get
(
'address'
,
''
);
if
(
empty
(
$platform_id
)
||
empty
(
$address
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$page
=
\Yii
::
$app
->
request
->
get
(
'page'
,
1
);
$size
=
\Yii
::
$app
->
request
->
get
(
'size'
,
5
);
$query
=
CoinIssueCoin
::
find
()
->
select
(
'id, name, symbol, type, total, create_time, status, chain_id'
)
->
where
([
'owner'
=>
$address
])
->
andWhere
([
'in'
,
'status'
,
[
CoinIssueCoin
::
STATUS_PEDDING
,
CoinIssueCoin
::
STATUS_CANCEL_SUCCESS
,
CoinIssueCoin
::
STATUS_CANCEL_FAILED
,
CoinIssueCoin
::
STATUS_CONFIRM
,
CoinIssueCoin
::
STATUS_ALLOW
,
CoinIssueCoin
::
STATUS_REFUSE
,
CoinIssueCoin
::
STATUS_SUCCESS
,
CoinIssueCoin
::
STATUS_FAILED
]])
->
orderBy
(
'create_time desc'
);
$countQuery
=
clone
$query
;
$models
=
$query
->
offset
((
$page
-
1
)
*
$size
)
->
limit
(
$size
)
->
all
();
$pages
=
new
Pagination
([
'totalCount'
=>
$countQuery
->
count
(),
'pageSize'
=>
$size
]);
foreach
(
$models
as
&
$val
)
{
$val
->
chain_id
=
$val
->
chain
->
platform
;
$val
->
total
=
(
int
)
$val
->
total
*
1e8
;
}
$data
=
[
'list'
=>
$models
,
'page'
=>
[
'pageCount'
=>
$pages
->
pageCount
,
'pageSize'
=>
$size
,
'currentPage'
=>
$page
,
]
];
$msg
=
'ok'
;
$code
=
0
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
/**
* 申请详情
* @param integer id
* @return array
*/
public
function
actionApplyDetail
()
{
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
0
);
$data
=
null
;
if
(
empty
(
$id
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$data
=
CoinIssueCoin
::
find
()
->
where
([
'id'
=>
$id
])
->
one
();
if
(
false
==
$data
)
{
$msg
=
'不存在的记录'
;
$code
=
-
1
;
goto
doEnd
;
}
$data
->
total
=
(
int
)
$data
->
total
*
1e8
;
$data
->
chain_name
=
$data
->
chain
->
platform
;
$data
->
issue_charge
=
rtrim
(
sprintf
(
'%.3f'
,
floatval
(
$data
->
charge
)),
'0'
);
$data
->
charge_unit
=
isset
(
$data
->
gas
->
coin_name
)
?
$data
->
gas
->
coin_name
:
''
;
$code
=
0
;
$msg
=
'success'
;
if
(
CoinIssueCoin
::
STATUS_FAILED
==
$data
->
status
)
{
$code
=
-
1
;
if
(
$data
->
transfer
->
pre_query_transaction
!=
'success'
)
{
$msg
=
'预发行失败。失败原因:'
.
ErrorMessage
::
getMessage
(
$data
->
transfer
->
pre_query_transaction
);
}
if
(
$data
->
transfer
->
pre_query_transaction
==
'success'
&&
$data
->
transfer
->
finish_query_transaction
!=
'success'
)
{
$msg
=
'发行失败。失败原因:'
.
ErrorMessage
::
getMessage
(
$data
->
transfer
->
finish_query_transaction
);
}
}
if
(
CoinIssueCoin
::
STATUS_REFUSE
==
$data
->
status
)
{
$code
=
-
1
;
$msg
=
'发行失败。失败原因:'
.
$data
->
transfer
->
finish_query_transaction
;
}
if
(
CoinIssueCoin
::
STATUS_CANCEL_FAILED
==
$data
->
status
)
{
$code
=
-
1
;
$msg
=
'撤消失败。失败原因:'
.
ErrorMessage
::
getMessage
(
$data
->
revoke
->
revoke_query_transaction
);
}
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
/**
* 申请撤消/确认
* @param integer id
* @param string pre_create_tx
* @param string pre_send_transaction
* @return array
*/
public
function
actionSendTransfer
()
{
$data
=
null
;
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
if
(
empty
(
$platform_id
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$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
* @return array
*/
public
function
actionVerify
()
{
$data
=
null
;
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
if
(
empty
(
$platform_id
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$params
=
Yii
::
$app
->
request
->
post
();
$id
=
isset
(
$params
[
'id'
])
?
(
int
)
$params
[
'id'
]
:
0
;
if
(
false
==
$id
)
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$model
=
CoinIssueCoin
::
findOne
(
$id
);
if
(
false
==
$model
)
{
$msg
=
'不存在的记录'
;
$code
=
-
1
;
goto
doEnd
;
}
if
(
CoinIssueCoin
::
STATUS_PEDDING
!=
$model
->
status
)
{
$msg
=
'该状态下禁止发行'
;
$code
=
-
1
;
goto
doEnd
;
}
$record_model
=
CoinIssueChainRecord
::
find
()
->
where
([
'issue_coin_id'
=>
$id
])
->
one
();
if
(
false
==
$record_model
)
{
$msg
=
'交易记录不存在'
;
$code
=
-
1
;
goto
doEnd
;
}
$data
=
[
'status'
=>
CoinIssueCoin
::
STATUS_CONFIRM
,
];
$model
->
setScenario
(
CoinIssueCoin
::
SCENARIOS_CANCEL
);
$model
->
load
(
$data
,
''
);
if
(
!
$model
->
save
())
{
$msg
=
current
(
$model
->
firstErrors
);
$code
=
-
1
;
goto
doEnd
;
}
$record_model
->
pre_query_transaction
=
'success'
;
$record_model
->
update
();
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
/**
* 申请撤消
* @param integer id
* @param string revoke_tx
* @param string revoke_send_transaction
* @return array
*/
public
function
actionRevoke
()
{
$data
=
null
;
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
if
(
empty
(
$platform_id
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$params
=
Yii
::
$app
->
request
->
post
();
$id
=
isset
(
$params
[
'id'
])
?
(
int
)
$params
[
'id'
]
:
0
;
$revoke_tx
=
isset
(
$params
[
'revoke_tx'
])
?
$params
[
'revoke_tx'
]
:
''
;
$revoke_send_transaction
=
isset
(
$params
[
'revoke_send_transaction'
])
?
$params
[
'revoke_send_transaction'
]
:
''
;
if
(
false
==
$revoke_tx
||
false
==
$revoke_send_transaction
||
false
==
$id
)
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$issue_coin
=
CoinIssueCoin
::
findOne
(
$id
);
if
(
false
==
$issue_coin
)
{
$msg
=
'不存在的记录'
;
$code
=
-
1
;
goto
doEnd
;
}
$isExist
=
CoinIssueRevokeRecord
::
find
()
->
where
([
'issue_coin_id'
=>
$id
])
->
count
();
if
(
0
!=
$isExist
)
{
$msg
=
'撤消记录已存在'
;
$code
=
-
1
;
goto
doEnd
;
}
$issue_coin_data
=
[
'status'
=>
CoinIssueCoin
::
STATUS_CANCEL
,
];
$issue_coin
->
setScenario
(
CoinIssueCoin
::
SCENARIOS_CANCEL
);
$issue_coin
->
load
(
$issue_coin_data
,
''
);
if
(
!
$issue_coin
->
save
())
{
$msg
=
current
(
$issue_coin
->
firstErrors
);
$code
=
-
1
;
goto
doEnd
;
}
$issue_revoke_record
=
new
CoinIssueRevokeRecord
();
$issue_revoke_data
=
[
'issue_coin_id'
=>
$id
,
'revoke_tx'
=>
$revoke_tx
,
'revoke_send_transaction'
=>
$revoke_send_transaction
,
'revoke_query_transaction'
=>
'standby'
,
];
$issue_revoke_record
->
setScenario
(
CoinIssueRevokeRecord
::
SCENARIOS_CREATE
);
$issue_revoke_record
->
load
(
$issue_revoke_data
,
''
);
$issue_revoke_record
->
save
();
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
}
\ No newline at end of file
api/controllers/WalletController.php
View file @
30f735a0
...
...
@@ -4,6 +4,7 @@ namespace api\controllers;
use
api\base\BaseController
;
use
common\models\psources\CoinAirDropTrade
;
use
common\models\psources\CoinIssueTransfer
;
use
common\models\psources\CoinPlatform
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
...
...
@@ -16,7 +17,7 @@ class WalletController extends BaseController
$code
=
0
;
$msg
=
'success'
;
$platform_id
=
Yii
::
$app
->
request
->
get
(
'platform_id'
,
''
);
if
(
empty
(
$platform_id
))
{
if
(
empty
(
$platform_id
))
{
$msg
=
'参数不能为空'
;
$code
=
-
1
;
$data
=
null
;
...
...
@@ -24,7 +25,7 @@ class WalletController extends BaseController
}
$data
=
CoinPlatform
::
find
()
->
select
(
"name, download_url, introduce"
)
->
where
([
'id'
=>
$platform_id
])
->
asArray
()
->
one
();
if
(
empty
(
$data
))
{
if
(
empty
(
$data
))
{
$msg
=
'数据不存在'
;
$data
=
null
;
$code
=
-
1
;
...
...
@@ -39,16 +40,16 @@ class WalletController extends BaseController
public
function
actionGameTradeUpdate
()
{
$coinAirDropTrade
=
CoinAirDropTrade
::
find
()
->
where
([
'attach'
=>
2
,
'msg'
=>
'0'
])
->
limit
(
30
)
->
all
();
foreach
(
$coinAirDropTrade
as
$val
){
$coinAirDropTrade
=
CoinAirDropTrade
::
find
()
->
where
([
'attach'
=>
2
,
'msg'
=>
'0'
])
->
limit
(
30
)
->
all
();
foreach
(
$coinAirDropTrade
as
$val
)
{
$fee
=
100000
;
$amount
=
1
*
1e8
;
$execer
=
'coins'
;
$note
=
''
;
$service
=
new
Chain33Service
();
$createRawTransaction
=
$service
->
createRawTransaction
(
$val
->
coins_address
,
$amount
,
$fee
,
$note
,
$execer
);
if
(
0
!=
$createRawTransaction
[
'code'
])
{
$createRawTransaction
=
$service
->
createRawTransaction
(
$val
->
coins_address
,
$amount
,
$fee
,
$note
,
$execer
);
if
(
0
!=
$createRawTransaction
[
'code'
])
{
continue
;
}
...
...
@@ -57,13 +58,13 @@ class WalletController extends BaseController
$expire
=
'1m'
;
$signRawTx
=
$service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
if
(
0
!=
$signRawTx
[
'code'
])
{
continue
;
}
$sign_str
=
$signRawTx
[
'result'
];
$result
=
$service
->
sendTransaction
(
$sign_str
);
if
(
0
!=
$result
[
'code'
])
{
if
(
0
!=
$result
[
'code'
])
{
continue
;
}
$currentModel
=
CoinAirDropTrade
::
findOne
(
$val
->
id
);
...
...
@@ -77,23 +78,59 @@ class WalletController extends BaseController
public
function
actionGetBalance
()
{
$coinAirDropTrade
=
CoinAirDropTrade
::
find
()
->
where
([
'balance'
=>
0
])
->
limit
(
60
)
->
all
();
$address
=
[];
foreach
(
$coinAirDropTrade
as
$val
){
$address
[]
=
$val
->
coins_address
;
$code
=
0
;
$msg
=
'success'
;
$platform_id
=
Yii
::
$app
->
request
->
get
(
'platform_id'
,
''
);
$token
=
Yii
::
$app
->
request
->
get
(
'address'
,
''
);
if
(
empty
(
$platform_id
)
||
empty
(
$token
))
{
$msg
=
'参数不能为空'
;
$code
=
-
1
;
$data
=
null
;
goto
doEnd
;
}
$service
=
new
Chain33Service
();
$node
=
Yii
::
$app
->
params
[
'chain_parallel'
][
'primary'
];
$service
=
new
Chain33Service
(
$node
);
$address
[]
=
$token
;
$execer
=
'coins'
;
$result
=
$service
->
getBalance
(
$address
,
$execer
);
if
(
0
==
$result
[
'code'
]){
$result_balance
=
$result
[
'result'
];
foreach
(
$result_balance
as
$val
){
$coinAirDropTrade
=
CoinAirDropTrade
::
find
()
->
where
([
'coins_address'
=>
$val
[
'addr'
]])
->
one
();
if
(
empty
(
$coinAirDropTrade
))
continue
;
$coinAirDropTrade
->
balance
=
$val
[
'balance'
];
$coinAirDropTrade
->
save
();
}
$result
=
$service
->
getBalance
(
$address
,
$execer
);
if
(
0
!==
$result
[
'code'
])
{
$msg
=
$result
[
'msg'
];
$code
=
-
1
;
$data
=
null
;
goto
doEnd
;
}
return
[
'code'
=>
1
,
'msg'
=>
'ok'
];
$data
=
$result
[
'result'
];
doEnd
:
return
[
'code'
=>
$code
,
'data'
=>
$data
,
'msg'
=>
$msg
];
}
public
function
actionTransfer
()
{
$code
=
-
1
;
$request
=
Yii
::
$app
->
request
;
$post
=
$request
->
post
();
if
(
!
$request
->
isPost
)
{
$msg
=
'请求错误!'
;
goto
doEnd
;
}
$txhex
=
isset
(
$post
[
'txhex'
])
?
$post
[
'txhex'
]
:
''
;
$issue_coin_id
=
isset
(
$post
[
'issue_coin_id'
])
?
$post
[
'issue_coin_id'
]
:
0
;
if
(
false
==
$txhex
||
false
==
$issue_coin_id
)
{
$msg
=
'参数错误!'
;
goto
doEnd
;
}
$model
=
new
CoinIssueTransfer
();
$data
[
'txhex'
]
=
$txhex
;
$data
[
'issue_coin_id'
]
=
(
int
)
$issue_coin_id
;
$model
->
load
(
$data
,
''
);
$model
->
save
();
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
}
\ No newline at end of file
backend/assets/coinSupportedCoin/IndexAsset.php
0 → 100644
View file @
30f735a0
<?php
namespace
backend\assets\coinSupportedCoin
;
use
yii\web\AssetBundle
;
use
yii\web\View
;
class
IndexAsset
extends
AssetBundle
{
public
$sourcePath
=
'@backend/web/js/coin-supported-coin'
;
public
$js
=
[
'index.js'
,
];
public
$jsOptions
=
[
'position'
=>
View
::
POS_END
,
];
}
backend/controllers/CoinSupportedCoinController.php
0 → 100644
View file @
30f735a0
<?php
namespace
backend\controllers
;
use
common\models\psources\CoinSupportedCoin
;
use
Yii
;
class
CoinSupportedCoinController
extends
BaseController
{
public
function
actionList
()
{
$platform_id
=
Yii
::
$app
->
request
->
get
(
'id'
);
if
(
Yii
::
$app
->
request
->
isAjax
)
{
Yii
::
$app
->
response
->
format
=
'json'
;
$request
=
Yii
::
$app
->
request
;
$page
=
$request
->
get
(
'page'
,
1
);
$limit
=
$request
->
get
(
'limit'
,
10
);
$id
=
$request
->
get
(
'id'
,
''
);
$where
=
[];
if
(
$id
)
{
$where
[]
=
[
'platform_id'
=>
$id
];
}
$data
=
CoinSupportedCoin
::
getList
(
$page
,
$limit
,
$where
);
$data
[
'code'
]
=
0
;
Yii
::
$app
->
response
->
format
=
'json'
;
return
$data
;
}
return
$this
->
render
(
'index'
,
[
'platform_id'
=>
$platform_id
]);
}
public
function
actionAdd
()
{
$this
->
layout
=
false
;
$model
=
new
CoinSupportedCoin
();
$model
->
setScenario
(
CoinSupportedCoin
::
SCENARIOS_CREATE
);
if
(
Yii
::
$app
->
request
->
isPost
)
{
Yii
::
$app
->
response
->
format
=
'json'
;
$data
=
Yii
::
$app
->
request
->
post
();
if
(
$model
->
load
(
$data
,
''
)
&&
$model
->
save
())
{
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
}
$error
=
$model
->
errors
;
if
(
$error
)
{
return
[
'code'
=>
-
1
,
'msg'
=>
current
(
$model
->
firstErrors
)];
}
}
$platform_id
=
Yii
::
$app
->
request
->
get
(
'platform_id'
);
return
$this
->
render
(
'add'
,
[
'model'
=>
$model
,
'platform_id'
=>
$platform_id
]);
}
public
function
actionDelete
()
{
Yii
::
$app
->
response
->
format
=
'json'
;
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
0
);
if
(
$id
)
{
$model
=
CoinSupportedCoin
::
findOne
([
'id'
=>
$id
]);
if
(
$model
)
{
try
{
$model
->
delete
();
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
}
catch
(
\Throwable
$t
)
{
return
[
'code'
=>
$t
->
getCode
(),
'msg'
=>
$t
->
getMessage
()];
}
}
}
return
[
'code'
=>
-
1
,
'msg'
=>
'删除失败'
];
}
}
\ No newline at end of file
backend/controllers/WalletController.php
View file @
30f735a0
...
...
@@ -10,6 +10,7 @@ namespace backend\controllers;
use
backend\models\coin\CoinPlatformForm
;
use
common\models\psources\CoinPlatform
;
use
common\models\psources\CoinPlatformWithHold
;
use
Yii
;
...
...
@@ -39,6 +40,7 @@ class WalletController extends BaseController
{
$model
=
new
CoinPlatformForm
();
$model
->
scenario
=
'add'
;
$platform_withhold
=
CoinPlatformWithHold
::
find
()
->
select
(
'id, platform'
)
->
orderBy
(
'platform'
)
->
asArray
()
->
all
();
if
(
Yii
::
$app
->
request
->
isPost
)
{
$data
=
Yii
::
$app
->
request
->
post
();
if
(
$model
->
load
(
$data
,
''
)
&&
$model
->
validate
())
{
...
...
@@ -60,7 +62,8 @@ class WalletController extends BaseController
}
$this
->
error
(
$errors
,
Yii
::
$app
->
request
->
getReferrer
());
}
return
$this
->
render
(
'add'
,
[
'model'
=>
$model
]);
return
$this
->
render
(
'add'
,
[
'model'
=>
$model
,
'platform_withhold'
=>
$platform_withhold
]);
}
public
function
actionEdit
()
...
...
@@ -90,9 +93,10 @@ class WalletController extends BaseController
}
elseif
(
Yii
::
$app
->
request
->
isGet
)
{
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
null
);
if
(
$id
)
{
$platform_withhold
=
CoinPlatformWithHold
::
find
()
->
select
(
'id, platform'
)
->
orderBy
(
'platform'
)
->
asArray
()
->
all
();
$coin
=
CoinPlatform
::
findOne
([
'id'
=>
$id
]);
$this
->
layout
=
false
;
return
$this
->
render
(
'edit'
,
[
'model'
=>
$coin
]);
return
$this
->
render
(
'edit'
,
[
'model'
=>
$coin
,
'platform_withhold'
=>
$platform_withhold
]);
}
}
}
...
...
backend/models/coin/CoinPlatformForm.php
View file @
30f735a0
...
...
@@ -14,6 +14,7 @@ class CoinPlatformForm extends Model
{
public
$id
;
public
$name
;
public
$chain_id
;
public
$download_url
;
public
$introduce
;
...
...
@@ -27,6 +28,7 @@ class CoinPlatformForm extends Model
return
[
[[
'name'
],
'required'
,
'on'
=>
'add'
],
[[
'id'
,
'name'
],
'required'
,
'on'
=>
'update'
],
[[
'chain_id'
,
'download_url'
,
'introduce'
],
'safe'
]
];
}
...
...
@@ -34,6 +36,7 @@ class CoinPlatformForm extends Model
{
return
[
'id'
=>
'ID'
,
'chain_id'
=>
'所属链'
,
'name'
=>
'名称'
,
'download_url'
=>
'下载链接'
,
'introduce'
=>
'介绍'
...
...
@@ -46,10 +49,16 @@ class CoinPlatformForm extends Model
'add'
=>
[
'id'
,
'name'
,
'chain_id'
,
'download_url'
,
'introduce'
],
'update'
=>
[
'id'
,
'name'
,
'chain_id'
,
'download_url'
,
'introduce'
],
];
}
...
...
backend/views/coin-supported-coin/add.php
0 → 100644
View file @
30f735a0
<div
style=
"padding: 5px 20px;"
>
<br>
<form
id=
"addData"
>
<input
name=
"_csrf"
type=
"hidden"
value=
"
<?=
Yii
::
$app
->
request
->
getCsrfToken
()
?>
"
>
<div
class=
"input-group my-group"
>
<span
class=
"input-group-addon"
>
币种名称
</span>
<input
name=
"coin_name"
type=
"text"
class=
"form-control"
lay-verify=
"required"
>
</div>
<input
class=
"layui-input"
name=
"platform_id"
type=
"hidden"
value=
"
<?=
$platform_id
?>
"
lay-verify=
"required"
>
</form>
</div>
backend/views/coin-supported-coin/index.php
0 → 100644
View file @
30f735a0
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午9:59
*/
use
backend\assets\coinSupportedCoin\IndexAsset
;
IndexAsset
::
register
(
$this
);
?>
<style>
.layui-table-tips-c
{
padding
:
0px
;
}
</style>
<h4>
货币列表
</h4>
<div
class=
"layui-row"
>
<div
class=
"layui-col-md1"
>
<button
class=
"layui-btn layui-btn-sm"
lay-event=
"add"
id=
"add"
>
单笔添加
</button>
</div>
</div>
<input
id=
"platform_id"
type=
"hidden"
value=
"
<?=
$platform_id
?>
"
>
<div
class=
"layui-row"
>
<table
class=
"layui-table"
id=
"table1"
lay-filter=
"table1"
></table>
</div>
<script
type=
"text/html"
id=
"operationTpl"
>
<
a
lay
-
event
=
"delete"
>
<
button
class
=
"layui-btn layui-btn-sm layui-btn-danger"
><
i
class
=
"layui-icon"
>&
#
xe640
;
<
/i></
button
>
<
/a
>
</script>
backend/views/wallet/add.php
View file @
30f735a0
...
...
@@ -23,6 +23,18 @@
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
所属链
</label>
<div
class=
"layui-input-block"
>
<select
name=
"chain_id"
>
<?php
foreach
(
$platform_withhold
as
$val
)
:
?>
<option
value=
"
<?=
$val
[
'id'
]
?>
"
<?php
if
(
$model
->
chain_id
==
$val
[
'id'
])
{
echo
"selected"
;
}
?>
>
<?=
$val
[
'platform'
]
?>
</option>
<?php
endforeach
;
?>
</select>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
下载地址
</label>
<div
class=
"layui-input-block"
>
<input
class=
"layui-input"
name=
"download_url"
value=
"
<?=
$model
->
download_url
?>
"
>
...
...
@@ -40,3 +52,6 @@
</form>
</div>
</div>
<script>
layui
.
form
.
render
();
</script>
backend/views/wallet/edit.php
View file @
30f735a0
...
...
@@ -24,6 +24,18 @@
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
所属链
</label>
<div
class=
"layui-input-block"
>
<select
name=
"chain_id"
>
<?php
foreach
(
$platform_withhold
as
$val
)
:
?>
<option
value=
"
<?=
$val
[
'id'
]
?>
"
<?php
if
(
$model
->
chain_id
==
$val
[
'id'
])
{
echo
"selected"
;
}
?>
>
<?=
$val
[
'platform'
]
?>
</option>
<?php
endforeach
;
?>
</select>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
下载地址
</label>
<div
class=
"layui-input-block"
>
<input
class=
"layui-input"
name=
"download_url"
value=
"
<?=
$model
->
download_url
?>
"
>
...
...
backend/views/wallet/index.php
View file @
30f735a0
...
...
@@ -42,10 +42,7 @@ IndexAsset::register($this);
</div>
<script
type=
"text/html"
id=
"operationTpl"
>
<
a
lay
-
event
=
"edit"
>
<
button
class
=
"layui-btn layui-btn-sm"
><
i
class
=
"layui-icon"
>&
#
xe642
;
<
/i></
button
>
<
/a
>
<
a
lay
-
event
=
"delete"
>
<
button
class
=
"layui-btn layui-btn-sm layui-btn-danger"
><
i
class
=
"layui-icon"
>&
#
xe640
;
<
/i></
button
>
<
/a
>
<
a
class
=
"layui-btn layui-btn-xs"
lay
-
event
=
"edit"
>
编辑
<
/a
>
<
a
class
=
"layui-btn layui-btn-xs"
lay
-
event
=
"delete"
>
删除
<
/a
>
<
a
class
=
"layui-btn layui-btn-primary layui-btn-xs"
href
=
"/admin/coin-supported-coin/list?id={{d.id}}"
>
支持发行货币种类
<
/a
>
</script>
backend/web/js/coin-supported-coin/index.js
0 → 100644
View file @
30f735a0
/**
* @author rlgyzhcn@qq.com
*/
var
table
=
layui
.
table
;
var
form
=
layui
.
form
;
var
layer
=
layui
.
layer
;
form
.
render
();
var
platform_id
=
$
(
"#platform_id"
).
val
();
var
tableIns
=
table
.
render
({
elem
:
"#table1"
,
url
:
'/admin/coin-supported-coin/list?id='
+
platform_id
,
limit
:
10
,
page
:
1
,
loading
:
true
,
cols
:
[[
{
field
:
'id'
,
title
:
'ID'
},
{
field
:
'coin_name'
,
title
:
'货币对'
},
{
field
:
'create_time'
,
title
:
'创建时间'
},
{
field
:
'id'
,
title
:
'操作'
,
templet
:
'#operationTpl'
}
]],
});
form
.
on
(
'submit(form1)'
,
function
(
data
)
{
table
.
reload
(
"table1"
,
{
where
:
data
.
field
,
page
:
{
curr
:
1
},
});
return
false
;
});
//监听单元格事件
table
.
on
(
'tool(table1)'
,
function
(
obj
)
{
var
data
=
obj
.
data
;
if
(
obj
.
event
==
'delete'
)
{
layer
.
confirm
(
'真的要删除'
+
data
.
coin_name
+
'吗?'
,
{
icon
:
3
,
title
:
'删除'
},
function
(
index
)
{
layer
.
close
(
index
);
//向服务端发送删除指令
$
.
get
(
'/admin/coin-supported-coin/delete?id='
+
obj
.
data
.
id
,
function
(
data
,
status
)
{
if
(
data
.
code
==
0
)
{
obj
.
del
();
//删除对应行(tr)的DOM结构
}
layer
.
msg
(
data
.
msg
);
});
});
}
});
$
(
'#add'
).
click
(
function
()
{
//打开弹窗
$
.
get
(
'/admin/coin-supported-coin/add?platform_id='
+
platform_id
,
{},
function
(
str
)
{
var
index
=
layer
.
open
({
type
:
1
,
title
:
'添加数据'
,
id
:
'add-one'
,
skin
:
'layui-layer-lan'
,
area
:
[
'320px'
,
'auto'
],
content
:
str
,
btn
:
[
'确认'
,
'取消'
],
btn1
:
function
()
{
$
.
post
(
'/admin/coin-supported-coin/add'
,
$
(
"#addData"
).
serialize
(),
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
rev
.
code
==
0
)
{
layer
.
close
(
index
);
table
.
reload
(
"table1"
,
{});
}
});
}
});
layui
.
form
.
render
();
});
return
false
;
});
\ No newline at end of file
common/behaviors/LoginStatusAuthInterceptor.php
View file @
30f735a0
...
...
@@ -26,14 +26,14 @@ class LoginStatusAuthInterceptor extends ActionFilter
$token_string
=
Yii
::
$app
->
request
->
headers
->
get
(
'Token'
);
if
(
false
==
$token_string
){
$msg
=
'platform auth error'
;
$code
=
'4000
4
'
;
$code
=
'4000
1
'
;
goto
doEnd
;
}
$model
=
new
Admin
();
$user
=
$model
->
loginByAccessToken
(
$token_string
,
''
);
if
(
false
==
$user
){
$msg
=
'user auth error'
;
$code
=
'4000
4
'
;
$code
=
'4000
2
'
;
goto
doEnd
;
}
$user_id
=
$user
->
uid
;
...
...
common/components/ErrorMessage.php
0 → 100644
View file @
30f735a0
<?php
namespace
common\components
;
use
yii\base\Component
;
class
ErrorMessage
extends
Component
{
/**
* 预定义错误信息
*/
public
static
$errors
=
[
'ErrTokenNameLen'
=>
"token名字太长"
,
'ErrTokenSymbolLen'
=>
" token符号太长"
,
'ErrTokenTotalOverflow'
=>
' token 总数过大, 或是负的'
,
'ErrTokenSymbolUpper'
=>
' token symbol 需要全是大写字母'
,
'ErrTokenIntroLen'
=>
' Token介绍太长'
,
'ErrTokenExist'
=>
' Token Symbol 已经存在'
,
'ErrTokenNotPrecreated'
=>
' Token 还没有预创建'
,
'ErrTokenCreatedApprover'
=>
'Token Approver 没有权限'
,
'ErrTokenRevoker'
=>
' Token Revoker 错误 (需要创建者自己撤销)'
,
'ErrTokenCanotRevoked'
=>
'Token 不能撤销'
,
'ErrTokenOwner'
=>
'Token Owner 错误'
,
'ErrTokenHavePrecreated'
=>
'Token已经被预创建'
,
'ErrTokenBlacklist'
=>
'Token 在黑名单里'
,
'ErrTokenNotExist'
=>
'Token 不存在'
,
'ErrTokenSymbolExistAlready'
=>
'Token Symbol 已经存在'
];
/**
* 获取错误信息
*/
public
static
function
getMessage
(
$msg
)
{
$message
=
isset
(
self
::
$errors
[
$msg
])
?
self
::
$errors
[
$msg
]
:
'未知错误'
;
return
$message
;
}
}
\ No newline at end of file
common/models/Tools.php
0 → 100644
View file @
30f735a0
<?php
namespace
common\models
;
use
Yii
;
use
yii\helpers\Url
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\FileHelper
;
class
Tools
{
/**
* 获取随机验证码
* @return string
*/
public
static
function
getRandomNumber
(
$count
=
6
,
$type
=
'mixed'
)
{
$chars
=
'1234567890abcdefghijklmnopqrstuvwxyz'
;
switch
(
$type
)
{
case
'number'
:
$startIndex
=
0
;
$endIndex
=
9
;
break
;
case
'letter'
:
$startIndex
=
10
;
$endIndex
=
35
;
break
;
default
:
$startIndex
=
0
;
$endIndex
=
35
;
break
;
}
$randomNumber
=
''
;
for
(
$i
=
0
;
$i
<
$count
;
$i
++
)
{
$randomNumber
.=
substr
(
$chars
,
rand
(
$startIndex
,
$endIndex
),
1
);
}
return
$randomNumber
;
}
/**
* 获取文件全路径
* @param type $filename
* @param type $type
* @return string
*/
public
static
function
getFileUrl
(
$fileName
)
{
return
$fileName
?
Url
::
to
(
'@resDomain'
.
$fileName
)
:
''
;
}
/**
* 判断当前日期是否是可用日期
* @param type $startData
* @param type $endData
*/
public
static
function
isAvailableDate
(
$start
,
$end
)
{
$current
=
date
(
'Y-m-d'
);
$start
=
$start
?
date
(
'Y-m-d'
,
strtotime
(
$start
))
:
$current
;
$end
=
$end
?
date
(
'Y-m-d'
,
strtotime
(
$end
))
:
$current
;
if
(
$start
<=
$current
&&
$end
>=
$current
)
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 添加get查询数据
* @param type $values
*/
public
static
function
addQueryParams
(
$values
)
{
Yii
::
$app
->
request
->
setQueryParams
(
\yii\helpers\ArrayHelper
::
merge
(
Yii
::
$app
->
request
->
get
(),
$values
));
}
/**
* 获取post数据, 可附加额外数据
* @param array $values 附加数据,必须是数组形式
* @param string $formName 指定数据附加到特定键
*/
public
static
function
getPost
(
array
$values
,
$formName
=
null
)
{
if
(
Yii
::
$app
->
request
->
isPost
)
{
$data
=
Yii
::
$app
->
request
->
post
();
if
(
$formName
!==
null
)
{
$data
[
$formName
]
=
ArrayHelper
::
merge
(
$data
[
$formName
],
$values
);
}
else
{
$data
=
ArrayHelper
::
merge
(
$data
,
$values
);
}
return
$data
;
}
else
{
return
;
}
}
/**
* 获取到下个给定时间点还有多长时间,单位 秒
* @param mixed $time 可以是一个时间字符串,也可以是时间字符串数组
* 格式为 h:m:s
* @return $duration 返回值为到下个时间点还有多长时间,以秒为单位
*/
public
static
function
getDuration
(
$time
)
{
if
(
!
is_array
(
$time
))
{
$time
=
(
array
)
$time
;
}
$seconds
=
[];
foreach
(
$time
as
$value
)
{
$timeArray
=
explode
(
':'
,
$value
);
if
(
3
!=
count
(
$timeArray
))
{
return
false
;
}
list
(
$hour
,
$minute
,
$second
)
=
$timeArray
;
if
((
int
)
$hour
<
0
||
(
int
)
$hour
>
23
||
(
int
)
$minute
<
0
||
(
int
)
$minute
>
59
||
(
int
)
$second
<
0
||
(
int
)
$second
>
59
)
{
return
false
;
}
$seconds
[]
=
$hour
*
3600
+
$minute
*
60
+
$second
;
}
sort
(
$seconds
);
$currentTimeSecond
=
idate
(
'H'
)
*
3600
+
idate
(
'i'
)
*
60
+
idate
(
's'
);
foreach
(
$seconds
as
$second
)
{
if
((
$second
-
$currentTimeSecond
)
>
0
)
{
return
$second
-
$currentTimeSecond
;
}
}
return
$seconds
[
0
]
+
(
24
*
3600
-
$currentTimeSecond
);
}
/**
* 保留小数位数,向下取数
* @param float $number //数字
* @param int $precision //精度
* 例如, roundDown(1.20058, 4) return 1.2005
*/
public
static
function
roundDown
(
$number
,
$precision
)
{
$pow
=
pow
(
10
,
(
int
)
$precision
);
return
floor
(
$number
*
$pow
)
/
$pow
;
}
/**
* 获取一条错误信息
* @param type $errors
* @return type
*/
public
static
function
getFirstError
(
$errors
,
$defaultError
=
null
)
{
if
(
count
(
$errors
)
>
0
){
foreach
(
$errors
as
$error
)
{
return
$error
[
0
];
}
}
$defaultError
=
'请求数据有误'
;
return
$defaultError
;
}
/**
* 格式化数字
* @param int $num
* @return string
*/
public
static
function
formatNumber
(
$num
)
{
return
(
$num
/
100000000
>
1
)
?
sprintf
(
'%.2f'
,
$num
/
100000000
)
.
'亿'
:
((
$num
/
10000
>
1
)
?
sprintf
(
'%.2f'
,
$num
/
10000
)
.
'万'
:
sprintf
(
'%.2f'
,
$num
));
}
/**
* 获取配置参数
* @param string $moduleId 模块ID
* @param mixed $keys
* @param mixed $default 默认值
*/
public
static
function
getModuleParams
(
$moduleId
,
$keys
,
$default
=
null
)
{
if
(
is_string
(
$keys
)
&&
isset
(
Yii
::
$app
->
params
[
$moduleId
][
$keys
]))
{
return
Yii
::
$app
->
params
[
$moduleId
][
$keys
];
}
elseif
(
is_array
(
$keys
)
&&
isset
(
Yii
::
$app
->
params
[
$moduleId
]))
{
$params
=
Yii
::
$app
->
params
[
$moduleId
];
foreach
(
$keys
as
$key
)
{
if
(
isset
(
$params
[
$key
]))
{
$params
=
$params
[
$key
];
}
else
{
return
$default
;
}
}
return
$params
;
}
return
$default
;
}
/**
* 获取上传文件目录
* @param string $moduleId 模块ID
* @param array $moduleSubDir 模块子目录
*/
public
static
function
getUploadDir
(
$moduleId
,
$moduleSubdir
=
null
)
{
$uploadDir
=
'/'
.
$moduleId
;
if
(
is_array
(
$moduleSubdir
))
{
foreach
(
$moduleSubdir
as
$dirName
)
{
$uploadDir
.=
'/'
.
$dirName
;
}
}
return
$uploadDir
;
}
/**
* 复制文件夹及子目录文件
* @param string $source
* @param string $destination
*/
public
static
function
xCopy
(
$source
,
$destination
)
{
if
(
!
is_dir
(
$source
))
{
return
;
}
FileHelper
::
createDirectory
(
$destination
,
0755
,
true
);
$handle
=
opendir
(
$source
);
while
((
$file
=
readdir
(
$handle
))
!==
false
)
{
if
(
$file
===
'.'
||
$file
===
'..'
)
{
continue
;
}
$path
=
$source
.
DIRECTORY_SEPARATOR
.
$file
;
if
(
is_dir
(
$path
))
{
static
::
xCopy
(
$path
,
$destination
.
DIRECTORY_SEPARATOR
.
$file
);
}
else
{
copy
(
$path
,
$destination
.
DIRECTORY_SEPARATOR
.
$file
);
}
}
closedir
(
$handle
);
}
/**
* 压缩文件或文件夹
* @param string $source 文件夹或文件路径
*/
public
static
function
folderToZip
(
$source
,
&
$zipArchive
,
$exclusiveLength
)
{
if
(
is_dir
(
$source
)
||
is_file
(
$source
))
{
$handle
=
opendir
(
$source
);
while
((
$file
=
readdir
(
$handle
))
!==
false
)
{
if
(
$file
===
'.'
||
$file
===
'..'
)
{
continue
;
}
$path
=
$source
.
DIRECTORY_SEPARATOR
.
$file
;
$localPath
=
substr
(
$path
,
$exclusiveLength
);
if
(
is_file
(
$path
))
{
$zipArchive
->
addFile
(
$path
,
$localPath
);
}
elseif
(
is_dir
(
$path
))
{
$zipArchive
->
addEmptyDir
(
$localPath
);
static
::
folderToZip
(
$path
,
$zipArchive
,
$exclusiveLength
);
}
}
closedir
(
$handle
);
}
}
/**
* 压缩文件夹
* @param string $source
*/
public
static
function
zipDir
(
$source
)
{
$pathinfo
=
pathinfo
(
$source
);
$basename
=
$pathinfo
[
'basename'
];
$dirname
=
$pathinfo
[
'dirname'
];
$zipArchive
=
new
\ZipArchive
();
$zipArchive
->
open
(
$dirname
.
DIRECTORY_SEPARATOR
.
$basename
.
'.zip'
,
\ZipArchive
::
CREATE
);
$exclusiveLength
=
strlen
(
$dirname
)
+
1
;
static
::
folderToZip
(
$source
,
$zipArchive
,
$exclusiveLength
);
$zipArchive
->
close
();
}
public
static
function
unZip
(
$source
)
{
$pathinfo
=
pathinfo
(
$source
);
$dirname
=
$pathinfo
[
'dirname'
];
$zipArchive
=
new
\ZipArchive
();
$resource
=
$zipArchive
->
open
(
$source
);
if
(
$resource
===
true
)
{
$zipArchive
->
extractTo
(
$dirname
);
$zipArchive
->
close
();
}
}
/**
* 生成全球唯一标识uuid
* @param string $source
*/
public
function
uuid
(){
if
(
function_exists
(
'com_create_guid'
))
{
return
com_create_guid
();
}
else
{
mt_srand
((
double
)
microtime
()
*
10000
);
//optional for php 4.2.0 and up.
$charid
=
strtoupper
(
md5
(
uniqid
(
rand
(),
true
)));
$hyphen
=
chr
(
45
);
// "-"
$uuid
=
substr
(
$charid
,
0
,
8
)
.
$hyphen
.
substr
(
$charid
,
8
,
4
)
.
$hyphen
.
substr
(
$charid
,
12
,
4
)
.
$hyphen
.
substr
(
$charid
,
16
,
4
)
.
$hyphen
.
substr
(
$charid
,
20
,
12
);
return
$uuid
;
}
}
}
\ No newline at end of file
common/models/psources/CoinIssueChainRecord.php
0 → 100644
View file @
30f735a0
<?php
namespace
common\models\psources
;
use
Yii
;
class
CoinIssueChainRecord
extends
CommonActiveRecord
{
//定义场景
const
SCENARIOS_PRE_CREATE
=
'create'
;
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coin_issue_chain_record}}'
;
}
public
function
rules
()
{
return
[
[[
'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_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'
]);
}
public
function
getAdvance
()
{
return
$this
->
hasOne
(
CoinIssueCoin
::
className
(),
[
'id'
=>
'issue_coin_id'
])
->
where
([
'status'
=>
CoinIssueCoin
::
STATUS_ADVANCE
]);
}
public
function
getConfirm
()
{
return
$this
->
hasOne
(
CoinIssueCoin
::
className
(),
[
'id'
=>
'issue_coin_id'
])
->
where
([
'>'
,
'status'
,
CoinIssueCoin
::
STATUS_CONFIRM
]);
}
}
\ No newline at end of file
common/models/psources/CoinIssueCoin.php
0 → 100644
View file @
30f735a0
<?php
namespace
common\models\psources
;
use
Yii
;
use
yii\db\Expression
;
class
CoinIssueCoin
extends
CommonActiveRecord
{
const
UN_PAY
=
0
;
const
ALLOW_PAY
=
1
;
const
SUCCESS_PAY
=
2
;
const
STATUS_ADVANCE
=
0
;
//预发行,待确认
const
STATUS_PEDDING
=
1
;
//预发行成功,待用户确认
const
STATUS_CANCEL
=
2
;
//用户点击撤消后的状态
const
STATUS_CANCEL_SUCCESS
=
3
;
//撤消成功
const
STATUS_CANCEL_FAILED
=
4
;
//撤消失败
const
STATUS_CONFIRM
=
5
;
//用户点击确认后的状态
const
STATUS_ALLOW
=
6
;
//开启人工审核,管理员后台点击通过后的状态 (未开启人工审核,跳过该状态)
const
STATUS_REFUSE
=
7
;
//开启人工审核,管理员后台点击拒绝后的状态 (未开启人工审核,跳过该状态)
const
STATUS_SUCCESS
=
8
;
//发行成功
const
STATUS_FAILED
=
9
;
//(预)发行失败
const
TYPE_NO
=
0
;
//不是增发
const
TYPE_YES
=
1
;
//是增发
const
ISSUE_TOKEN
=
'issue_token'
;
const
REVOKE_TOKEN
=
'revoke_token'
;
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
const
SCENARIOS_CANCEL
=
'cancel'
;
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coin_issue_coin}}'
;
}
public
function
rules
()
{
return
[
[[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'type'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
,
'charge'
],
'required'
],
[[
'total'
,
'category'
,
'type'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
],
'integer'
],
[
'introduction'
,
'string'
,
'length'
=>
[
1
,
20
]],
[
'symbol'
,
'string'
,
'length'
=>
[
1
,
6
]],
[
'name'
,
'string'
,
'length'
=>
[
1
,
20
]],
#['status', 'in', 'range' => [1, 2, 0]],
[
'name'
,
'verfiyName'
],
[
'symbol'
,
'verfiySymbol'
],
[
'total'
,
'verfiyAmount'
]
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'type'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
,
'charge'
],
self
::
SCENARIOS_UPDATE
=>
[
'status'
],
self
::
SCENARIOS_CANCEL
=>
[
'status'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
public
function
verfiyName
(
$attribute
,
$params
)
{
//增发
if
(
CoinIssueCoin
::
TYPE_YES
==
$this
->
type
)
{
$model
=
CoinIssueCoin
::
find
()
->
where
([
'name'
=>
$this
->
name
,
'owner'
=>
$this
->
owner
,
'platform_id'
=>
$this
->
platform_id
,
'status'
=>
CoinIssueCoin
::
STATUS_SUCCESS
])
->
orderBy
(
'id desc'
)
->
one
();
if
(
false
==
$model
)
{
$this
->
addError
(
$attribute
,
'该Token币种尚未发行'
);
return
false
;
}
if
(
0
==
$model
->
category
)
{
$this
->
addError
(
$attribute
,
'该Token币种不可增发'
);
return
false
;
}
}
//非增发
if
(
CoinIssueCoin
::
TYPE_NO
==
$this
->
type
)
{
$model
=
CoinIssueCoin
::
find
()
->
where
([
'name'
=>
$this
->
name
,
'platform_id'
=>
$this
->
platform_id
,
'status'
=>
CoinIssueCoin
::
STATUS_SUCCESS
])
->
orderBy
(
'id desc'
)
->
one
();
if
(
$model
)
{
$this
->
addError
(
$attribute
,
'Token名称已存在'
);
return
false
;
}
}
}
public
function
verfiySymbol
(
$attribute
,
$params
)
{
if
(
!
preg_match
(
'/^[A-Z]+$/'
,
$this
->
symbol
))
{
$this
->
addError
(
$attribute
,
'Token简称必须大写'
);
return
false
;
}
if
(
CoinIssueCoin
::
TYPE_YES
==
$this
->
type
)
{
$model
=
CoinIssueCoin
::
find
()
->
where
([
'symbol'
=>
$this
->
symbol
,
'owner'
=>
$this
->
owner
,
'platform_id'
=>
$this
->
platform_id
,
'status'
=>
CoinIssueCoin
::
STATUS_SUCCESS
])
->
orderBy
(
'id desc'
)
->
one
();
if
(
false
==
$model
)
{
$this
->
addError
(
$attribute
,
'该Token币种尚未发行'
);
return
false
;
}
if
(
0
==
$model
->
category
)
{
$this
->
addError
(
$attribute
,
'该Token币种不可增发'
);
return
false
;
}
}
if
(
CoinIssueCoin
::
TYPE_NO
==
$this
->
type
)
{
$model
=
CoinIssueCoin
::
find
()
->
where
([
'symbol'
=>
$this
->
symbol
,
'platform_id'
=>
$this
->
platform_id
,
'status'
=>
CoinIssueCoin
::
STATUS_SUCCESS
])
->
orderBy
(
'id desc'
)
->
one
();
if
(
$model
)
{
$this
->
addError
(
$attribute
,
'Token名称已存在'
);
return
false
;
}
}
}
public
function
verfiyAmount
(
$attribute
,
$params
)
{
if
(
CoinIssueCoin
::
TYPE_YES
==
$this
->
type
)
{
if
(
$this
->
$attribute
>
10
)
{
$this
->
addError
(
$attribute
,
'增发发行量不能超过10亿'
);
return
false
;
}
}
$issue_record
=
CoinIssueCoin
::
find
()
->
where
([
'platform_id'
=>
$this
->
platform_id
,
'symbol'
=>
$this
->
symbol
,
'status'
=>
CoinIssueCoin
::
STATUS_SUCCESS
])
->
sum
(
'total'
);
$issue_record
=
empty
(
$issue_record
)
?
0
:
$issue_record
;
if
(
$issue_record
+
$this
->
$attribute
>
20
)
{
$this
->
addError
(
$attribute
,
'最大发行量20亿,目前已发行'
.
$issue_record
.
'亿'
);
return
false
;
}
}
public
function
attributeLabels
()
{
return
[
'name'
=>
'Token全称'
,
'symbol'
=>
'Token简称'
,
'total'
=>
'发行数量'
,
'owner'
=>
'接收地址'
,
'introduction'
=>
'Token简介'
,
'category'
=>
'是否增发'
,
'chain_id'
=>
'平行链名称'
,
'msg'
=>
'失败原因'
,
'status'
=>
'状态'
,
'charge_unit_id'
=>
'手续费'
,
];
}
public
function
attributes
()
{
return
array_merge
(
parent
::
attributes
(),
[
'issue_charge'
,
'charge_unit'
,
'url'
,
'chain_name'
]);
}
/**
* 获取状态数组
* @return array
*/
public
static
function
getAgentStatus
()
{
return
[
self
::
STATUS_SUCCESS
=>
'发行成功'
,
self
::
STATUS_FAIL
=>
'发行失败'
,
];
}
public
function
getChain
()
{
return
$this
->
hasOne
(
CoinPlatformWithHold
::
className
(),
[
'id'
=>
'chain_id'
]);
}
public
function
getPlatform
()
{
return
$this
->
hasOne
(
CoinPlatform
::
className
(),
[
'id'
=>
'platform_id'
]);
}
public
function
getGas
()
{
return
$this
->
hasOne
(
CoinSupportedCoin
::
className
(),
[
'id'
=>
'charge_unit_id'
]);
}
public
function
getTransfer
()
{
return
$this
->
hasOne
(
CoinIssueChainRecord
::
className
(),
[
'issue_coin_id'
=>
'id'
]);
}
public
function
getRevoke
()
{
return
$this
->
hasOne
(
CoinIssueRevokeRecord
::
className
(),
[
'issue_coin_id'
=>
'id'
]);
}
}
\ No newline at end of file
common/models/psources/CoinIssueRecord.php
0 → 100644
View file @
30f735a0
<?php
namespace
common\models\psources
;
use
Yii
;
class
CoinIssueRecord
extends
CommonActiveRecord
{
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coin_issue_record}}'
;
}
public
function
rules
()
{
return
[
[[
'platform_id'
,
'total'
],
'required'
],
[[
'total'
,
'platform_id'
],
'integer'
],
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'platform_id'
,
'total'
],
self
::
SCENARIOS_UPDATE
=>
[
'platform_id'
,
'total'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
}
\ No newline at end of file
common/models/psources/CoinIssueRevokeRecord.php
0 → 100644
View file @
30f735a0
<?php
namespace
common\models\psources
;
use
Yii
;
class
CoinIssueRevokeRecord
extends
CommonActiveRecord
{
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coins_issue_revoke_record}}'
;
}
public
function
rules
()
{
return
[
[[
'revoke_tx'
,
'revoke_send_transaction'
,
'issue_coin_id'
],
'required'
],
[[
'issue_coin_id'
],
'integer'
],
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'revoke_tx'
,
'revoke_send_transaction'
,
'issue_coin_id'
,
'revoke_query_transaction'
],
];
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/CoinPlatform.php
View file @
30f735a0
...
...
@@ -10,6 +10,7 @@ namespace common\models\psources;
class
CoinPlatform
extends
BaseActiveRecord
{
public
static
function
tableName
()
{
return
'{{%coin_platform}}'
;
...
...
@@ -18,8 +19,8 @@ class CoinPlatform extends BaseActiveRecord
/**
* 获取钱包信息列表
*
* @param int
$page
* @param int
$limit
* @param int $page
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord[]
*/
...
...
@@ -30,7 +31,7 @@ class CoinPlatform extends BaseActiveRecord
$query
=
$query
->
andWhere
(
$item
);
}
$count
=
$query
->
count
();
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
return
[
'count'
=>
$count
,
'data'
=>
$data
];
}
...
...
@@ -73,4 +74,19 @@ class CoinPlatform extends BaseActiveRecord
return
[
'code'
=>
$exception
->
getCode
(),
'message'
=>
$exception
->
getMessage
()];
}
}
public
function
attributes
()
{
return
array_merge
(
parent
::
attributes
(),
[
'chain_name'
,
'charge_unit'
]);
}
public
function
getChain
()
{
return
$this
->
hasOne
(
CoinPlatformWithHold
::
className
(),
[
'id'
=>
'chain_id'
]);
}
public
function
getGas
()
{
return
$this
->
hasOne
(
CoinSupportedCoin
::
className
(),
[
'id'
=>
'charge_unit_id'
]);
}
}
common/models/psources/CoinSupportedCoin.php
0 → 100644
View file @
30f735a0
<?php
namespace
common\models\psources
;
use
Yii
;
use
yii\db\Expression
;
class
CoinSupportedCoin
extends
CommonActiveRecord
{
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coin_supported_coin}}'
;
}
public
function
rules
()
{
return
[
[[
'platform_id'
,
'coin_name'
],
'required'
],
[[
'platform_id'
],
'integer'
],
[
'coin_name'
,
'string'
,
'length'
=>
[
1
,
50
]],
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'platform_id'
,
'coin_name'
],
self
::
SCENARIOS_UPDATE
=>
[
'platform_id'
,
'coin_name'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
public
function
attributeLabels
()
{
return
[
'platform_id'
=>
'所属钱包'
,
'coin_name'
=>
'币种名称'
,
];
}
public
static
function
getList
(
$page
=
1
,
$limit
=
10
,
$condition
=
[])
{
$query
=
self
::
find
();
foreach
(
$condition
as
$item
)
{
$query
=
$query
->
andWhere
(
$item
);
}
$count
=
$query
->
count
();
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
return
[
'count'
=>
$count
,
'data'
=>
$data
];
}
public
function
addOne
(
$params
)
{
$params
=
array_filter
(
$params
,
function
(
$value
)
{
if
(
null
==
$value
)
{
return
false
;
}
return
true
;
});
$this
->
setAttributes
(
$params
,
false
);
try
{
return
(
bool
)
$this
->
save
();
}
catch
(
\Exception
$exception
)
{
return
[
'code'
=>
$exception
->
getCode
(),
'message'
=>
$exception
->
getMessage
()];
}
}
}
\ No newline at end of file
common/models/psources/CommonActiveRecord.php
0 → 100644
View file @
30f735a0
<?php
namespace
common\models\psources
;
use
Yii
;
use
yii\db\ActiveRecord
;
use
yii\helpers\ArrayHelper
;
use
yii\web\Linkable
;
use
yii\web\Link
;
class
CommonActiveRecord
extends
ActiveRecord
{
public
$cacheKeyStorage
=
[];
//缓存key寄存器
public
function
toArray
(
array
$fields
=
[],
array
$expand
=
[],
$recursive
=
true
)
{
$data
=
[];
$cachePrefix
=
__CLASS__
;
$cache
=
Yii
::
$app
->
cache
;
foreach
(
$this
->
resolveFields
(
$fields
,
$expand
)
as
$field
=>
$definition
)
{
if
(
strpos
(
$field
,
'.'
))
{
$fieldChunks
=
explode
(
'.'
,
$field
);
$primaryKey
=
is_array
(
$this
->
primaryKey
)
?
implode
(
'-'
,
$this
->
primaryKey
)
:
$this
->
primaryKey
;
$uniqueRelationCacheKey
=
"
{
$cachePrefix
}
_
{
$primaryKey
}
_
{
$fieldChunks
[
0
]
}
"
;
$this
->
addCacheKeyToStorage
(
$uniqueRelationCacheKey
);
$relation
=
$cache
->
get
(
$uniqueRelationCacheKey
);
if
(
!
$relation
)
{
$relation
=
$this
->
{
$fieldChunks
[
0
]};
$cache
->
set
(
$uniqueRelationCacheKey
,
$relation
);
}
if
(
is_array
(
$relation
))
{
foreach
(
$relation
as
$relatedField
=>
$relatedObject
)
{
if
(
!
is_object
(
$relatedObject
))
{
continue
;
}
$data
[
$fieldChunks
[
0
]][
$relatedField
][
$fieldChunks
[
1
]]
=
$this
->
getRelationField
(
$relatedObject
,
$fieldChunks
[
1
]);
}
}
else
{
if
(
!
is_object
(
$relation
))
{
continue
;
}
$data
[
$fieldChunks
[
0
]][
$fieldChunks
[
1
]]
=
$this
->
getRelationField
(
$relation
,
$fieldChunks
[
1
]);
}
}
else
{
$data
[
$field
]
=
is_string
(
$definition
)
?
$this
->
$definition
:
call_user_func
(
$definition
,
$this
,
$field
);
}
}
$this
->
deleteStorageCaches
();
if
(
$this
instanceof
Linkable
)
{
$data
[
'_links'
]
=
Link
::
serialize
(
$this
->
getLinks
());
}
return
$recursive
?
ArrayHelper
::
toArray
(
$data
)
:
$data
;
}
/**
* This method also will check relations which are declared in [[extraFields()]]
* to determine which related fields can be returned.
* @inheritdoc
*/
protected
function
resolveFields
(
array
$fields
,
array
$expand
)
{
$result
=
[];
foreach
(
$this
->
fields
()
as
$field
=>
$definition
)
{
if
(
is_integer
(
$field
))
{
$field
=
$definition
;
}
if
(
empty
(
$fields
)
||
in_array
(
$field
,
$fields
,
true
))
{
$result
[
$field
]
=
$definition
;
}
}
if
(
empty
(
$expand
))
{
return
$result
;
}
$extraFieldsKeys
=
array_keys
(
$this
->
extraFields
());
foreach
(
$expand
as
$expandedAttribute
)
{
if
(
in_array
(
explode
(
'.'
,
$expandedAttribute
)[
0
],
$this
->
extraFields
()))
{
$result
[
$expandedAttribute
]
=
$expandedAttribute
;
}
else
if
(
in_array
(
$expandedAttribute
,
$extraFieldsKeys
))
{
$result
[
$expandedAttribute
]
=
$this
->
extraFields
()[
$expandedAttribute
];
}
}
return
$result
;
}
/**
* Additional method to check the related model has specified field
*/
private
function
getRelationField
(
$relatedRecord
,
$field
)
{
if
(
!
$relatedRecord
->
hasAttribute
(
$field
)
&&
!
$relatedRecord
->
isRelationPopulated
(
$field
))
{
throw
new
\yii\web\ServerErrorHttpException
(
sprintf
(
"Related record '%s' does not have attribute '%s'"
,
get_class
(
$relatedRecord
),
$field
)
);
}
if
(
$relatedRecord
->
hasAttribute
(
$field
))
{
return
ArrayHelper
::
toArray
(
$relatedRecord
)[
$field
];
}
else
{
return
$relatedRecord
->
{
$field
};
}
}
public
static
function
quoteDbName
(
$dbname
)
{
return
'`'
.
$dbname
.
'`'
;
}
/**
* 添加cache key到寄存器
* @param type $cacheKey
*/
public
function
addCacheKeyToStorage
(
$cacheKey
)
{
if
(
!
in_array
(
$cacheKey
,
$this
->
cacheKeyStorage
))
{
$this
->
cacheKeyStorage
[]
=
$cacheKey
;
}
}
/**
* 删除寄存器里所有的cache
*/
public
function
deleteStorageCaches
()
{
foreach
(
$this
->
cacheKeyStorage
as
$cacheKey
)
{
Yii
::
$app
->
cache
->
delete
(
$cacheKey
);
}
}
}
\ No newline at end of file
common/service/chain33/Chain33Service.php
View file @
30f735a0
...
...
@@ -246,6 +246,16 @@ class Chain33Service
return
$this
->
send
(
$params
,
'Chain33.QueryTransaction'
);
}
public
function
query
()
{
$params
=
[
"execer"
=>
'manage'
,
"funcName"
=>
"GetConfigItem"
,
"payload"
=>
[
'data'
=>
'token-finisher'
]
];
return
$this
->
send
(
$params
,
'Chain33.Query'
);
}
public
function
getBalance
(
$address
,
$execer
)
{
$params
=
[
...
...
@@ -298,6 +308,29 @@ class Chain33Service
return
$this
->
send
(
$params
,
'Chain33.SignRawTx'
);
}
public
function
createRawTokenPreCreateTx
(
$params
)
{
return
$this
->
send
(
$params
,
'token.CreateRawTokenPreCreateTx'
);
}
public
function
createRawTokenFinishTx
(
$symbol
,
$owner
)
{
$params
=
[
'symbol'
=>
$symbol
,
'owner'
=>
$owner
];
return
$this
->
send
(
$params
,
'token.CreateRawTokenFinishTx'
);
}
public
function
createRawTokenRevokeTx
(
$symbol
,
$owner
)
{
$params
=
[
'symbol'
=>
$symbol
,
'owner'
=>
$owner
];
return
$this
->
send
(
$params
,
'token.CreateRawTokenRevokeTx'
);
}
public
function
getBlock2MainInfo
(
$start
,
$end
)
{
$params
=
[
...
...
console/controllers/CrossChainController.php
View file @
30f735a0
...
...
@@ -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 @
30f735a0
<?php
namespace
console\controllers
;
use
common\models\psources\CoinIssueRevokeRecord
;
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
)
{
$manual_review
=
Yii
::
$app
->
redis
->
get
(
'issue_chain_manual_review'
);
if
(
'close'
==
$manual_review
)
{
$status
=
CoinIssueCoin
::
STATUS_CONFIRM
;
}
else
{
$status
=
CoinIssueCoin
::
STATUS_ALLOW
;
}
$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
::
STATUS_FAILED
;
$data
=
[
'status'
=>
CoinIssueCoin
::
STATUS_FAILED
,
'finish_query_transaction'
=>
$result
[
'msg'
]
];
goto
doEnd
;
}
$txHex
=
$result
[
'result'
];
$privkey
=
'8ac19c0b8858ccd6ed34e2bce0f11be2fc696e658d0b98fb1d3ef85ec5a3992c'
;
#$privkey = $val->coin->chain->private_key;
$expire
=
'1m'
;
//执行1.2签名
$signRawTx
=
$chain_service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
$status
=
CoinIssueCoin
::
STATUS_FAILED
;
$data
=
[
'finish_query_transaction'
=>
$signRawTx
[
'msg'
]
];
goto
doEnd
;
}
//执行1.2交易
$result
=
$chain_service
->
sendTransaction
(
$signRawTx
[
'result'
]);
if
(
0
!=
$result
[
'code'
])
{
$status
=
CoinIssueCoin
::
STATUS_FAILED
;
$data
=
[
'finish_tx'
=>
$signRawTx
[
'result'
],
'finish_query_transaction'
=>
$result
[
'msg'
]
];
goto
doEnd
;
}
$status
=
CoinIssueCoin
::
STATUS_SUCCESS
;
$data
=
[
'finish_tx'
=>
$signRawTx
[
'result'
],
'finish_send_transaction'
=>
$result
[
'result'
]
];
doEnd
:
CoinIssueChainRecord
::
updateAll
(
$data
,
[
'id'
=>
$val
->
id
,
]);
//交易失败
if
(
$status
==
CoinIssueCoin
::
STATUS_FAILED
)
{
CoinIssueCoin
::
updateAll
([
'status'
=>
$status
],
[
'id'
=>
$val
->
coin
->
id
,
]);
}
}
echo
date
(
'Y-m-d H:i:s'
)
.
'执行完成'
.
PHP_EOL
;
return
0
;
}
public
function
actionQueryTransaction
(
$step
)
{
$redis
=
Yii
::
$app
->
redis
;
if
(
1
==
$step
)
{
$model
=
CoinIssueChainRecord
::
find
()
->
where
([
'pre_query_transaction'
=>
'standby'
])
->
all
();
}
if
(
2
==
$step
)
{
$model
=
CoinIssueChainRecord
::
find
()
->
where
([
'pre_query_transaction'
=>
'success'
])
->
andWhere
([
'not in'
,
'finish_send_transaction'
,
[
'standby'
,
'success'
,
'failed'
]])
->
andWhere
([
'finish_query_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_nodes'
][
'STO'
];
$service
=
new
Chain33Service
(
$node
);
$current_time
=
time
();
foreach
(
$model
as
$val
)
{
if
(
1
==
$step
)
{
$result
=
$service
->
QueryTransaction
(
$val
->
pre_send_transaction
);
$column
=
'pre_query_transaction'
;
}
if
(
2
==
$step
)
{
$result
=
$service
->
QueryTransaction
(
$val
->
finish_send_transaction
);
$column
=
'finish_query_transaction'
;
}
if
(
isset
(
$result
[
'result'
][
'actionName'
])
&&
'unknown'
==
$result
[
'result'
][
'actionName'
])
{
$data
=
[
$column
=>
'success'
];
if
(
1
==
$step
)
{
if
(
CoinIssueCoin
::
TYPE_YES
==
$val
->
coin
->
type
)
{
$data
[
'finish_tx'
]
=
'success'
;
$data
[
'finish_send_transaction'
]
=
'success'
;
$data
[
'finish_query_transaction'
]
=
'success'
;
$status
=
CoinIssueCoin
::
STATUS_SUCCESS
;
}
else
{
$status
=
CoinIssueCoin
::
STATUS_PEDDING
;
}
}
else
{
$status
=
CoinIssueCoin
::
STATUS_SUCCESS
;
}
$redis
->
hdel
(
CoinIssueCoin
::
ISSUE_TOKEN
,
$val
->
id
);
goto
doEnd
;
}
else
if
(
isset
(
$result
[
'result'
][
'receipt'
][
'ty'
])
&&
2
==
$result
[
'result'
][
'receipt'
][
'ty'
])
{
$data
=
[
$column
=>
'success'
];
if
(
1
==
$step
)
{
if
(
CoinIssueCoin
::
TYPE_YES
==
$val
->
coin
->
type
)
{
$data
[
'finish_tx'
]
=
'success'
;
$data
[
'finish_send_transaction'
]
=
'success'
;
$data
[
'finish_query_transaction'
]
=
'success'
;
$status
=
CoinIssueCoin
::
STATUS_SUCCESS
;
}
else
{
$status
=
CoinIssueCoin
::
STATUS_PEDDING
;
}
}
else
{
$status
=
CoinIssueCoin
::
STATUS_SUCCESS
;
}
$redis
->
hdel
(
CoinIssueCoin
::
ISSUE_TOKEN
,
$val
->
id
);
goto
doEnd
;
}
else
{
$status
=
CoinIssueCoin
::
STATUS_FAILED
;
if
(
isset
(
$result
[
'result'
][
'receipt'
][
'logs'
]))
{
foreach
(
$result
[
'result'
][
'receipt'
][
'logs'
]
as
$log
)
{
if
(
isset
(
$log
[
'tyName'
])
&&
'LogErr'
==
$log
[
'tyName'
])
{
$data
=
[
$column
=>
$log
[
'log'
]
];
break
;
}
}
}
else
{
$data
=
[
$column
=>
$result
[
'msg'
]
];
}
if
(
CoinIssueCoin
::
TYPE_YES
==
$val
->
coin
->
type
)
{
$data
[
'finish_tx'
]
=
'failed'
;
$data
[
'finish_send_transaction'
]
=
'failed'
;
$data
[
'finish_query_transaction'
]
=
'failed'
;
}
$cache_error_time
=
$redis
->
hget
(
CoinIssueCoin
::
ISSUE_TOKEN
,
$val
->
id
);
if
(
false
==
$cache_error_time
)
{
$redis
->
hmset
(
CoinIssueCoin
::
ISSUE_TOKEN
,
$val
->
id
,
$current_time
);
continue
;
}
if
((
$current_time
-
$cache_error_time
)
<
30
)
{
continue
;
}
$redis
->
hdel
(
CoinIssueCoin
::
ISSUE_TOKEN
,
$val
->
id
);
goto
doEnd
;
}
doEnd
:
CoinIssueChainRecord
::
updateAll
(
$data
,
[
'id'
=>
$val
->
id
,
]);
//查询后,交易失败
if
(
$status
==
CoinIssueCoin
::
STATUS_FAILED
)
{
CoinIssueCoin
::
updateAll
([
'status'
=>
$status
],
[
'id'
=>
$val
->
coin
->
id
,
]);
}
//1.1查询后,交易成功
if
(
1
==
$step
)
{
CoinIssueCoin
::
updateAll
([
'status'
=>
$status
],
[
'id'
=>
$val
->
coin
->
id
,
]);
}
//1.2查询后,交易成功
if
(
2
==
$step
&&
$status
==
CoinIssueCoin
::
STATUS_SUCCESS
)
{
CoinIssueCoin
::
updateAll
([
'status'
=>
$status
,
'charge_pay'
=>
CoinIssueCoin
::
SUCCESS_PAY
],
[
'id'
=>
$val
->
coin
->
id
,
]);
if
(
CoinIssueCoin
::
TYPE_NO
==
$val
->
coin
->
type
)
{
$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
->
syncCoin
(
$params
);
}
}
}
echo
date
(
'Y-m-d H:i:s'
)
.
'查询完成,同步完成'
.
PHP_EOL
;
return
0
;
}
public
function
actionCancel
()
{
$redis
=
Yii
::
$app
->
redis
;
$issue_coin_model
=
CoinIssueCoin
::
find
()
->
where
([
'status'
=>
CoinIssueCoin
::
STATUS_CANCEL
])
->
all
();
if
(
false
==
$issue_coin_model
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无需要撤消的发行'
.
PHP_EOL
;
return
0
;
}
$node
=
Yii
::
$app
->
params
[
'chain_nodes'
][
'STO'
];
$service
=
new
Chain33Service
(
$node
);
$current_time
=
time
();
foreach
(
$issue_coin_model
as
$val
)
{
$result
=
$service
->
QueryTransaction
(
$val
->
revoke
->
revoke_send_transaction
);
if
(
isset
(
$result
[
'result'
][
'actionName'
])
&&
'unknown'
==
$result
[
'result'
][
'actionName'
])
{
$data
=
[
'revoke_query_transaction'
=>
'success'
];
$status
=
CoinIssueCoin
::
STATUS_CANCEL_SUCCESS
;
$redis
->
hdel
(
CoinIssueCoin
::
REVOKE_TOKEN
,
$val
->
id
);
goto
doEnd
;
}
else
if
(
isset
(
$result
[
'result'
][
'receipt'
][
'ty'
])
&&
2
==
$result
[
'result'
][
'receipt'
][
'ty'
])
{
$data
=
[
'revoke_query_transaction'
=>
'success'
];
$status
=
CoinIssueCoin
::
STATUS_CANCEL_SUCCESS
;
$redis
->
hdel
(
CoinIssueCoin
::
REVOKE_TOKEN
,
$val
->
id
);
goto
doEnd
;
}
else
{
$status
=
CoinIssueCoin
::
STATUS_CANCEL_FAILED
;
if
(
isset
(
$result
[
'result'
][
'receipt'
][
'logs'
]))
{
foreach
(
$result
[
'result'
][
'receipt'
][
'logs'
]
as
$log
)
{
if
(
isset
(
$log
[
'tyName'
])
&&
'LogErr'
==
$log
[
'tyName'
])
{
$data
=
[
'revoke_query_transaction'
=>
$log
[
'log'
]
];
break
;
}
}
}
else
{
$data
=
[
'revoke_query_transaction'
=>
$result
[
'msg'
]
];
}
$cache_error_time
=
$redis
->
hget
(
CoinIssueCoin
::
REVOKE_TOKEN
,
$val
->
id
);
if
(
false
==
$cache_error_time
)
{
$redis
->
hmset
(
CoinIssueCoin
::
REVOKE_TOKEN
,
$val
->
id
,
$current_time
);
continue
;
}
if
((
$current_time
-
$cache_error_time
)
<
30
)
{
continue
;
}
$redis
->
hdel
(
CoinIssueCoin
::
REVOKE_TOKEN
,
$val
->
id
);
goto
doEnd
;
}
doEnd
:
CoinIssueCoin
::
updateAll
([
'status'
=>
$status
],
[
'id'
=>
$val
->
id
,
]);
CoinIssueRevokeRecord
::
updateAll
(
$data
,
[
'issue_coin_id'
=>
$val
->
id
,
]);
}
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
->
publish_count
=
$params
[
'total'
]
*
1e8
;
$model
->
chain
=
'BTY'
;
$model
->
treaty
=
1
;
$model
->
save
();
}
else
{
$model_coin
->
publish_count
=
$model_coin
->
publish_count
+
$params
[
'total'
]
*
1e8
;
$model_coin
->
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
();
}
}
\ No newline at end of file
console/controllers/IssueCoinController.php
0 → 100644
View file @
30f735a0
<?php
namespace
console\controllers
;
use
common\models\psources\Coin
;
use
common\models\psources\CoinIssueCoin
;
use
common\models\psources\CoinIssueRecord
;
use
common\models\psources\CoinIssueTransfer
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
use
yii\console\Controller
;
use
yii\helpers\ArrayHelper
;
class
IssueCoinController
extends
Controller
{
/**
* 手续费划转
* @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
();
}
}
/**
* 自动发币
* @param $type 0 未开启人工 1 已开启人工
* @return
*/
public
function
actionAutoTransfer
()
{
$issue_coin_model
=
CoinIssueCoin
::
find
()
->
select
(
'id, step_one_tx'
)
->
where
([
'step_one_result'
=>
0
])
->
andWhere
([
'<>'
,
'step_one_tx'
,
''
])
->
asArray
()
->
all
();
if
(
false
==
$issue_coin_model
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无1.1执行任务'
.
PHP_EOL
;
return
0
;
}
$node
=
Yii
::
$app
->
params
[
'chain_nodes'
][
'STO'
];
$service
=
new
Chain33Service
(
$node
);
foreach
(
$issue_coin_model
as
$val
)
{
go
(
function
()
use
(
$val
,
$service
)
{
\Co
::
sleep
(
0.5
);
$result
=
$service
->
sendTransaction
(
$val
[
'step_one_tx'
]);
$send_result
=
$result
[
'result'
];
$currentModel
=
CoinIssueCoin
::
findOne
(
$val
[
'id'
]);
$currentModel
->
step_one_result
=
$send_result
;
$currentModel
->
save
();
});
}
echo
date
(
'Y-m-d H:i:s'
)
.
'1.1 交易完成'
.
PHP_EOL
;
return
0
;
}
/**
* 自动发币
* @param $type 0 未开启人工 1 已开启人工
* @return
*/
public
function
actionAutoIssue
(
$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, name, platform_id, chain_id, symbol, introduction, total, category, owner'
)
->
where
([
'status'
=>
$status
])
->
andWhere
([
'<>'
,
'step_one_result'
,
0
])
->
all
();
if
(
false
==
$issue_coin_model
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无发行任务'
.
PHP_EOL
;
return
0
;
}
$node
=
Yii
::
$app
->
params
[
'chain_nodes'
][
'STO'
];
$chain_service
=
new
Chain33Service
(
$node
);
foreach
(
$issue_coin_model
as
$issue_coin
)
{
//执行1.2构造
$result
=
$chain_service
->
createRawTokenFinishTx
(
$issue_coin
->
symbol
,
$issue_coin
->
owner
);
if
(
null
!=
$result
[
'error'
])
{
$data
=
[
'status'
=>
CoinIssueCoin
::
FAIL_ISSUE
,
'msg'
=>
$result
[
'msg'
]
];
goto
doEnd
;
}
$txHex
=
$result
[
'result'
];
#$privkey = '72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e21';
$privkey
=
$issue_coin
->
chain
->
private_key
;
$expire
=
'1m'
;
//执行1.2签名
$signRawTx
=
$chain_service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
$data
=
[
'status'
=>
CoinIssueCoin
::
FAIL_ISSUE
,
'msg'
=>
$result
[
'msg'
]
];
goto
doEnd
;
}
//执行1.2交易
$result
=
$chain_service
->
sendTransaction
(
$signRawTx
[
'result'
]);
if
(
0
!=
$result
[
'code'
])
{
$data
=
[
'status'
=>
CoinIssueCoin
::
FAIL_ISSUE
,
'msg'
=>
$result
[
'msg'
]
];
goto
doEnd
;
}
$data
=
[
'msg'
=>
$result
[
'result'
],
'status'
=>
CoinIssueCoin
::
SUCCESS_ISSUE
,
'charge_pay'
=>
CoinIssueCoin
::
ALLOW_PAY
];
$params
[
'platform_id'
]
=
$issue_coin
->
platform_id
;
$params
[
'platform'
]
=
$issue_coin
->
chain
->
platform
;
$this
->
syncRecord
(
$params
);
$this
->
syncCoin
(
$params
);
doEnd
:
CoinIssueCoin
::
updateAll
(
$data
,
[
'id'
=>
$issue_coin
->
id
,
]);
}
echo
date
(
'Y-m-d H:i:s'
)
.
'发行成功'
.
PHP_EOL
;
return
0
;
$params
=
[
'name'
=>
$issue_coin
->
name
,
'symbol'
=>
$issue_coin
->
symbol
,
'introduction'
=>
$issue_coin
->
introduction
,
'total'
=>
(
int
)
$issue_coin
->
total
,
'price'
=>
isset
(
$issue_coin
->
platform
->
issue_charge
)
?
(
int
)
$issue_coin
->
platform
->
issue_charge
:
0
,
'category'
=>
(
int
)
$issue_coin
->
category
,
'owner'
=>
$issue_coin
->
owner
];
$result
=
$chain_service
->
createRawTokenPreCreateTx
(
$params
);
if
(
null
==
$result
[
'error'
]
&&
false
==
$result
[
'code'
])
{
$data
=
[
'msg'
=>
$result
[
'result'
],
'status'
=>
CoinIssueCoin
::
SUCCESS_ISSUE
,
'charge_pay'
=>
CoinIssueCoin
::
ALLOW_PAY
];
$params
[
'platform_id'
]
=
$issue_coin
->
platform_id
;
$params
[
'platform'
]
=
$issue_coin
->
chain
->
platform
;
#$this->syncTransfer($issue_transfer['id']);
$this
->
syncRecord
(
$params
);
$this
->
syncCoin
(
$params
);
}
else
{
$data
=
[
'status'
=>
CoinIssueCoin
::
FAIL_ISSUE
,
];
}
if
(
$data
[
'status'
]
>
CoinIssueCoin
::
REFUSE_ISSUE
)
{
CoinIssueCoin
::
updateAll
(
$data
,
[
'id'
=>
$issue_coin
->
id
,
]);
}
}
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
console/controllers/TickerController.php
View file @
30f735a0
...
...
@@ -22,6 +22,8 @@ class TickerController extends Controller
$ticker_builder
->
TickerSort
();
});
}
echo
date
(
'Y-m-d H:i:s'
)
.
'排序更新成功'
.
PHP_EOL
;
return
0
;
}
public
function
actionHot
()
...
...
wallet/controllers/IssueChainController.php
0 → 100644
View file @
30f735a0
<?php
namespace
wallet\controllers
;
use
common\models\psources\CoinPlatform
;
use
common\models\psources\CoinSupportedCoin
;
use
Yii
;
use
wallet\base\BaseController
;
class
IssueChainController
extends
BaseController
{
/**
* 可发行链列表
* @return array
*/
public
function
actionIndex
()
{
$data
=
null
;
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
1
==
$platform_id
)
{
$chain_model
=
CoinPlatform
::
find
()
->
all
();
}
else
{
$chain_model
=
CoinPlatform
::
find
()
->
where
([
'id'
=>
$platform_id
])
->
all
();
}
if
(
false
==
$chain_model
)
{
$msg
=
'不存在的链'
;
$code
=
-
1
;
goto
doEnd
;
}
foreach
(
$chain_model
as
&
$val
)
{
$val
->
chain_name
=
isset
(
$val
->
chain
->
platform
)
?
$val
->
chain
->
platform
:
''
;
unset
(
$val
->
download_url
);
unset
(
$val
->
introduce
);
unset
(
$val
->
create_time
);
unset
(
$val
->
update_time
);
unset
(
$val
->
chain_id
);
}
$msg
=
'ok'
;
$code
=
0
;
$data
=
$chain_model
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
/**
* 发行链信息
* @return array
*/
public
function
actionChainInfo
()
{
$data
=
null
;
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
empty
(
$platform_id
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
if
(
1
==
$platform_id
)
{
$chain_model
=
CoinPlatform
::
find
()
->
select
(
'id, chain_id'
)
->
all
();
}
else
{
$chain_model
=
CoinPlatform
::
find
()
->
select
(
'id, chain_id'
)
->
where
([
'id'
=>
$platform_id
])
->
all
();
}
if
(
false
==
$chain_model
)
{
$msg
=
'不存在的链'
;
$code
=
-
1
;
goto
doEnd
;
}
foreach
(
$chain_model
as
&
$val
)
{
$val
->
chain_name
=
isset
(
$val
->
chain
->
platform
)
?
$val
->
chain
->
platform
:
''
;
$coin_supported_coin
=
CoinSupportedCoin
::
find
()
->
select
(
'id, coin_name'
)
->
where
([
'platform_id'
=>
$val
->
id
])
->
asArray
()
->
all
();
$val
->
charge_unit
=
$coin_supported_coin
;
}
$msg
=
'ok'
;
$code
=
0
;
$data
=
is_array
(
$chain_model
)
?
$chain_model
:
[
$chain_model
];
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
/**
* 设置手续费
* @param integer issue_charge
* @param integer charge_unit_id
* @param integer platform_id
* @return array
*/
public
function
actionSetCharge
()
{
$data
=
null
;
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
$result
=
Yii
::
$app
->
request
->
post
();
$issue_charge
=
isset
(
$result
[
'issue_charge'
])
?
$result
[
'issue_charge'
]
:
''
;
$charge_unit_id
=
isset
(
$result
[
'charge_unit_id'
])
?
strtoupper
(
$result
[
'charge_unit_id'
])
:
''
;
$id
=
isset
(
$result
[
'platform_id'
])
?
(
int
)
$result
[
'platform_id'
]
:
0
;
if
(
false
==
$issue_charge
||
false
==
$charge_unit_id
)
{
$msg
=
'提交数据有误'
;
$code
=
-
1
;
goto
doEnd
;
}
if
(
1
==
$platform_id
)
{
$platform_id
=
$id
;
}
$chain_model
=
CoinPlatform
::
find
()
->
where
([
'id'
=>
$platform_id
])
->
one
();
if
(
false
==
$chain_model
)
{
$msg
=
'不存在的链'
;
$code
=
-
1
;
goto
doEnd
;
}
$chain_model
->
issue_charge
=
$issue_charge
;
$chain_model
->
charge_unit_id
=
$charge_unit_id
;
if
(
false
==
$chain_model
->
save
())
{
$msg
=
'手续费设置失败'
;
$code
=
-
1
;
goto
doEnd
;
}
$msg
=
'ok'
;
$code
=
0
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
/**
* 人工审核开启/关闭
* @param string manual_review
* @return array
*/
public
function
actionManageReview
()
{
$data
=
null
;
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
1
!=
$platform_id
)
{
$msg
=
'当前账户无权限操作'
;
$code
=
-
1
;
goto
doEnd
;
}
$manual_review
=
\Yii
::
$app
->
request
->
post
(
'manual_review'
,
''
);
if
(
!
in_array
(
$manual_review
,
[
'open'
,
'close'
]))
{
$msg
=
'参数错误'
;
$code
=
-
1
;
goto
doEnd
;
}
Yii
::
$app
->
redis
->
set
(
'issue_chain_manual_review'
,
$manual_review
);
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
}
\ No newline at end of file
wallet/controllers/IssueCoinController.php
0 → 100644
View file @
30f735a0
<?php
namespace
wallet\controllers
;
use
common\models\psources\CoinIssueChainRecord
;
use
Yii
;
use
yii\data\Pagination
;
use
wallet\base\BaseController
;
use
common\models\psources\CoinIssueCoin
;
class
IssueCoinController
extends
BaseController
{
/**
* 申请列表
* @param integer page
* @param integer size
* @param integer status
* @param string owner
* @param integer chain_id
* @return array
*/
public
function
actionApplyList
()
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
$page
=
\Yii
::
$app
->
request
->
get
(
'page'
,
1
);
$size
=
\Yii
::
$app
->
request
->
get
(
'size'
,
10
);
$status
=
\Yii
::
$app
->
request
->
get
(
'status'
,
-
1
);
$owner
=
\Yii
::
$app
->
request
->
get
(
'owner'
,
''
);
$chain_id
=
\Yii
::
$app
->
request
->
get
(
'chain_id'
,
''
);
if
(
1
==
$platform_id
)
{
$query
=
CoinIssueCoin
::
find
()
->
select
(
'id, name, total, status, chain_id, charge_unit_id, charge, platform_id, owner, category, type, symbol, introduction, create_time'
)
->
where
([
'in'
,
'status'
,
[
CoinIssueCoin
::
STATUS_CONFIRM
,
CoinIssueCoin
::
STATUS_ALLOW
,
CoinIssueCoin
::
STATUS_REFUSE
,
CoinIssueCoin
::
STATUS_SUCCESS
,
CoinIssueCoin
::
STATUS_FAILED
]])
->
orderBy
(
'create_time desc'
);
}
else
{
$query
=
CoinIssueCoin
::
find
()
->
select
(
'id, name, total, status, chain_id, charge_unit_id, charge, platform_id, owner, category, type, symbol, introduction, create_time'
)
->
where
([
'platform_id'
=>
$platform_id
])
->
andWhere
([
'in'
,
'status'
,
[
CoinIssueCoin
::
STATUS_CONFIRM
,
CoinIssueCoin
::
STATUS_ALLOW
,
CoinIssueCoin
::
STATUS_REFUSE
,
CoinIssueCoin
::
STATUS_SUCCESS
,
CoinIssueCoin
::
STATUS_FAILED
]])
->
orderBy
(
'create_time desc'
);
}
if
(
$status
>
-
1
)
{
$query
->
andWhere
([
'status'
=>
$status
]);
}
if
(
false
!=
$owner
)
{
$query
->
andWhere
([
'owner'
=>
$owner
]);
}
if
(
false
!=
$chain_id
)
{
$query
->
andWhere
([
'chain_id'
=>
$chain_id
]);
}
$countQuery
=
clone
$query
;
$pages
=
new
Pagination
([
'totalCount'
=>
$countQuery
->
count
(),
'pageSize'
=>
$size
]);
$models
=
$query
->
offset
(
$pages
->
offset
)
->
limit
(
$pages
->
limit
)
->
all
();
foreach
(
$models
as
&
$val
)
{
$platform
=
isset
(
$val
->
chain
->
platform
)
?
$val
->
chain
->
platform
:
''
;
$val
->
chain_name
=
$platform
;
$val
->
charge_unit
=
isset
(
$val
->
gas
->
coin_name
)
?
$val
->
gas
->
coin_name
:
''
;
$val
->
url
=
Yii
::
$app
->
redis
->
hget
(
'platform_brower_info'
,
$platform
);
$val
->
total
=
(
int
)
$val
->
total
*
1e8
;
}
$data
=
[
'list'
=>
$models
,
'page'
=>
[
'pageCount'
=>
$pages
->
pageCount
,
'pageSize'
=>
$size
,
'currentPage'
=>
(
int
)
$page
,
]
];
$msg
=
'ok'
;
$code
=
0
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
/**
* 申请详情
* @param integer id
* @return array
*/
public
function
actionApplyDetail
()
{
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
''
);
$data
=
null
;
if
(
empty
(
$id
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$data
=
CoinIssueCoin
::
find
()
->
where
([
'id'
=>
$id
])
->
one
();
$platform
=
isset
(
$data
->
chain
->
platform
)
?
$data
->
chain
->
platform
:
''
;
$data
->
total
=
(
int
)
$data
->
total
*
1e8
;
$data
->
issue_charge
=
rtrim
(
sprintf
(
'%.3f'
,
floatval
(
$data
->
charge
)),
'0'
);
$data
->
charge_unit
=
isset
(
$data
->
gas
->
coin_name
)
?
$data
->
gas
->
coin_name
:
''
;
$data
->
url
=
Yii
::
$app
->
redis
->
hget
(
'platform_brower_info'
,
$platform
);
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
/**
* 申请操作管理
* @param integer id
* @param integer status
* @param string msg
* @return array
*/
public
function
actionVerify
()
{
$id
=
Yii
::
$app
->
request
->
post
(
'id'
,
''
);
$status
=
Yii
::
$app
->
request
->
post
(
'status'
,
''
);
$msg
=
Yii
::
$app
->
request
->
post
(
'msg'
,
''
);
if
(
false
==
$id
||
false
==
$status
)
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
if
(
!
in_array
(
$status
,
[
CoinIssueCoin
::
STATUS_ALLOW
,
CoinIssueCoin
::
STATUS_REFUSE
]))
{
$msg
=
'状态值错误'
;
$code
=
-
1
;
goto
doEnd
;
}
$model
=
CoinIssueCoin
::
findOne
(
$id
);
if
(
false
==
$model
)
{
$msg
=
'不存在的记录'
;
$code
=
-
1
;
goto
doEnd
;
}
$data
=
[
'status'
=>
$status
,
#'msg' => $msg
];
$model
->
setScenario
(
CoinIssueCoin
::
SCENARIOS_UPDATE
);
$model
->
load
(
$data
,
''
);
if
(
!
$model
->
save
())
{
$msg
=
current
(
$model
->
firstErrors
);
$code
=
-
1
;
goto
doEnd
;
}
$record
=
CoinIssueChainRecord
::
find
()
->
where
([
'issue_coin_id'
=>
$id
])
->
one
();
$record
->
finish_tx
=
'failed'
;
$record
->
finish_send_transaction
=
'failed'
;
$record
->
finish_query_transaction
=
$msg
;
$record
->
save
();
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
}
\ 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