Commit 463cdcb3 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into develop

parents 6544a8f1 06afd62d
......@@ -414,7 +414,7 @@ class CoinController extends BaseController
$request = Yii::$app->request;
$platform = $request->post('platform', '');
if ($platform) {
$brower_url = Yii::$app->redis->hget('platform_brower_info', $platform);
$brower_url = Yii::$app->redis->hget('platform_brower_info', strtolower($platform));
return ['code' => 0, 'data' => $brower_url];
} else {
return ['code' => 1, 'data' => [], 'msg' => '平台参数不能为空'];
......
......@@ -288,7 +288,7 @@ class TickerController extends BaseController
public function actionHotTicker()
{
$platform_id = Yii::$app->request->get('platform_id', 0);
$platform_id = $this->platform_id ?? 0;
$datas = [
[
'exchange' => 'huobi',
......@@ -335,6 +335,54 @@ class TickerController extends BaseController
]
];
}
if (52 == $platform_id) {
$datas = [
[
'exchange' => 'huobi',
'symbol' => [
'btcusdt',
'ethusdt'
],
], [
'exchange' => 'ztb',
'symbol' => [
'zycusdt'
],
]
];
}
if (53 == $platform_id) {
$datas = [
[
'exchange' => 'huobi',
'symbol' => [
'btcusdt',
'ethusdt'
],
], [
'exchange' => 'wbf',
'symbol' => [
'leleusdt'
],
]
];
}
if (54 == $platform_id) {
$datas = [
[
'exchange' => 'huobi',
'symbol' => [
'btcusdt',
'ethusdt'
],
], [
'exchange' => 'hd',
'symbol' => [
'hdusdt'
],
]
];
}
$ticker = [];
foreach ($datas as $data) {
$builder = ExchangeBuilderFactory::create($data['exchange']);
......
......@@ -116,29 +116,28 @@ class WalletController extends BaseController
$token = Yii::$app->request->get('address', '');
$symbol = Yii::$app->request->get('symbol', '');
if (empty($platform_id) || empty($token) || empty($symbol)) {
$msg = '参数不能为空';
$code = -1;
$data = null;
$this->msg = '参数不能为空';
$this->code = -1;
goto doEnd;
}
$chain_model = CoinPlatform::find()->select('chain_id')->where(['id' => $platform_id])->andWhere(['<>', 'chain_id', 0])->one();
if (empty($chain_model)) {
$msg = '此功能为付费功能,有兴趣请与销售联系';
$code = -1;
$this->msg = '此功能为付费功能,有兴趣请与销售联系';
$this->code = -1;
goto doEnd;
}
$platform = CoinPlatformWithHold::find()->select('exer, platform')->where(['id' => $chain_model->chain_id])->one();
if (empty($platform)) {
$msg = '此功能为付费功能,有兴趣请与销售联系';
$code = -1;
$this->msg = '此功能为付费功能,有兴趣请与销售联系';
$this->code = -1;
goto doEnd;
}
$node = Yii::$app->params['chain_nodes'][strtoupper($platform->platform)];
$node = Yii::$app->params['chain_nodes'][strtoupper($platform->platform)] ?? null;
if (empty($node)) {
$msg = '此功能为付费功能,有兴趣请与销售联系';
$code = -1;
$this->msg = '此功能为付费功能,有兴趣请与销售联系';
$this->code = -1;
goto doEnd;
}
......@@ -170,14 +169,13 @@ class WalletController extends BaseController
}
if (0 !== $result['code']) {
$msg = '当前发币人数过多,请客官稍后再试';
$code = -1;
$data = null;
$this->msg = '当前发币人数过多,请客官稍后再试';
$this->code = -1;
goto doEnd;
}
$data = $result['result'];
$this->data = $result['result'];
doEnd :
return ['code' => $code, 'data' => $data, 'msg' => $msg];
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
public function actionTransfer()
......
......@@ -2,6 +2,7 @@
namespace backend\controllers;
use common\components\Tools;
use common\models\psources\CoinPlatform;
use Yii;
use common\models\Admin;
......@@ -47,9 +48,19 @@ class AuthController extends BaseController
/* 获取角色列表 */
$self_roles = current($auth->getRolesByUser(Yii::$app->user->id));
$roles = $auth->getChildRoles($self_roles->name);
$roles_temp = [];
foreach ($roles as $key => $role) {
$roles_temp[$role->name]['type'] = $role->type;
$roles_temp[$role->name]['name'] = $role->name;
$roles_temp[$role->name]['description'] = $role->description;
$roles_temp[$role->name]['ruleName'] = $role->ruleName;
$roles_temp[$role->name]['data'] = $role->data;
$roles_temp[$role->name]['createdAt'] = $role->createdAt;
$roles_temp[$role->name]['updatedAt'] = $role->updatedAt;
}
$roles_temp = Tools::arraySort($roles_temp, 'createdAt');
return $this->render('index', [
'roles' => $roles,
'roles' => $roles_temp,
]);
}
......
......@@ -32,10 +32,10 @@ use yii\helpers\Url;
<tr class="odd gradeX">
<?php $nn++;?>
<td><?=$nn?></td>
<td style = 'white-space: nowrap;'><?=$value->name?></td>
<td style = 'white-space: nowrap;'><?=$value->description?></td>
<td style = 'white-space: nowrap;'><?=date('Y-m-d H:i',$value->createdAt)?></td>
<td style = 'white-space: nowrap;'><?=date('Y-m-d H:i',$value->updatedAt)?></td>
<td style = 'white-space: nowrap;'><?=$value['name']?></td>
<td style = 'white-space: nowrap;'><?=$value['description']?></td>
<td style = 'white-space: nowrap;'><?=date('Y-m-d H:i',$value['createdAt'])?></td>
<td style = 'white-space: nowrap;'><?=date('Y-m-d H:i',$value['updatedAt'])?></td>
<td style = 'white-space: nowrap;'>
<a href="<?=Url::toRoute(['edit', 'role'=>$key])?>" class="btn btn-xs blue"><i class="fa fa-edit"></i> 编辑</a>
<a href="<?=Url::toRoute(['auth', 'role'=>$key])?>" class="btn btn-xs blue"><i class="icon-key"></i> 授权</a>
......
......@@ -32,21 +32,18 @@ class ExchangeBusiness
3 => 'Bitfinex',
4 => 'Bittrex',
5 => 'Zb',
6 => 'Token7',
7 => 'Zg',
8 => 'Go',
9 => 'Zhaobi',
10 => 'Ex',
11 => 'Zt',
12 => 'Tsc',
13 => 'Binance',
14 => 'Bilaxy',
15 => 'Bitnasdaq',
16 => 'Dag',
17 => 'Coinka',
18 => 'Isummit',
19 => 'Boc',
20 => 'Jinwang'
6 => 'Zg',
7 => 'Go',
8 => 'Zhaobi',
9 => 'Binance',
10 => 'Bilaxy',
11 => 'Bitnasdaq',
12 => 'Isummit',
13 => 'Boc',
14 => 'Jinwang',
15 => 'Hd',
16 => 'Ztb',
17 => 'Wbf'
//1 => 'Hadax', //不需要
//2 => 'Bitfinex', //不需要
......@@ -58,6 +55,11 @@ class ExchangeBusiness
//7 => 'Gdpro',//已挂
//8 => 'Ceohk', //已挂
//14 => 'Biki',//已挂
//6 => 'Token7',//已挂
//10 => 'Ex',//已挂
//12 => 'Tsc',//已挂
//16 => 'Dag',//已挂
//17 => 'Coinka',//已挂
];
/**
......@@ -142,10 +144,10 @@ class ExchangeBusiness
if (strtoupper($tag) == 'POKE') {
$quotation = [
'low' => 0.1601,
'high' => 0.1601,
'last' => 0.1601,
'rmb' => 0.1601,
'low' => 0.1611,
'high' => 0.1611,
'last' => 0.1611,
'rmb' => 0.1611,
];
goto doEnd;
}
......@@ -273,9 +275,9 @@ class ExchangeBusiness
goto doEnd;
}
if (in_array(strtoupper($tag), ['CIC'])) {
$exchange = ExchangeFactory::createExchange("Zt");
$quotation = $exchange->getTicker('CIC', 'USDT');
if (in_array(strtoupper($tag), ['CIC', 'ZYC'])) {
$exchange = ExchangeFactory::createExchange("Ztb");
$quotation = $exchange->getTicker(strtoupper($tag), 'USDT');
goto doEnd;
}
......@@ -339,6 +341,12 @@ class ExchangeBusiness
goto doEnd;
}
if (in_array(strtoupper($tag), ['HDC'])) {
$exchange = ExchangeFactory::createExchange("Hd");
$quotation = $exchange->getTicker('HD', 'USDT');
goto doEnd;
}
foreach (self::$exchanges as $exchange) {
/**
* @var $exchange \common\service\exchange\Exchange
......@@ -396,7 +404,7 @@ class ExchangeBusiness
$exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD");
$cny_usd_rate = 1 / $rate['last'];
if (in_array(strtoupper($tag), ['FOLI', 'CIC', 'KPC8', 'BVA', 'DAG', 'BNC', 'GHP', 'DRA', 'ETC', 'PAX', 'STH', 'XJH', 'SFT', 'TSC', 'SUM', 'USDW', 'FUT', 'MBTC', 'METH', 'GLCW'])) {
if (in_array(strtoupper($tag), ['FOLI', 'CIC', 'ZYC', 'KPC8', 'BVA', 'DAG', 'BNC', 'GHP', 'DRA', 'ETC', 'PAX', 'STH', 'XJH', 'SFT', 'TSC', 'SUM', 'USDW', 'FUT', 'MBTC', 'METH', 'GLCW', 'HDC'])) {
$quotation['usd'] = (float)sprintf("%0.4f", $quotation['last']);
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last'] / $cny_usd_rate);
$quotation['low'] = (float)sprintf("%0.4f", $quotation['low']);
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Hd extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_hd';
protected $quotation_prefix = 'quotation_hd_';
protected $base_url = 'https://app.honordecent.com/exchange/getHdcCurrPrice';
public function symbolExists($tag = 'HD', $aim = "USDT")
{
$supported = $this->redis->smembers($this->supported_symbol);
if (is_array($supported) && in_array($this->formatSymbol($tag, $aim), $supported)) {
return true;
}
return false;
}
/**
* 转化交易对为请求变量
*
* @param string $tag
* @param string $aim
* @return mixed
*/
public function formatSymbol($tag = 'HD', $aim = 'USDT')
{
return strtoupper($tag . $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$res = $curl->get($this->base_url, false);
if (is_array($res) && 1 == $res['code']) {
$key = $this->quotation_prefix . 'HDUSDT';
$this->redis->hmset($key, 'low', $res['data'], 'high', $res['data'], 'last', $res['data']);
if (!$this->redis->sismember($this->supported_symbol, 'HDUSDT')) {
$this->redis->sadd($this->supported_symbol, 'HDUSDT');
}
}
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Wbf extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_wbf';
protected $quotation_prefix = 'quotation_wbf_';
protected $base_url = 'https://openapi.wbf.live/open/api/get_allticker';
public function symbolExists($tag = 'LELE', $aim = "USDT")
{
$supported = $this->redis->smembers($this->supported_symbol);
if (is_array($supported) && in_array($this->formatSymbol($tag, $aim), $supported)) {
return true;
}
return false;
}
/**
* 转化交易对为请求变量
*
* @param string $tag
* @param string $aim
* @return mixed
*/
public function formatSymbol($tag = 'LELE', $aim = 'USDT')
{
return strtoupper($tag . $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$res = $curl->get($this->base_url, false);
if (is_array($res) && isset($res['data'])) {
$data = $res['data']['ticker'];
foreach ($data as $item) {
$key = $this->quotation_prefix . strtoupper($item['symbol']);
$this->redis->hmset($key, 'low', $item['low'], 'high', $item['high'], 'last', $item['last'], 'vol', $item['vol'], 'change', $item['change']);
if (!$this->redis->sismember($this->supported_symbol, strtoupper($item['symbol']))){
$this->redis->sadd($this->supported_symbol, strtoupper($item['symbol']));
}
}
}
}
}
\ No newline at end of file
......@@ -10,14 +10,14 @@ namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Zt extends Exchange implements ExchangeInterface
class Ztb extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_zt';
protected $quotation_prefix = 'quotation_zt_';
protected $base_url = 'https://www.zt.com/api/v1/tickers';
protected $supported_symbol = 'supported_symbol_ztb';
protected $quotation_prefix = 'quotation_ztb_';
protected $base_url = 'https://www.ztb.com/api/v1/tickers';
public function symbolExists($tag = 'CIC', $aim = "USDT")
public function symbolExists($tag = 'ZYC', $aim = "USDT")
{
$supported = $this->redis->smembers($this->supported_symbol);
if (is_array($supported) && in_array($this->formatSymbol($tag, $aim), $supported)) {
......@@ -25,6 +25,7 @@ class Zt extends Exchange implements ExchangeInterface
}
return false;
}
/**
* 转化交易对为请求变量
*
......@@ -32,9 +33,9 @@ class Zt extends Exchange implements ExchangeInterface
* @param string $aim
* @return mixed
*/
public function formatSymbol($tag = 'CIC', $aim = 'USDT')
public function formatSymbol($tag = 'ZYC', $aim = 'USDT')
{
return strtoupper($tag .'_'. $aim);
return strtoupper($tag . $aim);
}
/**
......@@ -44,7 +45,7 @@ class Zt extends Exchange implements ExchangeInterface
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'CICUSDT');
$this->redis->sadd($this->supported_symbol, 'ZYCUSDT');
}
/**
......@@ -55,15 +56,16 @@ class Zt extends Exchange implements ExchangeInterface
public function setQuotation()
{
$curl = new Curl();
$content = $curl->get($this->base_url, false);
$content = $curl->get($this->base_url, true);
$content = json_decode($content, true);
if (is_array($content) && isset($content['ticker'])) {
$data = $content['ticker'];
foreach ($data as $item) {
if (in_array($item['symbol'], ['CIC_USDT'])) {
if (in_array($item['symbol'], ['ZYC_USDT'])) {
$data = $item;
$key = $this->quotation_prefix . $item['symbol'];
$this->redis->hmset($key, 'low', $data['low'], 'high', $data['high'], 'last', $data['last']);
$this->redis->sadd($this->supported_symbol, $item['symbol']);
$key = $this->quotation_prefix . str_replace('_', '', $item['symbol']);
$this->redis->hmset($key, 'low', $data['low'], 'high', $data['high'], 'last', $data['last'], 'vol', $data['vol'], 'change', $data['change']);
$this->redis->sadd($this->supported_symbol, str_replace('_', '', $item['symbol']));
}
}
}
......
<?php
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/15
* Time: 10:10
*/
namespace common\service\exchange\factory;
use common\components\Tools;
use linslin\yii2\curl\Curl;
class HdBuilder extends FactoryService
{
protected $base_url = 'https://api.hd.pro';
protected $supported_symbol = 'supported_symbol_hd';
protected $supported_symbol_list = 'supported_symbol_hd_list';
protected $supported_symbol_close_asc = 'supported_symbol_close_asc_hd';
protected $supported_symbol_close_desc = 'supported_symbol_close_desc_hd';
protected $supported_symbol_change_asc = 'supported_symbol_change_asc_hd';
protected $supported_symbol_change_desc = 'supported_symbol_change_desc_hd';
protected $quotation_prefix = 'quotation_hd_';
public function getHotTicker($symbol = [])
{
if (empty($symbol)) {
return ['code' => $this->code, 'ticker' => []];
}
$ticker = [];
foreach ($symbol as $val) {
list($low, $high, $last) = $this->redis->hmget($this->quotation_prefix . strtoupper($val), 'low', 'high', 'last');
$explode_arr = explode('usdt', $val);
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/USDT';
$temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = 'USDT';
$temp['close'] = (float)sprintf("%0.6f", $last);
$temp['close_usd'] = (float)sprintf("%0.6f", $last * $this->basic_price['USDT']['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $last * $this->basic_price['USDT']['rmb']);
$temp['change'] = (0 == $low) ? 0 : (float)sprintf("%0.2f", ($last - $low) / $low * 100);
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['rmb']);
$temp['low_rmb'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['rmb']);
array_push($ticker, $temp);
}
if (count($ticker) > 0) {
$this->code = 0;
}
return ['code' => $this->code, 'ticker' => $ticker];
}
}
This diff is collapsed.
<?php
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/8/15
* Time: 10:10
*/
namespace common\service\exchange\factory;
use common\components\Tools;
use linslin\yii2\curl\Curl;
class ZtbBuilder extends FactoryService
{
protected $base_url = 'https://api.ztb.pro';
protected $supported_symbol = 'supported_symbol_ztb';
protected $supported_symbol_list = 'supported_symbol_ztb_list';
protected $supported_symbol_close_asc = 'supported_symbol_close_asc_ztb';
protected $supported_symbol_close_desc = 'supported_symbol_close_desc_ztb';
protected $supported_symbol_change_asc = 'supported_symbol_change_asc_ztb';
protected $supported_symbol_change_desc = 'supported_symbol_change_desc_ztb';
protected $quotation_prefix = 'quotation_ztb_';
public function getHotTicker($symbol = [])
{
if (empty($symbol)) {
return ['code' => $this->code, 'ticker' => []];
}
$ticker = [];
foreach ($symbol as $val) {
list($low, $high, $change, $last, $vol) = $this->redis->hmget($this->quotation_prefix . strtoupper(str_replace('USDT', '_USDT', $val)), 'low', 'high', 'change', 'last', 'vol');
$explode_arr = explode('usdt', $val);
$temp = [];
$temp['symbol'] = strtoupper($explode_arr[0]) . '/USDT';
$temp['currency'] = strtoupper($explode_arr[0]);
$temp['base_currency'] = 'USDT';
$temp['close'] = (float)sprintf("%0.6f", $last);
$temp['close_usd'] = (float)sprintf("%0.6f", $last * $this->basic_price['USDT']['usd']);
$temp['close_rmb'] = (float)sprintf("%0.4f", $last * $this->basic_price['USDT']['rmb']);
$temp['change'] = (float)sprintf("%0.2f", $change);;
$temp['high_usd'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['usd']);
$temp['low_usd'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['usd']);
$temp['high_rmb'] = (float)sprintf("%0.4f", $high * $this->basic_price['USDT']['rmb']);
$temp['low_rmb'] = (float)sprintf("%0.4f", $low * $this->basic_price['USDT']['rmb']);
$temp['vol'] = (float)sprintf("%0.4f", $vol);
array_push($ticker, $temp);
}
if (count($ticker) > 0) {
$this->code = 0;
}
return ['code' => $this->code, 'ticker' => $ticker];
}
}
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