Commit 6bc52020 authored by rlgy's avatar rlgy

api v2

parent cdde6ddc
<?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) {
return CoinBusiness::getCoinAllById($id);
}
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 [$miner_fee];
}
/**
* 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 CoinBusiness::SearchByName($page, $limit, $condition);
}
}
}
\ 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