Commit 673ae21f authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into develop

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