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
280f981e
Commit
280f981e
authored
Apr 01, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/airdrop' into develop
parents
332dde66
ec71026d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
11 deletions
+65
-11
AirDropController.php
api/controllers/AirDropController.php
+62
-7
AirDrop.php
common/models/psources/AirDrop.php
+2
-1
AirDropController.php
console/controllers/AirDropController.php
+1
-3
No files found.
api/controllers/AirDropController.php
View file @
280f981e
...
...
@@ -8,6 +8,7 @@ use common\models\psources\AirDrop;
use
common\service\chain33\Chain33Service
;
use
common\models\psources\CoinAirDropTrade
;
use
common\models\psources\AirDropApplyRecord
;
use
yii\db\Exception
;
class
AirDropController
extends
BaseController
{
...
...
@@ -22,13 +23,43 @@ class AirDropController extends BaseController
{
if
(
Yii
::
$app
->
request
->
isPost
)
{
$data
=
Yii
::
$app
->
request
->
post
();
$model
=
new
AirDrop
();
$model
->
setScenario
(
AirDrop
::
SCENARIOS_CREATE
);
if
(
$model
->
load
(
$data
,
''
)
&&
$model
->
save
())
{
$create_time
=
date
(
'Y-m-d'
);
$finish_time
=
date
(
'Y-m-d'
,
strtotime
(
"+7 day"
));
$transaction
=
Yii
::
$app
->
db
->
beginTransaction
();
try
{
$model
=
new
AirDrop
();
$model
->
setScenario
(
AirDrop
::
SCENARIOS_CREATE
);
$model
->
load
(
$data
,
''
);
if
(
!
$model
->
validate
())
{
$this
->
code
=
-
1
;
$this
->
msg
=
$model
->
errors
;
goto
doEnd
;
}
$model
->
save
();
$apply_id
=
$model
->
id
;
$expiry_date
=
$this
->
getDatesFromRange
(
$create_time
,
$finish_time
);
$apply_record_model
=
new
AirDropApplyRecord
();
foreach
(
$expiry_date
as
$val
)
{
$apply_record_model
->
setIsNewRecord
(
true
);
$apply_record_model
->
apply_id
=
$apply_id
;
$apply_record_model
->
reach
=
AirDropApplyRecord
::
REACH_NO
;
$apply_record_model
->
bonus_token
=
3
;
$apply_record_model
->
draw_status
=
AirDropApplyRecord
::
STATUS_UNDRAW
;
$apply_record_model
->
create_time
=
$val
;
$apply_record_model
->
update_time
=
$val
;
$apply_record_model
->
save
()
&&
$apply_record_model
->
id
=
0
;;
}
$transaction
->
commit
();
}
catch
(
Exception
$e
)
{
$transaction
->
rollback
();
$this
->
code
=
-
1
;
$this
->
msg
=
$e
->
getMessage
();
goto
doEnd
;
}
$this
->
code
=
-
1
;
$this
->
msg
=
$model
->
errors
;
if
(
empty
(
$this
->
msg
))
{
$this
->
msg
=
'Validation failed.'
;
}
...
...
@@ -63,8 +94,8 @@ class AirDropController extends BaseController
$apply_id_arr
=
explode
(
','
,
$apply_ids
);
$query
->
andWhere
([
'in'
,
'id'
,
$apply_id_arr
]);
}
// $expiry_date = date("Y-m-d", time()) . " 00:00:00"
;
//
$query->andWhere(['<', 'create_time', $expiry_date]);
$expiry_date
=
date
(
"Y-m-d"
,
strtotime
(
"+1 day"
))
;
$query
->
andWhere
([
'<'
,
'create_time'
,
$expiry_date
]);
$items
=
$query
->
offset
((
$page
-
1
)
*
$size
)
->
orderBy
(
'id desc'
)
->
limit
(
$size
)
->
all
();
$countQuery
=
clone
$query
;
...
...
@@ -310,4 +341,27 @@ class AirDropController extends BaseController
}
return
[
'code'
=>
1
,
'msg'
=>
'ok'
];
}
function
getDatesFromRange
(
$start
,
$end
,
$format
=
'Y-m-d'
)
{
// Declare an empty array
$array
=
array
();
// Variable that store the date interval
// of period 1 day
$interval
=
new
\DateInterval
(
'P1D'
);
$realEnd
=
new
\DateTime
(
$end
);
$realEnd
->
add
(
$interval
);
$period
=
new
\DatePeriod
(
new
\DateTime
(
$start
),
$interval
,
$realEnd
);
// Use loop to store date into array
foreach
(
$period
as
$date
)
{
$array
[]
=
$date
->
format
(
$format
);
}
// Return the array elements
return
$array
;
}
}
\ No newline at end of file
common/models/psources/AirDrop.php
View file @
280f981e
...
...
@@ -26,6 +26,7 @@ class AirDrop extends CommonActiveRecord
return
[
[[
'identifier'
,
'wallet_address'
,
'miner_address'
],
'required'
],
[[
'reach_times'
],
'integer'
],
[[
'create_time'
,
'finish_time'
],
'safe'
],
[[
'identifier'
],
'string'
,
'length'
=>
[
5
,
50
]],
[[
'wallet_address'
,
'miner_address'
],
'string'
,
'length'
=>
[
10
,
50
]],
[
'identifier'
,
'unique'
,
'message'
=>
'树莓派编号已存在'
],
...
...
@@ -36,7 +37,7 @@ class AirDrop extends CommonActiveRecord
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'identifier'
,
'miner_address'
],
self
::
SCENARIOS_CREATE
=>
[
'identifier'
,
'miner_address'
,
'reach_times'
,
'create_time'
,
'finish_time'
],
self
::
SCENARIOS_UPDATE
=>
[
'wallet_address'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
...
...
console/controllers/AirDropController.php
View file @
280f981e
...
...
@@ -49,7 +49,6 @@ class AirDropController extends Controller
*/
public
function
actionReach
()
{
$begin
=
date
(
"Y-m-d"
,
time
())
.
" 00:00:00"
;
$end
=
date
(
"Y-m-d"
,
time
())
.
" 23:59:59"
;
...
...
@@ -140,8 +139,7 @@ class AirDropController extends Controller
/**
* 获取游戏状态
*
* @return array
* @return
*/
public
function
actionAutoAirDrop
()
{
...
...
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