Commit 9060f31c authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into develop

parents 07d48b97 735bdb8a
...@@ -22,6 +22,10 @@ class BaseController extends Controller ...@@ -22,6 +22,10 @@ class BaseController extends Controller
public $currency_id; public $currency_id;
public $platform_id; public $platform_id;
public $code = 0;
public $msg = 'success';
public $data = null;
private static $default_header_list = []; private static $default_header_list = [];
public function init() public function init()
......
<?php
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\business\ExchangeBusiness;
use common\models\psources\RecommendCoin;
class RecommendCoinController extends BaseController
{
public function actionIndex()
{
$recommend = Yii::$app->request->post('recommend', 0);
$platform_id = Yii::$app->request->post('platform_id', 0);
if (false == $recommend || false == $platform_id) {
$this->code = -1;
$this->msg = '参数错误';
goto doEnd;
}
$recommend_coins = RecommendCoin::find()->where(['platform_id' => (int)$platform_id])->all();
if (empty($recommend_coins)) {
goto doEnd;
}
$this->data = [];
foreach ($recommend_coins as $coin) {
//$this->data[$coin->coin[0]['chain']] = $coin->coin;
$this->data = array_merge($this->data, $coin->coin);
}
$chains = array_column($this->data, 'chain');
$coin_quotations = ExchangeBusiness::getQuatationByNames($chains);
$i = 0;
foreach ($coin_quotations as $key => $val) {
$nickname = json_decode($this->data[$i]['nickname'], true);
$this->data[$i]['nickname'] = isset($nickname[$this->lang]) ? $nickname[$this->lang] : '';
$introduce = json_decode($this->data[$i]['introduce'], true);
$this->data[$i]['introduce'] = isset($introduce[$this->lang]) ? $introduce[$this->lang] : '';
$this->data[$i]['chain_quotation'] = $val;
foreach ($val as $key => $cloumn) {
$this->data[$i][$key] = $cloumn;
}
$i++;
}
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
use common\core\BaseActiveRecord;
use yii\behaviors\TimestampBehavior;
class RecommendCoin extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{wallet_recommend_coin}}';
}
public function getCoin()
{
return $this->hasOne(Coin::className(), ['id' => 'cid'])->select(['id', 'sid', 'icon', 'name', 'introduce', 'optional_name', 'nickname', 'platform', 'chain', 'treaty'])->asArray()->all();
}
}
\ 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