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
ca4c1267
Commit
ca4c1267
authored
Apr 02, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
后端空投接口
parent
f8ce4672
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
107 additions
and
23 deletions
+107
-23
AirDropController.php
api/controllers/AirDropController.php
+1
-1
AirDrop.php
common/models/psources/AirDrop.php
+5
-0
AirDropController.php
console/controllers/AirDropController.php
+35
-22
AirDropController.php
wallet/controllers/AirDropController.php
+66
-0
No files found.
api/controllers/AirDropController.php
View file @
ca4c1267
...
...
@@ -65,7 +65,7 @@ class AirDropController extends BaseController
}
$redis
=
Yii
::
$app
->
redis_app
;
$redis
->
hmset
(
'airdrop:'
.
$data
[
'identifier'
],
'
draw_success'
,
0
,
'income'
,
0
,
'reach_time
'
,
0
);
$redis
->
hmset
(
'airdrop:'
.
$data
[
'identifier'
],
'
reach'
,
0
,
'draw_success'
,
0
,
'income'
,
0
,
'un_draw
'
,
0
);
goto
doEnd
;
}
...
...
common/models/psources/AirDrop.php
View file @
ca4c1267
...
...
@@ -55,6 +55,11 @@ class AirDrop extends CommonActiveRecord
];
}
public
function
attributes
()
{
return
array_merge
(
parent
::
attributes
(),
[
'reach'
,
'draw_success'
,
'income'
,
'un_draw'
]);
}
public
function
getRecord
()
{
return
$this
->
hasMany
(
AirDropApplyRecord
::
className
(),
[
'apply_id'
=>
'id'
])
->
all
();
...
...
console/controllers/AirDropController.php
View file @
ca4c1267
...
...
@@ -18,32 +18,45 @@ class AirDropController extends Controller
*/
public
function
actionStatistics
()
{
$expiry_date
=
date
(
"Y-m-d 00:00:00"
,
strtotime
(
"+1 day"
));
$apply
=
AirDrop
::
find
()
->
select
(
'id, identifier, finish_time'
)
->
where
([
'<'
,
'create_time'
,
$expiry_date
])
->
asArray
()
->
all
();
if
(
empty
(
$apply
)
||
empty
(
$apply
->
record
))
{
$expiry_date
=
date
(
"Y-m-d"
,
strtotime
(
"+1 day"
));
$apply
=
AirDrop
::
find
()
->
select
(
'id, identifier, finish_time'
)
->
all
();
if
(
empty
(
$apply
))
{
return
0
;
}
$redis
=
Yii
::
$app
->
redis_app
;
foreach
(
$apply
as
$val
)
{
//达标次数
$reach
=
AirDropApplyRecord
::
find
()
->
where
([
'apply_id'
=>
$val
[
'id'
],
'reach'
=>
AirDropApplyRecord
::
REACH_YES
])
->
sum
(
'reach'
);
$reach
=
empty
(
$reach
)
?
0
:
$reach
;
//已领取
$draw
=
AirDropApplyRecord
::
find
()
->
where
([
'apply_id'
=>
$val
[
'id'
],
'draw_status'
=>
AirDropApplyRecord
::
STATUS_DRAW_SUEEESS
])
->
sum
(
'bonus_token'
);
$draw
=
empty
(
$draw
)
?
0
:
$draw
;
//总收益
$income
=
AirDropApplyRecord
::
find
()
->
where
([
'apply_id'
=>
$val
[
'id'
],
'reach'
=>
AirDropApplyRecord
::
REACH_YES
])
->
sum
(
'bonus_token'
);
$income
=
empty
(
$income
)
?
0
:
$income
;
go
(
function
()
use
(
$val
,
$redis
,
$expiry_date
)
{
\Co
::
sleep
(
0.5
);
if
(
!
empty
(
$val
->
record
))
{
//达标次数
$reach
=
AirDropApplyRecord
::
find
()
->
where
([
'apply_id'
=>
$val
[
'id'
],
'reach'
=>
AirDropApplyRecord
::
REACH_YES
])
->
andWhere
([
'<'
,
'create_time'
,
$expiry_date
])
->
sum
(
'reach'
);
$reach
=
empty
(
$reach
)
?
0
:
(
int
)
$reach
;
//已领取
$draw_success
=
AirDropApplyRecord
::
find
()
->
where
([
'apply_id'
=>
$val
[
'id'
],
'draw_status'
=>
AirDropApplyRecord
::
STATUS_DRAW_SUEEESS
])
->
andWhere
([
'<'
,
'create_time'
,
$expiry_date
])
->
sum
(
'bonus_token'
);
$draw_success
=
empty
(
$draw_success
)
?
0
:
(
int
)
$draw_success
;
//总收益
$income
=
AirDropApplyRecord
::
find
()
->
where
([
'apply_id'
=>
$val
[
'id'
],
'reach'
=>
AirDropApplyRecord
::
REACH_YES
])
->
andWhere
([
'<'
,
'create_time'
,
$expiry_date
])
->
sum
(
'bonus_token'
);
$income
=
empty
(
$income
)
?
0
:
(
int
)
$income
;
//未领取
$un_draw
=
$income
-
$draw_success
;
$redis
->
hmset
(
'airdrop:'
.
$val
->
identifier
,
'reach'
,
$reach
,
'draw_success'
,
$draw_success
,
'income'
,
$income
,
'un_draw'
,
$un_draw
);
}
});
}
return
0
;
}
...
...
wallet/controllers/AirDropController.php
View file @
ca4c1267
...
...
@@ -3,12 +3,61 @@
namespace
wallet\controllers
;
use
common\models\psources\AirDropApplyRecord
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
use
wallet\base\BaseController
;
use
common\models\psources\AirDrop
;
class
AirDropController
extends
BaseController
{
/**
* 空投地址余额
* @param
* @return array
*/
public
function
actionGetBalance
()
{
$address
=
Yii
::
$app
->
params
[
'AirDrop'
][
'address'
];
$service
=
new
Chain33Service
();
$execer
=
'coins'
;
$result
=
$service
->
getBalance
(
$address
,
$execer
);
if
(
0
!=
$result
[
'code'
])
{
$this
->
code
=
-
1
;
$this
->
msg
=
'余额获取失败。失败原因:'
.
$result
[
'error'
];
goto
doEnd
;
}
$this
->
data
=
$result
[
'result'
][
0
][
'balance'
]
??
0
;
doEnd
:
return
[
'code'
=>
$this
->
code
,
'msg'
=>
$this
->
msg
,
'data'
=>
$this
->
data
];
}
/**
* 总空投金额
* @param
* @return array
*/
public
function
actionExpenses
()
{
$expiry_date
=
date
(
"Y-m-d"
,
strtotime
(
"+1 day"
));
$this
->
data
=
AirDropApplyRecord
::
find
()
->
where
([
'draw_status'
=>
AirDropApplyRecord
::
STATUS_DRAW_SUEEESS
])
->
andWhere
([
'<'
,
'create_time'
,
$expiry_date
])
->
sum
(
'bonus_token'
);
if
(
empty
(
$this
->
data
))
{
$this
->
data
=
0
;
}
doEnd
:
return
[
'code'
=>
$this
->
code
,
'msg'
=>
$this
->
msg
,
'data'
=>
(
int
)
$this
->
data
];
}
/**
* 空投申请列表
* @param page 页码
* @param size 每页显示条数
* @return array
*/
public
function
actionIndex
()
{
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
...
...
@@ -25,6 +74,14 @@ class AirDropController extends BaseController
goto
doEnd
;
}
$countQuery
=
clone
$query
;
$redis
=
Yii
::
$app
->
redis_app
;
foreach
(
$model
as
&
$val
)
{
list
(
$reach
,
$draw_success
,
$income
,
$un_draw
)
=
$redis
->
hmget
(
'airdrop:'
.
$val
->
identifier
,
'reach'
,
'draw_success'
,
'income'
,
'un_draw'
);
$val
->
reach
=
empty
(
$reach
)
?
0
:
(
int
)
$reach
;
$val
->
draw_success
=
empty
(
$draw_success
)
?
0
:
(
int
)
$draw_success
;
$val
->
income
=
empty
(
$income
)
?
0
:
(
int
)
$income
;
$val
->
un_draw
=
empty
(
$un_draw
)
?
0
:
(
int
)
$un_draw
;
}
$this
->
data
=
[
'items'
=>
$model
,
'total'
=>
(
int
)
$countQuery
->
count
()
...
...
@@ -34,6 +91,15 @@ class AirDropController extends BaseController
return
[
'code'
=>
$this
->
code
,
'msg'
=>
$this
->
msg
,
'data'
=>
$this
->
data
];
}
/**
* 每个树莓派的空投记录
* @param identifier 树莓派编号
* @param miner_address 矿工地址
* @param apply_ids
* @param page 页码
* @param size 每页显示条数
* @return array
*/
public
function
actionApply
()
{
$page
=
\Yii
::
$app
->
request
->
get
(
'page'
,
1
);
...
...
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