Commit e4ddd791 authored by rlgy's avatar rlgy

添加主链行情

parent fedccb4d
......@@ -20,6 +20,8 @@ class BaseResponse extends Response
$this->data = [
'code' => $excpetion->getCode(),
'msg' => $excpetion->getMessage(),
'line' => $excpetion->getLine(),
'file' => $excpetion->getFile(),
];
}
//TODO 在这里对数据进行format,这样控制器中可以直接return一个array,保存到数据域data中即可,eg:['code'=>0,'data'=>$data]
......
......@@ -49,7 +49,18 @@ class CoinController extends BaseController
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$condition = [['recommend' => '1']];
return ExchangeBusiness::getApiListForIndex($page, $limit, $condition);
$result = ExchangeBusiness::getApiListForIndex($page, $limit, $condition);
if ($result) {
$chains = array_unique(array_column($result['data'], 'chain'));
$chain_quotation=[];
foreach ($chains as $key => $value) {
$chain_quotation[$value]=ExchangeBusiness::getquatation($value);
}
foreach ($result['data'] as $key => &$value) {
$value['chain_quotation']=$chain_quotation[$value['chain']];
}
return $result;
}
}
/**
......@@ -84,7 +95,18 @@ class CoinController extends BaseController
{
$names = Yii::$app->request->post('names');
$condition = [['in', 'name', $names]];
return ExchangeBusiness::getApiListForIndex(1, 999, $condition);
$result = ExchangeBusiness::getApiListForIndex(1, 999, $condition);
if ($result) {
$chains = array_unique(array_column($result['data'], 'chain'));
$chain_quotation=[];
foreach ($chains as $key => $value) {
$chain_quotation[$value]=ExchangeBusiness::getquatation($value);
}
foreach ($result['data'] as $key => &$value) {
$value['chain_quotation']=$chain_quotation[$value['chain']];
}
return $result;
}
}
/**
......@@ -99,7 +121,18 @@ class CoinController extends BaseController
$limit = $request->post('limit', 10);
if ($name) {
$condition = [['!=', 'chain', 'other'], ['or', ['like', 'name', $name], ['like', 'nickname', $name]]];
return ExchangeBusiness::SearchByName($page, $limit, $condition);
$result = ExchangeBusiness::SearchByName($page, $limit, $condition);
if ($result) {
$chains = array_unique(array_column($result,'chain'));
$chain_quotation=[];
foreach ($chains as $key => $value) {
$chain_quotation[$value]=ExchangeBusiness::getquatation($value);
}
foreach ($result as $key => $value) {
$result[$key]['chain_quotation']=$chain_quotation[$value['chain']];
}
return $result;
}
}
}
......
......@@ -36,7 +36,7 @@ class ExchangeBusiness
* @param string $aim 计数币种
* @return array|bool
*/
private static function getquatation($tag = 'btc', $aim = '')
public static function getquatation($tag = 'btc', $aim = '')
{
$f = false;
$quotation = [];
......@@ -170,19 +170,6 @@ class ExchangeBusiness
$rows = $rows['data'];
foreach ($rows as $key => $row) {
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
// $quotation = self::getquatation($row['name']);
// if (!$quotation) {
// $quotation = [];
// //使用Coin服务
// $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();
// }
// $rows[$key] = array_merge($rows[$key], $quotation);
}
return $rows;
}
......
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