Commit 2bb15a91 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ticker' into develop

parents df7f0eb1 7f5e535c
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace api\controllers; namespace api\controllers;
use common\components\Tools;
use Yii; use Yii;
use yii\data\Pagination; use yii\data\Pagination;
use linslin\yii2\curl\Curl; use linslin\yii2\curl\Curl;
...@@ -22,8 +23,8 @@ class TickerController extends BaseController ...@@ -22,8 +23,8 @@ class TickerController extends BaseController
$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); $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_value = Yii::$app->request->get('sort-value', ''); $sort_value = Yii::$app->request->get('sort_value', '');
$exchange_arr = ['huobi', 'binance', 'okex', 'zhaobi']; $exchange_arr = ['huobi', 'binance', 'okex', 'zhaobi'];
...@@ -127,21 +128,26 @@ class TickerController extends BaseController ...@@ -127,21 +128,26 @@ class TickerController extends BaseController
$msg = '参数错误'; $msg = '参数错误';
goto doEnd; goto doEnd;
} }
$data_value = Yii::$app->request->get('data_value', '');
$sort_value = Yii::$app->request->get('sort_value', '');
$condition = [];
if (false != $data_value && false != $sort_value) {
$condition = [
'data_value' => $data_value,
'sort_value' => $sort_value
];
}
$temp = []; $temp = [];
$query = CoinOptional::find()->select('symbol, platform') $data = CoinOptional::find()->select('symbol, platform')
->where(['device_code' => $device_code, 'platform_id' => (int)$platform_id]) ->where(['device_code' => $device_code, 'platform_id' => (int)$platform_id])
->orderBy('update_time desc'); ->orderBy('update_time desc')
$data = $query->offset(($page - 1) * 50)->limit(50)->asArray()->all(); ->asArray()
->all();
if (false == $data) { if (false == $data) {
$msg = 'success'; $msg = 'success';
$code = 0; $code = 0;
$data = [ $data = [];
'ticker' => [],
'page' => [
'pageSize' => 50,
'currentPage' => (int)$page,
]
];
goto doEnd; goto doEnd;
} }
$ticker = []; $ticker = [];
...@@ -165,8 +171,8 @@ class TickerController extends BaseController ...@@ -165,8 +171,8 @@ class TickerController extends BaseController
$temp['symbol'] = $val['symbol']; $temp['symbol'] = $val['symbol'];
$temp['currency'] = strtoupper($tag_first); $temp['currency'] = strtoupper($tag_first);
$temp['base_currency'] = strtoupper($tag_second); $temp['base_currency'] = strtoupper($tag_second);
$temp['close'] = number_format($quotation['last'], 6, '.', ''); $temp['close'] = rtrim(sprintf('%.8f', floatval($quotation['last'])), '0');
$temp['close_usd'] = (float)sprintf("%0.6f", $quotation['last'] * $this->basic_price[$tag_second]['usd']); $temp['close_usd'] = rtrim(sprintf('%.6f', floatval($quotation['last'] * $this->basic_price[$tag_second]['usd'])), '0');
$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.2f", ($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']);
...@@ -189,7 +195,24 @@ class TickerController extends BaseController ...@@ -189,7 +195,24 @@ class TickerController extends BaseController
} }
array_push($ticker, $temp); array_push($ticker, $temp);
} }
if (!empty($condition)) {
if ('price' == $condition['data_value']) {
if ('price-asc' == $condition['sort_value']) {
$ticker = Tools::arraySort($ticker, 'close', SORT_ASC);
}
if ('price-desc' == $condition['sort_value']) {
$ticker = Tools::arraySort($ticker, 'close', SORT_DESC);
}
}
if ('change' == $condition['data_value']) {
if ('change-asc' == $condition['sort_value']) {
$ticker = Tools::arraySort($ticker, 'change', SORT_ASC);
}
if ('change-desc' == $condition['sort_value']) {
$ticker = Tools::arraySort($ticker, 'change', SORT_DESC);
}
}
}
} }
$data = [ $data = [
......
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