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
3ad3580f
Commit
3ad3580f
authored
Jun 05, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上架交易所
parent
f1593aa5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
139 additions
and
0 deletions
+139
-0
NoticeController.php
api/controllers/NoticeController.php
+45
-0
CoinBusiness.php
common/business/CoinBusiness.php
+36
-0
CoinService.php
common/service/CoinService.php
+58
-0
No files found.
api/controllers/NoticeController.php
0 → 100644
View file @
3ad3580f
<?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
common/business/CoinBusiness.php
0 → 100644
View file @
3ad3580f
<?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
common/service/CoinService.php
0 → 100644
View file @
3ad3580f
<?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
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