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
9518c599
Commit
9518c599
authored
Jun 15, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
速度优化 后台 币种列表
parent
b5a4553b
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
98 additions
and
19 deletions
+98
-19
CoinController.php
backend/controllers/CoinController.php
+14
-2
exchange.php
backend/views/coin/exchange.php
+14
-0
index.php
backend/views/coin/index.php
+5
-8
CoinBusiness.php
common/business/CoinBusiness.php
+27
-7
main.php
common/config/main.php
+3
-0
params.php
common/config/params.php
+6
-0
CoinService.php
common/service/CoinService.php
+29
-2
No files found.
backend/controllers/CoinController.php
View file @
9518c599
...
...
@@ -148,12 +148,23 @@ class CoinController extends BaseController
if
(
$model
)
{
try
{
// $model->delete();
$this
->
success
(
'删除成功'
,
'/admin/coin/index'
,
true
);
$this
->
success
(
'删除成功'
,
'/admin/coin/index'
,
true
);
}
catch
(
\Throwable
$t
)
{
}
catch
(
\Exception
$e
)
{
}
}
}
$this
->
error
(
'删除失败'
,
Yii
::
$app
->
request
->
getReferrer
(),
true
);
$this
->
error
(
'删除失败'
,
Yii
::
$app
->
request
->
getReferrer
(),
true
);
}
public
function
actionGetExchangeListById
()
{
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
0
);
$exchanges
=
[];
if
(
$id
)
{
$exchanges
=
CoinBusiness
::
getExchangeListById
(
$id
);
}
$this
->
layout
=
false
;
return
$this
->
render
(
'exchange'
,
[
'exchanges'
=>
$exchanges
]);
}
}
\ No newline at end of file
backend/views/coin/exchange.php
0 → 100644
View file @
9518c599
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-6-15
* Time: 下午2:10
*/
/**
* @var array $exchanges
*/
?>
<?php
foreach
(
$exchanges
as
$exchange
)
:
?>
<li><a
href=
"
<?=
$exchange
[
'url'
]
?>
"
>
<?=
$exchange
[
'name'
]
?>
</a></li>
<?php
endforeach
;
?>
backend/views/coin/index.php
View file @
9518c599
...
...
@@ -102,15 +102,12 @@
table
.
on
(
'tool(table1)'
,
function
(
obj
)
{
var
data
=
obj
.
data
;
if
(
obj
.
event
===
'getExchange'
)
{
var
content
=
''
;
$
.
each
(
data
.
exchange
.
data
,
function
(
index
,
item
)
{
content
+=
'<li>'
+
item
+
'</li>'
;
});
$
.
get
(
'/admin/coin/get-exchange-list-by-id?id='
+
obj
.
data
.
id
,
{},
function
(
str
)
{
layer
.
open
({
type
:
0
,
type
:
1
,
title
:
'上架交易所列表'
,
content
:
content
,
tips
:
3
content
:
str
,
});
});
}
else
if
(
obj
.
event
==
'delete'
)
{
layer
.
confirm
(
'真的删除行么'
,
function
(
index
)
{
...
...
@@ -155,7 +152,7 @@
<
/a
>
</script>
<script
type=
"text/html"
id=
"exchangeTpl"
>
{{
d
.
exchange
.
count
}}
家
{{
d
.
exchange
}}
家
</script>
<script
type=
"text/html"
id=
"recommendTpl"
>
{{
#
if
(
d
.
recommend
==
0
){
}}
...
...
common/business/CoinBusiness.php
View file @
9518c599
...
...
@@ -29,17 +29,37 @@ 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']);
//
}
//
}
if
(
$rows
[
'count'
]
>
0
)
{
$datas
=
$rows
[
'data'
];
foreach
(
$datas
as
$key
=>
$value
)
{
//获取交易所信息
$rows
[
'data'
][
$key
][
'exchange'
]
=
CoinService
::
exchange_count
(
$value
[
'sid'
]);
}
}
return
$rows
;
}
/**
* 返回交易所列表
*
* @param $id
* @return array
*/
public
static
function
getExchangeListById
(
$id
=
0
)
{
if
(
$id
)
{
$coin
=
Coin
::
findOne
([
'id'
=>
$id
]);
if
(
$coin
)
{
$datas
=
CoinService
::
exchange
(
$coin
->
sid
);
if
(
$datas
[
'count'
]
>
0
)
{
return
$datas
[
'data'
];
}
}
}
return
[];
}
/**
* api获取行情列表
* @param int $page
* @param int $limit
...
...
common/config/main.php
View file @
9518c599
...
...
@@ -72,6 +72,9 @@ return [
'cache'
=>
[
'class'
=>
'yii\caching\FileCache'
,
],
// 'cache' => [
// 'class' => 'yii\redis\Connection',
// ],
'i18n'
=>
[
'translations'
=>
[
'*'
=>
[
...
...
common/config/params.php
View file @
9518c599
...
...
@@ -36,4 +36,10 @@ return [
'currencies'
=>
'/currencies/'
,
//币种详情
'coinmarket'
=>
'/coinmarket/'
,
//上市交易所
],
/** 爬虫数据缓存时间 */
'curl_cache_time'
=>
[
'exchange'
=>
60
*
5
,
'exchange_count'
=>
60
*
5
,
]
];
common/service/CoinService.php
View file @
9518c599
...
...
@@ -34,7 +34,7 @@ class CoinService
$name
,
//sid
];
$result
=
Yii
::
$app
->
cache
->
get
(
$key
);
if
(
$result
===
false
||
YII_ENV_DEV
)
{
if
(
$result
===
false
)
{
$url
=
Yii
::
$app
->
params
[
'feixiaohao_domain'
]
.
Yii
::
$app
->
params
[
'feixiaohao_page'
][
'coinmarket'
]
.
$name
.
'/'
;
$ch
=
new
Curl
();
try
{
...
...
@@ -64,7 +64,7 @@ class CoinService
}
}
unset
(
$content
,
$i
,
$r
,
$url
,
$matchs2
);
Yii
::
$app
->
cache
->
set
(
$key
,
$result
,
180
);
//set caching
Yii
::
$app
->
cache
->
set
(
$key
,
$result
,
Yii
::
$app
->
params
[
'curl_cache_time'
][
'exchange'
]
);
//set caching
return
[
'count'
=>
count
(
$result
),
'data'
=>
$result
];
}
catch
(
\Exception
$exception
)
{
return
[
'count'
=>
0
,
'data'
=>
[]];
...
...
@@ -80,6 +80,33 @@ class CoinService
*/
public
static
function
exchange_count
(
$sid
=
'eos'
)
{
$key
=
[
__CLASS__
,
__METHOD__
,
'coin'
,
//表名
$sid
,
//sid
];
$result
=
Yii
::
$app
->
cache
->
get
(
$key
);
if
(
!
$result
)
{
$url
=
Yii
::
$app
->
params
[
'feixiaohao_domain'
]
.
Yii
::
$app
->
params
[
'feixiaohao_page'
][
'coinmarket'
]
.
$sid
.
'/'
;
$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
]);
$result
=
count
(
$result
);
unset
(
$content
,
$matchs2
);
Yii
::
$app
->
cache
->
set
(
$key
,
$result
,
Yii
::
$app
->
params
[
'curl_cache_time'
][
'exchange_count'
]);
//set caching
}
catch
(
\Exception
$exception
)
{
}
}
return
$result
;
}
/**
...
...
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