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
cdab42c9
Commit
cdab42c9
authored
Jun 11, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推介币种
parent
0ea1024d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
119 additions
and
66 deletions
+119
-66
CoinController.php
api/controllers/CoinController.php
+6
-1
CoinController.php
backend/controllers/CoinController.php
+8
-7
form.php
backend/views/coin/form.php
+12
-0
index.php
backend/views/coin/index.php
+21
-2
CoinBusiness.php
common/business/CoinBusiness.php
+1
-1
Coin.php
common/models/pwallet/Coin.php
+1
-1
MinerFee.php
common/models/pwallet/MinerFee.php
+4
-0
CoinService.php
common/service/CoinService.php
+66
-54
No files found.
api/controllers/CoinController.php
View file @
cdab42c9
...
@@ -86,7 +86,12 @@ class CoinController extends BaseController
...
@@ -86,7 +86,12 @@ class CoinController extends BaseController
*/
*/
public
function
actionGetRecList
()
public
function
actionGetRecList
()
{
{
//todo 推介币种列表
$request
=
Yii
::
$app
->
request
;
$page
=
$request
->
post
(
'page'
,
1
);
$limit
=
$request
->
post
(
'limit'
,
999
);
$condition
=
[[
'recommend'
=>
'1'
]];
$data
=
CoinBusiness
::
getApiList
(
$page
,
$limit
,
$condition
);
Yii
::
$app
->
response
->
data
=
$data
;
}
}
/**
/**
...
...
backend/controllers/CoinController.php
View file @
cdab42c9
...
@@ -11,8 +11,6 @@ namespace backend\controllers;
...
@@ -11,8 +11,6 @@ namespace backend\controllers;
use
Yii
;
use
Yii
;
use
common\models\pwallet\Coin
;
use
common\models\pwallet\Coin
;
use
backend\models\coin\CoinForm
;
use
backend\models\coin\CoinForm
;
use
yii\base\InvalidConfigException
;
use
yii\db\Exception
;
use
yii\web\UploadedFile
;
use
yii\web\UploadedFile
;
use
yii\validators\ImageValidator
;
use
yii\validators\ImageValidator
;
use
common\business\CoinBusiness
;
use
common\business\CoinBusiness
;
...
@@ -31,14 +29,19 @@ class CoinController extends BaseController
...
@@ -31,14 +29,19 @@ class CoinController extends BaseController
$page
=
$request
->
get
(
'page'
,
1
);
$page
=
$request
->
get
(
'page'
,
1
);
$limit
=
$request
->
get
(
'limit'
,
10
);
$limit
=
$request
->
get
(
'limit'
,
10
);
$name
=
$request
->
get
(
'name'
,
null
);
$name
=
$request
->
get
(
'name'
,
null
);
$platform
=
$request
->
get
(
'platform'
,
null
);
$platform
=
$request
->
get
(
'platform'
,
'all'
);
$recommend
=
$request
->
get
(
'recommend'
,
'all'
);
$condition
=
[];
$condition
=
[];
if
(
$name
)
{
if
(
$name
)
{
$condition
[]
=
[
'like'
,
'name'
,
$name
];
$condition
[]
=
[
'like'
,
'name'
,
$name
];
}
}
if
(
$platform
)
{
if
(
$platform
!=
'all'
)
{
$condition
[]
=
[
'platform'
=>
$platform
];
$condition
[]
=
[
'platform'
=>
$platform
];
}
}
if
(
$recommend
!=
'all'
)
{
$recommend
=
$recommend
?
1
:
0
;
$condition
[]
=
[
'recommend'
=>
$recommend
];
}
$data
=
CoinBusiness
::
getList
(
$page
,
$limit
,
$condition
);
$data
=
CoinBusiness
::
getList
(
$page
,
$limit
,
$condition
);
$data
[
'code'
]
=
0
;
$data
[
'code'
]
=
0
;
//ajax return
//ajax return
...
@@ -131,9 +134,7 @@ class CoinController extends BaseController
...
@@ -131,9 +134,7 @@ class CoinController extends BaseController
return
[
'code'
=>
0
,
'data'
=>
[
'src'
=>
$src
]];
return
[
'code'
=>
0
,
'data'
=>
[
'src'
=>
$src
]];
}
}
}
}
}
catch
(
InvalidConfigException
$e
)
{
}
catch
(
\Exception
$exception
)
{
}
catch
(
Exception
$exception
)
{
return
[
'code'
=>
$exception
->
getCode
(),
'msg'
=>
$exception
->
getMessage
()];
return
[
'code'
=>
$exception
->
getCode
(),
'msg'
=>
$exception
->
getMessage
()];
}
}
}
}
...
...
backend/views/coin/form.php
View file @
cdab42c9
...
@@ -57,6 +57,15 @@
...
@@ -57,6 +57,15 @@
</div>
</div>
</div>
</div>
<div
class=
"layui-form-item"
>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
推介该币种
</label>
<div
class=
"layui-input-block"
>
<select
name=
"recommend"
>
<option
value=
"0"
>
否
</option>
<option
value=
"1"
>
是
</option>
</select>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
区块查询
</label>
<label
class=
"layui-form-label"
>
区块查询
</label>
<div
class=
"layui-input-block"
>
<div
class=
"layui-input-block"
>
<input
type=
"text"
class=
"layui-input"
value=
""
name=
"area_search"
>
<input
type=
"text"
class=
"layui-input"
value=
""
name=
"area_search"
>
...
@@ -127,4 +136,7 @@
...
@@ -127,4 +136,7 @@
}
}
});
});
//form render
var
form
=
layui
.
form
;
form
.
render
();
</script>
</script>
backend/views/coin/index.php
View file @
cdab42c9
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
<button
class=
"layui-btn layui-btn-default"
id=
"add"
>
添加币种
</button>
<button
class=
"layui-btn layui-btn-default"
id=
"add"
>
添加币种
</button>
</a>
</a>
</div>
</div>
<div
class=
"layui-col-md
6
"
>
<div
class=
"layui-col-md
8
"
>
<form
class=
"layui-form"
method=
"get"
action=
""
>
<form
class=
"layui-form"
method=
"get"
action=
""
>
<div
class=
"layui-inline"
>
<div
class=
"layui-inline"
>
<label
class=
"layui-form-label"
style=
"margin-bottom: 0; width: 100px;"
>
币种名称
</label>
<label
class=
"layui-form-label"
style=
"margin-bottom: 0; width: 100px;"
>
币种名称
</label>
...
@@ -31,12 +31,22 @@
...
@@ -31,12 +31,22 @@
<label
class=
"layui-form-label"
style=
"margin-bottom: 0; width: 100px;"
>
平台
</label>
<label
class=
"layui-form-label"
style=
"margin-bottom: 0; width: 100px;"
>
平台
</label>
<div
class=
"layui-input-inline"
>
<div
class=
"layui-input-inline"
>
<select
name=
"platform"
>
<select
name=
"platform"
>
<option
>
all
</option>
<option
value=
"all"
>
全部
</option>
<option
value=
"ethereum"
>
eth
</option>
<option
value=
"ethereum"
>
eth
</option>
</select>
</select>
</div>
</div>
</div>
</div>
<div
class=
"layui-inline"
>
<div
class=
"layui-inline"
>
<label
class=
"layui-form-label"
style=
"margin-bottom: 0; width: 100px;"
>
推介币种
</label>
<div
class=
"layui-input-inline"
>
<select
name=
"recommend"
>
<option
value=
"all"
>
全部
</option>
<option
value=
"0"
>
否
</option>
<option
value=
"1"
>
是
</option>
</select>
</div>
</div>
<div
class=
"layui-inline"
>
<button
class=
"layui-btn"
lay-submit
lay-filter=
"form1"
>
搜索
</button>
<button
class=
"layui-btn"
lay-submit
lay-filter=
"form1"
>
搜索
</button>
</div>
</div>
</form>
</form>
...
@@ -74,6 +84,7 @@
...
@@ -74,6 +84,7 @@
},
},
{
field
:
'price'
,
title
:
'众筹价格'
},
{
field
:
'price'
,
title
:
'众筹价格'
},
{
field
:
'release'
,
title
:
'发行时间'
},
{
field
:
'release'
,
title
:
'发行时间'
},
{
field
:
'recommend'
,
title
:
'推介该币种'
,
templet
:
"#recommendTpl"
},
{
field
:
'id'
,
title
:
'操作'
,
templet
:
'#operationTpl'
}
{
field
:
'id'
,
title
:
'操作'
,
templet
:
'#operationTpl'
}
]]
]]
})
})
...
@@ -131,4 +142,11 @@
...
@@ -131,4 +142,11 @@
</script>
</script>
<script
type=
"text/html"
id=
"exchangeTpl"
>
<script
type=
"text/html"
id=
"exchangeTpl"
>
{{
d
.
exchange
.
count
}}
家
{{
d
.
exchange
.
count
}}
家
</script>
<script
type=
"text/html"
id=
"recommendTpl"
>
{{
#
if
(
d
.
recommend
==
0
){
}}
否
{{
#
}
else
{
}}
是
{{
#
}
}}
</script>
</script>
\ No newline at end of file
common/business/CoinBusiness.php
View file @
cdab42c9
...
@@ -52,7 +52,7 @@ class CoinBusiness
...
@@ -52,7 +52,7 @@ class CoinBusiness
if
(
$rows
[
'count'
]
>
0
)
{
if
(
$rows
[
'count'
]
>
0
)
{
$datas
=
$rows
[
'data'
];
$datas
=
$rows
[
'data'
];
foreach
(
$datas
as
$key
=>
$value
)
{
foreach
(
$datas
as
$key
=>
$value
)
{
//获取
交易所
信息
//获取
行情
信息
$rows
[
'data'
][
$key
][
'quotation'
]
=
CoinService
::
quotation
(
$value
[
'sid'
]);
$rows
[
'data'
][
$key
][
'quotation'
]
=
CoinService
::
quotation
(
$value
[
'sid'
]);
}
}
}
}
...
...
common/models/pwallet/Coin.php
View file @
cdab42c9
...
@@ -44,7 +44,7 @@ class Coin extends BaseActiveRecord
...
@@ -44,7 +44,7 @@ class Coin extends BaseActiveRecord
{
{
$query
=
self
::
find
();
$query
=
self
::
find
();
foreach
(
$condition
as
$item
)
{
foreach
(
$condition
as
$item
)
{
$query
=
$query
->
and
Filter
Where
(
$item
);
$query
=
$query
->
andWhere
(
$item
);
}
}
$count
=
$query
->
count
();
$count
=
$query
->
count
();
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
...
...
common/models/pwallet/MinerFee.php
View file @
cdab42c9
...
@@ -13,6 +13,10 @@ use common\core\BaseActiveRecord;
...
@@ -13,6 +13,10 @@ use common\core\BaseActiveRecord;
class
MinerFee
extends
BaseActiveRecord
class
MinerFee
extends
BaseActiveRecord
{
{
/**
* @return null|object|\yii\db\Connection
* @throws \yii\base\InvalidConfigException
*/
public
static
function
getDb
()
public
static
function
getDb
()
{
{
return
Yii
::
$app
->
get
(
'db_pwallet'
);
return
Yii
::
$app
->
get
(
'db_pwallet'
);
...
...
common/service/CoinService.php
View file @
cdab42c9
...
@@ -8,10 +8,8 @@
...
@@ -8,10 +8,8 @@
namespace
common\service
;
namespace
common\service
;
use
common\base\Exception
;
use
Yii
;
use
Yii
;
use
common\helpers\Curl
;
use
common\helpers\Curl
;
use
yii\base\ErrorException
;
/**
/**
* 币种服务类
* 币种服务类
...
@@ -49,7 +47,7 @@ class CoinService
...
@@ -49,7 +47,7 @@ class CoinService
$result
=
array_unique
(
$matchs
[
1
]);
$result
=
array_unique
(
$matchs
[
1
]);
Yii
::
$app
->
cache
->
set
(
$key
,
$result
,
180
);
//set caching
Yii
::
$app
->
cache
->
set
(
$key
,
$result
,
180
);
//set caching
return
[
'count'
=>
count
(
$result
),
'data'
=>
$result
];
return
[
'count'
=>
count
(
$result
),
'data'
=>
$result
];
}
catch
(
Exception
$exception
)
{
}
catch
(
\
Exception
$exception
)
{
return
[
'count'
=>
0
,
'data'
=>
[]];
return
[
'count'
=>
0
,
'data'
=>
[]];
}
}
}
}
...
@@ -64,63 +62,76 @@ class CoinService
...
@@ -64,63 +62,76 @@ class CoinService
*/
*/
public
static
function
quotation
(
$sid
=
'eos'
)
public
static
function
quotation
(
$sid
=
'eos'
)
{
{
$url
=
Yii
::
$app
->
params
[
'feixiaohao_domain'
]
.
Yii
::
$app
->
params
[
'feixiaohao_page'
][
'currencies'
]
.
$sid
.
'/'
;
//使用缓存
$ch
=
new
Curl
();
$key
=
[
try
{
__CLASS__
,
$content
=
$ch
->
get
(
$url
,
true
);
__METHOD__
,
$result
=
[
'coin'
,
//表名
'price'
=>
''
,
//价格
$sid
,
//sid
'dollar'
=>
''
,
//价格美元
];
'btc'
=>
''
,
//价格btc
$result
=
Yii
::
$app
->
cache
->
get
(
$key
);
'high'
=>
''
,
//最高价
if
(
$result
===
false
)
{
'low'
=>
''
,
//最低价
$url
=
Yii
::
$app
->
params
[
'feixiaohao_domain'
]
.
Yii
::
$app
->
params
[
'feixiaohao_page'
][
'currencies'
]
.
$sid
.
'/'
;
'change'
=>
''
,
//涨幅(跌幅)
$ch
=
new
Curl
();
'rank'
=>
''
,
//流通市值排名
try
{
'circulate_value_rmb'
=>
''
,
//流通市值人民币
$content
=
$ch
->
get
(
$url
,
true
);
'circulate_value_usd'
=>
''
,
//流通市值美元
$result
=
[
'circulate_value_btc'
=>
''
,
//流通市值btc
'price'
=>
''
,
//价格
'publish_count'
=>
''
,
//发行总量
'dollar'
=>
''
,
//价格美元
'circulate_count'
=>
''
,
//流通总量
'btc'
=>
''
,
//价格btc
];
'high'
=>
''
,
//最高价
'low'
=>
''
,
//最低价
'change'
=>
''
,
//涨幅(跌幅)
'rank'
=>
''
,
//流通市值排名
'circulate_value_rmb'
=>
''
,
//流通市值人民币
'circulate_value_usd'
=>
''
,
//流通市值美元
'circulate_value_btc'
=>
''
,
//流通市值btc
'publish_count'
=>
''
,
//发行总量
'circulate_count'
=>
''
,
//流通总量
];
//价格与涨幅
//价格与涨幅
$pattern
=
'/<div class=coinprice>(.*?)<span class=(tags-red|tags-green)>(.*?)<\/span><\/div>/is'
;
$pattern
=
'/<div class=coinprice>(.*?)<span class=(tags-red|tags-green)>(.*?)<\/span><\/div>/is'
;
preg_match_all
(
$pattern
,
$content
,
$matchs
,
PREG_SET_ORDER
);
preg_match_all
(
$pattern
,
$content
,
$matchs
,
PREG_SET_ORDER
);
$result
[
'price'
]
=
$matchs
[
0
][
1
];
$result
[
'price'
]
=
$matchs
[
0
][
1
];
$result
[
'change'
]
=
$matchs
[
0
][
3
];
$result
[
'change'
]
=
$matchs
[
0
][
3
];
//最高最低值
//最高最低值
preg_match_all
(
'/<div class=lowHeight>(.*?)<\/div><div class=sub>/is'
,
$content
,
$matchs
);
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
);
preg_match_all
(
'/<span class=value>(.*?)<\/span>/is'
,
$matchs
[
1
][
0
],
$matchs
);
$result
[
'high'
]
=
$matchs
[
1
][
0
];
$result
[
'high'
]
=
$matchs
[
1
][
0
];
$result
[
'low'
]
=
$matchs
[
1
][
1
];
$result
[
'low'
]
=
$matchs
[
1
][
1
];
//美元 btc
//美元 btc
preg_match_all
(
'/<div class=sub><span>(.*?)<\/span>(.*?)<span>(.*?)<\/span><\/div>/is'
,
$content
,
$matchs
,
preg_match_all
(
'/<div class=sub><span>(.*?)<\/span>(.*?)<span>(.*?)<\/span><\/div>/is'
,
$content
,
PREG_SET_ORDER
);
$matchs
,
$result
[
'dollar'
]
=
$matchs
[
0
][
1
];
PREG_SET_ORDER
);
$result
[
'btc'
]
=
$matchs
[
0
][
3
];
$result
[
'dollar'
]
=
$matchs
[
0
][
1
];
$result
[
'btc'
]
=
$matchs
[
0
][
3
];
//爬取市值与排名
//爬取市值与排名
$pattern
=
'/<div class=value>(.*?)<span class=tag-marketcap>(.*?)<\/span><\/div><div class=sub>(.*?)<\/div><div class=sub>(.*?)<\/div>/is'
;
$pattern
=
'/<div class=value>(.*?)<span class=tag-marketcap>(.*?)<\/span><\/div><div class=sub>(.*?)<\/div><div class=sub>(.*?)<\/div>/is'
;
preg_match_all
(
$pattern
,
$content
,
$matches
,
PREG_SET_ORDER
);
preg_match_all
(
$pattern
,
$content
,
$matches
,
PREG_SET_ORDER
);
$result
[
'circulate_value_rmb'
]
=
$matches
[
0
][
1
];
$result
[
'circulate_value_rmb'
]
=
$matches
[
0
][
1
];
$result
[
'rank'
]
=
$matches
[
0
][
2
];
$result
[
'rank'
]
=
$matches
[
0
][
2
];
$result
[
'circulate_value_usd'
]
=
$matches
[
0
][
3
];
$result
[
'circulate_value_usd'
]
=
$matches
[
0
][
3
];
$result
[
'circulate_value_btc'
]
=
$matches
[
0
][
4
];
$result
[
'circulate_value_btc'
]
=
$matches
[
0
][
4
];
//爬取流通总量,发行总量
//爬取流通总量,发行总量
$pattern
=
'/<div class=tit>流通量<\/div><div class=value>(.*?)<\/div><div class=tit>总发行量<\/div><div class=value>(.*?)<\/div>/is'
;
$pattern
=
'/<div class=tit>流通量<\/div><div class=value>(.*?)<\/div><div class=tit>总发行量<\/div><div class=value>(.*?)<\/div>/is'
;
preg_match_all
(
$pattern
,
$content
,
$matches
,
PREG_SET_ORDER
);
preg_match_all
(
$pattern
,
$content
,
$matches
,
PREG_SET_ORDER
);
$result
[
'circulate_count'
]
=
$matches
[
0
][
1
];
$result
[
'circulate_count'
]
=
$matches
[
0
][
1
];
$result
[
'publish_count'
]
=
$matches
[
0
][
2
];
$result
[
'publish_count'
]
=
$matches
[
0
][
2
];
$result
=
array_map
(
function
(
$value
)
{
$result
=
array_map
(
function
(
$value
)
{
return
trim
(
$value
);
return
trim
(
$value
);
},
$result
);
},
$result
);
return
$result
;
Yii
::
$app
->
cache
->
set
(
$key
,
$result
,
60
);
//set cache
}
catch
(
Exception
$exception
)
{
return
$result
;
return
false
;
}
catch
(
\Exception
$exception
)
{
return
false
;
}
}
}
return
$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