Commit 673ae21f authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into develop

parents 73b9e091 5f0d6c95
......@@ -2,59 +2,80 @@
namespace api\controllers;
use common\business\ExchangeBusiness;
use Yii;
use api\base\BaseController;
use common\business\ExchangeBusiness;
use common\models\psources\RecommendCoin;
use common\models\psources\WalletRecommendCoin;
use common\models\psources\WalletRecommendCategory;
class RecommendCoinController extends BaseController
{
/**
* 获取推荐币种
* @param integer recommend 1首页推介,2次页推介
* @return array
*/
public function actionIndex()
{
$recommend = Yii::$app->request->post('recommend', 0);
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
if (false == $recommend || false == $platform_id) {
$platform_id = $this->platform_id;
if (false == $platform_id) {
$this->code = -1;
$this->msg = '参数错误';
goto doEnd;
}
$recommend_coins = RecommendCoin::find()->where(['platform_id' => (int)$platform_id])->orderBy("sort desc")->all();
if (empty($recommend_coins)) {
$type = Yii::$app->request->get('type', 1);
$is_top = Yii::$app->request->get('is_top', '');
if (false == $is_top) {
$recommend_category = WalletRecommendCategory::find()->select('id, name')
->where(['wallet_type' => (int)$type, 'platform_id' => (int)$platform_id])
->andWhere(['>', 'sort', 1])
->orderBy('sort')->asArray()->all();
} else {
$recommend_category = WalletRecommendCategory::find()->select('id, name')
->where(['wallet_type' => (int)$type, 'platform_id' => (int)$platform_id, 'sort' => 1])
->orderBy('sort')->limit(1)->asArray()->all();
}
if (empty($recommend_category)) {
goto doEnd;
}
$this->data = [];
foreach ($recommend_coins as $coin) {
$recommend_coin_info = [
'recommend' => $coin->recommend,
'sort' => $coin->sort,
'type' => $coin->type,
];
$this->data = array_merge($this->data, [array_merge($coin->coin[0], $recommend_coin_info)]);
$ticker = ['low' => 0, 'high' => 0, 'last' => 0, 'open' => 0, 'vol' => 0, 'rmb' => 0, 'usd' => 0];
foreach ($recommend_category as &$category) {
$name = json_decode($category['name'], true);
$category['name'] = isset($name[$this->lang]) ? $name[$this->lang] : '';
$recommend_coin = WalletRecommendCoin::find()->where(['category_id' => $category['id']])->all();
$items = [];
foreach ($recommend_coin as $coin) {
$temp['icon'] = $coin->coin['icon'];
$temp['name'] = $coin->coin['name'];
$temp['platform'] = $coin->coin['platform'];
$temp['chain'] = $coin->coin['chain'];
$temp['treaty'] = $coin->coin['treaty'];
$temp['exchange_id'] = $coin->coin['exchange_id'];
$nickname = json_decode($coin->coin['nickname'], true);
$temp['nickname'] = isset($nickname[$this->lang]) ? $nickname[$this->lang] : '';
$introduce = json_decode($coin->coin['introduce'], true);
$temp['introduce'] = isset($introduce[$this->lang]) ? $introduce[$this->lang] : '';
array_push($items, $temp);
}
$category['items'] = $items;
}
$chains = array_column($this->data, 'chain');
$symbol = array_column($this->data, 'name');
$chains_symbols = array_keys(array_flip($chains) + array_flip($symbol));
$coin_quotations = ExchangeBusiness::getQuatationByNames($chains_symbols);
if (!empty($is_top)) {
$result = $recommend_category[0]['items'];
//获取行情信息
$coin_names = array_column($result, 'name');
$coin_names = array_merge($coin_names, array_column($result, 'chain'));
$coin_quotations = ExchangeBusiness::getQuatationByNames($coin_names);
$ticker = ['low' => 0, 'high' => 0, 'last' => 0, 'open' => 0, 'vol' => 0, 'rmb' => 0, 'usd' => 0];
foreach ($this->data as $key => &$val) {
$val['chain_quotation'] = isset($coin_quotations[strtoupper($val['chain'])]) ? $coin_quotations[strtoupper($val['chain'])] : [];
$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] : '';
$this->data[$key] = array_merge($val, isset($coin_quotations[strtoupper($val['name'])]) ? $coin_quotations[strtoupper($val['name'])] : $ticker);
$ticker = ['low' => 0, 'high' => 0, 'last' => 0, 'open' => 0, 'vol' => 0, 'rmb' => 0, 'usd' => 0];
foreach ($result as $key => &$val) {
$val['chain_quotation'] = isset($coin_quotations[strtoupper($val['chain'])]) ? $coin_quotations[strtoupper($val['chain'])] : [];
$result[$key] = array_merge($val, isset($coin_quotations[strtoupper($val['name'])]) ? $coin_quotations[strtoupper($val['name'])] : $ticker);
$val['chain_rmb'] = isset($val['chain_quotation']['rmb']) ? $val['chain_quotation']['rmb'] : 0;
$val['chain_usd'] = isset($val['chain_quotation']['usd']) ? $val['chain_quotation']['usd'] : 0;
}
$this->data = $result;
goto doEnd;
}
$this->data = $recommend_category;
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
......
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class WalletRecommendCategory extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{wallet_recommend_category}}';
}
public function getRecommendCoin()
{
return $this->hasMany(WalletRecommendCoin::className(), ['category_id' => 'id'])->asArray()->all();
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class RecommendCoin extends BaseActiveRecord
class WalletRecommendCoin extends BaseActiveRecord
{
public static function getDb()
{
......@@ -19,6 +19,6 @@ class RecommendCoin extends BaseActiveRecord
public function getCoin()
{
return $this->hasOne(WalletCoin::className(), ['id' => 'cid'])->select(['id', 'sid', 'icon', 'name', 'introduce', 'nickname', 'platform', 'chain', 'treaty', 'exchange_id'])->asArray()->all();
return $this->hasOne(WalletCoin::className(), ['id' => 'cid'])->select(['id', 'icon', 'name', 'introduce', 'nickname', 'platform', 'chain', 'treaty', 'exchange_id'])->asArray();
}
}
\ No newline at end of file
......@@ -231,7 +231,11 @@ class Chain33Service
$params = [
'data' => $data
];
return $this->send($params, 'Chain33.SendTransaction');
$timeout = [
'connect_timeout' => 50000,
'timeout_ms' => 50000
];
return $this->send($params, 'Chain33.SendTransaction', $timeout);
}
public function QueryTransaction($data)
......
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