Commit 9b1035ad authored by rlgy's avatar rlgy

结构规范

parent 4f70fb8a
......@@ -35,6 +35,7 @@ class CoinBusiness
//获取交易所信息
$coin = CoinFactory::createCoin($value['name'], $value['id'], $value['sid']);
$rows['data'][$key]['exchange'] = $coin->exchange_count();
$coin->__destruct();
}
}
return $rows;
......@@ -53,6 +54,7 @@ class CoinBusiness
if ($coin) {
$model = CoinFactory::createCoin($coin->name, $coin->id, $coin->sid);
$datas = $model->exchange();
$model->__destruct();
if ($datas['count'] > 0) {
return $datas['data'];
}
......@@ -76,6 +78,7 @@ class CoinBusiness
foreach ($rows as $key => $value) {
$coin = CoinFactory::createCoin($value['name'], $value['id'], $value['sid']);
$rows[$key]['quotation'] = $coin->quotation();
$coin->__destruct();
}
}
return $rows;
......@@ -129,6 +132,7 @@ class CoinBusiness
/**
* 获取币种的所有信息
* @param integer $id
* @return array
*/
public static function getCoinAllById($id)
......@@ -136,10 +140,9 @@ class CoinBusiness
$row = Coin::find()->where(['id' => $id])->asArray()->One();
if ($row) {
$coin = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
//TODO 获取行情
$row['quotation'] = $coin->quotation($row['sid']);
//TODO 获取交易所详情
$row['exchange'] = $coin->exchange($row['sid']);
$row['quotation'] = $coin->quotation();
$row['exchange'] = $coin->exchange();
$coin->__destruct();
}
return $row ? [$row] : [];
}
......
......@@ -22,9 +22,47 @@ class CoinBTYService extends Coin implements CoinInterface
return 0;
}
/**
* 行情获取
*/
public function quotation()
{
// TODO: Implement quotation() method.
$result = [
'price' => '',//价格
'dollar' => '',//价格美元
'btc' => '',//价格btc
'high' => '',//最高价
'low' => '',//最低价
'change' => '',//涨幅(跌幅)
'rank' => '',//流通市值排名
'circulate_value_rmb' => '',//流通市值人民币
'circulate_value_usd' => '',//流通市值美元
'circulate_value_btc' => '',//流通市值btc
'publish_count' => '',//发行总量
'circulate_count' => '',//流通总量
];
$ch = curl_init('https://kdata.zhaobi.com:4062/kdata?datafile=db&c=BTYUSDT&p=H1&action=init&count=24&ind=volumes&out=json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$content = curl_exec($ch);
$content = json_decode($content, true);
$content = $content['main']['y'];
$min = 10e9;
$max = 0;
foreach ($content as $item) {
for ($i = 0; $i < 4; $i++) {
$min = min($min, $item[$i]);
$max = max($max, $item[$i]);
}
}
$change = ($content[23][3] - $content[0][0]) / $content[0][0] * 100;
$result['dollar'] = $content[23][3];
$result['low'] = $min;
$result['high'] = $max;
$result['change'] = sprintf("%0.2f%%", $change);
return $result;
}
public function __construct($id, $sid)
......@@ -62,105 +100,4 @@ class CoinBTYService extends Coin implements CoinInterface
parent::setDollar($dollar); // TODO: Change the autogenerated stub
}
public function getBtc()
{
return parent::getBtc(); // TODO: Change the autogenerated stub
}
public function setBtc($btc)
{
parent::setBtc($btc); // TODO: Change the autogenerated stub
}
public function getHigh()
{
return parent::getHigh(); // TODO: Change the autogenerated stub
}
public function setHigh($high)
{
parent::setHigh($high); // TODO: Change the autogenerated stub
}
public function getLow()
{
return parent::getLow(); // TODO: Change the autogenerated stub
}
public function setLow($low)
{
parent::setLow($low); // TODO: Change the autogenerated stub
}
public function getChange()
{
return parent::getChange(); // TODO: Change the autogenerated stub
}
public function setChange($change)
{
parent::setChange($change); // TODO: Change the autogenerated stub
}
public function getRank()
{
return parent::getRank(); // TODO: Change the autogenerated stub
}
public function setRank($rank)
{
parent::setRank($rank); // TODO: Change the autogenerated stub
}
public function getCirculateValueRmb()
{
return parent::getCirculateValueRmb(); // TODO: Change the autogenerated stub
}
public function setCirculateValueRmb($circulate_value_rmb)
{
parent::setCirculateValueRmb($circulate_value_rmb); // TODO: Change the autogenerated stub
}
public function getCirculateValueUsd()
{
return parent::getCirculateValueUsd(); // TODO: Change the autogenerated stub
}
public function setCirculateValueUsd($circulate_value_usd)
{
parent::setCirculateValueUsd($circulate_value_usd); // TODO: Change the autogenerated stub
}
public function getCirculateValueBtc()
{
return parent::getCirculateValueBtc(); // TODO: Change the autogenerated stub
}
public function setCirculateValueBtc($circulate_value_btc)
{
parent::setCirculateValueBtc($circulate_value_btc); // TODO: Change the autogenerated stub
}
public function getPublishCount()
{
return parent::getPublishCount(); // TODO: Change the autogenerated stub
}
public function setPublishCount($publish_count)
{
parent::setPublishCount($publish_count); // TODO: Change the autogenerated stub
}
public function getCirculateCount()
{
return parent::getCirculateCount(); // TODO: Change the autogenerated stub
}
public function setCirculateCount($circulate_count)
{
parent::setCirculateCount($circulate_count); // TODO: Change the autogenerated stub
}
}
\ No newline at end of file
......@@ -564,47 +564,4 @@ class CoinService extends Coin implements CoinInterface
}
return $result;
}
/**
* 快速修复方法,之后再改
*/
public static function quotationBTY()
{
$result = [
'price' => '',//价格
'dollar' => '',//价格美元
'btc' => '',//价格btc
'high' => '',//最高价
'low' => '',//最低价
'change' => '',//涨幅(跌幅)
'rank' => '',//流通市值排名
'circulate_value_rmb' => '',//流通市值人民币
'circulate_value_usd' => '',//流通市值美元
'circulate_value_btc' => '',//流通市值btc
'publish_count' => '',//发行总量
'circulate_count' => '',//流通总量
];
$ch = curl_init('https://kdata.zhaobi.com:4062/kdata?datafile=db&c=BTYUSDT&p=H1&action=init&count=24&ind=volumes&out=json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$content = curl_exec($ch);
$content = json_decode($content, true);
$content = $content['main']['y'];
$min = 10e9;
$max = 0;
foreach ($content as $item) {
for ($i = 0; $i < 4; $i++) {
$min = min($min, $item[$i]);
$max = max($max, $item[$i]);
}
}
$change = ($content[23][3] - $content[0][0]) / $content[0][0] * 100;
$result['dollar'] = $content[23][3];
$result['low'] = $min;
$result['high'] = $max;
$result['change'] = sprintf("%0.2f%%", $change);
return $result;
}
}
\ No newline at end of file
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