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
712f10fe
Commit
712f10fe
authored
Aug 05, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into feature/optimize
parents
6c68c3d1
af4b7bda
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
331 additions
and
210 deletions
+331
-210
CoinController.php
api/controllers/CoinController.php
+5
-15
GameBetController.php
api/controllers/GameBetController.php
+4
-52
GameController.php
api/controllers/GameController.php
+85
-40
Chain33Business.php
common/business/Chain33Business.php
+5
-8
ExchangeBusiness.php
common/business/ExchangeBusiness.php
+33
-10
CoinGameBet.php
common/models/psources/CoinGameBet.php
+1
-1
GameUserAddress.php
common/models/pwallet/GameUserAddress.php
+25
-0
Ex.php
common/service/exchange/Ex.php
+75
-0
GameBetController.php
console/controllers/GameBetController.php
+98
-84
No files found.
api/controllers/CoinController.php
View file @
712f10fe
...
...
@@ -219,23 +219,13 @@ class CoinController extends BaseController
public
function
actionCoinIndex
()
{
$names
=
Yii
::
$app
->
request
->
post
(
'names'
);
$platforms
=
[];
$newNames
=
[];
if
(
!
$names
)
{
return
[
'code'
=>
0
,
'data'
=>
[]];
}
foreach
(
$names
as
$item
)
{
$item_array
=
explode
(
','
,
$item
);
$newNames
[]
=
$item_array
[
0
];
if
(
isset
(
$item_array
[
1
]))
{
if
(
!
in_array
(
$item_array
[
1
],
$platforms
))
{
$platforms
[]
=
$item_array
[
1
];
}
}
}
$condition
=
[[
'in'
,
'name'
,
$newNames
]];
if
(
$platforms
)
{
$condition
[]
=
[
'in'
,
'platform'
,
$platforms
];
foreach
(
$names
as
$key
=>
$val
)
{
$val_array
=
explode
(
','
,
$val
);
if
(
count
(
$val_array
)
<
2
)
continue
;
$condition
[]
=
[
$val_array
[
0
],
$val_array
[
1
]];
}
$result
=
ExchangeBusiness
::
getApiListForIndex
(
1
,
999
,
$condition
);
if
(
$result
)
{
...
...
@@ -354,7 +344,7 @@ class CoinController extends BaseController
return
[
'code'
=>
0
,
'data'
=>
$platform_with_hold
];
}
$platform_with_hold
=
CoinPlatformWithHold
::
getRecord
(
$platform
);
$coin_info
=
Coin
::
find
()
->
select
(
'treaty'
)
->
where
([
'name'
=>
strtoupper
(
$coin_name
)])
->
asArray
()
->
one
();
$coin_info
=
Coin
::
find
()
->
select
(
'treaty'
)
->
where
([
'name'
=>
strtoupper
(
$coin_name
)
,
'platform'
=>
$platform
])
->
asArray
()
->
one
();
$des
=
Yii
::
$app
->
des
;
$platform_with_hold
[
'private_key'
]
=
$des
->
encrypt
(
$platform_with_hold
[
'private_key'
]);
if
(
1
==
$coin_info
[
'treaty'
])
{
...
...
api/controllers/GameBetController.php
View file @
712f10fe
...
...
@@ -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'
,
'ts_wallet'
);
$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
;
...
...
@@ -72,8 +23,9 @@ class GameBetController extends BaseController
}
$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
, platform
'
)
->
where
(
'player= :player'
,[
':player'
=>
$player
])
->
andWhere
([
'platform'
=>
$platform
])
#->andWhere(['valid' => CoinGameBet::VAILD_TRUE])
->
orderBy
(
'update_time desc'
);
...
...
api/controllers/GameController.php
View file @
712f10fe
...
...
@@ -11,46 +11,90 @@ namespace api\controllers;
use
Yii
;
use
api\base\BaseController
;
use
common\models\pwallet\GameUser
;
use
common\models\pwallet\GameUserAddress
;
class
GameController
extends
BaseController
{
/**
* 保存地址与昵称
*/
public
function
actionSaveAddressAndNickname
(){
$post
=
Yii
::
$app
->
request
->
post
();
$address
=
$post
[
'address'
]
??
''
;
$nickname
=
$post
[
'nickname'
]
??
''
;
if
(
empty
(
$address
)
||
empty
(
$nickname
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'地址和昵称不能为空'
,
'data'
=>
''
];
}
//判断重复
$count
=
GameUser
::
find
()
->
where
([
'nickname'
=>
$nickname
])
->
count
();
if
(
$count
>
0
)
{
return
[
'code'
=>
-
1
,
'msg'
=>
'昵称重复'
];
}
// todo 保存
$models
=
new
GameUser
();
$models
->
nickname
=
$nickname
;
$models
->
address
=
$address
;
if
(
$models
->
save
())
{
return
[
'code'
=>
0
,
'msg'
=>
'Succeed'
,
'data'
=>
$models
->
id
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'Failed'
];
}
class
GameController
extends
BaseController
{
/**
* 保存地址与昵称
*/
public
function
actionSaveAddressAndNickname
()
{
$post
=
Yii
::
$app
->
request
->
post
();
$address
=
$post
[
'address'
]
??
''
;
$nickname
=
$post
[
'nickname'
]
??
''
;
if
(
empty
(
$address
)
||
empty
(
$nickname
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'地址和昵称不能为空'
,
'data'
=>
null
];
}
//判断重复
$count
=
GameUser
::
find
()
->
where
([
'nickname'
=>
$nickname
])
->
count
();
if
(
$count
>
0
)
{
return
[
'code'
=>
-
1
,
'msg'
=>
'昵称重复'
];
}
// todo 保存
$models
=
new
GameUser
();
$models
->
nickname
=
$nickname
;
$models
->
address
=
$address
;
if
(
$models
->
save
())
{
return
[
'code'
=>
0
,
'msg'
=>
'Succeed'
,
'data'
=>
$models
->
id
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'Failed'
];
}
/**
* 根据地址获取昵称
*/
public
function
actionGetNicknameByAddress
(){
$address
=
Yii
::
$app
->
request
->
post
(
'address'
,
''
);
if
(
empty
(
$address
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'地址不能为空'
,
'data'
=>
''
];
}
//todo 获取地址
$address
=
GameUser
::
find
()
->
select
([
'nickname'
])
->
where
([
'address'
=>
$address
])
->
one
();
if
(
!
empty
(
$address
))
{
return
[
'code'
=>
0
,
'msg'
=>
'Succeed'
,
'data'
=>
$address
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'Failed'
];
}
/**
* 根据地址获取昵称
*/
public
function
actionGetNicknameByAddress
()
{
$address
=
Yii
::
$app
->
request
->
post
(
'address'
,
''
);
if
(
empty
(
$address
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'地址不能为空'
,
'data'
=>
null
];
}
//todo 获取地址
$address
=
GameUser
::
find
()
->
select
([
'nickname'
])
->
where
([
'address'
=>
$address
])
->
one
();
if
(
!
empty
(
$address
))
{
return
[
'code'
=>
0
,
'msg'
=>
'Succeed'
,
'data'
=>
$address
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'Failed'
];
}
public
function
actionSaveGameInfo
()
{
$post
=
Yii
::
$app
->
request
->
post
();
$address
=
$post
[
'address'
]
??
''
;
$nickname
=
$post
[
'nickname'
]
??
''
;
if
(
empty
(
$address
)
||
empty
(
$nickname
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'地址和昵称不能为空'
,
'data'
=>
null
];
}
//判断重复
$count
=
GameUserAddress
::
find
()
->
where
([
'address'
=>
$address
])
->
count
();
if
(
$count
>
0
)
{
return
[
'code'
=>
-
1
,
'msg'
=>
'地址已存在'
,
'data'
=>
null
];
}
// todo 保存
$models
=
new
GameUserAddress
();
$models
->
nickname
=
$nickname
;
$models
->
address
=
$address
;
if
(
$models
->
save
())
{
return
[
'code'
=>
0
,
'msg'
=>
'Succeed'
,
'data'
=>
$models
->
id
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'Failed'
,
'data'
=>
null
];
}
public
function
actionGetNicknameByAddressArr
()
{
$address
=
Yii
::
$app
->
request
->
post
(
'address'
,
''
);
if
(
empty
(
$address
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'地址不能为空'
,
'data'
=>
null
];
}
//todo 获取地址
$address
=
GameUserAddress
::
find
()
->
select
([
'nickname'
,
'address'
])
->
where
([
'in'
,
'address'
,
$address
])
->
asArray
()
->
all
();
if
(
!
empty
(
$address
))
{
return
[
'code'
=>
0
,
'msg'
=>
'Succeed'
,
'data'
=>
$address
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'数据为空'
,
'data'
=>
null
];
}
}
\ No newline at end of file
common/business/Chain33Business.php
View file @
712f10fe
...
...
@@ -159,13 +159,12 @@ class Chain33Business
* 获取游戏状态
* @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
);
$execer
=
'wasm'
;
$funcName
=
'WasmGetContractTable'
;
$contractName
=
'user.p.tschain.user.wasm.dice'
;
$contractName
=
$node_params
[
'contractName'
]
;
$items
[]
=
[
'tableName'
=>
'gamestatus'
,
'key'
=>
'dice_statics'
...
...
@@ -179,13 +178,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
[]
=
[
...
...
@@ -211,9 +209,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
();
}
...
...
common/business/ExchangeBusiness.php
View file @
712f10fe
...
...
@@ -38,7 +38,8 @@ class ExchangeBusiness
9
=>
'Go'
,
10
=>
'Zhaobi'
,
11
=>
'Gdpro'
,
12
=>
'Boc'
12
=>
'Boc'
,
13
=>
'Ex'
];
/**
...
...
@@ -97,45 +98,52 @@ class ExchangeBusiness
$f
=
false
;
$quotation
=
[];
if
(
in_array
(
strtoupper
(
$tag
),
[
'FOLI'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Ex"
);
$quotation
=
$exchange
->
getTicker
(
$tag
,
'USDT'
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]);
goto
doEnd
;
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'GM'
,
'BSTC'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Token7"
);
$quotation
=
$exchange
->
getTicker
(
$tag
,
'HA'
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
2
f"
,
$quotation
[
'last'
]);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
4
f"
,
$quotation
[
'last'
]);
goto
doEnd
;
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'BECC'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"S"
);
$quotation
=
$exchange
->
getTicker
(
$tag
,
'ST'
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
2
f"
,
$quotation
[
'last'
]);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
4
f"
,
$quotation
[
'last'
]);
goto
doEnd
;
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'GHP'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Zg"
);
$quotation
=
$exchange
->
getTicker
(
$tag
,
'CNZ'
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
2
f"
,
$quotation
[
'last'
]);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
4
f"
,
$quotation
[
'last'
]);
goto
doEnd
;
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'SFT'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Zhaobi"
);
$quotation
=
$exchange
->
getTicker
(
$tag
,
'CNY'
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
2
f"
,
$quotation
[
'last'
]);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
4
f"
,
$quotation
[
'last'
]);
goto
doEnd
;
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'CTG'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Gdpro"
);
$quotation
=
$exchange
->
getTicker
(
$tag
,
'CNY'
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
2
f"
,
$quotation
[
'last'
]);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
4
f"
,
$quotation
[
'last'
]);
goto
doEnd
;
}
if
(
in_array
(
strtoupper
(
$tag
),
[
'USDT'
]))
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Go"
);
$quotation
=
$exchange
->
getTicker
(
'CNY'
,
'USD'
);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
2
f"
,
$quotation
[
'last'
]);
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.
4
f"
,
$quotation
[
'last'
]);
goto
doEnd
;
}
...
...
@@ -252,10 +260,25 @@ class ExchangeBusiness
*/
public
static
function
getApiListForIndex
(
$page
=
1
,
$limit
=
999
,
$condition
=
[],
$fields
=
[])
{
if
(
!
$fields
)
{
$fields
=
[
'id'
,
'sid'
,
'icon'
,
'name'
,
'optional_name'
,
'nickname'
,
'platform'
,
'chain'
,
'address as contract_address'
,
'treaty'
];
foreach
(
$condition
as
$val
)
{
if
(
$val
[
1
]
==
'null'
){
$data
[]
=
Coin
::
find
()
->
select
(
'id,sid,icon,name,optional_name,nickname,platform,chain,address as contract_address,treaty'
)
->
where
([
'name'
=>
$val
[
0
]])
->
asArray
()
->
one
();
continue
;
}
$data
[]
=
Coin
::
find
()
->
select
(
'id,sid,icon,name,optional_name,nickname,platform,chain,address as contract_address,treaty'
)
->
where
([
'name'
=>
$val
[
0
]])
->
andWhere
([
'platform'
=>
$val
[
1
]])
->
asArray
()
->
one
();
}
$rows
=
Coin
::
getSelectList
(
$page
,
$limit
,
$fields
,
$condition
);
$rows
=
[
'count'
=>
count
(
$data
),
'data'
=>
$data
];
$count
=
0
;
if
(
!
empty
(
$rows
)
&&
is_array
(
$rows
)
&&
array_key_exists
(
'count'
,
$rows
))
{
$count
=
$rows
[
'count'
];
...
...
common/models/psources/CoinGameBet.php
View file @
712f10fe
...
...
@@ -63,7 +63,7 @@ class CoinGameBet extends BaseActiveRecord
public
static
function
loadArray
(
array
$data
)
{
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
();
}
}
common/models/pwallet/GameUserAddress.php
0 → 100644
View file @
712f10fe
<?php
/**
* Created By Sublime text 3
* User: rlgyzhcn
* Date: 18-08-12
* Time: 下午14:17
*/
namespace
common\models\pwallet
;
use
common\core\BaseActiveRecord
;
use
Yii
;
class
GameUserAddress
extends
BaseActiveRecord
{
public
static
function
getDb
(){
return
Yii
::
$app
->
get
(
'db_pwallet'
);
}
public
function
formName
()
{
return
''
;
}
}
\ No newline at end of file
common/service/exchange/Ex.php
0 → 100644
View file @
712f10fe
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace
common\service\exchange
;
use
linslin\yii2\curl\Curl
;
class
Ex
extends
Exchange
implements
ExchangeInterface
{
protected
$supported_symbol
=
'supported_symbol_zg'
;
protected
$quotation_prefix
=
'quotation_ex_'
;
protected
$base_url
=
'https://www.ex.pizza/api/v1/tickers'
;
public
function
symbolExists
(
$tag
=
'FOLI'
,
$aim
=
"USDT"
)
{
$supported
=
$this
->
redis
->
smembers
(
$this
->
supported_symbol
);
if
(
is_array
(
$supported
)
&&
in_array
(
$this
->
formatSymbol
(
$tag
,
$aim
),
$supported
))
{
return
true
;
}
return
false
;
}
/**
* 转化交易对为请求变量
*
* @param string $tag
* @param string $aim
* @return mixed
*/
public
function
formatSymbol
(
$tag
=
'FOLI'
,
$aim
=
'USDT'
)
{
return
strtoupper
(
$tag
.
'_'
.
$aim
);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public
function
setSupportedSymbol
()
{
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
'FOLI_USDT'
);
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public
function
setQuotation
()
{
$curl
=
new
Curl
();
$curl
->
setHeaders
([
'User-Agent'
=>
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
,
]);
$content
=
$curl
->
get
(
$this
->
base_url
,
false
);
if
(
is_array
(
$content
)
&&
isset
(
$content
[
'ticker'
]))
{
$data
=
$content
[
'ticker'
];
foreach
(
$data
as
$item
)
{
if
(
in_array
(
$item
[
'symbol'
],
[
'FOLI_USDT'
]))
{
$data
=
$item
;
$key
=
$this
->
quotation_prefix
.
$item
[
'symbol'
];
$this
->
redis
->
hmset
(
$key
,
'low'
,
$data
[
'low'
],
'high'
,
$data
[
'high'
],
'last'
,
$data
[
'last'
]);
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
$item
[
'symbol'
]);
}
}
}
}
}
\ No newline at end of file
console/controllers/GameBetController.php
View file @
712f10fe
...
...
@@ -16,105 +16,120 @@ class GameBetController extends Controller
*/
public
function
actionGameStatus
()
{
$service
=
new
Chain33Business
();
$result
=
$service
->
getGameStatus
();
if
(
0
!==
$result
[
'code'
]){
echo
date
(
'Y-m-d H:i:s'
)
.
$result
[
'msg'
]
.
PHP_EOL
;
$nodes
=
\Yii
::
$app
->
params
[
'chain_parallel'
][
'wasm'
];
if
(
empty
(
$nodes
)){
echo
date
(
'Y-m-d H:i:s'
)
.
'无节点'
.
PHP_EOL
;
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'
]
??
[];
if
(
empty
(
$queryResultItems
))
{
echo
date
(
'Y-m-d H:i:s'
)
.
'error'
.
PHP_EOL
;
return
0
;
}
$queryResultItems
=
$result
[
'result'
]
??
[];
if
(
empty
(
$queryResultItems
))
{
echo
$key
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'error'
.
PHP_EOL
;
continue
;
}
$resultJSON
=
json_decode
(
$queryResultItems
[
'queryResultItems'
][
0
][
'resultJSON'
],
true
);
$current_round
=
$resultJSON
[
'current_round'
];
$cache_current_round
=
Yii
::
$app
->
redis
->
get
(
'chain33_game_bet_status'
);
if
(
empty
(
$cache_current_round
))
{
$cache_current_round
=
CoinGameBet
::
find
(
)
->
max
(
'round'
);
Yii
::
$app
->
redis
->
set
(
'chain33_game_bet_status'
,
$cache_current_round
,
'EX'
,
300
);
}
$cache_current_round
=
(
false
==
$cache_current_round
?
0
:
$cache_current_round
);
if
(
$cache_current_round
>=
$current_round
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
'数据已为最新'
.
PHP_EOL
;
return
0
;
}
Yii
::
$app
->
redis
->
set
(
'chain33_game_bet_status'
,
$current_round
,
'EX'
,
300
);
$resultJSON
=
json_decode
(
$queryResultItems
[
'queryResultItems'
][
0
][
'resultJSON'
],
true
);
$current_round
=
$resultJSON
[
'current_round'
];
$cache_current_round
=
Yii
::
$app
->
redis
->
get
(
'chain33_game_bet_status_'
.
$key
);
if
(
empty
(
$cache_current_round
))
{
$cache_current_round
=
CoinGameBet
::
find
()
->
where
([
'platform'
=>
$key
]
)
->
max
(
'round'
);
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
);
if
(
$cache_current_round
>=
$current_round
)
{
echo
$key
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'数据已为最新'
.
PHP_EOL
;
continue
;
}
Yii
::
$app
->
redis
->
set
(
'chain33_game_bet_status_'
.
$key
,
$current_round
,
'EX'
,
300
);
$result
=
$service
->
getBetStatus
(
$cache_current_round
,
$current_round
);
if
(
0
!==
$result
[
'code'
])
{
echo
date
(
'Y-m-d H:i:s'
)
.
'数据错误'
.
PHP_EOL
;
return
0
;
}
$result
=
$service
->
getBetStatus
(
$cache_current_round
,
$current_round
,
''
,
$node
);
if
(
0
!==
$result
[
'code'
])
{
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
;
$queryResultItems
=
$result
[
'result'
]
??
[];
if
(
empty
(
$queryResultItems
))
{
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
);
$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
;
}
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
);
echo
date
(
'Y-m-d H:i:s'
)
.
'数据更新成功'
.
PHP_EOL
;
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
()
->
select
(
'round'
)
->
where
([
'and'
,
[
'valid'
=>
CoinGameBet
::
VAILD_FALSE
],
[
'<'
,
'height'
,
$height
-
12
]
])
->
all
();
if
(
empty
(
$models
)){
echo
date
(
'Y-m-d H:i:s'
)
.
'无需更新的数据'
.
PHP_EOL
;
return
0
;
}
$valid_arr
=
[];
foreach
(
$models
as
$model
)
{
$valid_arr
[]
=
$model
->
round
;
}
$result
=
$service
->
getBetStatus
(
''
,
''
,
$valid_arr
);
if
(
0
!==
$result
[
'code'
]){
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
;
}
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
],
[
'platform'
=>
$key
]
])
->
all
();
if
(
empty
(
$models
)){
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
,
$node
);
if
(
0
!==
$result
[
'code'
]){
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
;
}
foreach
(
$queryResultItems
[
'queryResultItems'
]
as
$key
=>
$val
){
if
(
false
==
$val
[
'found'
])
continue
;
$resultArr
=
json_decode
(
$val
[
'resultJSON'
],
true
);
CoinGameBet
::
updateAll
([
'amount'
=>
$resultArr
[
'amount'
],
'height'
=>
$resultArr
[
'height'
],
'guess_num'
=>
$resultArr
[
'guess_num'
],
'rand_num'
=>
$resultArr
[
'rand_num'
],
'player_win'
=>
$resultArr
[
'player_win'
],
'valid'
=>
CoinGameBet
::
VAILD_TRUE
],[
'round'
=>
$resultArr
[
'round'
]
]);
$queryResultItems
=
$result
[
'result'
]
??
[];
if
(
empty
(
$queryResultItems
)){
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
);
CoinGameBet
::
updateAll
([
'amount'
=>
$resultArr
[
'amount'
],
'height'
=>
$resultArr
[
'height'
],
'guess_num'
=>
$resultArr
[
'guess_num'
],
'rand_num'
=>
$resultArr
[
'rand_num'
],
'player_win'
=>
$resultArr
[
'player_win'
],
'valid'
=>
CoinGameBet
::
VAILD_TRUE
],[
'round'
=>
$resultArr
[
'round'
],
'platform'
=>
$platform
]);
}
echo
$platform
.
':'
.
date
(
'Y-m-d H:i:s'
)
.
'数据更新成功'
.
PHP_EOL
;
continue
;
}
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