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
2135ea03
Commit
2135ea03
authored
Jun 19, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
投注信息增加区块高度判断
parent
1e858c3a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
24 deletions
+53
-24
GameBetController.php
api/controllers/GameBetController.php
+1
-0
Chain33Business.php
common/business/Chain33Business.php
+12
-10
CoinGameBet.php
common/models/psources/CoinGameBet.php
+6
-3
GameBetController.php
console/controllers/GameBetController.php
+34
-11
No files found.
api/controllers/GameBetController.php
View file @
2135ea03
...
@@ -74,6 +74,7 @@ class GameBetController extends BaseController
...
@@ -74,6 +74,7 @@ class GameBetController extends BaseController
$query
=
CoinGameBet
::
find
()
$query
=
CoinGameBet
::
find
()
->
select
(
'round, player, amount, height, guess_num, guess_num, rand_num, player_win'
)
->
select
(
'round, player, amount, height, guess_num, guess_num, rand_num, player_win'
)
->
where
(
'player= :player'
,[
':player'
=>
$player
])
->
where
(
'player= :player'
,[
':player'
=>
$player
])
->
andWhere
([
'valid'
=>
CoinGameBet
::
VAILD_TRUE
])
->
orderBy
(
'update_time desc'
);
->
orderBy
(
'update_time desc'
);
$count
=
$query
->
count
();
$count
=
$query
->
count
();
...
...
common/business/Chain33Business.php
View file @
2135ea03
...
@@ -120,16 +120,6 @@ class Chain33Business
...
@@ -120,16 +120,6 @@ class Chain33Business
}
}
/**
/**
* 获取最新的区块
*/
public
static
function
getLastHeader
()
{
$service
=
new
Chain33Service
();
$result
=
$service
->
getLastHeader
();
return
$result
;
}
/**
* 获取区块hash
* 获取区块hash
*
*
* @param integer $height
* @param integer $height
...
@@ -199,6 +189,18 @@ class Chain33Business
...
@@ -199,6 +189,18 @@ class Chain33Business
return
$service
->
chain33Query
(
$execer
,
$funcName
,
$contractName
,
$items
);
return
$service
->
chain33Query
(
$execer
,
$funcName
,
$contractName
,
$items
);
}
}
/*
* 获取最新的区块头
* @param null
* @return array
*/
public
static
function
getLastHeader
()
{
$node_params
=
\Yii
::
$app
->
params
[
'chain_parallel'
][
'wasm'
];
$service
=
new
Chain33Service
(
$node_params
);
return
$service
->
getLastHeader
();
}
/**
/**
* 获取地址下的所有交易记录
* 获取地址下的所有交易记录
*
*
...
...
common/models/psources/CoinGameBet.php
View file @
2135ea03
...
@@ -18,6 +18,9 @@ class CoinGameBet extends BaseActiveRecord
...
@@ -18,6 +18,9 @@ class CoinGameBet extends BaseActiveRecord
const
SCENARIOS_ADD
=
'add'
;
const
SCENARIOS_ADD
=
'add'
;
const
SCENARIOS_UPDATE
=
'update'
;
const
SCENARIOS_UPDATE
=
'update'
;
const
VAILD_TRUE
=
1
;
const
VAILD_FALSE
=
0
;
public
static
function
getDb
()
public
static
function
getDb
()
{
{
return
Yii
::
$app
->
get
(
'p_sources'
);
return
Yii
::
$app
->
get
(
'p_sources'
);
...
@@ -44,7 +47,7 @@ class CoinGameBet extends BaseActiveRecord
...
@@ -44,7 +47,7 @@ class CoinGameBet extends BaseActiveRecord
public
function
rules
()
public
function
rules
()
{
{
return
[
return
[
[[
'round'
,
'amount'
,
'height'
,
'guess_num'
,
'rand_num'
,
'player_win'
],
'int'
],
[[
'round'
,
'amount'
,
'height'
,
'guess_num'
,
'rand_num'
,
'player_win'
,
'vaild'
],
'int'
],
[[
'player'
],
'string'
]
[[
'player'
],
'string'
]
];
];
}
}
...
@@ -52,8 +55,8 @@ class CoinGameBet extends BaseActiveRecord
...
@@ -52,8 +55,8 @@ class CoinGameBet extends BaseActiveRecord
public
function
sercians
()
public
function
sercians
()
{
{
return
[
return
[
self
::
SCENARIOS_ADD
=>
[
'round'
,
'amount'
,
'height'
,
'guess_num'
,
'rand_num'
,
'player_win'
,
'player'
],
self
::
SCENARIOS_ADD
=>
[
'round'
,
'amount'
,
'height'
,
'guess_num'
,
'rand_num'
,
'player_win'
,
'player'
,
'vaild'
],
self
::
SCENARIOS_UPDATE
=>
[
'round'
,
'amount'
,
'height'
,
'guess_num'
,
'rand_num'
,
'player_win'
,
'player'
],
self
::
SCENARIOS_UPDATE
=>
[
'round'
,
'amount'
,
'height'
,
'guess_num'
,
'rand_num'
,
'player_win'
,
'player'
,
'vaild'
],
];
];
}
}
...
...
console/controllers/GameBetController.php
View file @
2135ea03
...
@@ -31,17 +31,18 @@ class GameBetController extends Controller
...
@@ -31,17 +31,18 @@ class GameBetController extends Controller
$resultJSON
=
json_decode
(
$queryResultItems
[
'queryResultItems'
][
0
][
'resultJSON'
],
true
);
$resultJSON
=
json_decode
(
$queryResultItems
[
'queryResultItems'
][
0
][
'resultJSON'
],
true
);
$current_round
=
$resultJSON
[
'current_round'
];
$current_round
=
$resultJSON
[
'current_round'
];
$cache_current_round
=
Yii
::
$app
->
redis
->
get
(
'chain33_game_bet_status'
);
// $cache_current_round = Yii::$app->redis->get('chain33_game_bet_status');
if
(
empty
(
$cache_current_round
)){
// if(empty($cache_current_round)){
$cache_current_round
=
CoinGameBet
::
find
()
->
max
(
'round'
);
// $cache_current_round = CoinGameBet::find()->max('round');
Yii
::
$app
->
redis
->
set
(
'chain33_game_bet_status'
,
$cache_current_round
,
'EX'
,
300
);
// Yii::$app->redis->set('chain33_game_bet_status',$cache_current_round,'EX',300);
}
// }
$cache_current_round
=
(
false
==
$cache_current_round
?
0
:
$cache_current_round
);
// $cache_current_round = (false == $cache_current_round ? 0 : $cache_current_round);
if
(
$cache_current_round
>=
$current_round
){
// if($cache_current_round >= $current_round){
echo
date
(
'Y-m-d H:i:s'
)
.
'数据已为最新'
.
PHP_EOL
;
// echo date('Y-m-d H:i:s') . '数据已为最新'.PHP_EOL;
return
0
;
// return 0;
}
// }
Yii
::
$app
->
redis
->
set
(
'chain33_game_bet_status'
,
$current_round
,
'EX'
,
300
);
// Yii::$app->redis->set('chain33_game_bet_status',$current_round,'EX',300);
$cache_current_round
=
55470
;
$result
=
$service
->
getBetStatus
(
$cache_current_round
,
$current_round
);
$result
=
$service
->
getBetStatus
(
$cache_current_round
,
$current_round
);
if
(
0
!==
$result
[
'code'
]){
if
(
0
!==
$result
[
'code'
]){
echo
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
echo
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
...
@@ -64,4 +65,25 @@ class GameBetController extends Controller
...
@@ -64,4 +65,25 @@ class GameBetController extends Controller
echo
date
(
'Y-m-d H:i:s'
)
.
'数据更新成功'
.
PHP_EOL
;
echo
date
(
'Y-m-d H:i:s'
)
.
'数据更新成功'
.
PHP_EOL
;
return
0
;
return
0
;
}
}
public
function
actionBetUpdate
()
{
$service
=
new
Chain33Business
();
$result
=
$service
->
getLastHeader
();
$result
=
$result
[
'result'
]
??
[];
if
(
empty
(
$result
)){
echo
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
return
0
;
}
$height
=
$result
[
'height'
];
$models
=
CoinGameBet
::
find
()
->
where
([
'valid'
=>
CoinGameBet
::
VAILD_FALSE
])
->
all
();
foreach
(
$models
as
$model
)
{
if
(
$model
->
height
+
12
<
$height
){
$model
->
valid
=
1
;
$model
->
update
(
false
);
// skipping validation as no user input is involved
}
}
echo
date
(
'Y-m-d H:i:s'
)
.
'数据更新成功'
.
PHP_EOL
;
return
0
;
}
}
}
\ 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