Commit 33d5fe05 authored by shajiaming's avatar shajiaming

代币信息

parent 7dce0747
...@@ -128,11 +128,15 @@ class CoinController extends BaseController ...@@ -128,11 +128,15 @@ class CoinController extends BaseController
$limit = $request->post('limit', 999); $limit = $request->post('limit', 999);
$platform_id = $request->post('platform_id', 1);//默认币钱包 $platform_id = $request->post('platform_id', 1);//默认币钱包
$recommend = $request->post('recommend', ''); $recommend = $request->post('recommend', '');
$chain = $request->post('chain', '');
$condition = ['platform_id' => $platform_id, 'type' => 1]; $condition = ['platform_id' => $platform_id, 'type' => 1];
if ($recommend) { if ($recommend) {
$condition['recommend'] = $recommend; $condition['recommend'] = $recommend;
} }
if ($chain) {
$condition['chain'] = $chain;
}
$select = ['id', 'sid', 'icon', 'name', 'introduce', 'optional_name', 'nickname', 'platform', 'chain', 'treaty']; $select = ['id', 'sid', 'icon', 'name', 'introduce', 'optional_name', 'nickname', 'platform', 'chain', 'treaty'];
$order_by = ['sort' => SORT_ASC]; $order_by = ['sort' => SORT_ASC];
$datas = CoinRecommend::getList($page, $limit, $condition, $order_by, $select); $datas = CoinRecommend::getList($page, $limit, $condition, $order_by, $select);
......
...@@ -34,52 +34,57 @@ class MarketController extends BaseController ...@@ -34,52 +34,57 @@ class MarketController extends BaseController
return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []]; return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []];
} }
public function actionExchange()
{
$exchanges = array_unique(Yii::$app->params['exchange']);
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $exchanges];
}
public function actionIndex() public function actionIndex()
{ {
$currency = Yii::$app->request->post('currency', ''); $currency = Yii::$app->request->post('currency', '');
$base_currency = Yii::$app->request->post('base_currency', ''); $base_currency = Yii::$app->request->post('base_currency', '');
$exchange = Yii::$app->request->post("exchange", 'Zhaobi'); $exchange = Yii::$app->request->post("exchange", 'Zhaobi');
$base_exchange = Yii::$app->request->post("base_exchange", 'Zhaobi');
if (false == $currency || false == $base_currency) { if (false == $currency || false == $base_currency) {
$msg = 'invalid symbol'; $this->msg = 'invalid symbol';
$code = -1; $this->code = -1;
goto doEnd;
}
if (false == $exchange || !in_array($exchange, Yii::$app->params['exchange'])) {
$this->msg = 'invalid exchange';
$this->code = -1;
goto doEnd; goto doEnd;
} }
$exchange = ExchangeFactory::createExchange($exchange); $exchange = ExchangeFactory::createExchange($exchange);
$quotation = $exchange->getTicker($currency); $currency_ticker = $exchange->getTicker($currency, 'USDT');
$quotation = [ $base_currency_ticker = $exchange->getTicker($base_currency, 'USDT');
'low' => (float)sprintf("%0.4f", $quotation['low'] / 100), if (empty($currency_ticker) || empty($base_currency_ticker)) {
'high' => (float)sprintf("%0.4f", $quotation['high'] / 100), $this->code = -1;
'last' => (float)sprintf("%0.4f", $quotation['last'] / 100), $this->msg = '此交易所暂不支持所选币种!';
'rmb' => (float)sprintf("%0.2f", $quotation['last'] / 100), goto doEnd;
}
$currency_quotation = [
'low' => (float)sprintf("%0.4f", $currency_ticker['low']),
'high' => (float)sprintf("%0.4f", $currency_ticker['high']),
'last' => (float)sprintf("%0.4f", $currency_ticker['last']),
'rmb' => (float)sprintf("%0.2f", $currency_ticker['last']),
]; ];
echo json_encode($quotation);exit;
$base_exchange = ExchangeFactory::createExchange($base_exchange); $base_currency_quotation = [
$base_quotation = $base_exchange->getTicker($base_currency); 'low' => (float)sprintf("%0.4f", $base_currency_ticker['low']),
$base_quotation = [ 'high' => (float)sprintf("%0.4f", $base_currency_ticker['high']),
'low' => (float)sprintf("%0.4f", $base_quotation['low'] / 100), 'last' => (float)sprintf("%0.4f", $base_currency_ticker['last']),
'high' => (float)sprintf("%0.4f", $base_quotation['high'] / 100), 'rmb' => (float)sprintf("%0.2f", $base_currency_ticker['last']),
'last' => (float)sprintf("%0.4f", $base_quotation['last'] / 100),
'rmb' => (float)sprintf("%0.2f", $base_quotation['last'] / 100),
]; ];
$this->data = rtrim(sprintf('%.6f',$currency_quotation['last'] / $base_currency_quotation['last']), '0');
$builder = ExchangeBuilderFactory::create('Zhaobi');
$result = $builder->getDetail(strtoupper($currency), strtoupper($base_currency));
if (-1 == $result['code']) {
$msg = 'invalid symbol';
$code = -1;
goto doEnd;
}
$code = 0;
$msg = 'ok';
$ticker = $result['ticker'];
doEnd : doEnd :
return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []]; return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
} }
} }
\ No newline at end of file
...@@ -8,12 +8,42 @@ use common\models\psources\CoinAirDropTrade; ...@@ -8,12 +8,42 @@ use common\models\psources\CoinAirDropTrade;
use common\models\psources\CoinIssueTransfer; use common\models\psources\CoinIssueTransfer;
use common\models\psources\CoinPlatform; use common\models\psources\CoinPlatform;
use common\models\psources\CoinPlatformWithHold; use common\models\psources\CoinPlatformWithHold;
use common\models\psources\WalletSupportedTokenCategory;
use common\service\chain33\Chain33Service; use common\service\chain33\Chain33Service;
use Yii; use Yii;
class WalletController extends BaseController class WalletController extends BaseController
{ {
public function actionTokenCategory()
{
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
if (empty($platform_id)) {
$this->msg = '缺少必要参数';
$this->code = -1;
goto doEnd;
}
$this->data = [
[
'category' => '首页',
'chain' => null
],
[
'category' => '首页',
'chain' => null
]
];
$data = WalletSupportedTokenCategory::find()->select('category, chain')->where(['platform_id' => (int)$platform_id])->asArray()->all();
if (empty($data)) {
goto doEnd;
}
$this->data = array_merge($this->data, $data);
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
public function actionInfo() public function actionInfo()
{ {
$code = 0; $code = 0;
......
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class WalletSupportedTokenCategory extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{wallet_supported_token_catetory}}';
}
}
\ No newline at end of file
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