Commit 6f8d6cb6 authored by shajiaiming's avatar shajiaiming

Merge branch 'master' into feature/issue_coin

parents 32ff472b 12b7c8a8
......@@ -20,11 +20,13 @@ class TickerController extends BaseController
{
$page = Yii::$app->request->get('page', 1);
$device_code = Yii::$app->request->get('device_code', '');
$platform_id = Yii::$app->request->get('device_code', 0);
$exchange = Yii::$app->request->get('exchange', 'zhaobi');
$data_value = Yii::$app->request->get('data-value','');
$sort = Yii::$app->request->get('sort','');
$data_value = Yii::$app->request->get('data-value', '');
$sort = Yii::$app->request->get('sort', '');
$exchange_arr = ['huobi', 'binance', 'okex', 'zhaobi'];
if (!in_array($exchange, $exchange_arr)) {
$msg = '不存在的交易平台';
$code = -1;
......@@ -37,7 +39,12 @@ class TickerController extends BaseController
$data = $result['data'];
if (false != $device_code) {
$coin_optional = CoinOptional::find()->select('symbol')->where(['platform' => $exchange, 'device_code' => $device_code])->asArray()->all();
if (false != $platform_id) {
$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');
foreach ($data['ticker'] as &$val) {
if (in_array($val['symbol'], $coin_optional)) {
......@@ -66,7 +73,7 @@ class TickerController extends BaseController
$params = json_encode($data);
$curl->setHeader('Content-Type', 'application/json');
$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);
foreach ($res['data'] as $val) {
$this->basic_price[$val['name']]['rmb'] = $val['rmb'];
......@@ -82,12 +89,13 @@ class TickerController extends BaseController
$symbol = $request->post('symbol', '');
$platform = $request->post('platform', '');
$device_code = $request->post('device_code', '');
$platform_id = $request->post('platform_id', 0);
if (empty($symbol) || empty($platform) || empty($device_code)) {
if (empty($symbol) || empty($platform) || empty($device_code) || empty($platform_id)) {
$msg = '参数错误';
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) {
$msg = '数据已存在!';
goto doEnd;
......@@ -106,14 +114,15 @@ class TickerController extends BaseController
if ($request->isGet) {
$device_code = $request->get('device_code', '');
$platform_id = $request->get('platform_id', 0);
$page = Yii::$app->request->get('page', 1);
if (empty($device_code)) {
if (false == $device_code || false == $platform_id) {
$msg = '参数错误';
goto doEnd;
}
$temp = [];
$query = CoinOptional::find()->select('symbol, platform')
->where(['device_code' => $device_code])
->where(['device_code' => $device_code, 'platform_id' => (int)$platform_id])
->orderBy('update_time desc');
$data = $query->offset(($page - 1) * 50)->limit(50)->asArray()->all();
if (false == $data) {
......@@ -122,7 +131,7 @@ class TickerController extends BaseController
$data = [
'ticker' => [],
'page' => [
'pageSize' => 50,
'pageSize' => 50,
'currentPage' => (int)$page,
]
];
......@@ -145,14 +154,14 @@ class TickerController extends BaseController
$exchange = ExchangeFactory::createExchange($exchange);
$quotation = $exchange->getTicker(strtolower($tag_first), strtolower($tag_second));
if(empty($quotation)) continue;
if (empty($quotation)) continue;
$temp['symbol'] = $val['symbol'];
$temp['currency'] = strtoupper($tag_first);
$temp['base_currency'] = strtoupper($tag_second);
$temp['close'] = number_format($quotation['last'], 6, '.', '');
$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['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['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']);
......@@ -179,7 +188,7 @@ class TickerController extends BaseController
$data = [
'ticker' => $ticker,
'page' => [
'pageSize' => 50,
'pageSize' => 50,
'currentPage' => (int)$page,
]
];
......@@ -205,11 +214,12 @@ class TickerController extends BaseController
$symbol = $request->post('symbol', '');
$platform = $request->post('platform', '');
$device_code = $request->post('device_code', '');
if (empty($symbol) || empty($device_code) || empty($platform)) {
$platform_id = $request->post('platform_id', 0);
if (empty($symbol) || empty($device_code) || empty($platform) || empty($platform_id)) {
$msg = '请求参数错误!';
goto doEnd;
}
$model = CoinOptional::find()->where(['symbol' => $symbol, 'platform' => $platform, 'device_code' => $device_code])->one();
$model = CoinOptional::find()->where(['symbol' => $symbol, 'platform' => $platform, 'device_code' => $device_code, 'platform_id' => (int)$platform_id])->one();
if (empty($model)) {
$msg = '数据不存在!';
goto doEnd;
......
......@@ -21,16 +21,18 @@ class CoinOptional extends BaseActiveRecord
const SCENARIOS_CREATE = 'create';
public function rules() {
public function rules()
{
return [
[['symbol','platform', 'device_code'], 'required'],
[['symbol', 'platform', 'device_code', 'platform_id'], 'required'],
];
}
public function scenarios() {
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['symbol','platform', 'device_code'],
self:: SCENARIOS_CREATE => ['symbol', 'platform', 'device_code', 'platform_id'],
];
return array_merge( parent:: scenarios(), $scenarios);
return array_merge(parent:: scenarios(), $scenarios);
}
}
......@@ -90,7 +90,7 @@ class BinanceBuilder extends FactoryService
$temp['close'] = number_format($close, 6, '.', '');
$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['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['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']);
......
......@@ -35,7 +35,7 @@ abstract class FactoryService
$params = json_encode($data);
$curl->setHeader('Content-Type', 'application/json');
$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);
foreach ($res['data'] as $val) {
......
......@@ -90,7 +90,7 @@ class HuobiBuilder extends FactoryService
$temp['close'] = number_format($close, 6, '.', '');
$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['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['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']);
......
......@@ -41,7 +41,7 @@ class ZhaobiBuilder extends FactoryService
$temp['close'] = number_format($val['last'], 6, '.', '');
$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['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['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']);
......
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