Commit 6edafced authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into 'master'

Feature/optimize See merge request !402
parents 674d2bf9 1b728e04
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace api\controllers; namespace api\controllers;
use common\business\ExchangeBusiness; use common\business\ExchangeBusiness;
use common\models\psources\Coin;
use common\models\psources\CoinSupportedChain; use common\models\psources\CoinSupportedChain;
use Yii; use Yii;
use api\base\BaseController; use api\base\BaseController;
...@@ -122,4 +123,78 @@ class RecommendCoinController extends BaseController ...@@ -122,4 +123,78 @@ class RecommendCoinController extends BaseController
doEnd : doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg]; return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
} }
public function actionTrusteeship()
{
$platform_id = $this->platform_id;
if (false == $platform_id) {
$this->code = -1;
$this->msg = '参数错误';
goto doEnd;
}
$recommend = Yii::$app->request->get('recommend', 1);
if ($recommend != 1) {
$this->code = 1;
$this->msg = '数据为空';
goto doEnd;
}
$coin_trusteeship = WalletRecommendCoin::find()->select('cid')->where(['type' => WalletRecommendCoin::TYPE_TRUSTEESHIP, 'platform_id' => $platform_id])->asArray()->all();
$select = ['id', 'sid', 'icon', 'name', 'introduce', 'optional_name', 'nickname', 'platform', 'chain', 'treaty'];
$coin_ids = array_column($coin_trusteeship, 'cid');
if (false == $coin_ids) {
$this->code = 1;
$this->msg = '数据为空';
goto doEnd;
}
$coin_infos = Coin::getCoinInfoByIds($coin_ids, $select, 'id');
foreach ($coin_infos as $key => &$val) {
$nickname = json_decode($val['nickname'], true);
$val['nickname'] = isset($nickname[$this->lang]) ? $nickname[$this->lang] : '';
$introduce = json_decode($val['introduce'], true);
$val['introduce'] = isset($introduce[$this->lang]) ? $introduce[$this->lang] : '';
}
//获取行情信息
$coin_names = array_column($coin_infos, 'name');
$coin_names = array_merge($coin_names, array_column($coin_infos, 'chain'));
$coin_quotations = ExchangeBusiness::getQuatationByNames($coin_names);
if ($coin_infos) {
array_shift($select);
foreach ($coin_trusteeship as $key => &$value) {
$temp_key = $coin_infos[$value['cid']]['name'];
foreach ($select as $item) {
$value[$item] = $coin_infos[$value['cid']][$item];
if ($platform_id != 2) {
//国盾币不需要行情
$value['low'] = $coin_quotations[$temp_key]['low'];
$value['high'] = $coin_quotations[$temp_key]['high'];
$value['last'] = $coin_quotations[$temp_key]['last'];
$value['rmb'] = $coin_quotations[$temp_key]['rmb'];
$value['usd'] = $coin_quotations[$temp_key]['usd'] ?? 0;
} else {
$value['low'] = 0;
$value['high'] = 0;
$value['last'] = 0;
$value['rmb'] = 0;
$value['usd'] = 0;
}
}
$value['id'] = $value['cid'];
$value['sid'] = ucfirst($value['sid']);
$value['chain_quotation'] = $coin_quotations[$coin_infos[$value['cid']]['chain']];
$value['chain_rmb'] = isset($coin_quotations[$coin_infos[$value['cid']]['chain']]['rmb']) ? $coin_quotations[$coin_infos[$value['cid']]['chain']]['rmb'] : 0;
$value['chain_usd'] = isset($coin_quotations[$coin_infos[$value['cid']]['chain']]['usd']) ? $coin_quotations[$coin_infos[$value['cid']]['chain']]['usd'] : 0;
unset($value['create_time'], $value['update_time'], $value['cid']);
$value['type'] = WalletRecommendCoin::TYPE_TRUSTEESHIP;
$value['platform_id'] = $platform_id;
$value['sort'] = $value['recommend'] = 1;
$value['coin'] = $value['name'];
}
unset($key, $value);
}
$this->data = $coin_trusteeship;
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg, 'count' => empty($this->data) ? 0 : count($this->data)];
}
} }
\ No newline at end of file
...@@ -7,6 +7,9 @@ use common\core\BaseActiveRecord; ...@@ -7,6 +7,9 @@ use common\core\BaseActiveRecord;
class WalletRecommendCoin extends BaseActiveRecord class WalletRecommendCoin extends BaseActiveRecord
{ {
const TYPE_COMMON = 1; //去中心化
const TYPE_TRUSTEESHIP = 2; //托管钱包
public static function getDb() public static function getDb()
{ {
return Yii::$app->get('p_sources'); return Yii::$app->get('p_sources');
......
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