Commit c3327d47 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into 'master'

Feature/optimize See merge request !306
parents 059683b0 51c643e2
......@@ -2,59 +2,114 @@
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()
public function actionTop()
{
$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;
}
$type = Yii::$app->request->get('type', 1);
$recommend_coins = RecommendCoin::find()->where(['platform_id' => (int)$platform_id])->orderBy("sort desc")->all();
if (empty($recommend_coins)) {
$recommend_category = WalletRecommendCategory::find()->select('id, name')
->where(['wallet_type' => (int)$type, 'platform_id' => (int)$platform_id])
->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)]);
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;
}
$this->data = $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 ($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;
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
public function actionIndex()
{
$platform_id = $this->platform_id;
if (false == $platform_id) {
$this->code = -1;
$this->msg = '参数错误';
goto doEnd;
}
$type = Yii::$app->request->get('type', 1);
$recommend_category = WalletRecommendCategory::find()->select('id, name')
->where(['wallet_type' => (int)$type, 'platform_id' => (int)$platform_id])
->andWhere(['>', 'sort', 1])
->orderBy('sort')->asArray()->all();
if (empty($recommend_category)) {
goto doEnd;
}
foreach ($recommend_category as &$category) {
$name = json_decode($category['name'], true);
$category['name'] = isset($name[$this->lang]) ? $name[$this->lang] : '';
$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);
$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);
$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;
}
$this->data = $recommend_category;
doEnd :
return ['code' => $this->code, 'data' => $this->data, 'msg' => $this->msg];
}
......
......@@ -115,6 +115,16 @@ class ExchangeBusiness
goto doEnd;
}
if (strtoupper($tag) == 'FZM') {
$quotation = [
'low' => 41,
'high' => 41,
'last' => 41,
'rmb' => 41,
];
goto doEnd;
}
if (strtoupper($tag) == 'GST' || strtoupper($tag) == 'JNTK' || strtoupper($tag) == 'SPT' || strtoupper($tag) == 'STO' || strtoupper($tag) == 'GM' || strtoupper($tag) == 'BSTC' || strtoupper($tag) == 'RYH' || strtoupper($tag) == 'CNDT' || strtoupper($tag) == 'WL' || strtoupper($tag) == 'ETS' || strtoupper($tag) == 'LIMS' || strtoupper($tag) == 'AT' || strtoupper($tag) == 'BTJ') {
$quotation = [
'low' => 0,
......
<?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
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