Commit 6f087d47 authored by shajiaming's avatar shajiaming

币种关系

parent b590d45a
......@@ -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];
......
......@@ -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
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