Commit 67804f29 authored by rlgy's avatar rlgy

接口数据格式修改

parent 45fa6c80
...@@ -77,9 +77,9 @@ class ExchangeBusiness ...@@ -77,9 +77,9 @@ class ExchangeBusiness
} }
//格式化行情数据 //格式化行情数据
foreach ($quotation as $key => $item) { foreach ($quotation as $key => $item) {
$quotation[$key] = sprintf("%0.4f", (double)$item); $quotation[$key] = (float)sprintf("%0.4f", (double)$item);
} }
$quotation['rmb'] = sprintf("%0.2f", 6.6 * $quotation['last']); $quotation['rmb'] = (float)sprintf("%0.2f", 6.6 * $quotation['last']);
return $quotation; return $quotation;
} }
...@@ -131,10 +131,10 @@ class ExchangeBusiness ...@@ -131,10 +131,10 @@ class ExchangeBusiness
//使用Coin服务 //使用Coin服务
$coinServer = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']); $coinServer = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']); $rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
$rows[$key]['rmb'] = sprintf("%0.2f", $coinServer->getPrice()); $rows[$key]['rmb'] = $coinServer->getPrice();
$rows[$key]['last'] = sprintf("%0.4f", $coinServer->getDollar()); $rows[$key]['last'] = $coinServer->getDollar();
$rows[$key]['low'] = sprintf("%0.2f", $coinServer->getLow()); $rows[$key]['low'] = $coinServer->getLow();
$rows[$key]['high'] = sprintf("%0.2f", $coinServer->getHigh()); $rows[$key]['high'] = $coinServer->getHigh();
$coinServer->__destruct(); $coinServer->__destruct();
} }
$rows[$key] = array_merge($rows[$key], $quotation); $rows[$key] = array_merge($rows[$key], $quotation);
......
...@@ -58,7 +58,7 @@ class CoinBTYService extends Coin implements CoinInterface ...@@ -58,7 +58,7 @@ class CoinBTYService extends Coin implements CoinInterface
{ {
$key = $this->cache_key_prifx . $this->sid . 'all'; $key = $this->cache_key_prifx . $this->sid . 'all';
$result = Yii::$app->cache->get($key); $result = Yii::$app->cache->get($key);
if ($result === false||YII_ENV_DEV) { if ($result === false || YII_ENV_DEV) {
$url = 'https://zb2api.licai.cn/api/data/Ticker?sort=cname'; $url = 'https://zb2api.licai.cn/api/data/Ticker?sort=cname';
$ch = new Curl(); $ch = new Curl();
$content = $ch->get($url, false); $content = $ch->get($url, false);
...@@ -95,7 +95,7 @@ class CoinBTYService extends Coin implements CoinInterface ...@@ -95,7 +95,7 @@ class CoinBTYService extends Coin implements CoinInterface
public function setPrice($price) public function setPrice($price)
{ {
return $this->price = $price; return $this->price = (float)sprintf("%0.2f", $price);
} }
public function getDollar() public function getDollar()
...@@ -110,7 +110,7 @@ class CoinBTYService extends Coin implements CoinInterface ...@@ -110,7 +110,7 @@ class CoinBTYService extends Coin implements CoinInterface
public function setDollar($dollar) public function setDollar($dollar)
{ {
$this->dollar = $dollar; $this->dollar = (float)sprintf("%0.4f", $dollar);
} }
public function getHigh() public function getHigh()
...@@ -125,7 +125,7 @@ class CoinBTYService extends Coin implements CoinInterface ...@@ -125,7 +125,7 @@ class CoinBTYService extends Coin implements CoinInterface
public function setHigh($high) public function setHigh($high)
{ {
return $this->high = $high; return $this->high = (float)sprintf("%0.4f", $high);
} }
public function getLow() public function getLow()
...@@ -140,7 +140,7 @@ class CoinBTYService extends Coin implements CoinInterface ...@@ -140,7 +140,7 @@ class CoinBTYService extends Coin implements CoinInterface
public function setLow($low) public function setLow($low)
{ {
$this->low = $low; $this->low = (float)sprintf("%0.4f", $low);
} }
public function getChange() public function getChange()
......
...@@ -66,7 +66,7 @@ class CoinService extends Coin implements CoinInterface ...@@ -66,7 +66,7 @@ class CoinService extends Coin implements CoinInterface
*/ */
public function setPrice($price) public function setPrice($price)
{ {
$this->price = $price; $this->price = (float)sprintf("%0.2f", $price);
} }
/** /**
...@@ -96,7 +96,7 @@ class CoinService extends Coin implements CoinInterface ...@@ -96,7 +96,7 @@ class CoinService extends Coin implements CoinInterface
*/ */
public function setDollar($dollar) public function setDollar($dollar)
{ {
$this->dollar = $dollar; $this->dollar = (float)sprintf("%0.4f", $dollar);
} }
/** /**
...@@ -155,7 +155,7 @@ class CoinService extends Coin implements CoinInterface ...@@ -155,7 +155,7 @@ class CoinService extends Coin implements CoinInterface
*/ */
public function setHigh($high) public function setHigh($high)
{ {
$this->high = $high; $this->high = (float)sprintf("%0.2f", $high);
} }
/** /**
...@@ -184,7 +184,7 @@ class CoinService extends Coin implements CoinInterface ...@@ -184,7 +184,7 @@ class CoinService extends Coin implements CoinInterface
*/ */
public function setLow($low) public function setLow($low)
{ {
$this->low = $low; $this->low = (float)sprintf("%0.2f", $low);
} }
/** /**
...@@ -525,7 +525,7 @@ class CoinService extends Coin implements CoinInterface ...@@ -525,7 +525,7 @@ class CoinService extends Coin implements CoinInterface
//价格与涨幅 //价格与涨幅
$pattern = '/<div class=coinprice>(.*?)<span class=(tags-red|tags-green)>(.*?)<\/span><\/div>/is'; $pattern = '/<div class=coinprice>(.*?)<span class=(tags-red|tags-green)>(.*?)<\/span><\/div>/is';
preg_match_all($pattern, $content, $matchs, PREG_SET_ORDER); preg_match_all($pattern, $content, $matchs, PREG_SET_ORDER);
$result['price'] = sprintf("%0.2f", (float)str_replace(['¥'], '', $matchs[0][1])); $result['price'] = (float)sprintf("%0.2f", (float)str_replace(['¥'], '', $matchs[0][1]));
// $result['change'] = $matchs[0][3]; // $result['change'] = $matchs[0][3];
//最高最低值 //最高最低值
...@@ -538,7 +538,7 @@ class CoinService extends Coin implements CoinInterface ...@@ -538,7 +538,7 @@ class CoinService extends Coin implements CoinInterface
preg_match_all('/<div class=sub><span>(.*?)<\/span>(.*?)<span>(.*?)<\/span><\/div>/is', $content, preg_match_all('/<div class=sub><span>(.*?)<\/span>(.*?)<span>(.*?)<\/span><\/div>/is', $content,
$matchs, $matchs,
PREG_SET_ORDER); PREG_SET_ORDER);
$result['dollar'] = sprintf("%0.4f", (double)str_replace(['$', '≈'], '', $matchs[0][1])); $result['dollar'] = (float)sprintf("%0.4f", (double)str_replace(['$', '≈'], '', $matchs[0][1]));
// $result['btc'] = $matchs[0][3]; // $result['btc'] = $matchs[0][3];
// //爬取市值与排名 // //爬取市值与排名
...@@ -555,9 +555,9 @@ class CoinService extends Coin implements CoinInterface ...@@ -555,9 +555,9 @@ class CoinService extends Coin implements CoinInterface
$result['circulate_count'] = $matches[0][1]; $result['circulate_count'] = $matches[0][1];
$result['publish_count'] = $matches[0][2]; $result['publish_count'] = $matches[0][2];
$result = array_map(function ($value) { // $result = array_map(function ($value) {
return trim($value); // return trim($value);
}, $result); // }, $result);
Yii::$app->cache->set($key, $result, Yii::$app->params['curl_cache_time']['quotation']);//set cache Yii::$app->cache->set($key, $result, Yii::$app->params['curl_cache_time']['quotation']);//set cache
return $result; return $result;
......
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