Commit 79eeab89 authored by rlgy's avatar rlgy

搜索币api v2

parent 5e4bd1d5
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
namespace api\controllers; namespace api\controllers;
use common\base\Exception;
use common\business\ExchangeBusiness;
use common\models\pwallet\Coin;
use Yii; use Yii;
use common\base\Exception;
use api\base\BaseController; use api\base\BaseController;
use common\models\pwallet\Coin;
use common\business\CoinBusiness; use common\business\CoinBusiness;
use common\business\ExchangeBusiness;
/** /**
* 币种信息管理控制器 * 币种信息管理控制器
...@@ -31,7 +31,10 @@ class CoinController extends BaseController ...@@ -31,7 +31,10 @@ class CoinController extends BaseController
$request = Yii::$app->request; $request = Yii::$app->request;
$id = $request->post('id', 0); $id = $request->post('id', 0);
if ($id) { if ($id) {
return CoinBusiness::getCoinAllById($id); $ret = CoinBusiness::getCoinAllById($id);
if ($ret) {
return $ret[0];
}
} }
return []; return [];
} }
...@@ -67,24 +70,13 @@ class CoinController extends BaseController ...@@ -67,24 +70,13 @@ class CoinController extends BaseController
//如果coin为null,$coin->minerFee会抛出Trying to get property 'minerFee' of non-object",code=>8 //如果coin为null,$coin->minerFee会抛出Trying to get property 'minerFee' of non-object",code=>8
throw new Exception('8', '币种不存在'); throw new Exception('8', '币种不存在');
} }
return [$miner_fee]; return (array)$miner_fee->getAttributes();
}
/**
* app首页接口
*/
public function actionCoinIndex()
{
$names = Yii::$app->request->post('names');
$condition = [['in', 'name', $names]];
return CoinBusiness::getApiListForIndex($condition);
} }
/** /**
* app首页接口V2 * app首页接口V2
*/ */
public function actionCoinIndexV2() public function actionCoinIndex()
{ {
$names = Yii::$app->request->post('names'); $names = Yii::$app->request->post('names');
$condition = [['in', 'name', $names]]; $condition = [['in', 'name', $names]];
...@@ -103,7 +95,7 @@ class CoinController extends BaseController ...@@ -103,7 +95,7 @@ class CoinController extends BaseController
$limit = $request->post('limit', 10); $limit = $request->post('limit', 10);
if ($name) { if ($name) {
$condition = [['or', ['like', 'name', $name], ['like', 'nickname', $name]]]; $condition = [['or', ['like', 'name', $name], ['like', 'nickname', $name]]];
return CoinBusiness::SearchByName($page, $limit, $condition); return ExchangeBusiness::SearchByName($page, $limit, $condition);
} }
} }
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午1:02
*/
namespace api\controllers\v2;
use Yii;
use common\base\Exception;
use api\base\BaseController;
use common\models\pwallet\Coin;
use common\business\CoinBusiness;
use common\business\ExchangeBusiness;
/**
* 币种信息管理控制器
* Class CoinController
* @package api\controllers
*/
class CoinController extends BaseController
{
/**
* 单币种按照id查询
* @return array|null|\yii\db\ActiveRecord
*/
public function actionGetCoinById()
{
$request = Yii::$app->request;
$id = $request->post('id', 0);
if ($id) {
$ret = CoinBusiness::getCoinAllById($id);
if ($ret) {
return $ret[0];
}
}
return [];
}
/**
* 获取推介币种列表
*/
public function actionGetRecList()
{
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$condition = [['recommend' => '1']];
return CoinBusiness::getApiList($page, $limit, $condition);
}
/**
* 矿工费获取
*
* 根据name获取
* @throws Exception
*/
public function actionGetMinerFeeByName()
{
$names = Yii::$app->request->post('name');
$coin = Coin::findOne(['name' => $names]);
if ($coin) {
$miner_fee = $coin->minerFee;
if (empty($miner_fee)) {
return [];
}
} else {
//如果coin为null,$coin->minerFee会抛出Trying to get property 'minerFee' of non-object",code=>8
throw new Exception('8', '币种不存在');
}
return (array)$miner_fee->getAttributes();
}
/**
* app首页接口V2
*/
public function actionCoinIndex()
{
$names = Yii::$app->request->post('names');
$condition = [['in', 'name', $names]];
return ExchangeBusiness::getApiListForIndex($condition);
}
/**
* 按照名称搜索币种
* @return array
*/
public function actionSearchCoinByName()
{
$request = Yii::$app->request;
$name = $request->post('name', '');
$page = $request->post('page', 1);
$limit = $request->post('limit', 10);
if ($name) {
$condition = [['or', ['like', 'name', $name], ['like', 'nickname', $name]]];
return ExchangeBusiness::SearchByName($page, $limit, $condition);
}
}
}
\ No newline at end of file
...@@ -46,7 +46,7 @@ return [ ...@@ -46,7 +46,7 @@ return [
'http_proxy' => [ 'http_proxy' => [
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'port' => '1080', 'port' => '8118',
'use' => true 'use' => true
] ]
]; ];
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