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
e6bf216b
Commit
e6bf216b
authored
Mar 31, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
da76d9eb
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
191 additions
and
15 deletions
+191
-15
AirDropController.php
api/controllers/AirDropController.php
+18
-5
AirDropApplyRecord.php
common/models/psources/AirDropApplyRecord.php
+6
-0
AirDropApplyTransferRecord.php
common/models/psources/AirDropApplyTransferRecord.php
+55
-0
Chain33Service.php
common/service/chain33/Chain33Service.php
+2
-3
AirDropController.php
console/controllers/AirDropController.php
+110
-7
No files found.
api/controllers/AirDropController.php
View file @
e6bf216b
...
@@ -2,16 +2,22 @@
...
@@ -2,16 +2,22 @@
namespace
api\controllers
;
namespace
api\controllers
;
use
Yii
;
use
api\base\BaseController
;
use
api\base\BaseController
;
use
common\models\psources\AirDrop
;
use
common\models\psources\AirDrop
;
use
common\models\psources\AirDropApplyRecord
;
use
common\models\psources\CoinAirDropTrade
;
use
common\service\chain33\Chain33Service
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
use
common\models\psources\CoinAirDropTrade
;
use
common\models\psources\AirDropApplyRecord
;
class
AirDropController
extends
BaseController
class
AirDropController
extends
BaseController
{
{
/**
* 参于空投申请/空投申请列表
* @param identifier 树莓派编号
* @param miner_address 矿工地址
* @param apply_ids
* @return array
*/
public
function
actionApply
()
public
function
actionApply
()
{
{
if
(
Yii
::
$app
->
request
->
isPost
)
{
if
(
Yii
::
$app
->
request
->
isPost
)
{
...
@@ -36,6 +42,7 @@ class AirDropController extends BaseController
...
@@ -36,6 +42,7 @@ class AirDropController extends BaseController
$data
=
Yii
::
$app
->
request
->
get
();
$data
=
Yii
::
$app
->
request
->
get
();
$identifier
=
$data
[
'identifier'
]
??
''
;
$identifier
=
$data
[
'identifier'
]
??
''
;
$miner_address
=
$data
[
'miner_address'
]
??
''
;
$miner_address
=
$data
[
'miner_address'
]
??
''
;
$apply_ids
=
isset
(
$data
[
'apply_ids'
])
?
$data
[
'apply_ids'
]
:
''
;
if
(
false
==
$identifier
||
false
==
$miner_address
)
{
if
(
false
==
$identifier
||
false
==
$miner_address
)
{
$this
->
code
=
-
1
;
$this
->
code
=
-
1
;
$this
->
msg
=
'Validation failed.'
;
$this
->
msg
=
'Validation failed.'
;
...
@@ -51,6 +58,11 @@ class AirDropController extends BaseController
...
@@ -51,6 +58,11 @@ class AirDropController extends BaseController
$query
=
AirDropApplyRecord
::
find
()
$query
=
AirDropApplyRecord
::
find
()
->
select
(
'id, reach, bonus_token, draw_status, create_time'
)
->
select
(
'id, reach, bonus_token, draw_status, create_time'
)
->
where
([
'apply_id'
=>
$model
[
'id'
]]);
->
where
([
'apply_id'
=>
$model
[
'id'
]]);
if
(
!
empty
(
$apply_ids
))
{
$apply_ids
=
rtrim
(
$apply_ids
,
','
);
$apply_id_arr
=
explode
(
','
,
$apply_ids
);
$query
->
andWhere
([
'in'
,
'id'
,
$apply_id_arr
]);
}
$items
=
$query
->
offset
((
$page
-
1
)
*
$size
)
->
orderBy
(
'id desc'
)
->
limit
(
$size
)
->
all
();
$items
=
$query
->
offset
((
$page
-
1
)
*
$size
)
->
orderBy
(
'id desc'
)
->
limit
(
$size
)
->
all
();
$countQuery
=
clone
$query
;
$countQuery
=
clone
$query
;
...
@@ -58,7 +70,8 @@ class AirDropController extends BaseController
...
@@ -58,7 +70,8 @@ class AirDropController extends BaseController
$this
->
data
=
[
$this
->
data
=
[
'items'
=>
$items
,
'items'
=>
$items
,
'total'
=>
$total
'total'
=>
$total
,
'income'
=>
134
];
];
}
}
...
...
common/models/psources/AirDropApplyRecord.php
View file @
e6bf216b
...
@@ -55,4 +55,9 @@ class AirDropApplyRecord extends CommonActiveRecord
...
@@ -55,4 +55,9 @@ class AirDropApplyRecord extends CommonActiveRecord
'finish_time'
=>
'更新时间'
'finish_time'
=>
'更新时间'
];
];
}
}
public
function
getApply
()
{
return
$this
->
hasOne
(
AirDrop
::
className
(),
[
'id'
=>
'apply_id'
])
->
one
();
}
}
}
\ No newline at end of file
common/models/psources/AirDropApplyTransferRecord.php
0 → 100644
View file @
e6bf216b
<?php
namespace
common\models\psources
;
use
Yii
;
use
yii\db\Expression
;
class
AirDropApplyTransferRecord
extends
CommonActiveRecord
{
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%wallet_airdrop_apply_transfer_record}}'
;
}
public
function
rules
()
{
return
[
[[
'apply_record_id'
,
'create_result'
,
'sign_result'
,
'send_result'
],
'safe'
],
[[
'apply_record_id'
],
'integer'
],
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'apply_record_id'
,
'create_result'
,
'sign_result'
,
'send_result'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
public
function
attributeLabels
()
{
return
[
'apply_record_id'
=>
'申请记录id'
,
'create_result'
=>
'构造失败原因'
,
'sign_result'
=>
'签名失败原因'
,
'send_result'
=>
'发送失败原因'
,
'create_time'
=>
'创建时间'
,
];
}
public
function
getRecord
()
{
return
$this
->
hasOne
(
AirDropApplyRecord
::
className
(),
[
'id'
=>
'apply_record_id'
])
->
all
();
}
}
\ No newline at end of file
common/service/chain33/Chain33Service.php
View file @
e6bf216b
...
@@ -203,7 +203,7 @@ class Chain33Service
...
@@ -203,7 +203,7 @@ class Chain33Service
return
$this
->
send
(
$params
,
'Chain33.CreateRawTransaction'
);
return
$this
->
send
(
$params
,
'Chain33.CreateRawTransaction'
);
}
}
public
function
createRawTransaction
(
$to
,
$amount
,
$fee
,
$note
,
$execer
)
public
function
createRawTransaction
(
$to
,
$amount
,
$fee
,
$note
,
$execer
,
$tokenSymbol
=
''
)
{
{
$params
=
[
$params
=
[
"to"
=>
$to
,
"to"
=>
$to
,
...
@@ -211,7 +211,6 @@ class Chain33Service
...
@@ -211,7 +211,6 @@ class Chain33Service
"fee"
=>
$fee
,
"fee"
=>
$fee
,
"note"
=>
$note
,
"note"
=>
$note
,
"execer"
=>
$execer
,
"execer"
=>
$execer
,
];
];
return
$this
->
send
(
$params
,
'Chain33.CreateRawTransaction'
);
return
$this
->
send
(
$params
,
'Chain33.CreateRawTransaction'
);
}
}
...
@@ -259,7 +258,7 @@ class Chain33Service
...
@@ -259,7 +258,7 @@ class Chain33Service
public
function
getBalance
(
$address
,
$execer
=
""
)
public
function
getBalance
(
$address
,
$execer
=
""
)
{
{
$params
=
[
$params
=
[
'addresses'
=>
$address
,
'addresses'
=>
[
$address
]
,
'execer'
=>
$execer
,
'execer'
=>
$execer
,
];
];
return
$this
->
send
(
$params
,
'Chain33.GetBalance'
);
return
$this
->
send
(
$params
,
'Chain33.GetBalance'
);
...
...
console/controllers/AirDropController.php
View file @
e6bf216b
...
@@ -2,14 +2,20 @@
...
@@ -2,14 +2,20 @@
namespace
console\controllers
;
namespace
console\controllers
;
use
common\models\psources\AirDrop
;
use
Yii
;
use
Yii
;
use
yii\console\Controller
;
use
yii\console\Controller
;
use
common\models\psources\AirDrop
;
use
common\service\chain33\Chain33Service
;
use
common\service\chain33\Chain33Service
;
use
common\models\psources\AirDropApplyRecord
;
use
common\models\psources\CoinAirDropTransfer
;
use
common\models\psources\CoinAirDropTransfer
;
use
common\models\psources\AirDropApplyTransferRecord
;
class
AirDropController
extends
Controller
class
AirDropController
extends
Controller
{
{
/**
* 获取矿工地址的对应的冷钱包地址
* @return
*/
public
function
actionMinerSourceList
()
public
function
actionMinerSourceList
()
{
{
$model
=
AirDrop
::
find
()
->
where
([
'wallet_address'
=>
''
])
->
asArray
()
->
all
();
$model
=
AirDrop
::
find
()
->
where
([
'wallet_address'
=>
''
])
->
asArray
()
->
all
();
...
@@ -18,22 +24,119 @@ class AirDropController extends Controller
...
@@ -18,22 +24,119 @@ class AirDropController extends Controller
}
}
$service
=
new
Chain33Service
();
$service
=
new
Chain33Service
();
foreach
(
$model
as
$key
=>
$val
)
{
foreach
(
$model
as
$key
=>
$val
)
{
go
(
function
()
use
(
$val
,
$service
)
{
\Co
::
sleep
(
0.5
);
$playload
=
[
$playload
=
[
'data'
=>
$val
[
'miner_address'
]
'data'
=>
$val
[
'miner_address'
]
];
];
$result
=
$service
->
chainQuery
(
'ticket'
,
'MinerSourceList'
,
$playload
);
$result
=
$service
->
chainQuery
(
'ticket'
,
'MinerSourceList'
,
$playload
);
if
(
0
!=
$result
[
'code'
])
{
if
(
0
==
$result
[
'code'
])
{
continue
;
}
$wallet_address
=
isset
(
$result
[
'result'
][
'datas'
][
0
])
?
$result
[
'result'
][
'datas'
][
0
]
:
''
;
$wallet_address
=
isset
(
$result
[
'result'
][
'datas'
][
0
])
?
$result
[
'result'
][
'datas'
][
0
]
:
''
;
if
(
empty
(
$wallet_address
))
{
if
(
!
empty
(
$wallet_address
))
{
continue
;
}
$current_model
=
AirDrop
::
findOne
(
$val
[
'id'
]);
$current_model
=
AirDrop
::
findOne
(
$val
[
'id'
]);
$current_model
->
wallet_address
=
$wallet_address
;
$current_model
->
wallet_address
=
$wallet_address
;
$current_model
->
save
();
$current_model
->
save
();
}
}
}
}
});
}
}
/**
* 查询地址余额
* 通过矿主地址查询是否有冻结资金,有BTY代表达标
* @return
*/
public
function
actionReach
()
{
$begin
=
date
(
"Y-m-d"
,
time
())
.
" 00:00:00"
;
$end
=
date
(
"Y-m-d"
,
time
())
.
" 23:59:59"
;
$record
=
AirDropApplyRecord
::
find
()
->
where
([
'reach'
=>
AirDropApplyRecord
::
REACH_NO
])
->
andWhere
([
'between'
,
'create_time'
,
$begin
,
$end
])
->
all
();
if
(
empty
(
$record
))
return
0
;
$service
=
new
Chain33Service
();
$execer
=
'coins'
;
foreach
(
$record
as
$val
)
{
go
(
function
()
use
(
$val
,
$service
,
$execer
)
{
\Co
::
sleep
(
0.5
);
$result
=
$service
->
getBalance
(
$val
->
apply
->
wallet_address
,
$execer
);
if
(
0
==
$result
[
'code'
])
{
$frozen
=
$result
[
'result'
][
'frozen'
]
??
0
;
if
(
$frozen
>
0
)
{
$val
->
reach
=
AirDropApplyRecord
::
REACH_YES
;
$val
->
save
();
}
}
});
}
}
/**
* 领取符合条件的记录
* @return
*/
public
function
actionDraw
()
{
$record
=
AirDropApplyRecord
::
find
()
->
where
([
'reach'
=>
AirDropApplyRecord
::
REACH_YES
,
'draw_status'
=>
AirDropApplyRecord
::
STATUS_DRAWING
])
->
all
();
if
(
empty
(
$record
))
{
return
0
;
}
foreach
(
$record
as
$val
)
{
go
(
function
()
use
(
$val
)
{
\Co
::
sleep
(
0.5
);
$amount
=
1
;
$fee
=
1
;
$note
=
''
;
$execer
=
'token'
;
$isToken
=
true
;
$tokenSymbol
=
'CCNY'
;
$val
->
draw_status
=
AirDropApplyRecord
::
STATUS_DRAW_SUEEESS
;
$service
=
new
Chain33Service
();
$createTokenRawTransaction
=
$service
->
createTokenRawTransaction
(
$val
->
apply
->
wallet_address
,
$amount
,
$isToken
,
$tokenSymbol
,
$fee
,
$note
,
$execer
);
if
(
0
!=
$createTokenRawTransaction
[
'code'
])
{
$val
->
draw_status
=
AirDropApplyRecord
::
STATUS_DRAW_FAIL
;
$transfer_record
[
'create_result'
]
=
$createTokenRawTransaction
[
'msg'
];
goto
doEnd
;
}
$privkey
=
'72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e2'
;
$expire
=
'1m'
;
$signRawTx
=
$service
->
signRawTx
(
$privkey
,
$createTokenRawTransaction
[
'result'
],
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
$val
->
draw_status
=
AirDropApplyRecord
::
STATUS_DRAW_FAIL
;
$transfer_record
[
'sign_result'
]
=
$signRawTx
[
'msg'
];
goto
doEnd
;
}
$sendTransaction
=
$service
->
sendTransaction
(
$signRawTx
[
'result'
]);
if
(
0
!=
$sendTransaction
[
'code'
])
{
$val
->
draw_status
=
AirDropApplyRecord
::
STATUS_DRAW_FAIL
;
$transfer_record
[
'send_result'
]
=
$sendTransaction
[
'msg'
];
goto
doEnd
;
}
doEnd
:
if
(
$val
->
draw_status
==
AirDropApplyRecord
::
STATUS_DRAW_FAIL
)
{
$transfer_record_model
=
new
AirDropApplyTransferRecord
();
$transfer_record
[
'apply_record_id'
]
=
$val
->
id
;
$transfer_record_model
->
load
(
$transfer_record
,
''
);
$transfer_record_model
->
save
();
}
$val
->
save
();
});
}
return
0
;
}
/**
/**
* 获取游戏状态
* 获取游戏状态
...
...
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