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
6f7903ac
Commit
6f7903ac
authored
Jul 01, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
游戏链区分
parent
7d8ac310
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
44 deletions
+52
-44
Chain33Business.php
common/business/Chain33Business.php
+2
-3
CoinGameBet.php
common/models/psources/CoinGameBet.php
+1
-1
GameBetController.php
console/controllers/GameBetController.php
+49
-40
No files found.
common/business/Chain33Business.php
View file @
6f7903ac
...
@@ -153,13 +153,12 @@ class Chain33Business
...
@@ -153,13 +153,12 @@ class Chain33Business
* 获取游戏状态
* 获取游戏状态
* @return array
* @return array
*/
*/
public
static
function
getGameStatus
()
public
static
function
getGameStatus
(
$node_params
=
[]
)
{
{
$node_params
=
\Yii
::
$app
->
params
[
'chain_parallel'
][
'wasm'
];
$service
=
new
Chain33Service
(
$node_params
);
$service
=
new
Chain33Service
(
$node_params
);
$execer
=
'wasm'
;
$execer
=
'wasm'
;
$funcName
=
'WasmGetContractTable'
;
$funcName
=
'WasmGetContractTable'
;
$contractName
=
'user.p.tschain.user.wasm.dice'
;
$contractName
=
$node_params
[
'contractName'
]
;
$items
[]
=
[
$items
[]
=
[
'tableName'
=>
'gamestatus'
,
'tableName'
=>
'gamestatus'
,
'key'
=>
'dice_statics'
'key'
=>
'dice_statics'
...
...
common/models/psources/CoinGameBet.php
View file @
6f7903ac
...
@@ -63,7 +63,7 @@ class CoinGameBet extends BaseActiveRecord
...
@@ -63,7 +63,7 @@ class CoinGameBet extends BaseActiveRecord
public
static
function
loadArray
(
array
$data
)
public
static
function
loadArray
(
array
$data
)
{
{
return
self
::
getDb
()
->
createCommand
()
->
batchInsert
(
self
::
tableName
(),
return
self
::
getDb
()
->
createCommand
()
->
batchInsert
(
self
::
tableName
(),
[
'round'
,
'player'
,
'amount'
,
'height'
,
'guess_num'
,
'rand_num'
,
'player_win'
],
[
'round'
,
'player'
,
'amount'
,
'height'
,
'guess_num'
,
'rand_num'
,
'player_win'
,
'platform'
],
$data
)
->
execute
();
$data
)
->
execute
();
}
}
}
}
console/controllers/GameBetController.php
View file @
6f7903ac
...
@@ -16,53 +16,62 @@ class GameBetController extends Controller
...
@@ -16,53 +16,62 @@ class GameBetController extends Controller
*/
*/
public
function
actionGameStatus
()
public
function
actionGameStatus
()
{
{
$service
=
new
Chain33Business
();
$nodes
=
\Yii
::
$app
->
params
[
'chain_parallel'
][
'wasm'
];
$result
=
$service
->
getGameStatus
();
if
(
empty
(
$nodes
)){
if
(
0
!==
$result
[
'code'
]){
echo
date
(
'Y-m-d H:i:s'
)
.
'无节点'
.
PHP_EOL
;
echo
date
(
'Y-m-d H:i:s'
)
.
$result
[
'msg'
]
.
PHP_EOL
;
return
0
;
return
0
;
}
}
foreach
(
$nodes
as
$key
=>
$node
)
{
$service
=
new
Chain33Business
();
$result
=
$service
->
getGameStatus
(
$node
);
if
(
0
!==
$result
[
'code'
])
{
echo
$key
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
$result
[
'msg'
]
.
PHP_EOL
;
continue
;
}
$queryResultItems
=
$result
[
'result'
]
??
[];
$queryResultItems
=
$result
[
'result'
]
??
[];
if
(
empty
(
$queryResultItems
))
{
if
(
empty
(
$queryResultItems
))
{
echo
date
(
'Y-m-d H:i:s'
)
.
'error'
.
PHP_EOL
;
echo
$key
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'error'
.
PHP_EOL
;
return
0
;
continue
;
}
}
$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_'
.
$key
);
if
(
empty
(
$cache_current_round
))
{
if
(
empty
(
$cache_current_round
))
{
$cache_current_round
=
CoinGameBet
::
find
(
)
->
max
(
'round'
);
$cache_current_round
=
CoinGameBet
::
find
()
->
where
([
'platform'
=>
$key
]
)
->
max
(
'round'
);
Yii
::
$app
->
redis
->
set
(
'chain33_game_bet_status'
,
$cache_current_round
,
'EX'
,
300
);
Yii
::
$app
->
redis
->
set
(
'chain33_game_bet_status_'
.
$key
,
$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
$key
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'数据已为最新'
.
PHP_EOL
;
return
0
;
continue
;
}
}
Yii
::
$app
->
redis
->
set
(
'chain33_game_bet_status'
,
$current_round
,
'EX'
,
300
);
Yii
::
$app
->
redis
->
set
(
'chain33_game_bet_status_'
.
$key
,
$current_round
,
'EX'
,
300
);
$result
=
$service
->
getBetStatus
(
$cache_current_round
,
$current_round
);
$result
=
$service
->
getBetStatus
(
$cache_current_round
,
$current_round
,
''
,
$node
);
if
(
0
!==
$result
[
'code'
])
{
if
(
0
!==
$result
[
'code'
])
{
echo
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
echo
$key
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
return
0
;
continue
;
}
}
$queryResultItems
=
$result
[
'result'
]
??
[];
$queryResultItems
=
$result
[
'result'
]
??
[];
if
(
empty
(
$queryResultItems
)){
if
(
empty
(
$queryResultItems
))
{
echo
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
echo
$key
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
return
0
;
continue
;
}
}
foreach
(
$queryResultItems
[
'queryResultItems'
]
as
$key
=>
$val
){
$platform
=
$key
;
if
(
false
==
$val
[
'found'
]
)
continue
;
foreach
(
$queryResultItems
[
'queryResultItems'
]
as
$key
=>
$val
)
{
$resultArr
=
json_decode
(
$val
[
'resultJSON'
],
true
);
if
(
false
==
$val
[
'found'
])
continue
;
$datas
[]
=
[
$resultArr
=
json_decode
(
$val
[
'resultJSON'
],
true
);
$resultArr
[
'round'
],
$resultArr
[
'player'
],
$resultArr
[
'amount'
],
$resultArr
[
'height'
],
$resultArr
[
'guess_num'
],
$resultArr
[
'rand_num'
],
$resultArr
[
'player_win'
]
$datas
[]
=
[
];
$resultArr
[
'round'
],
$resultArr
[
'player'
],
$resultArr
[
'amount'
],
$resultArr
[
'height'
],
$resultArr
[
'guess_num'
],
$resultArr
[
'rand_num'
],
$resultArr
[
'player_win'
],
$platform
];
}
CoinGameBet
::
loadArray
(
$datas
);
echo
$platform
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'数据更新成功'
.
PHP_EOL
;
continue
;
}
}
CoinGameBet
::
loadArray
(
$datas
);
echo
date
(
'Y-m-d H:i:s'
)
.
'数据更新成功'
.
PHP_EOL
;
return
0
;
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