Commit 61885b6f authored by rlgy's avatar rlgy

矿池奖励

parent a4f58681
...@@ -4,4 +4,8 @@ ...@@ -4,4 +4,8 @@
* User: rlgyzhcn * User: rlgyzhcn
* Date: 18-5-31 * Date: 18-5-31
* Time: 上午10:27 * Time: 上午10:27
*/ */
\ No newline at end of file
return [
];
\ No newline at end of file
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
*/ */
$params = array_merge( $params = array_merge(
require __DIR__ . '/../../common/config/params.php',
require __DIR__ . '/../../common/config/params-local.php',
require __DIR__ . '/params.php', require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php' require __DIR__ . '/params-local.php'
); );
......
...@@ -4,4 +4,8 @@ ...@@ -4,4 +4,8 @@
* User: rlgyzhcn * User: rlgyzhcn
* Date: 18-5-31 * Date: 18-5-31
* Time: 上午10:31 * Time: 上午10:31
*/ */
\ No newline at end of file
return [
];
\ No newline at end of file
...@@ -4,4 +4,13 @@ ...@@ -4,4 +4,13 @@
* User: rlgyzhcn * User: rlgyzhcn
* Date: 18-5-31 * Date: 18-5-31
* Time: 上午10:31 * Time: 上午10:31
*/ */
\ No newline at end of file
return [
'feixiaohao_domain' => 'https://www.feixiaohao.com',
'feixiaohao_page' => [
'assets' => '/assets/',//代币
'currencies' => '/currencies/',//币种详情
'coinmarket' => '/coinmarket/',//上市交易所
],
];
\ No newline at end of file
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
namespace api\controllers; namespace api\controllers;
use api\base\BaseController;
use common\models\pwallet\Coin;
use Yii; use Yii;
use api\base\BaseController;
use common\business\CoinBusiness;
/** /**
* 币种信息管理控制器 * 币种信息管理控制器
...@@ -44,11 +44,44 @@ class CoinController extends BaseController ...@@ -44,11 +44,44 @@ class CoinController extends BaseController
public function actionQuotationList() public function actionQuotationList()
{ {
$request = Yii::$app->request; $request = Yii::$app->request;
$id = $request->post('id', null);
$name = $request->post('name', null);
$page = $request->post('page', 1); $page = $request->post('page', 1);
$limit = $request->post('limit', 10); $limit = $request->post('limit', 10);
$condition = ['id' => $id, 'name' => $name]; $condition = [];
$post = $request->post();
//过滤字段
$post = array_filter($post, function ($item, $key) {
if ($key == 'id' && is_numeric($item)) {
return true;
}
return $key;
}, ARRAY_FILTER_USE_BOTH);
//id筛选
if (isset($post['id'])) {
if (is_array($post['id'])) {
$condition[] = ['in', 'id', $post['id']];
} elseif (is_numeric($post['id'])) {
$condition[] = ['id' => $post['id']];
}
}
//名称模糊查询
if (isset($post['name'])) {
$condition[] = ['like', 'name', $post['name']];
}
//昵称模糊查询
if (isset($post['nickname'])) {
$condition[] = ['like', 'nickname', $post['nickname']];
}
//平台saixuan
if (isset($post['platform'])) {
$condition[] = ['platform' => $post['platform']];
}
$data = CoinBusiness::getApiList($page, $limit, $condition);
Yii::$app->response->data = $data;
} }
} }
\ No newline at end of file
...@@ -20,6 +20,13 @@ use common\service\CoinService; ...@@ -20,6 +20,13 @@ use common\service\CoinService;
*/ */
class CoinBusiness class CoinBusiness
{ {
/**
* 管理员后台获取币种列表
* @param int $page
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord[]
*/
public static function getList($page = 1, $limit = 10, $condition = []) public static function getList($page = 1, $limit = 10, $condition = [])
{ {
$rows = Coin::getList($page, $limit, $condition); $rows = Coin::getList($page, $limit, $condition);
...@@ -32,4 +39,23 @@ class CoinBusiness ...@@ -32,4 +39,23 @@ class CoinBusiness
} }
return $rows; return $rows;
} }
/**
* api获取行情列表
* @param int $page
* @param int $limit
* @param array $condition
*/
public static function getApiList($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]['quotation'] = CoinService::quotation($value['sid']);
}
}
return $rows;
}
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ namespace common\service; ...@@ -11,6 +11,7 @@ namespace common\service;
use common\base\Exception; use common\base\Exception;
use Yii; use Yii;
use common\helpers\Curl; use common\helpers\Curl;
use yii\base\ErrorException;
/** /**
* 币种服务类 * 币种服务类
...@@ -27,7 +28,7 @@ class CoinService ...@@ -27,7 +28,7 @@ class CoinService
*/ */
public static function exchange($name = 'eos') public static function exchange($name = 'eos')
{ {
//todo 缓存数据 //缓存数据
$key = [ $key = [
__CLASS__, __CLASS__,
__METHOD__, __METHOD__,
...@@ -54,4 +55,44 @@ class CoinService ...@@ -54,4 +55,44 @@ class CoinService
} }
return ['count' => count($result), 'data' => $result]; return ['count' => count($result), 'data' => $result];
} }
/**
* 爬取币种的实时行情,默认eos
* @param string $sid
*/
public static function quotation($sid = 'eos')
{
$url = Yii::$app->params['feixiaohao_domain'] . Yii::$app->params['feixiaohao_page']['currencies'] . $sid . '/';
$ch = new Curl();
try {
$content = $ch->get($url, true);
//价格 价格美元 价格btc 最高价 最低价 涨幅(跌幅)
$result = ['price' => '', 'dollar' => '', 'btc' => '', 'high' => '', 'low' => '', 'change' => ''];
//价格与涨幅
//价格与涨幅
$pattern = '/<div class=coinprice>(.*?)<span class=(tags-red|tags-green)>(.*?)<\/span><\/div>/is';
preg_match_all($pattern, $content, $matchs, PREG_SET_ORDER);
$result['price'] = $matchs[0][1];
$result['change'] = $matchs[0][3];
//最高最低值
preg_match_all('/<div class=lowHeight>(.*?)<\/div><div class=sub>/is', $content, $matchs);
preg_match_all('/<span class=value>(.*?)<\/span>/is', $matchs[1][0], $matchs);
$result['high'] = $matchs[1][0];
$result['low'] = $matchs[1][1];
//美元 btc
preg_match_all('/<div class=sub><span>(.*?)<\/span>(.*?)<span>(.*?)<\/span><\/div>/is', $content, $matchs,
PREG_SET_ORDER);
$result['dollar'] = $matchs[0][1];
$result['btc'] = $matchs[0][3];
$result = array_map(function ($value) {
return trim($value);
}, $result);
return $result;
} catch (Exception $exception) {
return false;
}
}
} }
\ 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