Commit 0abb42af authored by rlgy's avatar rlgy

找币api更新

parent 7fd2bcba
......@@ -17,7 +17,10 @@ class BaseResponse extends Response
//错误处理
$excpetion = \Yii::$app->errorHandler->exception;
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]
$data = \Yii::$app->response->data;
......
......@@ -121,7 +121,10 @@ class ExchangeBusiness
public static function getApiListForIndex($page = 1, $limit = 999, $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) {
$rows = $rows['data'];
foreach ($rows as $key => $row) {
......@@ -130,13 +133,14 @@ class ExchangeBusiness
if (!$quotation) {
$quotation = [];
//使用Coin服务
$coinServer = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
try {
$coinServer = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
$rows[$key]['rmb'] = $coinServer->getPrice();
$rows[$key]['last'] = $coinServer->getDollar();
$rows[$key]['low'] = $coinServer->getLow();
$rows[$key]['high'] = $coinServer->getHigh();
$coinServer->__destruct();
} catch (\Exception $exception) {
$rows[$key]['rmb'] = 0;
$rows[$key]['last'] = 0;
......@@ -144,7 +148,6 @@ class ExchangeBusiness
$rows[$key]['high'] = 0;
\Yii::error($exception->getMessage());
}
$coinServer->__destruct();
}
$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