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
29f13137
Commit
29f13137
authored
Apr 30, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/airdrop' into 'master'
游戏空投 See merge request
!4
parents
3a260f2c
da0f0201
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
0 deletions
+114
-0
AirDropController.php
api/controllers/AirDropController.php
+71
-0
CoinAirDropTrade.php
common/models/psources/CoinAirDropTrade.php
+43
-0
No files found.
api/controllers/AirDropController.php
0 → 100644
View file @
29f13137
<?php
namespace
api\controllers
;
use
api\base\BaseController
;
use
common\models\psources\CoinAirDropTrade
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
class
AirDropController
extends
BaseController
{
public
function
actionGameTrade
()
{
$coins_address
=
Yii
::
$app
->
request
->
post
(
'coins_address'
,
''
);
if
(
empty
(
$coins_address
)){
return
[
'code'
=>
-
1
,
'msg'
=>
'参数不能为空'
];
}
$coinTokenTransfer
=
CoinAirDropTrade
::
find
()
->
where
([
'coins_address'
=>
$coins_address
,
'type'
=>
CoinAirDropTrade
::
TYPE_GAME
])
->
one
();
if
(
$coinTokenTransfer
){
return
[
'code'
=>
-
1
,
'data'
=>
null
,
'msg'
=>
'record already exists'
];
}
$fee
=
100000
;
$amount
=
CoinAirDropTrade
::
AMOUNT_GAME
*
1e8
;
$execer
=
'coins'
;
$note
=
''
;
$service
=
new
Chain33Service
();
$createRawTransaction
=
$service
->
createRawTransaction
(
$coins_address
,
$amount
,
$fee
,
$note
,
$execer
);
if
(
0
!=
$createRawTransaction
[
'code'
]){
$msg
=
$createRawTransaction
[
'msg'
];
$code
=
-
1
;
goto
doEnd
;
}
$txHex
=
$createRawTransaction
[
'result'
];
$privkey
=
'72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e2'
;
$expire
=
'1m'
;
$signRawTx
=
$service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
]){
$msg
=
$signRawTx
[
'msg'
];
$code
=
-
1
;
goto
doEnd
;
}
$sign_str
=
$signRawTx
[
'result'
];
$result
=
$service
->
sendTransaction
(
$sign_str
);
if
(
0
!=
$result
[
'code'
]){
$msg
=
$result
[
'msg'
];
$code
=
-
1
;
goto
doEnd
;
}
$code
=
1
;
$msg
=
$result
[
'result'
];
doEnd
:
$airDropModel
=
new
CoinAirDropTrade
();
$airDropModel
->
coins_address
=
$coins_address
;
$airDropModel
->
amount
=
CoinAirDropTrade
::
AMOUNT_GAME
;
$airDropModel
->
msg
=
$msg
;
$airDropModel
->
type
=
CoinAirDropTrade
::
TYPE_GAME
;
$airDropModel
->
save
();
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
}
\ No newline at end of file
common/models/psources/CoinAirDropTrade.php
0 → 100644
View file @
29f13137
<?php
namespace
common\models\psources
;
use
Yii
;
use
common\core\BaseActiveRecord
;
class
CoinAirDropTrade
extends
BaseActiveRecord
{
const
TYPE_GAME
=
1
;
const
AMOUNT_GAME
=
0.2
;
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coin_airdrop_trade}}'
;
}
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
public
function
rules
()
{
return
[
[[
'coins_address'
,
'msg'
,
'amount'
,
'type'
],
'required'
],
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'coins_address'
,
'msg'
,
'amount'
,
'type'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
}
\ 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