Commit 4fc3b6bb authored by shajiaiming's avatar shajiaiming

fix

parent 112df354
......@@ -70,6 +70,7 @@ class NoticeController extends BaseController
public function actionIndex()
{
$id = Yii::$app->request->get('id', '');
$page = Yii::$app->request->get('page', 1);
$exchange = Yii::$app->request->get('exchange', 'zhaobi');
$exchange_arr = ['huobi', 'binance', 'okex', 'zhaobi'];
if (!in_array($exchange, $exchange_arr)) {
......@@ -78,8 +79,12 @@ class NoticeController extends BaseController
$data = [];
goto doEnd;
}
$params = [
'id' => $id,
'page' => $page
];
$builder = ExchangeBuilderFactory::create($exchange);
$result = $builder->getNotice($id);
$result = $builder->getNotice($params);
$code = $result['code'];
$data = $result['notice'];
$msg = isset($result['msg']) ? $result['msg'] : 'success';
......
......@@ -38,9 +38,4 @@ abstract class FactoryService
$this->basic_price[$val['name']] = $val['rmb'];
}
}
public function symbolPrice($symbol = 'ETH')
{
}
}
\ No newline at end of file
......@@ -47,27 +47,35 @@ class ZhaobiBuilder extends FactoryService
return ['code' => $this->code, 'ticker' => $ticker];
}
public function getNotice($id = '')
public function getNotice($params = [])
{
$curl = new Curl();
if (!empty($id)) {
$api = $this->base_url . '/api/data/noticedetail?id=' . $id;
if (isset($params['id']) && !empty($params['id'])) {
$api = $this->base_url . '/api/data/noticedetail?id=' . $params['id'];
$res = $curl->get($api, false);
if (isset($res['message']) && 'OK' == $res['message']) {
$this->code = 0;
$res['data']['abstract'] = str_replace(' ', '', str_replace(' ', '', $res['data']['abstract']));
$res['data']['content'] = str_replace(' ', '', str_replace(' ', '', $res['data']['content']));
return ['code' => $this->code, 'notice' => $res['data']];
} else {
return ['code' => $this->code, 'notice' => $res['data'], 'msg' => $res['message']];
}
}
$api = $this->base_url . '/api/data/noticelist';
$api = $this->base_url . '/api/data/noticelist?page=' . $params['page'];
$res = $curl->get($api, false);
$notice = [];
if (isset($res['message']) && 'OK' == $res['message']) {
$this->code = 0;
$notice = $res['data']['rows'];
$notices = $res['data']['rows'];
foreach ($notices as &$notice) {
$notice['abstract'] = str_replace(' ', '', str_replace(' ', '', $notice['abstract']));
}
return ['code' => $this->code, 'notice' => $notice];
$data = [
'list' => $notices,
'count' => $res['data']['count']
];
}
return ['code' => $this->code, 'notice' => $data];
}
}
\ No newline at end of file
......@@ -74,7 +74,7 @@ class WorkermanWebSocketController extends Controller
$con->transport = 'ssl';
$con->onMessage = function ($con, $data) use ($connection) {
$base_coin = [
'ETH', 'BTC', 'USDT', 'BTC'
'ETH', 'BTC', 'USDT', 'BTY'
];
$result = json_decode($data, true);
$ticker = [];
......@@ -82,12 +82,15 @@ class WorkermanWebSocketController extends Controller
foreach ($base_coin as $k => $coin) {
$explode_arr = explode($coin, $val['s']);
if (2 == count($explode_arr) && empty($explode_arr[1])) {
$ticker[$val['s']]['symbol'] = $explode_arr[0] . '/' . $coin;
$ticker[$val['s']]['close'] = (float)sprintf("%0.4f", $val['c']);
$ticker[$val['s']]['change'] = (float)sprintf("%0.4f", $val['p'] * 100);
$ticker[$val['s']]['high'] = (float)sprintf("%0.4f", $val['h']);
$ticker[$val['s']]['low'] = (float)sprintf("%0.4f", $val['l']);
$ticker[$val['s']]['vol'] = (float)sprintf("%0.4f", $val['v']);
$temp = [];
$temp['symbol'] = $explode_arr[0] . '/' . $coin;
$temp['close'] = (float)sprintf("%0.4f", $val['c']);
$temp['change'] = (float)sprintf("%0.4f", $val['p'] * 100);
$temp['high'] = (float)sprintf("%0.4f", $val['h']);
$temp['low'] = (float)sprintf("%0.4f", $val['l']);
$temp['vol'] = (float)sprintf("%0.4f", $val['v']);
array_push($ticker, $temp);
break;
}
}
}
......
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