Commit 6f087d47 authored by shajiaming's avatar shajiaming

币种关系

parent b590d45a
...@@ -7,6 +7,7 @@ use api\base\BaseController; ...@@ -7,6 +7,7 @@ use api\base\BaseController;
use common\business\ExchangeBusiness; use common\business\ExchangeBusiness;
use common\models\psources\WalletCoin; use common\models\psources\WalletCoin;
use common\models\psources\CoinCurrency; use common\models\psources\CoinCurrency;
use common\models\psources\WalletCoinRelation;
class WalletCoinController extends BaseController class WalletCoinController extends BaseController
{ {
...@@ -39,18 +40,26 @@ class WalletCoinController extends BaseController ...@@ -39,18 +40,26 @@ class WalletCoinController extends BaseController
} }
} }
$this->data = []; $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) { foreach ($condition as $val) {
if (is_array($val)) { if (is_array($val)) {
$model = WalletCoin::find()->select('id,sid,icon,name,nickname,introduce,platform,chain,address as contract_address,treaty') $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]) ->where(['name' => $val[0], 'platform' => $val[1]])
->andWhere(['platform' => $val[1]]) ->andWhere(['in', 'id', $relation_ids])
->asArray() ->asArray()
->one(); ->one();
} }
if (is_string($val)) { if (is_string($val)) {
$model = WalletCoin::find()->select('id,sid,icon,name,nickname,introduce,platform,chain,address as contract_address,treaty') $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() ->asArray()
->one(); ->one();
} }
...@@ -120,9 +129,15 @@ class WalletCoinController extends BaseController ...@@ -120,9 +129,15 @@ class WalletCoinController extends BaseController
$page = empty($params['page']) ? 1 : $params['page']; $page = empty($params['page']) ? 1 : $params['page'];
$limit = empty($params['limit']) ? 10 : $params['limit']; $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() $query = WalletCoin::find()
->select('id, sid, icon, name, nickname, platform, chain, address as contract_address, treaty') ->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'); ->orderBy('id');
if (false != $chain) { if (false != $chain) {
...@@ -172,12 +187,17 @@ class WalletCoinController extends BaseController ...@@ -172,12 +187,17 @@ class WalletCoinController extends BaseController
$this->msg = '参数错误'; $this->msg = '参数错误';
goto doEnd; goto doEnd;
} }
$relation = WalletCoinRelation::find()->where(['coin_id' => $id, 'platform_id' => (int)$platform_id])->one();
$this->data = WalletCoin::find()->where(['id' => $id, 'platform_id' => $platform_id])->asArray()->one(); if (empty($relation)){
if (empty($this->data)) {
goto doEnd; 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) { if ($quotation) {
$tikerdata['price'] = $quotation['rmb']; $tikerdata['price'] = $quotation['rmb'];
$tikerdata['dollar'] = $quotation['usd']; $tikerdata['dollar'] = $quotation['usd'];
...@@ -185,13 +205,10 @@ class WalletCoinController extends BaseController ...@@ -185,13 +205,10 @@ class WalletCoinController extends BaseController
$tikerdata['price'] = 0; $tikerdata['price'] = 0;
$tikerdata['dollar'] = 0; $tikerdata['dollar'] = 0;
} }
$this->data['quotation'] = $tikerdata;
$this->data['quotation']['publish_count'] = $this->data['publish_count']; $this->data->quotation = $tikerdata;
$this->data['quotation']['circulate_count'] = $this->data['circulate_count']; $this->data->nickname = isset($this->data->nickname[$this->lang]) ? $this->data->nickname[$this->lang] : '';
$nickname = json_decode($this->data['nickname'], true); $this->data->introduce = isset($this->data->introduce[$this->lang]) ? $this->data->introduce[$this->lang] : '';
$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] : '';
doEnd : doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg]; return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
......
...@@ -17,4 +17,9 @@ class WalletCoin extends BaseActiveRecord ...@@ -17,4 +17,9 @@ class WalletCoin extends BaseActiveRecord
{ {
return '{{wallet_coin}}'; 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
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