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
8cf7b6bb
Commit
8cf7b6bb
authored
Dec 29, 2018
by
ZhuChunYang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
faa89cc0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
ServiceController.php
api/controllers/ServiceController.php
+80
-0
No files found.
api/controllers/ServiceController.php
0 → 100644
View file @
8cf7b6bb
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/12/29
* Time: 16:26
*/
namespace
api\controllers
;
use
api\base\BaseController
;
use
common\business\ExchangeBusiness
;
use
common\models\psources\Coin
;
use
common\service\coin\CoinFactory
;
use
Yii
;
/**
* 对外服务控制器
* Class CoinController
*
* @package api\controllers
*/
class
ServiceController
extends
BaseController
{
/**
* 获取币种行情
*
* @return array|null|\yii\db\ActiveRecord
*/
public
function
actionCoinTickers
()
{
$request
=
Yii
::
$app
->
request
;
$coinItems
=
$request
->
post
(
'names'
);
if
(
!
is_array
(
$coinItems
)){
$coinItems
=
[
$coinItems
];
}
$tickerData
=
[];
if
(
$coinItems
){
foreach
(
$coinItems
as
$item
){
$item
=
strtoupper
(
$item
);
$quotation
=
ExchangeBusiness
::
getquatation
(
$item
);
if
(
!
$quotation
)
{
//使用Coin服务
try
{
$coinServer
=
CoinFactory
::
createCoin
(
$item
,
''
,
''
);
$tickerData
[
$item
][
'rmb'
]
=
$coinServer
->
getPrice
();
$tickerData
[
$item
][
'last'
]
=
$coinServer
->
getDollar
();
$tickerData
[
$item
][
'low'
]
=
$coinServer
->
getLow
();
$tickerData
[
$item
][
'high'
]
=
$coinServer
->
getHigh
();
$coinServer
->
__destruct
();
}
catch
(
\Exception
$exception
)
{
$tickerData
[
$item
][
'rmb'
]
=
0
;
$tickerData
[
$item
][
'last'
]
=
0
;
$tickerData
[
$item
][
'low'
]
=
0
;
$tickerData
[
$item
][
'high'
]
=
0
;
\Yii
::
error
(
$exception
->
getMessage
());
}
}
else
{
$tickerData
[
$item
]
=
$quotation
;
}
}
return
[
'code'
=>
0
,
'data'
=>
$tickerData
,
'msg'
=>
'行情获取成功'
];
}
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'币种不能为空'
];
}
public
function
actionCoinIndex
()
{
$request
=
Yii
::
$app
->
request
;
$coinItems
=
$request
->
post
(
'names'
);
if
(
!
is_array
(
$coinItems
)){
$coinItems
=
[
$coinItems
];
}
$fields
=
[
'id'
,
'sid'
,
'icon'
,
'name'
,
'nickname'
];
$rows
=
Coin
::
getSelectList
(
1
,
999
,
$fields
,[[
'in'
,
'name'
,
$coinItems
]]);
return
[
'code'
=>
0
,
'data'
=>
$rows
,
'msg'
=>
'币种列表获取成功'
];
}
}
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