Commit 3ad3580f authored by rlgy's avatar rlgy

上架交易所

parent f1593aa5
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-5
* Time: 上午10:27
*/
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\pwallet\Notice;
/**
* 公告控制器
* Class NoticeController
* @package api\controllers
*/
class NoticeController extends BaseController
{
/**
* 返回公告列表
*
* @var $page
* @var $limit
* @var $condition 筛选条件
*/
public function actionList()
{
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 10);
$condition = $request->post();
if (isset($condition['page'])) {
unset($condition['page']);
}
if (isset($condition['limit'])) {
unset($condition['limit']);
}
$data = Notice::getList($page, $limit, $condition);
Yii::$app->response->data = $data;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-5
* Time: 上午11:15
*/
namespace common\business;
use Yii;
use common\models\pwallet\Coin;
use common\service\CoinService;
/**
* 币种逻辑层
*
* Class CoinBusiness
* @package common\business
*/
class CoinBusiness
{
public static function getList($page = 1, $limit = 10, $condition = [])
{
$rows = Coin::getList($page, $limit, $condition);
if ($rows['count'] > 0) {
$datas = $rows['data'];
foreach ($datas as $key => $value) {
//获取交易所信息
$rows['data'][$key]['exchange'] = CoinService::exchange($value['sid']);
}
}
return $rows;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-5
* Time: 上午11:17
*/
namespace common\service;
use common\base\Exception;
use Yii;
use common\helpers\Curl;
/**
* 币种服务类
* Class CoinService
* @package common\service
*/
class CoinService
{
/**
* 爬取交易所列表,默认eos
*
* @param $name string 币种名称
* @return array
*/
public static function exchange($name = 'eos')
{
//todo 缓存数据
$key = [
__CLASS__,
__METHOD__,
'coin',//表名
$name,//sid
];
$result = Yii::$app->cache->get($key);
if ($result === false) {
$url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['coinmarket'] . $name . '/';
$ch = new Curl();
try {
$content = $ch->get($url, true);
preg_match_all("/<div class=boxContain><table class=table3 id=markets>(.*)?<\/table>/is", $content,
$matchs);
$content = $matchs[1][0];
preg_match_all('/alt=(.*?)>/is', $content, $matchs);
//匹配到了
$result = array_unique($matchs[1]);
Yii::$app->cache->set($key, $result, 180);//set caching
return ['count' => count($result), 'data' => $result];
} catch (Exception $exception) {
return ['count' => 0, 'data' => []];
}
}
return ['count' => count($result), 'data' => $result];
}
}
\ 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