Commit 0abb42af authored by rlgy's avatar rlgy

找币api更新

parent 7fd2bcba
...@@ -17,7 +17,10 @@ class BaseResponse extends Response ...@@ -17,7 +17,10 @@ class BaseResponse extends Response
//错误处理 //错误处理
$excpetion = \Yii::$app->errorHandler->exception; $excpetion = \Yii::$app->errorHandler->exception;
if ($excpetion !== null) { if ($excpetion !== null) {
$this->data = ['code' => $excpetion->getCode(), 'msg' => $excpetion->getMessage()]; $this->data = [
'code' => $excpetion->getCode(),
'msg' => $excpetion->getMessage(),
];
} }
//TODO 在这里对数据进行format,这样控制器中可以直接return一个array,保存到数据域data中即可,eg:['code'=>0,'data'=>$data] //TODO 在这里对数据进行format,这样控制器中可以直接return一个array,保存到数据域data中即可,eg:['code'=>0,'data'=>$data]
$data = \Yii::$app->response->data; $data = \Yii::$app->response->data;
......
...@@ -121,7 +121,10 @@ class ExchangeBusiness ...@@ -121,7 +121,10 @@ class ExchangeBusiness
public static function getApiListForIndex($page = 1, $limit = 999, $condition = []) public static function getApiListForIndex($page = 1, $limit = 999, $condition = [])
{ {
$rows = Coin::getSelectList($page, $limit, ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain'], $condition); $rows = Coin::getSelectList($page, $limit, ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain'], $condition);
$count = $rows['count'] ?? 0; $count = 0;
if (!empty($rows) && is_array($rows) && array_key_exists('count', $rows)) {
$count = $rows['count'];
}
if ($rows['count'] > 0) { if ($rows['count'] > 0) {
$rows = $rows['data']; $rows = $rows['data'];
foreach ($rows as $key => $row) { foreach ($rows as $key => $row) {
...@@ -130,13 +133,14 @@ class ExchangeBusiness ...@@ -130,13 +133,14 @@ class ExchangeBusiness
if (!$quotation) { if (!$quotation) {
$quotation = []; $quotation = [];
//使用Coin服务 //使用Coin服务
$coinServer = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
try { try {
$coinServer = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
$rows[$key]['rmb'] = $coinServer->getPrice(); $rows[$key]['rmb'] = $coinServer->getPrice();
$rows[$key]['last'] = $coinServer->getDollar(); $rows[$key]['last'] = $coinServer->getDollar();
$rows[$key]['low'] = $coinServer->getLow(); $rows[$key]['low'] = $coinServer->getLow();
$rows[$key]['high'] = $coinServer->getHigh(); $rows[$key]['high'] = $coinServer->getHigh();
$coinServer->__destruct();
} catch (\Exception $exception) { } catch (\Exception $exception) {
$rows[$key]['rmb'] = 0; $rows[$key]['rmb'] = 0;
$rows[$key]['last'] = 0; $rows[$key]['last'] = 0;
...@@ -144,7 +148,6 @@ class ExchangeBusiness ...@@ -144,7 +148,6 @@ class ExchangeBusiness
$rows[$key]['high'] = 0; $rows[$key]['high'] = 0;
\Yii::error($exception->getMessage()); \Yii::error($exception->getMessage());
} }
$coinServer->__destruct();
} }
$rows[$key] = array_merge($rows[$key], $quotation); $rows[$key] = array_merge($rows[$key], $quotation);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment