Commit 8cf7b6bb authored by ZhuChunYang's avatar ZhuChunYang

update

parent faa89cc0
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/12/29
* Time: 16:26
*/
namespace api\controllers;
use api\base\BaseController;
use common\business\ExchangeBusiness;
use common\models\psources\Coin;
use common\service\coin\CoinFactory;
use Yii;
/**
* 对外服务控制器
* Class CoinController
*
* @package api\controllers
*/
class ServiceController extends BaseController
{
/**
* 获取币种行情
*
* @return array|null|\yii\db\ActiveRecord
*/
public function actionCoinTickers()
{
$request = Yii::$app->request;
$coinItems = $request->post('names');
if(!is_array($coinItems)){
$coinItems = [$coinItems];
}
$tickerData = [];
if($coinItems){
foreach($coinItems as $item){
$item = strtoupper($item);
$quotation = ExchangeBusiness::getquatation($item);
if (!$quotation) {
//使用Coin服务
try {
$coinServer = CoinFactory::createCoin($item, '', '');
$tickerData[$item]['rmb'] = $coinServer->getPrice();
$tickerData[$item]['last'] = $coinServer->getDollar();
$tickerData[$item]['low'] = $coinServer->getLow();
$tickerData[$item]['high'] = $coinServer->getHigh();
$coinServer->__destruct();
} catch (\Exception $exception) {
$tickerData[$item]['rmb'] = 0;
$tickerData[$item]['last'] = 0;
$tickerData[$item]['low'] = 0;
$tickerData[$item]['high'] = 0;
\Yii::error($exception->getMessage());
}
}else{
$tickerData[$item] = $quotation;
}
}
return ['code' => 0,'data' => $tickerData,'msg' => '行情获取成功'];
}
return ['code' => 1,'data' => [],'msg' => '币种不能为空'];
}
public function actionCoinIndex()
{
$request = Yii::$app->request;
$coinItems = $request->post('names');
if(!is_array($coinItems)){
$coinItems = [$coinItems];
}
$fields =['id', 'sid', 'icon', 'name', 'nickname'];
$rows = Coin::getSelectList(1, 999, $fields,[['in','name',$coinItems]]);
return ['code' => 0,'data' => $rows,'msg' => '币种列表获取成功'];
}
}
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