Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
61885b6f
Commit
61885b6f
authored
Jun 05, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
矿池奖励
parent
a4f58681
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
135 additions
and
13 deletions
+135
-13
main-local.php
api/config/main-local.php
+6
-2
main.php
api/config/main.php
+2
-0
params-local.php
api/config/params-local.php
+6
-2
params.php
api/config/params.php
+11
-2
CoinController.php
api/controllers/CoinController.php
+40
-6
CoinBusiness.php
common/business/CoinBusiness.php
+27
-0
CoinService.php
common/service/CoinService.php
+43
-1
No files found.
api/config/main-local.php
View file @
61885b6f
...
...
@@ -4,4 +4,8 @@
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午10:27
*/
\ No newline at end of file
*/
return
[
];
\ No newline at end of file
api/config/main.php
View file @
61885b6f
...
...
@@ -7,6 +7,8 @@
*/
$params
=
array_merge
(
require
__DIR__
.
'/../../common/config/params.php'
,
require
__DIR__
.
'/../../common/config/params-local.php'
,
require
__DIR__
.
'/params.php'
,
require
__DIR__
.
'/params-local.php'
);
...
...
api/config/params-local.php
View file @
61885b6f
...
...
@@ -4,4 +4,8 @@
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午10:31
*/
\ No newline at end of file
*/
return
[
];
\ No newline at end of file
api/config/params.php
View file @
61885b6f
...
...
@@ -4,4 +4,13 @@
* User: rlgyzhcn
* Date: 18-5-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
api/controllers/CoinController.php
View file @
61885b6f
...
...
@@ -8,9 +8,9 @@
namespace
api\controllers
;
use
api\base\BaseController
;
use
common\models\pwallet\Coin
;
use
Yii
;
use
api\base\BaseController
;
use
common\business\CoinBusiness
;
/**
* 币种信息管理控制器
...
...
@@ -44,11 +44,44 @@ class CoinController extends BaseController
public
function
actionQuotationList
()
{
$request
=
Yii
::
$app
->
request
;
$id
=
$request
->
post
(
'id'
,
null
);
$name
=
$request
->
post
(
'name'
,
null
);
$page
=
$request
->
post
(
'page'
,
1
);
$limit
=
$request
->
post
(
'limit'
,
10
);
$condition
=
[
'id'
=>
$id
,
'name'
=>
$name
];
$limit
=
$request
->
post
(
'limit'
,
10
);
$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
common/business/CoinBusiness.php
View file @
61885b6f
...
...
@@ -20,6 +20,13 @@ use common\service\CoinService;
*/
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
=
[])
{
$rows
=
Coin
::
getList
(
$page
,
$limit
,
$condition
);
...
...
@@ -32,4 +39,23 @@ class CoinBusiness
}
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
common/service/CoinService.php
View file @
61885b6f
...
...
@@ -11,6 +11,7 @@ namespace common\service;
use
common\base\Exception
;
use
Yii
;
use
common\helpers\Curl
;
use
yii\base\ErrorException
;
/**
* 币种服务类
...
...
@@ -27,7 +28,7 @@ class CoinService
*/
public
static
function
exchange
(
$name
=
'eos'
)
{
//
todo
缓存数据
//缓存数据
$key
=
[
__CLASS__
,
__METHOD__
,
...
...
@@ -54,4 +55,44 @@ class CoinService
}
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment