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
8e2bb30c
Commit
8e2bb30c
authored
Sep 11, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
5a9c02a0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
36 deletions
+41
-36
ServiceController.php
api/controllers/ServiceController.php
+41
-36
No files found.
api/controllers/ServiceController.php
View file @
8e2bb30c
...
...
@@ -5,6 +5,7 @@
* Date: 2018/12/29
* Time: 16:26
*/
namespace
api\controllers
;
use
api\base\BaseController
;
...
...
@@ -33,23 +34,23 @@ class ServiceController extends BaseController
public
function
actionCoinTickers
()
{
$request
=
Yii
::
$app
->
request
;
$coinItems
=
$request
->
post
(
'names'
);
if
(
!
$coinItems
)
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'币种不能为空'
];
$coinItems
=
$request
->
post
(
'names'
);
if
(
!
$coinItems
)
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'币种不能为空'
];
}
if
(
!
is_array
(
$coinItems
))
{
if
(
!
is_array
(
$coinItems
))
{
$coinItems
=
[
$coinItems
];
}
$tol_coins
=
[
'ETC'
];
$tickerData
=
[];
if
(
$coinItems
)
{
foreach
(
$coinItems
as
$item
)
{
if
(
$coinItems
)
{
foreach
(
$coinItems
as
$item
)
{
$item
=
strtoupper
(
$item
);
if
(
in_array
(
$item
,
$tol_coins
))
{
if
(
in_array
(
$item
,
$tol_coins
))
{
$exchange
=
ExchangeFactory
::
createExchange
(
'HuoBi'
);
if
(
$exchange
->
symbolExists
(
$item
))
{
$quotation
=
$exchange
->
getTicker
(
$item
);
if
(
$quotation
)
{
if
(
$quotation
)
{
//格式化行情数据
foreach
(
$quotation
as
$key
=>
$value
)
{
$quotation
[
$key
]
=
(
float
)
sprintf
(
"%0.4f"
,
(
double
)
$value
);
...
...
@@ -58,30 +59,34 @@ class ServiceController extends BaseController
$quotation
[
'rmb'
]
=
(
float
)
sprintf
(
"%0.4f"
,
$rate
*
$quotation
[
'last'
]);
}
}
}
else
{
$quotation
=
ExchangeBusiness
::
getquatation
(
$item
);
}
else
{
$quotation
=
ExchangeBusiness
::
getquatation
(
$item
);
}
if
(
!
$quotation
)
{
//使用Coin服务
try
{
$coinServer
=
CoinFactory
::
createCoin
(
$item
,
''
,
''
);
$tickerData
[
$item
][
'rmb'
]
=
$coinServer
->
getPrice
();
$coinServer
=
CoinFactory
::
createCoin
(
$item
,
''
,
''
);
$tickerData
[
$item
][
'rmb'
]
=
$coinServer
->
getPrice
();
$tickerData
[
$item
][
'last'
]
=
$coinServer
->
getDollar
();
$tickerData
[
$item
][
'low'
]
=
$coinServer
->
getLow
();
$tickerData
[
$item
][
'low'
]
=
$coinServer
->
getLow
();
$tickerData
[
$item
][
'high'
]
=
$coinServer
->
getHigh
();
$tickerData
[
$item
][
'open'
]
=
$coinServer
->
getDollar
();
$tickerData
[
$item
][
'usd'
]
=
$coinServer
->
getDollar
();
$coinServer
->
__destruct
();
}
catch
(
\Exception
$exception
)
{
$tickerData
[
$item
][
'rmb'
]
=
0
;
$tickerData
[
$item
][
'rmb'
]
=
0
;
$tickerData
[
$item
][
'last'
]
=
0
;
$tickerData
[
$item
][
'low'
]
=
0
;
$tickerData
[
$item
][
'low'
]
=
0
;
$tickerData
[
$item
][
'high'
]
=
0
;
$tickerData
[
$item
][
'open'
]
=
0
;
$tickerData
[
$item
][
'usd'
]
=
0
;
\Yii
::
error
(
$exception
->
getMessage
());
}
}
else
{
}
else
{
$tickerData
[
$item
]
=
$quotation
;
}
}
return
[
'code'
=>
0
,
'data'
=>
$tickerData
,
'msg'
=>
'行情获取成功'
];
return
[
'code'
=>
0
,
'data'
=>
$tickerData
,
'msg'
=>
'行情获取成功'
];
}
}
...
...
@@ -94,13 +99,13 @@ class ServiceController extends BaseController
$platform_id
=
Yii
::
$app
->
request
->
get
(
'platform_id'
,
6
);
$type
=
Yii
::
$app
->
request
->
get
(
'type'
,
1
);
$coin_recommendItems
=
$this
->
coinRecommendList
(
$platform_id
,
$type
);
$fields
=
[
'id'
,
'sid'
,
'icon'
,
'name'
,
'nickname'
,
'chain'
,
'platform'
];
$rows
=
Coin
::
getSelectList
(
1
,
999
,
$fields
,[[
'in'
,
'id'
,
$coin_recommendItems
]]);
$fields
=
[
'id'
,
'sid'
,
'icon'
,
'name'
,
'nickname'
,
'chain'
,
'platform'
];
$rows
=
Coin
::
getSelectList
(
1
,
999
,
$fields
,
[[
'in'
,
'id'
,
$coin_recommendItems
]]);
foreach
(
$rows
[
'data'
]
as
$key
=>
&
$value
)
{
$nickname
=
json_decode
(
$value
[
'nickname'
],
true
);
$value
[
'nickname'
]
=
$nickname
[
$this
->
lang
];
}
return
[
'code'
=>
0
,
'data'
=>
$rows
,
'msg'
=>
'币种列表获取成功'
];
return
[
'code'
=>
0
,
'data'
=>
$rows
,
'msg'
=>
'币种列表获取成功'
];
}
/**
...
...
@@ -109,9 +114,9 @@ class ServiceController extends BaseController
*/
private
function
coinRecommendList
(
$platform_id
,
$type
=
1
)
{
$recommend_list
=
CoinRecommend
::
find
()
->
select
(
'cid'
)
->
where
([
'platform_id'
=>
$platform_id
,
'type'
=>
$type
])
->
all
();
if
(
$recommend_list
)
{
$coin_ids
=
array_column
(
$recommend_list
,
'cid'
);
$recommend_list
=
CoinRecommend
::
find
()
->
select
(
'cid'
)
->
where
([
'platform_id'
=>
$platform_id
,
'type'
=>
$type
])
->
all
();
if
(
$recommend_list
)
{
$coin_ids
=
array_column
(
$recommend_list
,
'cid'
);
return
$coin_ids
;
}
return
[];
...
...
@@ -124,15 +129,15 @@ class ServiceController extends BaseController
public
function
actionFee
()
{
$request
=
Yii
::
$app
->
request
;
$coin
=
$request
->
post
(
'name'
);
if
(
!
$coin
)
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'币种不能为空'
];
$coin
=
$request
->
post
(
'name'
);
if
(
!
$coin
)
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'币种不能为空'
];
}
$fee
=
MinerFee
::
find
()
->
where
([
'platform'
=>
$coin
,
'type'
=>
2
])
->
select
(
'id,platform,type,fee,create_at,update_at'
)
->
asArray
()
->
one
();
if
(
!
$fee
)
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'旷工费未设置'
];
$fee
=
MinerFee
::
find
()
->
where
([
'platform'
=>
$coin
,
'type'
=>
2
])
->
select
(
'id,platform,type,fee,create_at,update_at'
)
->
asArray
()
->
one
();
if
(
!
$fee
)
{
return
[
'code'
=>
1
,
'data'
=>
[],
'msg'
=>
'旷工费未设置'
];
}
return
[
'code'
=>
0
,
'data'
=>
$fee
,
'msg'
=>
'旷工费获取成功'
];
return
[
'code'
=>
0
,
'data'
=>
$fee
,
'msg'
=>
'旷工费获取成功'
];
}
/**
...
...
@@ -141,8 +146,8 @@ class ServiceController extends BaseController
*/
private
function
getRate
()
{
$exchange
=
ExchangeFactory
::
createExchange
(
"Bty"
);
$rate
=
$exchange
->
getTicker
(
"BTY"
,
"USDT"
);
$exchange
=
ExchangeFactory
::
createExchange
(
"Bty"
);
$rate
=
$exchange
->
getTicker
(
"BTY"
,
"USDT"
);
return
(
float
)
$rate
[
'rmb'
]
/
$rate
[
'last'
];
}
...
...
@@ -153,12 +158,12 @@ class ServiceController extends BaseController
public
function
actionChain
()
{
$request
=
Yii
::
$app
->
request
;
$currency
=
$request
->
post
(
'currency'
,
''
);
$currency
=
$request
->
post
(
'currency'
,
''
);
$coin
=
Coin
::
find
()
->
where
([
'name'
=>
$currency
])
->
select
(
'name,nickname,chain'
)
->
asArray
()
->
one
();
if
(
$coin
)
{
return
[
'code'
=>
0
,
'data'
=>
$coin
];
if
(
$coin
)
{
return
[
'code'
=>
0
,
'data'
=>
$coin
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'币种不存在'
];
return
[
'code'
=>
-
1
,
'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