Commit 1474ccf7 authored by shajiaiming's avatar shajiaiming

自选行情加分页

parent 19ecbec7
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
namespace api\controllers; namespace api\controllers;
use common\business\Chain33Business;
use common\models\psources\CoinGameBet;
use Yii; use Yii;
use api\base\BaseController;
use yii\data\Pagination; use yii\data\Pagination;
use api\base\BaseController;
use common\models\psources\CoinGameBet;
class GameBetController extends BaseController class GameBetController extends BaseController
{ {
......
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
namespace api\controllers; namespace api\controllers;
use linslin\yii2\curl\Curl;
use Yii; use Yii;
use yii\data\Pagination;
use linslin\yii2\curl\Curl;
use yii\helpers\ArrayHelper;
use api\base\BaseController; use api\base\BaseController;
use common\models\psources\CoinOptional; use common\models\psources\CoinOptional;
use common\service\exchange\ExchangeFactory; use common\service\exchange\ExchangeFactory;
use common\service\exchange\ExchangeBuilderFactory; use common\service\exchange\ExchangeBuilderFactory;
use yii\helpers\ArrayHelper;
class TickerController extends BaseController class TickerController extends BaseController
{ {
...@@ -102,14 +103,30 @@ class TickerController extends BaseController ...@@ -102,14 +103,30 @@ class TickerController extends BaseController
if ($request->isGet) { if ($request->isGet) {
$device_code = $request->get('device_code', ''); $device_code = $request->get('device_code', '');
$page = Yii::$app->request->get('page', 1);
if (empty($device_code)) { if (empty($device_code)) {
$msg = '参数错误'; $msg = '参数错误';
goto doEnd; goto doEnd;
} }
$data = $temp = []; $temp = [];
$model = CoinOptional::find()->select('symbol, platform')->where(['device_code' => $device_code])->asArray()->all(); $query = CoinOptional::find()->select('symbol, platform')
foreach ($model as $val) { ->where(['device_code' => $device_code])
->orderBy('update_time desc');
$data = $query->offset(($page - 1) * 50)->limit(50)->asArray()->all();
if (false == $data) {
$msg = 'success';
$code = 0;
$data = [
'ticker' => [],
'page' => [
'pageSize' => 50,
'currentPage' => (int)$page,
]
];
goto doEnd;
}
$ticker = [];
foreach ($data as $val) {
if ('huobi' == $val['platform']) { if ('huobi' == $val['platform']) {
$exchange = 'HuoBi'; $exchange = 'HuoBi';
} else if ('binance' == $val['platform']) { } else if ('binance' == $val['platform']) {
...@@ -129,7 +146,7 @@ class TickerController extends BaseController ...@@ -129,7 +146,7 @@ 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'] = (float)sprintf("%0.6f", $quotation['last']); $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.4f", ($quotation['last'] - $quotation['open']) / $quotation['open'] * 100);
...@@ -150,12 +167,21 @@ class TickerController extends BaseController ...@@ -150,12 +167,21 @@ class TickerController extends BaseController
$temp['platform_zh'] = '币安'; $temp['platform_zh'] = '币安';
$temp['platform_us'] = 'binance'; $temp['platform_us'] = 'binance';
} }
array_push($data, $temp); array_push($ticker, $temp);
} }
$msg = 'success';
$code = 0;
} }
$data = [
'ticker' => $ticker,
'page' => [
'pageSize' => 50,
'currentPage' => (int)$page,
]
];
$msg = 'success';
$code = 0;
doEnd : doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data]; return ['code' => $code, 'msg' => $msg, '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