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
7d8ac310
Commit
7d8ac310
authored
Jul 01, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多个链上投注信息
parent
ce361c42
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
72 deletions
+29
-72
GameBetController.php
api/controllers/GameBetController.php
+3
-51
Chain33Business.php
common/business/Chain33Business.php
+3
-5
GameBetController.php
console/controllers/GameBetController.php
+23
-16
No files found.
api/controllers/GameBetController.php
View file @
7d8ac310
...
...
@@ -10,61 +10,12 @@ use yii\data\Pagination;
class
GameBetController
extends
BaseController
{
/**
* 获取游戏状态
*
* @return array
*/
public
function
actionGameStatus
()
{
$service
=
new
Chain33Business
();
$result
=
$service
->
getGameStatus
();
if
(
0
!==
$result
[
'code'
]){
return
[
'code'
=>
-
1
,
'data'
=>
[],
'msg'
=>
$result
[
'msg'
]];
}
$queryResultItems
=
$result
[
'result'
]
??
[];
if
(
empty
(
$queryResultItems
)){
return
[
'code'
=>
-
1
,
'data'
=>
[],
'msg'
=>
'error'
];
}
$resultJSON
=
json_decode
(
$queryResultItems
[
'queryResultItems'
][
0
][
'resultJSON'
],
true
);
$current_round
=
$resultJSON
[
'current_round'
];
$cache_current_round
=
Yii
::
$app
->
redis
->
get
(
'chain33_game_status'
);
if
(
empty
(
$cache_current_round
)){
$cache_current_round
=
CoinGameBet
::
find
()
->
max
(
'round'
);
Yii
::
$app
->
redis
->
set
(
'chain33_game_status'
,
$cache_current_round
,
'EX'
,
300
);
}
$cache_current_round
=
(
false
==
$cache_current_round
?
0
:
$cache_current_round
);
if
(
$cache_current_round
>=
$current_round
){
return
[
'code'
=>
-
1
,
'data'
=>
[],
'msg'
=>
'数据已为最新'
];
}
Yii
::
$app
->
redis
->
set
(
'chain33_game_status'
,
$current_round
,
'EX'
,
300
);
$result
=
$service
->
getBetStatus
(
$cache_current_round
,
$current_round
);
if
(
0
!==
$result
[
'code'
]){
return
[
'code'
=>
-
1
,
'data'
=>
[],
'msg'
=>
'数据错误'
];
}
$queryResultItems
=
$result
[
'result'
]
??
[];
if
(
empty
(
$queryResultItems
)){
return
[
'code'
=>
-
1
,
'data'
=>
[],
'msg'
=>
'数据错误'
];
}
foreach
(
$queryResultItems
[
'queryResultItems'
]
as
$key
=>
$val
){
if
(
false
==
$val
[
'found'
]
)
continue
;
$resultArr
=
json_decode
(
$val
[
'resultJSON'
],
true
);
$datas
[]
=
[
$resultArr
[
'round'
],
$resultArr
[
'player'
],
$resultArr
[
'amount'
],
$resultArr
[
'height'
],
$resultArr
[
'guess_num'
],
$resultArr
[
'rand_num'
],
$resultArr
[
'player_win'
]
];
}
CoinGameBet
::
loadArray
(
$datas
);
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'数据更新成功'
];
}
public
function
actionBetStatus
()
{
$platform
=
Yii
::
$app
->
request
->
get
(
'platform'
,
''
);
$player
=
Yii
::
$app
->
request
->
get
(
'player'
,
''
);
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
if
(
empty
(
$player
)){
if
(
empty
(
$player
)
||
empty
(
$platform
)
){
$msg
=
'请求参数错误'
;
$code
=
-
1
;
$data
=
null
;
...
...
@@ -75,6 +26,7 @@ class GameBetController extends BaseController
->
select
(
'round, player, amount, height, guess_num, guess_num, rand_num, player_win'
)
->
where
(
'player= :player'
,[
':player'
=>
$player
])
->
andWhere
([
'valid'
=>
CoinGameBet
::
VAILD_TRUE
])
->
andWhere
([
'platform'
=>
$platform
])
->
orderBy
(
'update_time desc'
);
$count
=
$query
->
count
();
...
...
common/business/Chain33Business.php
View file @
7d8ac310
...
...
@@ -173,13 +173,12 @@ class Chain33Business
* @param integer $end
* @return array
*/
public
static
function
getBetStatus
(
$start
,
$end
,
$roundArr
=
[])
public
static
function
getBetStatus
(
$start
,
$end
,
$roundArr
=
[]
,
$node_params
=
[]
)
{
$node_params
=
\Yii
::
$app
->
params
[
'chain_parallel'
][
'wasm'
];
$service
=
new
Chain33Service
(
$node_params
);
$execer
=
'wasm'
;
$funcName
=
'WasmGetContractTable'
;
$contractName
=
'user.p.tschain.user.wasm.dice'
;
$contractName
=
$node_params
[
'contractName'
]
;
if
(
empty
(
$roundArr
))
{
for
(
$i
=
$start
+
1
;
$i
<=
$end
;
$i
++
){
$items
[]
=
[
...
...
@@ -205,9 +204,8 @@ class Chain33Business
* @param null
* @return array
*/
public
static
function
getLastHeader
()
public
static
function
getLastHeader
(
$node_params
=
[]
)
{
$node_params
=
\Yii
::
$app
->
params
[
'chain_parallel'
][
'wasm'
];
$service
=
new
Chain33Service
(
$node_params
);
return
$service
->
getLastHeader
();
}
...
...
console/controllers/GameBetController.php
View file @
7d8ac310
...
...
@@ -68,38 +68,41 @@ class GameBetController extends Controller
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
;
$nodes
=
\Yii
::
$app
->
params
[
'chain_parallel'
][
'wasm'
];
if
(
empty
(
$nodes
)){
echo
date
(
'Y-m-d H:i:s'
)
.
'无节点'
.
PHP_EOL
;
return
0
;
}
$height
=
$result
[
'height'
];
foreach
(
$nodes
as
$key
=>
$node
)
{
$service
=
new
Chain33Business
();
$result
=
$service
->
getLastHeader
(
$node
);
$height
=
$result
[
'result'
][
'height'
];
$models
=
CoinGameBet
::
find
()
->
select
(
'round'
)
->
where
([
'and'
,
[
'valid'
=>
CoinGameBet
::
VAILD_FALSE
],
[
'<'
,
'height'
,
$height
-
12
]
[
'<'
,
'height'
,
$height
-
12
],
[
'platform'
=>
$key
]
])
->
all
();
if
(
empty
(
$models
)){
echo
date
(
'Y-m-d H:i:s'
)
.
'无需更新的数据'
.
PHP_EOL
;
return
0
;
echo
$key
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'无需更新的数据'
.
PHP_EOL
;
continue
;
}
$valid_arr
=
[];
foreach
(
$models
as
$model
)
{
$valid_arr
[]
=
$model
->
round
;
}
$result
=
$service
->
getBetStatus
(
''
,
''
,
$valid_arr
);
$result
=
$service
->
getBetStatus
(
''
,
''
,
$valid_arr
,
$node
);
if
(
0
!==
$result
[
'code'
]){
echo
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
return
0
;
echo
$key
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
continue
;
}
$queryResultItems
=
$result
[
'result'
]
??
[];
if
(
empty
(
$queryResultItems
)){
echo
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
return
0
;
echo
$key
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
continue
;
}
$platform
=
$key
;
foreach
(
$queryResultItems
[
'queryResultItems'
]
as
$key
=>
$val
){
if
(
false
==
$val
[
'found'
])
continue
;
$resultArr
=
json_decode
(
$val
[
'resultJSON'
],
true
);
...
...
@@ -111,10 +114,13 @@ class GameBetController extends Controller
'player_win'
=>
$resultArr
[
'player_win'
],
'valid'
=>
CoinGameBet
::
VAILD_TRUE
],[
'round'
=>
$resultArr
[
'round'
]
'round'
=>
$resultArr
[
'round'
],
'platform'
=>
$platform
]);
}
echo
date
(
'Y-m-d H:i:s'
)
.
'数据更新成功'
.
PHP_EOL
;
echo
$platform
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'数据更新成功'
.
PHP_EOL
;
continue
;
}
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