Commit 6db5b1b5 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into 'master'

Feature/optimize See merge request !291
parents dd7137e7 83e5bf78
......@@ -128,11 +128,15 @@ class CoinController extends BaseController
$limit = $request->post('limit', 999);
$platform_id = $request->post('platform_id', 1);//默认币钱包
$recommend = $request->post('recommend', '');
$chain = $request->post('chain', '');
$condition = ['platform_id' => $platform_id, 'type' => 1];
if ($recommend) {
$condition['recommend'] = $recommend;
}
if ($chain) {
$condition['chain'] = $chain;
}
$select = ['id', 'sid', 'icon', 'name', 'introduce', 'optional_name', 'nickname', 'platform', 'chain', 'treaty'];
$order_by = ['sort' => SORT_ASC];
$datas = CoinRecommend::getList($page, $limit, $condition, $order_by, $select);
......
......@@ -31,7 +31,7 @@ class ExploreController extends BaseController
foreach ($app_category_model as $key => $val) {
unset($val->apps);
$val->name = isset($val->name[$this->lang]) ? $val->name[$this->lang] : '';
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan')
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan, email, phone, real_name')
->where(['app_category_id' => (int)$val->id, 'status' => ExploreApp::STATUS_ON])
->orderBy('sort')
->limit($val->limit)
......@@ -111,7 +111,7 @@ class ExploreController extends BaseController
$id_arr = explode(',', $ids);
$order = "FIELD(`id`,$ids)";
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan')
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan, email, phone, real_name')
->where(['status' => ExploreApp::STATUS_ON])
->andWhere(['in', 'id', $id_arr])
->orderBy([$order => true])
......
......@@ -34,52 +34,86 @@ class MarketController extends BaseController
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()
{
$currency = Yii::$app->request->post('currency', '');
$base_currency = Yii::$app->request->post('base_currency', '');
$exchange = Yii::$app->request->post("exchange", 'Zhaobi');
$base_exchange = Yii::$app->request->post("base_exchange", 'Zhaobi');
if (false == $currency || false == $base_currency) {
$msg = 'invalid symbol';
$code = -1;
$this->msg = 'invalid symbol';
$this->code = -1;
goto doEnd;
}
$exchange = ExchangeFactory::createExchange($exchange);
$quotation = $exchange->getTicker($currency);
$quotation = [
'low' => (float)sprintf("%0.4f", $quotation['low'] / 100),
'high' => (float)sprintf("%0.4f", $quotation['high'] / 100),
'last' => (float)sprintf("%0.4f", $quotation['last'] / 100),
'rmb' => (float)sprintf("%0.2f", $quotation['last'] / 100),
];
echo json_encode($quotation);exit;
$base_exchange = ExchangeFactory::createExchange($base_exchange);
$base_quotation = $base_exchange->getTicker($base_currency);
$base_quotation = [
'low' => (float)sprintf("%0.4f", $base_quotation['low'] / 100),
'high' => (float)sprintf("%0.4f", $base_quotation['high'] / 100),
'last' => (float)sprintf("%0.4f", $base_quotation['last'] / 100),
'rmb' => (float)sprintf("%0.2f", $base_quotation['last'] / 100),
];
if ('USDT' == strtoupper($base_currency) && 'USDT' == strtoupper($currency)) {
$this->msg = 'invalid symbol';
$this->code = -1;
goto doEnd;
}
if (false == $exchange || !in_array($exchange, Yii::$app->params['exchange'])) {
$this->msg = 'invalid exchange';
$this->code = -1;
goto doEnd;
}
$exchange = ExchangeFactory::createExchange($exchange);
if ('USDT' == strtoupper($base_currency)) {
$currency_ticker = $exchange->getTicker($currency, 'USDT');
if (empty($currency_ticker)){
$this->code = -1;
$this->msg = '此交易所暂不支持所选币种!';
goto doEnd;
}
$this->data = rtrim(sprintf('%.6f',$currency_ticker['last']), '0');
goto doEnd;
}
$builder = ExchangeBuilderFactory::create('Zhaobi');
$result = $builder->getDetail(strtoupper($currency), strtoupper($base_currency));
if (-1 == $result['code']) {
$msg = 'invalid symbol';
$code = -1;
if ('USDT' == strtoupper($currency)) {
$currency_ticker = $exchange->getTicker($base_currency, 'USDT');
if (empty($currency_ticker)) {
$this->code = -1;
$this->msg = '此交易所暂不支持所选币种!';
goto doEnd;
}
$code = 0;
$msg = 'ok';
$ticker = $result['ticker'];
$this->data = rtrim(sprintf('%.6f', 1 / $currency_ticker['last']), '0');
goto doEnd;
}
$currency_ticker = $exchange->getTicker($currency, 'USDT');
$base_currency_ticker = $exchange->getTicker($base_currency, 'USDT');
if (empty($currency_ticker) || empty($base_currency_ticker)) {
$this->code = -1;
$this->msg = '此交易所暂不支持所选币种!';
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']),
];
$base_currency_quotation = [
'low' => (float)sprintf("%0.4f", $base_currency_ticker['low']),
'high' => (float)sprintf("%0.4f", $base_currency_ticker['high']),
'last' => (float)sprintf("%0.4f", $base_currency_ticker['last']),
'rmb' => (float)sprintf("%0.2f", $base_currency_ticker['last']),
];
$this->data = rtrim(sprintf('%.6f',$currency_quotation['last'] / $base_currency_quotation['last']), '0');
doEnd :
return ['code' => $code, 'msg' => $msg, 'tick' => $ticker ?? []];
return ['code' => $this->code, 'msg' => $this->msg, 'data' => $this->data];
}
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ class WalletChainController extends BaseController
$size = Yii::$app->request->get('size', 10);
$query = WalletChain::find()
->select('id, token, platform, status')
->select('id, token, platform, create_time, status')
->where(['wallet_address' => $wallet_address])
->orderBy('id');
......
......@@ -7,6 +7,7 @@ use api\base\BaseController;
use common\business\ExchangeBusiness;
use common\models\psources\WalletCoin;
use common\models\psources\CoinCurrency;
use common\models\psources\WalletCoinRelation;
class WalletCoinController extends BaseController
{
......@@ -39,18 +40,26 @@ class WalletCoinController extends BaseController
}
}
$this->data = [];
$relation_model = WalletCoinRelation::find()->select('coin_id')->where(['platform_id' => (int)$platform_id])->asArray()->all();
if (empty($relation_model)) {
goto doEnd;
}
$relation_ids = array_column($relation_model, 'coin_id');
foreach ($condition as $val) {
if (is_array($val)) {
$model = WalletCoin::find()->select('id,sid,icon,name,nickname,introduce,platform,chain,address as contract_address,treaty')
->where(['name' => $val[0], 'platform_id' => (int)$platform_id])
->andWhere(['platform' => $val[1]])
->where(['name' => $val[0], 'platform' => $val[1]])
->andWhere(['in', 'id', $relation_ids])
->asArray()
->one();
}
if (is_string($val)) {
$model = WalletCoin::find()->select('id,sid,icon,name,nickname,introduce,platform,chain,address as contract_address,treaty')
->where(['name' => $val, 'platform_id' => (int)$platform_id])
->where(['name' => $val])
->andWhere(['in', 'id', $relation_ids])
->asArray()
->one();
}
......@@ -120,9 +129,15 @@ class WalletCoinController extends BaseController
$page = empty($params['page']) ? 1 : $params['page'];
$limit = empty($params['limit']) ? 10 : $params['limit'];
$relation_model = WalletCoinRelation::find()->select('coin_id')->where(['platform_id' => (int)$platform_id])->asArray()->all();
if (empty($relation_model)) {
goto doEnd;
}
$relation_ids = array_column($relation_model, 'coin_id');
$query = WalletCoin::find()
->select('id, sid, icon, name, nickname, platform, chain, address as contract_address, treaty')
->where(['>', "find_in_set($platform_id, platform_id)", 0])
->where(['in', 'id', $relation_ids])
->orderBy('id');
if (false != $chain) {
......@@ -172,12 +187,17 @@ class WalletCoinController extends BaseController
$this->msg = '参数错误';
goto doEnd;
}
$this->data = WalletCoin::find()->where(['id' => $id, 'platform_id' => $platform_id])->asArray()->one();
if (empty($this->data)) {
$relation = WalletCoinRelation::find()->where(['coin_id' => $id, 'platform_id' => (int)$platform_id])->one();
if (empty($relation)){
goto doEnd;
}
$quotation = ExchangeBusiness::getquatation($this->data['name']);
$this->data = $relation->coin;
$quotation = ExchangeBusiness::getquatation($this->data->name);
$tikerdata = [
'publish_count' => $this->data->publish_count,
'circulate_count' => $this->data->circulate_count
];
if ($quotation) {
$tikerdata['price'] = $quotation['rmb'];
$tikerdata['dollar'] = $quotation['usd'];
......@@ -185,13 +205,10 @@ class WalletCoinController extends BaseController
$tikerdata['price'] = 0;
$tikerdata['dollar'] = 0;
}
$this->data['quotation'] = $tikerdata;
$this->data['quotation']['publish_count'] = $this->data['publish_count'];
$this->data['quotation']['circulate_count'] = $this->data['circulate_count'];
$nickname = json_decode($this->data['nickname'], true);
$this->data['nickname'] = isset($nickname[$this->lang]) ? $nickname[$this->lang] : '';
$introduce = json_decode($this->data['introduce'], true);
$this->data['introduce'] = isset($introduce[$this->lang]) ? $introduce[$this->lang] : '';
$this->data->quotation = $tikerdata;
$this->data->nickname = isset($this->data->nickname[$this->lang]) ? $this->data->nickname[$this->lang] : '';
$this->data->introduce = isset($this->data->introduce[$this->lang]) ? $this->data->introduce[$this->lang] : '';
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
......
......@@ -8,12 +8,42 @@ use common\models\psources\CoinAirDropTrade;
use common\models\psources\CoinIssueTransfer;
use common\models\psources\CoinPlatform;
use common\models\psources\CoinPlatformWithHold;
use common\models\psources\WalletSupportedTokenCategory;
use common\service\chain33\Chain33Service;
use Yii;
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()
{
$code = 0;
......
......@@ -30,8 +30,9 @@ class ExploreApp extends BaseActiveRecord
public function rules()
{
return [
[['name', 'icon', 'app_url', 'type', 'sort', 'status', 'platform_id', 'app_category_id'], 'required'],
[['type', 'sort', 'status', 'platform_id', 'app_category_id'], 'integer'],
[['name', 'icon', 'app_url', 'type', 'sort', 'status', 'platform_id', 'app_category_id', 'email', 'phone', 'real_name'], 'required'],
[['type', 'sort', 'status', 'platform_id', 'app_category_id', 'email', 'phone', 'real_name'], 'integer'],
[['email', 'phone', 'real_name'], 'in', 'range' => array(0, 1)],
['slogan', 'string', 'max' => 50],
[['slogan'], 'safe'],
[['icon'], 'url']
......@@ -47,15 +48,18 @@ class ExploreApp extends BaseActiveRecord
'slogan' => '应用宣传语',
'type' => '应用类型',
'sort' => '应用排序',
'status' => '应用状态'
'status' => '应用状态',
'phone' => '准入条件 - 手机',
'email' => '准入条件 - 邮箱',
'real_name' => '准入条件 - 实名'
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'icon', 'app_url', 'slogan', 'type', 'sort', 'status', 'platform_id', 'app_category_id'],
self:: SCENARIOS_UPDATE => ['id', 'name', 'icon', 'app_url', 'slogan', 'type', 'sort', 'status', 'platform_id', 'app_category_id'],
self:: SCENARIOS_CREATE => ['name', 'icon', 'app_url', 'slogan', 'type', 'sort', 'status', 'platform_id', 'app_category_id', 'email', 'phone', 'real_name'],
self:: SCENARIOS_UPDATE => ['id', 'name', 'icon', 'app_url', 'slogan', 'type', 'sort', 'status', 'platform_id', 'app_category_id', 'email', 'phone', 'real_name'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
......
......@@ -17,4 +17,9 @@ class WalletCoin extends BaseActiveRecord
{
return '{{wallet_coin}}';
}
public function attributes()
{
return array_merge(parent::attributes(), ['quotation']);
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class WalletCoinRelation extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{wallet_coin_relation}}';
}
public function getCoin()
{
return $this->hasOne(WalletCoin::className(), ['id' => 'coin_id']);
}
}
\ No newline at end of file
<?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
......@@ -232,7 +232,7 @@ class ExploreAppController extends BaseController
if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id');
$data = ExploreApp::find()->select('id, name, icon, app_url, slogan, type, sort, status')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
$data = ExploreApp::find()->select('id, name, icon, app_url, slogan, type, sort, status, email, phone, real_name')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
goto doEnd;
}
......
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