Commit 2456f93b authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into develop

parents 28ce08f8 2b8654fb
......@@ -3,6 +3,7 @@
namespace api\controllers;
use common\business\ExchangeBusiness;
use common\models\psources\Coin;
use common\models\psources\CoinSupportedChain;
use Yii;
use api\base\BaseController;
......@@ -122,4 +123,73 @@ class RecommendCoinController extends BaseController
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
public function actionTrusteeship()
{
$platform_id = $this->platform_id;
if (false == $platform_id) {
$this->code = -1;
$this->msg = '参数错误';
goto doEnd;
}
$coin_trusteeship = WalletRecommendCoin::find()->select('cid')->where(['type' => WalletRecommendCoin::TYPE_TRUSTEESHIP, 'platform_id' => $platform_id])->asArray()->all();
$select = ['id', 'sid', 'icon', 'name', 'introduce', 'optional_name', 'nickname', 'platform', 'chain', 'treaty'];
$coin_ids = array_column($coin_trusteeship, 'cid');
if (false == $coin_ids) {
$this->code = 1;
$this->msg = '数据为空';
goto doEnd;
}
$coin_infos = Coin::getCoinInfoByIds($coin_ids, $select, 'id');
foreach ($coin_infos as $key => &$val) {
$nickname = json_decode($val['nickname'], true);
$val['nickname'] = isset($nickname[$this->lang]) ? $nickname[$this->lang] : '';
$introduce = json_decode($val['introduce'], true);
$val['introduce'] = isset($introduce[$this->lang]) ? $introduce[$this->lang] : '';
}
//获取行情信息
$coin_names = array_column($coin_infos, 'name');
$coin_names = array_merge($coin_names, array_column($coin_infos, 'chain'));
$coin_quotations = ExchangeBusiness::getQuatationByNames($coin_names);
if ($coin_infos) {
array_shift($select);
foreach ($coin_trusteeship as $key => &$value) {
$temp_key = $coin_infos[$value['cid']]['name'];
foreach ($select as $item) {
$value[$item] = $coin_infos[$value['cid']][$item];
if ($platform_id != 2) {
//国盾币不需要行情
$value['low'] = $coin_quotations[$temp_key]['low'];
$value['high'] = $coin_quotations[$temp_key]['high'];
$value['last'] = $coin_quotations[$temp_key]['last'];
$value['rmb'] = $coin_quotations[$temp_key]['rmb'];
$value['usd'] = $coin_quotations[$temp_key]['usd'] ?? 0;
} else {
$value['low'] = 0;
$value['high'] = 0;
$value['last'] = 0;
$value['rmb'] = 0;
$value['usd'] = 0;
}
}
$value['id'] = $value['cid'];
$value['sid'] = ucfirst($value['sid']);
$value['chain_quotation'] = $coin_quotations[$coin_infos[$value['cid']]['chain']];
$value['chain_rmb'] = isset($coin_quotations[$coin_infos[$value['cid']]['chain']]['rmb']) ? $coin_quotations[$coin_infos[$value['cid']]['chain']]['rmb'] : 0;
$value['chain_usd'] = isset($coin_quotations[$coin_infos[$value['cid']]['chain']]['usd']) ? $coin_quotations[$coin_infos[$value['cid']]['chain']]['usd'] : 0;
unset($value['create_time'], $value['update_time'], $value['cid']);
$value['type'] = WalletRecommendCoin::TYPE_TRUSTEESHIP;
$value['platform_id'] = $platform_id;
$value['sort'] = $value['recommend'] = 1;
$value['coin'] = $value['name'];
}
unset($key, $value);
}
$this->data = $coin_trusteeship;
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg, 'count' => count($this->data)];
}
}
\ No newline at end of file
......@@ -49,7 +49,7 @@ class WalletCoinController extends BaseController
foreach ($condition as $val) {
if (is_array($val)) {
$model = WalletCoin::find()->select('id,icon,name,nickname,introduce,platform,chain,address as contract_address,treaty')
$model = WalletCoin::find()->select('id,icon,name,nickname,optional_name,introduce,platform,chain,address as contract_address,treaty')
->where(['name' => $val[0], 'platform' => $val[1]])
->andWhere(['>', "find_in_set($platform_id, platform_id)", 0])
->asArray()
......@@ -57,7 +57,7 @@ class WalletCoinController extends BaseController
}
if (is_string($val)) {
$model = WalletCoin::find()->select('id,icon,name,nickname,introduce,platform,chain,address as contract_address,treaty')
$model = WalletCoin::find()->select('id,icon,name,nickname,optional_name,introduce,platform,chain,address as contract_address,treaty')
->where(['name' => $val])
->andWhere(['>', "find_in_set($platform_id, platform_id)", 0])
->asArray()
......
......@@ -142,10 +142,10 @@ class ExchangeBusiness
if (strtoupper($tag) == 'POKE') {
$quotation = [
'low' => 0.1591,
'high' => 0.1591,
'last' => 0.1591,
'rmb' => 0.1591,
'low' => 0.1601,
'high' => 0.1601,
'last' => 0.1601,
'rmb' => 0.1601,
];
goto doEnd;
}
......@@ -175,6 +175,12 @@ class ExchangeBusiness
}
$f = false;
$quotation = [];
if (in_array(strtoupper($tag), ['GLCW'])) {
$exchange = ExchangeFactory::createExchange("Jinwang");
$quotation = $exchange->getTicker($tag, 'USDT');
goto doEnd;
}
if (in_array(strtoupper($tag), ['SUM', 'USDW', 'FUT'])) {
$exchange = ExchangeFactory::createExchange("Isummit");
$quotation = $exchange->getTicker($tag, 'USDT');
......@@ -390,7 +396,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'])) {
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'])) {
$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']);
......
......@@ -7,6 +7,9 @@ use common\core\BaseActiveRecord;
class WalletRecommendCoin extends BaseActiveRecord
{
const TYPE_COMMON = 1; //去中心化
const TYPE_TRUSTEESHIP = 2; //托管钱包
public static function getDb()
{
return Yii::$app->get('p_sources');
......@@ -17,8 +20,5 @@ class WalletRecommendCoin extends BaseActiveRecord
return '{{wallet_recommend_coin}}';
}
public function getCoin()
{
return $this->hasOne(Coin::className(), ['id' => 'cid'])->select(['id', 'icon', 'name', 'introduce', 'nickname', 'platform', 'chain', 'treaty'])->asArray();
}
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ class Jinwang extends Exchange implements ExchangeInterface
*/
public function formatSymbol($tag = 'TG', $aim = 'USDT')
{
return strtoupper($tag . $aim);
return strtolower($tag . '_' . $aim);
}
/**
......
......@@ -34,7 +34,7 @@ class JinwangBuilder extends FactoryService
$keys = $this->redis->smembers($this->supported_symbol);
if (false == $this->redis->exists($this->supported_symbol_list)) {
foreach ($keys as $val) {
if (in_array(strtoupper($val), ['LTC_USDT', 'BTC_USDT', 'EOS_USDT', 'TG_USDT', 'TPC_USDT', 'ETH_USDT'])) {
if (in_array(strtoupper($val), ['LTC_USDT', 'BTC_USDT', 'EOS_USDT', 'TG_USDT', 'TPC_USDT', 'ETH_USDT', 'GLCW_USDT'])) {
$this->redis->lpush($this->supported_symbol_list, strtoupper($val));
}
}
......
......@@ -110,7 +110,10 @@ class CrossChainController extends Controller
// 'port' => 8801
// ];
$service = new Chain33Service($node_params);
$result = $service->getHeight();
$payload = [
"data" => 'user.p.game',
];
$result = $service->chainQuery('paracross', 'GetHeight', $payload);
$consensHeight = $result['result']['consensHeight'];
$current_time = time();
......
......@@ -65,7 +65,7 @@ class IpExceptionController extends Controller
return false;
}
$redis_ticker = \Yii::$app->redis_es;
//$redis_ticker = \Yii::$app->redis_es;
$limit = \Yii::$app->params['api_ip_limit']['limit'];
$white_list = \Yii::$app->params['api_ip_limit']['white_list'];
$ips = '';
......@@ -73,14 +73,17 @@ class IpExceptionController extends Controller
if (in_array($val['key'], $white_list)) continue;
if (!isset($val['request']['buckets'])) continue;
foreach ($val['request']['buckets'] as $b => $item) {
if (strpos($item['key'],'/interface/ticker/hot-ticker') !== false) {
if ($item['doc_count'] > $limit) {
foreach ($val['request']['buckets'] as $bucket) {
$redis_ticker->hmset($val['key'], $bucket['key'], $bucket['doc_count']);
}
$ips .= $val['key'] . ',';
}
if ($item['doc_count'] > $limit) {
$ips .= $val['key'] . ',';
}
// if (strpos($item['key'],'/interface/ticker/hot-ticker') !== false) {
// if ($item['doc_count'] > $limit) {
// foreach ($val['request']['buckets'] as $bucket) {
// $redis_ticker->hmset($val['key'], $bucket['key'], $bucket['doc_count']);
// }
// $ips .= $val['key'] . ',';
// }
// }
}
}
......
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