Commit 12b7c8a8 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ticker' into 'master'

Feature/ticker See merge request !161
parents 680470cd 59d36a31
...@@ -20,6 +20,7 @@ class TickerController extends BaseController ...@@ -20,6 +20,7 @@ class TickerController extends BaseController
{ {
$page = Yii::$app->request->get('page', 1); $page = Yii::$app->request->get('page', 1);
$device_code = Yii::$app->request->get('device_code', ''); $device_code = Yii::$app->request->get('device_code', '');
$platform_id = Yii::$app->request->get('device_code', 0);
$exchange = Yii::$app->request->get('exchange', 'zhaobi'); $exchange = Yii::$app->request->get('exchange', 'zhaobi');
$data_value = Yii::$app->request->get('data-value', ''); $data_value = Yii::$app->request->get('data-value', '');
$sort = Yii::$app->request->get('sort', ''); $sort = Yii::$app->request->get('sort', '');
...@@ -38,7 +39,12 @@ class TickerController extends BaseController ...@@ -38,7 +39,12 @@ class TickerController extends BaseController
$data = $result['data']; $data = $result['data'];
if (false != $device_code) { if (false != $device_code) {
if (false != $platform_id) {
$coin_optional = CoinOptional::find()->select('symbol')->where(['platform' => $exchange, 'device_code' => $device_code])->asArray()->all(); $coin_optional = CoinOptional::find()->select('symbol')->where(['platform' => $exchange, 'device_code' => $device_code])->asArray()->all();
} else {
$coin_optional = CoinOptional::find()->select('symbol')->where(['platform' => $exchange, 'device_code' => $device_code, 'platform_id' => $platform_id])->asArray()->all();
}
$coin_optional = ArrayHelper::getColumn($coin_optional, 'symbol'); $coin_optional = ArrayHelper::getColumn($coin_optional, 'symbol');
foreach ($data['ticker'] as &$val) { foreach ($data['ticker'] as &$val) {
if (in_array($val['symbol'], $coin_optional)) { if (in_array($val['symbol'], $coin_optional)) {
...@@ -67,7 +73,7 @@ class TickerController extends BaseController ...@@ -67,7 +73,7 @@ class TickerController extends BaseController
$params = json_encode($data); $params = json_encode($data);
$curl->setHeader('Content-Type', 'application/json'); $curl->setHeader('Content-Type', 'application/json');
$curl->setRawPostData($params); $curl->setRawPostData($params);
$res = $curl->post('https://b.biqianbao.net/interface/coin/coin-index', true); $res = $curl->post(Yii::$app->params['biqianbao'] . '/interface/coin/coin-index', true);
$res = json_decode($res, true); $res = json_decode($res, true);
foreach ($res['data'] as $val) { foreach ($res['data'] as $val) {
$this->basic_price[$val['name']]['rmb'] = $val['rmb']; $this->basic_price[$val['name']]['rmb'] = $val['rmb'];
...@@ -89,7 +95,7 @@ class TickerController extends BaseController ...@@ -89,7 +95,7 @@ class TickerController extends BaseController
$msg = '参数错误'; $msg = '参数错误';
goto doEnd; goto doEnd;
} }
$model = CoinOptional::find()->where(['device_code' => $device_code, 'symbol' => $symbol])->one(); $model = CoinOptional::find()->where(['device_code' => $device_code, 'symbol' => $symbol, 'platform_id' => (int)$platform_id])->one();
if ($model) { if ($model) {
$msg = '数据已存在!'; $msg = '数据已存在!';
goto doEnd; goto doEnd;
...@@ -155,7 +161,7 @@ class TickerController extends BaseController ...@@ -155,7 +161,7 @@ class TickerController extends BaseController
$temp['close'] = number_format($quotation['last'], 6, '.', ''); $temp['close'] = number_format($quotation['last'], 6, '.', '');
$temp['close_usd'] = (float)sprintf("%0.6f", $quotation['last'] * $this->basic_price[$tag_second]['usd']); $temp['close_usd'] = (float)sprintf("%0.6f", $quotation['last'] * $this->basic_price[$tag_second]['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $quotation['last'] * $this->basic_price[$tag_second]['rmb']); $temp['close_rmb'] = (float)sprintf("%0.4f", $quotation['last'] * $this->basic_price[$tag_second]['rmb']);
$temp['change'] = (0 == $quotation['open']) ? 0 : (float)sprintf("%0.4f", ($quotation['last'] - $quotation['open']) / $quotation['open'] * 100); $temp['change'] = (0 == $quotation['open']) ? 0 : (float)sprintf("%0.2f", ($quotation['last'] - $quotation['open']) / $quotation['open'] * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $quotation['high'] * $this->basic_price[$tag_second]['usd']); $temp['high_usd'] = (float)sprintf("%0.4f", $quotation['high'] * $this->basic_price[$tag_second]['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $quotation['low'] * $this->basic_price[$tag_second]['usd']); $temp['low_usd'] = (float)sprintf("%0.4f", $quotation['low'] * $this->basic_price[$tag_second]['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $quotation['high'] * $this->basic_price[$tag_second]['rmb']); $temp['high_rmb'] = (float)sprintf("%0.4f", $quotation['high'] * $this->basic_price[$tag_second]['rmb']);
......
...@@ -90,7 +90,7 @@ class BinanceBuilder extends FactoryService ...@@ -90,7 +90,7 @@ class BinanceBuilder extends FactoryService
$temp['close'] = number_format($close, 6, '.', ''); $temp['close'] = number_format($close, 6, '.', '');
$temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price[$coin]['usd']); $temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price[$coin]['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']); $temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
$temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.4f", ($close - $open) / $open * 100); $temp['change'] = (0 == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']); $temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price[$coin]['usd']); $temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price[$coin]['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['rmb']); $temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['rmb']);
......
...@@ -35,7 +35,7 @@ abstract class FactoryService ...@@ -35,7 +35,7 @@ abstract class FactoryService
$params = json_encode($data); $params = json_encode($data);
$curl->setHeader('Content-Type', 'application/json'); $curl->setHeader('Content-Type', 'application/json');
$curl->setRawPostData($params); $curl->setRawPostData($params);
$res = $curl->post('http://127.0.0.1:8082/interface/coin/coin-index', true); $res = $curl->post(\Yii::$app->params['biqianbao'].'/interface/coin/coin-index', true);
$res = json_decode($res, true); $res = json_decode($res, true);
foreach ($res['data'] as $val) { foreach ($res['data'] as $val) {
......
...@@ -90,7 +90,7 @@ class HuobiBuilder extends FactoryService ...@@ -90,7 +90,7 @@ class HuobiBuilder extends FactoryService
$temp['close'] = number_format($close, 6, '.', ''); $temp['close'] = number_format($close, 6, '.', '');
$temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price[$coin]['usd']); $temp['close_usd'] = (float)sprintf("%0.6f", $close * $this->basic_price[$coin]['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']); $temp['close_rmb'] = (float)sprintf("%0.4f", $close * $this->basic_price[$coin]['rmb']);
$temp['change'] = (false == $open) ? 0 : (float)sprintf("%0.4f", ($close - $open) / $open * 100); $temp['change'] = (false == $open) ? 0 : (float)sprintf("%0.2f", ($close - $open) / $open * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']); $temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price[$coin]['usd']); $temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price[$coin]['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['rmb']); $temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price[$coin]['rmb']);
......
...@@ -41,7 +41,7 @@ class ZhaobiBuilder extends FactoryService ...@@ -41,7 +41,7 @@ class ZhaobiBuilder extends FactoryService
$temp['close'] = number_format($val['last'], 6, '.', ''); $temp['close'] = number_format($val['last'], 6, '.', '');
$temp['close_usd'] = (float)sprintf("%0.6f", $val['last'] * $this->basic_price[$coin]['usd']); $temp['close_usd'] = (float)sprintf("%0.6f", $val['last'] * $this->basic_price[$coin]['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $val['last'] * $this->basic_price[$coin]['rmb']); $temp['close_rmb'] = (float)sprintf("%0.4f", $val['last'] * $this->basic_price[$coin]['rmb']);
$temp['change'] = (0 == $val['open']) ? 0 : (float)sprintf("%0.4f", ($val['last'] - $val['open']) / $val['open'] * 100); $temp['change'] = (0 == $val['open']) ? 0 : (float)sprintf("%0.2f", ($val['last'] - $val['open']) / $val['open'] * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $val['high'] * $this->basic_price[$coin]['usd']); $temp['high_usd'] = (float)sprintf("%0.4f", $val['high'] * $this->basic_price[$coin]['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $val['low'] * $this->basic_price[$coin]['usd']); $temp['low_usd'] = (float)sprintf("%0.4f", $val['low'] * $this->basic_price[$coin]['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $val['high'] * $this->basic_price[$coin]['rmb']); $temp['high_rmb'] = (float)sprintf("%0.4f", $val['high'] * $this->basic_price[$coin]['rmb']);
......
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