Commit 2b85dcd2 authored by rlgy's avatar rlgy

CoinServer update&index API

parent d26e197c
...@@ -20,6 +20,15 @@ class BaseResponse extends Response ...@@ -20,6 +20,15 @@ class BaseResponse extends Response
$this->data = ['code' => $excpetion->getCode(), 'msg' => $excpetion->getMessage()]; $this->data = ['code' => $excpetion->getCode(), 'msg' => $excpetion->getMessage()];
} }
//TODO 在这里对数据进行format,这样控制器中可以直接return一个array,保存到数据域data中即可,eg:['code'=>0,'data'=>$data] //TODO 在这里对数据进行format,这样控制器中可以直接return一个array,保存到数据域data中即可,eg:['code'=>0,'data'=>$data]
$data = \Yii::$app->response->data;
if (empty($data)) {
$return['code'] = 1;
$return['msg'] = '数据为空';
} else {
$return['code'] = 0;
$return['data'] = $data;
}
\Yii::$app->response->data = $return;
parent::send(); parent::send();
} }
} }
\ No newline at end of file
...@@ -123,9 +123,10 @@ class CoinController extends BaseController ...@@ -123,9 +123,10 @@ class CoinController extends BaseController
/** /**
* app首页接口 * app首页接口
*/ */
public function actionSearchByNames() public function actionCoinIndex()
{ {
$names = Yii::$app->request->post('names'); $names = Yii::$app->request->post('names');
$condition = [['in', 'name', $names]];
Yii::$app->response->data = CoinBusiness::getApiListForIndex($condition);
} }
} }
\ No newline at end of file
...@@ -82,4 +82,25 @@ class CoinBusiness ...@@ -82,4 +82,25 @@ class CoinBusiness
} }
return $rows; return $rows;
} }
/**
* @param array $condition 需要的币种sid列表
* @return array
*/
public static function getApiListForIndex($condition = [])
{
$rows = Coin::getSelectList(1, 999, ['id', 'sid', 'icon', 'name', 'nickname'], $condition);
if ($rows['count'] > 0) {
$rows = $rows['data'];
foreach ($rows as $key => $row) {
$coinServer = new CoinService($row['id'], $row['sid']);
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
$rows[$key]['rmb'] = $coinServer->getPrice();
$rows[$key]['usd'] = $coinServer->getDollar();
$coinServer->__destruct();
}
return $rows;
}
return [];
}
} }
\ No newline at end of file
...@@ -56,6 +56,24 @@ class Coin extends BaseActiveRecord ...@@ -56,6 +56,24 @@ class Coin extends BaseActiveRecord
} }
/** /**
* 获取币种信息列表
* @param int $page
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord[]
*/
public static function getSelectList($page = 1, $limit = 10, $columns = [], $condition = [])
{
$query = self::find();
foreach ($condition as $item) {
$query = $query->andWhere($item);
}
$count = $query->count();
$data = $query->select($columns)->offset(($page - 1) * 10)->limit($limit)->asArray()->all();
return ['count' => $count, 'data' => $data];
}
/**
* 添加一个币种信息 * 添加一个币种信息
*/ */
public function addOne($params) public function addOne($params)
......
This diff is collapsed.
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