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
0b5d3b45
Commit
0b5d3b45
authored
Nov 26, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/platform_currency' into 'master'
Feature/platform currency See merge request
!216
parents
c2e3bf26
9f204057
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
339 additions
and
21 deletions
+339
-21
BaseController.php
api/base/BaseController.php
+12
-4
TickerController.php
api/controllers/TickerController.php
+35
-3
CoinCurrency.php
common/models/psources/CoinCurrency.php
+51
-0
CoinPlatform.php
common/models/psources/CoinPlatform.php
+5
-0
CoinSupportedCurrency.php
common/models/psources/CoinSupportedCurrency.php
+68
-0
TickerController.php
console/controllers/TickerController.php
+37
-8
WalletController.php
wallet/controllers/WalletController.php
+131
-6
No files found.
api/base/BaseController.php
View file @
0b5d3b45
...
...
@@ -19,12 +19,14 @@ class BaseController extends Controller
public
$header_list
=
[];
public
$lang
;
public
$currency_id
;
public
$platform_id
;
private
static
$default_header_list
=
[];
public
function
init
()
{
if
(
'cli'
!==
php_sapi_name
()){
if
(
'cli'
!==
php_sapi_name
())
{
$this
->
header_list
=
self
::
$default_header_list
;
$this
->
fzmCrossHeader
();
}
...
...
@@ -33,9 +35,15 @@ class BaseController extends Controller
public
function
fzmCrossHeader
()
{
$this
->
lang
=
\Yii
::
$app
->
request
->
headers
->
get
(
'lang'
)
??
'zh-CN'
;
if
(
'en'
==
strtolower
(
$this
->
lang
)){
if
(
'en'
==
strtolower
(
$this
->
lang
))
{
$this
->
lang
=
'en-US'
;
}
if
(
\Yii
::
$app
->
request
->
headers
->
get
(
'FZM-PLATFORM-ID'
))
{
$this
->
platform_id
=
\Yii
::
$app
->
request
->
headers
->
get
(
'FZM-PLATFORM-ID'
);
}
if
(
\Yii
::
$app
->
request
->
headers
->
get
(
'FZM-CURRENCY-ID'
))
{
$this
->
currency_id
=
\Yii
::
$app
->
request
->
headers
->
get
(
'FZM-CURRENCY-ID'
);
}
}
public
function
beforeAction
(
$action
)
...
...
@@ -75,7 +83,7 @@ class BaseController extends Controller
'errmsg'
=>
$errmsg
,
];
if
(
$data
!==
null
)
{
if
(
$data
!==
null
)
{
$result
[
'data'
]
=
Yii
::
createObject
(
'yii\rest\Serializer'
)
->
serialize
(
$data
);
}
...
...
@@ -83,7 +91,7 @@ class BaseController extends Controller
$response
->
format
=
Response
::
FORMAT_JSON
;
//jsonp数据格式
if
(
!
is_null
(
$callback
))
{
if
(
!
is_null
(
$callback
))
{
Yii
::
$app
->
getResponse
()
->
format
=
Response
::
FORMAT_JSONP
;
$result
=
[
'data'
=>
$result
,
...
...
api/controllers/TickerController.php
View file @
0b5d3b45
...
...
@@ -3,6 +3,8 @@
namespace
api\controllers
;
use
common\components\Tools
;
use
common\models\psources\CoinCurrency
;
use
common\models\psources\CoinSupportedCurrency
;
use
Yii
;
use
yii\data\Pagination
;
use
linslin\yii2\curl\Curl
;
...
...
@@ -291,7 +293,7 @@ class TickerController extends BaseController
'btcusdt'
,
'ethusdt'
]
],[
],
[
'exchange'
=>
'zhaobi'
,
'symbol'
=>
[
'btyusdt'
...
...
@@ -306,7 +308,7 @@ class TickerController extends BaseController
'btcusdt'
,
'ethusdt'
],
],[
],
[
'exchange'
=>
'dag'
,
'symbol'
=>
[
'dagusdt'
...
...
@@ -322,7 +324,7 @@ class TickerController extends BaseController
'btcusdt'
,
'ethusdt'
],
],[
],
[
'exchange'
=>
'bitnasdaq'
,
'symbol'
=>
[
'bncusdt'
...
...
@@ -344,4 +346,33 @@ class TickerController extends BaseController
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
public
function
actionCurrency
()
{
$code
=
0
;
$data
=
null
;
$platform_id
=
$this
->
platform_id
;
if
(
false
==
$platform_id
)
{
$code
=
-
1
;
$msg
=
'请求参数错误!'
;
goto
doEnd
;
}
$currency
=
CoinSupportedCurrency
::
find
()
->
where
([
'platform_id'
=>
$platform_id
])
->
all
();
foreach
(
$currency
as
$val
)
{
list
(
$rate
)
=
Yii
::
$app
->
redis_currency
->
hmget
(
'quotation_boc_'
.
'CNY_'
.
$val
->
currency
->
symbol
,
'last'
);
$val
->
pj_id
=
$val
->
currency
->
pj_id
;
$val
->
pj_name
=
$val
->
currency
->
pj_name
;
$val
->
pj_symbol
=
$val
->
currency
->
pj_symbol
;
$val
->
rate
=
$rate
;
unset
(
$val
->
id
);
unset
(
$val
->
platform_id
);
unset
(
$val
->
currency_id
);
}
$data
=
$currency
;
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
}
\ No newline at end of file
common/models/psources/CoinCurrency.php
0 → 100644
View file @
0b5d3b45
<?php
namespace
common\models\psources
;
use
Yii
;
use
common\core\BaseActiveRecord
;
class
CoinCurrency
extends
BaseActiveRecord
{
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{coin_currency}}'
;
}
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
public
function
rules
()
{
return
[
[[
'pj_id'
,
'pj_name'
],
'required'
],
[[
'pj_symbol'
,
'lang'
],
'safe'
],
[[
'platform_id'
,
'currency_id'
],
'integer'
],
];
}
public
function
attributeLabels
()
{
return
[
'platform_id'
=>
'钱包Id'
,
'currency_id'
=>
'货币Id'
,
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'pj_id'
,
'pj_name'
,
'pj_symbol'
,
'lang'
],
self
::
SCENARIOS_UPDATE
=>
[
'id'
,
'pj_id'
,
'pj_name'
,
'pj_symbol'
,
'lang'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
}
\ No newline at end of file
common/models/psources/CoinPlatform.php
View file @
0b5d3b45
...
...
@@ -89,4 +89,9 @@ class CoinPlatform extends BaseActiveRecord
{
return
$this
->
hasOne
(
CoinSupportedCoin
::
className
(),
[
'id'
=>
'charge_unit_id'
]);
}
public
function
getCurrency
()
{
return
$this
->
hasMany
(
CoinSupportedCurrency
::
className
(),
[
'platform_id'
=>
'id'
]);
}
}
common/models/psources/CoinSupportedCurrency.php
0 → 100644
View file @
0b5d3b45
<?php
namespace
common\models\psources
;
use
Yii
;
use
common\core\BaseActiveRecord
;
class
CoinSupportedCurrency
extends
BaseActiveRecord
{
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{coin_supported_currency}}'
;
}
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
public
function
rules
()
{
return
[
[[
'platform_id'
,
'currency_id'
],
'required'
],
[[
'platform_id'
,
'currency_id'
,
'sort'
],
'integer'
],
];
}
public
function
attributeLabels
()
{
return
[
'platform_id'
=>
'钱包Id'
,
'currency_id'
=>
'货币Id'
,
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'platform_id'
,
'currency_id'
,
'sort'
],
self
::
SCENARIOS_UPDATE
=>
[
'id'
,
'platform_id'
,
'currency_id'
,
'sort'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
public
function
attributes
()
{
return
array_merge
(
parent
::
attributes
(),
[
'pj_id'
,
'pj_name'
,
'pj_symbol'
,
'rate'
]);
}
public
function
getCurrency
()
{
return
$this
->
hasOne
(
CoinCurrency
::
className
(),
[
'id'
=>
'currency_id'
]);
}
public
static
function
loadArray
(
array
$data
)
{
return
self
::
getDb
()
->
createCommand
()
->
batchInsert
(
self
::
tableName
(),
[
'platform_id'
,
'currency_id'
],
$data
)
->
execute
();
}
}
\ No newline at end of file
console/controllers/TickerController.php
View file @
0b5d3b45
...
...
@@ -2,13 +2,12 @@
namespace
console\controllers
;
use
common\business\Chain33Business
;
use
common\models\psources\CoinGameBet
;
use
common\service\chain33\Chain33Service
;
use
common\service\exchange\ExchangeBuilderFactory
;
use
common\service\exchange\ExchangeFactory
;
use
yii\console\Controller
;
use
Yii
;
use
linslin\yii2\curl\Curl
;
use
yii\console\Controller
;
use
voku\helper\HtmlDomParser
;
use
common\models\psources\CoinSupportedCurrency
;
use
common\service\exchange\ExchangeBuilderFactory
;
class
TickerController
extends
Controller
{
...
...
@@ -22,7 +21,7 @@ class TickerController extends Controller
$ticker_builder
->
TickerSort
();
});
}
echo
date
(
'Y-m-d H:i:s'
)
.
'排序更新成功'
.
PHP_EOL
;
echo
date
(
'Y-m-d H:i:s'
)
.
'排序更新成功'
.
PHP_EOL
;
return
0
;
}
...
...
@@ -30,7 +29,36 @@ class TickerController extends Controller
{
$ticker_builder
=
ExchangeBuilderFactory
::
create
(
'Huobi'
);
$ticker_builder
->
hotTickerUpdate
();
echo
date
(
'Y-m-d H:i:s'
)
.
'更新成功'
.
PHP_EOL
;
echo
date
(
'Y-m-d H:i:s'
)
.
'更新成功'
.
PHP_EOL
;
return
0
;
}
public
function
actionCurrency
()
{
$currency_model
=
CoinSupportedCurrency
::
find
()
->
groupBy
(
'currency_id'
)
->
all
();
$curl
=
new
Curl
();
foreach
(
$currency_model
as
$val
)
{
go
(
function
()
use
(
$val
,
$curl
)
{
\Co
::
sleep
(
0.5
);
$response
=
$curl
->
setPostParams
([
'erectDate'
=>
''
,
'nothing'
=>
''
,
'pjname'
=>
$val
->
currency
->
pj_id
])
->
post
(
'http://srh.bankofchina.com/search/whpj/search.jsp'
);
$response
=
iconv
(
'UTF-8'
,
'GBK//TRANSLIT'
,
$response
);
$html
=
HtmlDomParser
::
str_get_html
(
$response
);
$div
=
(
$html
->
find
(
'div.BOC_main'
));
foreach
(
$div
->
find
(
'td'
)
as
$key
=>
$e
)
{
if
(
$key
==
5
)
{
$key
=
'quotation_boc_'
.
'CNY_'
.
$val
->
currency
->
symbol
;
$currency
=
rtrim
(
sprintf
(
'%.6f'
,
1
/
(
$e
->
innertext
/
100
)),
'0'
);
Yii
::
$app
->
redis_currency
->
hmset
(
$key
,
'low'
,
$currency
,
'high'
,
$currency
,
'last'
,
$currency
,
'open'
,
$currency
);
}
}
});
}
echo
date
(
'Y-m-d H:i:s'
)
.
'计价货币更新成功'
.
PHP_EOL
;
return
0
;
}
}
\ No newline at end of file
wallet/controllers/WalletController.php
View file @
0b5d3b45
...
...
@@ -2,11 +2,13 @@
namespace
wallet\controllers
;
use
common\service\trusteeship\TrusteeShipService
;
use
Yii
;
use
common\models\Admin
;
use
yii\helpers\ArrayHelper
;
use
wallet\base\BaseController
;
use
common\models\psources\CoinPlatform
;
use
common\models\psources\CoinCurrency
;
use
common\models\psources\CoinSupportedCurrency
;
use
common\service\trusteeship\TrusteeShipService
;
class
WalletController
extends
BaseController
{
...
...
@@ -27,16 +29,16 @@ class WalletController extends BaseController
public
function
actionWalletBallance
()
{
$current_platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
1
===
$current_platform_id
)
{
if
(
1
===
$current_platform_id
)
{
$platform_id
=
Yii
::
$app
->
request
->
get
(
'platform_id'
,
1
);
$platform_id
=
empty
(
$platform_id
)
?
1
:
$platform_id
;
}
else
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
}
if
(
!
isset
(
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
]))
{
if
(
!
isset
(
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
]))
{
return
[
'code'
=>
-
1
,
'data'
=>
[],
'msg'
=>
'此钱包节点尚未开通'
];
}
$node_params
=
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
];
$node_params
=
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
];
$type
=
Yii
::
$app
->
request
->
get
(
'type'
,
1
);
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
...
...
@@ -71,7 +73,7 @@ class WalletController extends BaseController
public
function
actionUserAsset
()
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
$node_params
=
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
];
$node_params
=
Yii
::
$app
->
params
[
'trusteeship'
][
'node_'
.
$platform_id
];
$uid
=
Yii
::
$app
->
request
->
get
(
'uid'
,
''
);
$params
=
[
'uid'
=>
$uid
...
...
@@ -96,4 +98,126 @@ class WalletController extends BaseController
return
[
'code'
=>
1
,
'data'
=>
$result
[
'msg'
],
'msg'
=>
'success'
];
}
public
function
actionCurrency
()
{
$code
=
0
;
$msg
=
'success'
;
$data
=
null
;
if
(
Yii
::
$app
->
request
->
isGet
)
{
$platform_id
=
Yii
::
$app
->
request
->
get
(
'platform_id'
,
0
);
if
(
false
==
$platform_id
)
{
$msg
=
'参数错误'
;
$code
=
-
1
;
goto
doEnd
;
}
$coin_currency
=
CoinCurrency
::
find
()
->
select
(
'id, pj_name, pj_symbol'
)
->
asArray
()
->
all
();
$coin_supported_currency
=
CoinSupportedCurrency
::
find
()
->
where
([
'platform_id'
=>
$platform_id
])
->
asArray
()
->
all
();
$coin_supported_currency_id
=
ArrayHelper
::
getColumn
(
$coin_supported_currency
,
'currency_id'
);
foreach
(
$coin_currency
as
&
$val
)
{
$val
[
'checked'
]
=
false
;
if
(
in_array
(
$val
[
"id"
],
$coin_supported_currency_id
))
{
$val
[
'checked'
]
=
true
;
}
}
$data
=
$coin_currency
;
goto
doEnd
;
}
if
(
Yii
::
$app
->
request
->
isPost
)
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
1
!=
$platform_id
)
{
$msg
=
'权限未开通'
;
$code
=
-
1
;
goto
doEnd
;
}
$params
=
Yii
::
$app
->
request
->
post
();
$platform_id
=
isset
(
$params
[
'platform_id'
])
?
$params
[
'platform_id'
]
:
null
;
$currency_id
=
isset
(
$params
[
'currency_id'
])
?
$params
[
'currency_id'
]
:
null
;
$sort
=
isset
(
$params
[
'sort'
])
?
$params
[
'sort'
]
:
1
;
$datas
=
[
'platform_id'
=>
$platform_id
,
'currency_id'
=>
$currency_id
,
'sort'
=>
$sort
];
$isExist
=
CoinSupportedCurrency
::
find
()
->
where
([
'platform_id'
=>
$platform_id
,
'currency_id'
=>
$currency_id
])
->
one
();
if
(
false
!=
$isExist
)
{
$msg
=
'记录已存在'
;
$code
=
-
1
;
goto
doEnd
;
}
$model
=
new
CoinSupportedCurrency
();
$model
->
setScenario
(
CoinSupportedCurrency
::
SCENARIOS_CREATE
);
$model
->
load
(
$datas
,
''
);
if
(
!
$model
->
validate
())
{
$msg
=
$model
->
errors
;
$code
=
-
1
;
goto
doEnd
;
}
$model
->
save
();
goto
doEnd
;
}
if
(
Yii
::
$app
->
request
->
isPut
)
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
1
!=
$platform_id
)
{
$msg
=
'权限未开通'
;
$code
=
-
1
;
goto
doEnd
;
}
$params
=
Yii
::
$app
->
request
->
post
();
$id
=
isset
(
$params
[
'id'
])
?
$params
[
'id'
]
:
null
;
$platform_id
=
isset
(
$params
[
'platform_id'
])
?
$params
[
'platform_id'
]
:
null
;
$currency_id
=
isset
(
$params
[
'currency_id'
])
?
$params
[
'currency_id'
]
:
null
;
$sort
=
isset
(
$params
[
'sort'
])
?
$params
[
'sort'
]
:
1
;
$datas
=
[
'platform_id'
=>
$platform_id
,
'currency_id'
=>
$currency_id
,
'sort'
=>
$sort
,
'id'
=>
$id
];
$model
=
CoinSupportedCurrency
::
find
()
->
where
([
'id'
=>
$id
])
->
one
();
if
(
false
==
$model
)
{
$msg
=
'记录未存在'
;
$code
=
-
1
;
goto
doEnd
;
}
$model
->
setScenario
(
CoinSupportedCurrency
::
SCENARIOS_UPDATE
);
$model
->
load
(
$datas
,
''
);
if
(
!
$model
->
validate
())
{
$msg
=
$model
->
errors
;
$code
=
-
1
;
goto
doEnd
;
}
$model
->
save
();
goto
doEnd
;
}
if
(
Yii
::
$app
->
request
->
isDelete
)
{
$platform_id
=
Yii
::
$app
->
request
->
getPlatformId
();
if
(
1
!=
$platform_id
)
{
$msg
=
'权限未开通'
;
$code
=
-
1
;
goto
doEnd
;
}
$params
=
Yii
::
$app
->
request
->
get
();
$id
=
isset
(
$params
[
'id'
])
?
$params
[
'id'
]
:
null
;
$model
=
CoinSupportedCurrency
::
find
()
->
where
([
'id'
=>
$id
])
->
one
();
if
(
false
==
$model
)
{
$msg
=
'记录未存在'
;
$code
=
-
1
;
goto
doEnd
;
}
$model
->
delete
();
goto
doEnd
;
}
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
}
\ 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