Commit 568d7a0f authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/ticker' into 'master'

Feature/ticker See merge request !189
parents 88278cd8 b9b9175b
...@@ -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,11 +128,22 @@ class TickerController extends BaseController ...@@ -127,11 +128,22 @@ 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;
...@@ -165,8 +177,8 @@ class TickerController extends BaseController ...@@ -165,8 +177,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 +201,24 @@ class TickerController extends BaseController ...@@ -189,7 +201,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 = [
......
...@@ -44,18 +44,18 @@ class BinanceBuilder extends FactoryService ...@@ -44,18 +44,18 @@ class BinanceBuilder extends FactoryService
} }
if (false != $condition) { if (false != $condition) {
if ('price' == $condition['data_value']) { if ('price' == $condition['data_value']) {
if ('price-asc' == $condition['sort_value']) { if ('price_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_asc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_close_asc, $this->start, $this->end);
} }
if ('price-desc' == $condition['sort_value']) { if ('price_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_desc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_close_desc, $this->start, $this->end);
} }
} }
if ('change' == $condition['data_value']) { if ('change' == $condition['data_value']) {
if ('change-asc' == $condition['sort_value']) { if ('change_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_asc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_change_asc, $this->start, $this->end);
} }
if ('change-desc' == $condition['sort_value']) { if ('change_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_desc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_change_desc, $this->start, $this->end);
} }
} }
......
...@@ -64,18 +64,18 @@ class HuobiBuilder extends FactoryService ...@@ -64,18 +64,18 @@ class HuobiBuilder extends FactoryService
} }
if (false != $condition) { if (false != $condition) {
if ('price' == $condition['data_value']) { if ('price' == $condition['data_value']) {
if ('price-asc' == $condition['sort_value']) { if ('price_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_asc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_close_asc, $this->start, $this->end);
} }
if ('price-desc' == $condition['sort_value']) { if ('price_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_desc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_close_desc, $this->start, $this->end);
} }
} }
if ('change' == $condition['data_value']) { if ('change' == $condition['data_value']) {
if ('change-asc' == $condition['sort_value']) { if ('change_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_asc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_change_asc, $this->start, $this->end);
} }
if ('change-desc' == $condition['sort_value']) { if ('change_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_desc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_change_desc, $this->start, $this->end);
} }
} }
......
...@@ -28,18 +28,18 @@ class ZhaobiBuilder extends FactoryService ...@@ -28,18 +28,18 @@ class ZhaobiBuilder extends FactoryService
$this->end = 50; $this->end = 50;
if (false != $condition) { if (false != $condition) {
if ('price' == $condition['data_value']) { if ('price' == $condition['data_value']) {
if ('price-asc' == $condition['sort_value']) { if ('price_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_asc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_close_asc, $this->start, $this->end);
} }
if ('price-desc' == $condition['sort_value']) { if ('price_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_close_desc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_close_desc, $this->start, $this->end);
} }
} }
if ('change' == $condition['data_value']) { if ('change' == $condition['data_value']) {
if ('change-asc' == $condition['sort_value']) { if ('change_asc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_asc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_change_asc, $this->start, $this->end);
} }
if ('change-desc' == $condition['sort_value']) { if ('change_desc' == $condition['sort_value']) {
$keys = $this->redis_ticker->lrange($this->supported_symbol_change_desc, $this->start, $this->end); $keys = $this->redis_ticker->lrange($this->supported_symbol_change_desc, $this->start, $this->end);
} }
} }
......
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