Commit 0ea1024d authored by rlgy's avatar rlgy

矿工费api

parent 8c982e00
......@@ -14,7 +14,12 @@ class BaseResponse extends Response
{
public function send()
{
//TODO 错误处理
//错误处理
$excpetion = \Yii::$app->errorHandler->exception;
if ($excpetion !== null) {
$this->data = ['code' => $excpetion->getCode(), 'msg' => $excpetion->getMessage()];
}
//TODO 在这里对数据进行format,这样控制器中可以直接return一个array,保存到数据域data中即可,eg:['code'=>0,'data'=>$data]
parent::send();
}
}
\ No newline at end of file
......@@ -8,6 +8,8 @@
namespace api\controllers;
use common\base\Exception;
use common\models\pwallet\Coin;
use Yii;
use api\base\BaseController;
use common\business\CoinBusiness;
......@@ -20,23 +22,13 @@ use common\business\CoinBusiness;
class CoinController extends BaseController
{
/**
* 获取币种列表
*/
public function actionList()
{
\Yii::$app->response->data = Coin::getList();
}
/**
* 获取行情列表,可簺选(coin.id,coin.name),可分页
* 获取行情列表,可筛选可分页
*
* @var int $id coin.id
* @var string $name coin.name
* @var int $page 第几页
* @var int $limit 多少条数据
*
* @return array 格式 [code,msg,count,data]
*
* 返回data数组格式[coin.id coin.name coin.nickname coin.quotation]
* coin.quatation=>['price' => '', 'dollar' => '', 'btc' => '', 'high' => '', 'low' => '', 'change' => '']
* 对应:价格 价格美元 价格btc 最高价 最低价 涨幅(跌幅)
......@@ -79,7 +71,7 @@ class CoinController extends BaseController
$condition[] = ['like', 'nickname', $post['nickname']];
}
//平台saixuan
//平台筛选
if (isset($post['platform'])) {
$condition[] = ['platform' => $post['platform']];
}
......@@ -88,4 +80,35 @@ class CoinController extends BaseController
Yii::$app->response->data = $data;
}
/**
* 获取推介币种列表
*/
public function actionGetRecList()
{
//todo 推介币种列表
}
/**
* 矿工费获取
*
* 根据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 ['code' => 1, 'msg' => '数据为空'];
}
} else {
//如果coin为null,$coin->minerFee会抛出Trying to get property 'minerFee' of non-object",code=>8
throw new Exception('8', '币种不存在');
}
return ['code' => 0, 'data' => $miner_fee];
}
}
\ No newline at end of file
......@@ -8,7 +8,6 @@
namespace common\business;
use Yii;
use common\models\pwallet\Coin;
use common\service\CoinService;
......@@ -45,6 +44,7 @@ class CoinBusiness
* @param int $page
* @param int $limit
* @param array $condition
* @return array
*/
public static function getApiList($page = 1, $limit = 10, $condition = [])
{
......
......@@ -8,12 +8,21 @@
namespace common\models\pwallet;
use common\base\Exception;
use common\core\BaseActiveRecord;
use Yii;
use common\core\BaseActiveRecord;
/**
* Class Coin
*
* @property array $minerFee 矿工费用
* @package common\models\pwallet
*/
class Coin extends BaseActiveRecord
{
/**
* @return null|object|\yii\db\Connection
* @throws \yii\base\InvalidConfigException
*/
public static function getDb()
{
return Yii::$app->get('db_pwallet');
......@@ -80,9 +89,13 @@ class Coin extends BaseActiveRecord
$coin->setAttributes($params, false);
try {
return (bool)$coin->save();
} catch (Exception $exception) {
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
}
}
public function getMinerFee()
{
return $this->hasOne(MinerFee::className(), ['platform' => 'platform']);
}
}
\ 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