Commit 5376e157 authored by rlgy's avatar rlgy

bugfixed

parent add65b5c
......@@ -495,7 +495,7 @@ class CoinService extends Coin implements CoinInterface
public function quotation()
{
//使用缓存
$key = [
$key = [
__CLASS__,
__METHOD__,
'coin',//表名
......@@ -510,14 +510,6 @@ class CoinService extends Coin implements CoinInterface
$result = [
'price' => '',//价格
'dollar' => '',//价格美元
// 'btc' => '',//价格btc
// 'high' => '',//最高价
// 'low' => '',//最低价
// 'change' => '',//涨幅(跌幅)
// 'rank' => '',//流通市值排名
// 'circulate_value_rmb' => '',//流通市值人民币
// 'circulate_value_usd' => '',//流通市值美元
// 'circulate_value_btc' => '',//流通市值btc
'publish_count' => '',//发行总量
'circulate_count' => '',//流通总量
];
......@@ -525,29 +517,13 @@ class CoinService extends Coin implements CoinInterface
//价格与涨幅
$pattern = '/<div class=coinprice>(.*?)<span class=(tags-red|tags-green)>(.*?)<\/span><\/div>/is';
preg_match_all($pattern, $content, $matchs, PREG_SET_ORDER);
$result['price'] = (float)sprintf("%0.2f", (float)str_replace(['¥'], '', $matchs[0][1]));
// $result['change'] = $matchs[0][3];
//最高最低值
// preg_match_all('/<div class=lowHeight>(.*?)<\/div><div class=sub>/is', $content, $matchs);
// preg_match_all('/<span class=value>(.*?)<\/span>/is', $matchs[1][0], $matchs);
// $result['high'] = $matchs[1][0];
// $result['low'] = $matchs[1][1];
$result['price'] = (float)sprintf("%0.2f", (float)str_replace(['¥', ','], '', $matchs[0][1]));
//美元 btc
preg_match_all('/<div class=sub><span>(.*?)<\/span>(.*?)<span>(.*?)<\/span><\/div>/is', $content,
$matchs,
PREG_SET_ORDER);
$result['dollar'] = (float)sprintf("%0.4f", (double)str_replace(['$', '≈'], '', $matchs[0][1]));
// $result['btc'] = $matchs[0][3];
// //爬取市值与排名
// $pattern = '/<div class=value>(.*?)<span class=tag-marketcap>(.*?)<\/span><\/div><div class=sub>(.*?)<\/div><div class=sub>(.*?)<\/div>/is';
// preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
// $result['circulate_value_rmb'] = $matches[0][1];
// $result['rank'] = $matches[0][2];
// $result['circulate_value_usd'] = $matches[0][3];
// $result['circulate_value_btc'] = $matches[0][4];
$result['dollar'] = (float)sprintf("%0.4f", (double)str_replace(['$', '≈', ','], '', $matchs[0][1]));
//爬取流通总量,发行总量
$pattern = '/<div class=tit>流通量<\/div><div class=value>(.*?)<\/div><div class=tit>总发行量<\/div><div class=value>(.*?)<\/div>/is';
......@@ -555,10 +531,6 @@ class CoinService extends Coin implements CoinInterface
$result['circulate_count'] = $matches[0][1];
$result['publish_count'] = $matches[0][2];
// $result = array_map(function ($value) {
// return trim($value);
// }, $result);
Yii::$app->cache->set($key, $result, Yii::$app->params['curl_cache_time']['quotation']);//set cache
return $result;
} catch (\Exception $exception) {
......
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