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
fa7d82c0
Commit
fa7d82c0
authored
Sep 12, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推荐币种
parent
eaa2e923
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
671 additions
and
104 deletions
+671
-104
CoinController.php
api/controllers/CoinController.php
+63
-36
CoreAsset.php
backend/assets/CoreAsset.php
+2
-2
JqueryAsset.php
backend/assets/JqueryAsset.php
+11
-11
LayoutAsset.php
backend/assets/LayoutAsset.php
+2
-2
IndexAsset.php
backend/assets/coin/IndexAsset.php
+3
-1
CoinRecommendController.php
backend/controllers/CoinRecommendController.php
+105
-0
index.php
backend/views/coin-recommend/index.php
+256
-0
add.php
backend/views/coin/add.php
+3
-11
edit.php
backend/views/coin/edit.php
+0
-19
main.php
backend/views/layouts/main.php
+12
-10
ExchangeBusiness.php
common/business/ExchangeBusiness.php
+28
-0
BaseActiveRecord.php
common/models/psources/BaseActiveRecord.php
+19
-0
Coin.php
common/models/psources/Coin.php
+38
-12
CoinPlatform.php
common/models/psources/CoinPlatform.php
+17
-0
CoinRecommend.php
common/models/psources/CoinRecommend.php
+112
-0
No files found.
api/controllers/CoinController.php
View file @
fa7d82c0
...
...
@@ -8,13 +8,14 @@
namespace
api\controllers
;
use
Yii
;
use
common\base\Exception
;
use
api\base\BaseController
;
use
common\models\psources\Coin
;
use
common\base\Exception
;
use
common\business\BrowerBusiness
;
use
common\business\CoinBusiness
;
use
common\business\ExchangeBusiness
;
use
common\business\BrowerBusiness
;
use
common\models\psources\Coin
;
use
common\models\psources\CoinRecommend
;
use
Yii
;
/**
* 币种信息管理控制器
...
...
@@ -45,31 +46,58 @@ class CoinController extends BaseController
*/
public
function
actionGetRecList
()
{
$request
=
Yii
::
$app
->
request
;
$page
=
$request
->
post
(
'page'
,
1
);
$limit
=
$request
->
post
(
'limit'
,
999
);
$platform_ids
=
$request
->
post
(
'platform_id'
,
null
);
$condition
=
[[
'>'
,
'recommend'
,
'0'
]];
if
(
$platform_ids
)
{
$platform_id_arr
=
explode
(
','
,
$platform_ids
);
$condition_arr
=
[
'OR'
];
foreach
(
$platform_id_arr
as
$key
=>
$value
)
{
array_push
(
$condition_arr
,
[
'>'
,
"find_in_set(
$value
, [[platform_id]])"
,
0
]);
}
$condition
[]
=
$condition_arr
;
$request
=
Yii
::
$app
->
request
;
$page
=
$request
->
post
(
'page'
,
1
);
$limit
=
$request
->
post
(
'limit'
,
999
);
$platform_id
=
$request
->
post
(
'platform_id'
,
1
);
$recommend
=
$request
->
post
(
'recommend'
,
''
);
$condition
=
[
'platform_id'
=>
$platform_id
];
if
(
$recommend
)
{
$condition
[
'recommend'
]
=
$recommend
;
}
$result
=
ExchangeBusiness
::
getApiListForIndex
(
$page
,
$limit
,
$condition
);
if
(
$result
)
{
$chains
=
array_unique
(
array_column
(
$result
[
'data'
],
'chain'
));
$chain_quotation
=
[];
foreach
(
$chains
as
$key
=>
$value
)
{
$chain_quotation
[
$value
]
=
ExchangeBusiness
::
getquatation
(
$value
);
}
foreach
(
$result
[
'data'
]
as
$key
=>
&
$value
)
{
$value
[
'chain_quotation'
]
=
$chain_quotation
[
$value
[
'chain'
]];
$select
=
[
'id'
,
'sid'
,
'icon'
,
'name'
,
'nickname'
,
'platform'
,
'chain'
];
$datas
=
CoinRecommend
::
getList
(
$page
,
$limit
,
$condition
,
[],
$select
);
//获取详细信息
$coin_recommends
=
&
$datas
[
'data'
];
if
(
!
empty
(
$coin_recommends
))
{
$coin_ids
=
array_column
(
$coin_recommends
,
'cid'
);
//获取币种信息
$coin_infos
=
Coin
::
getCoinInfoByIds
(
$coin_ids
,
$select
,
'id'
);
//获取行情信息
$coin_names
=
array_column
(
$coin_infos
,
'name'
);
$coin_names
=
array_merge
(
$coin_names
,
array_column
(
$coin_infos
,
'chain'
));
$coin_quotations
=
ExchangeBusiness
::
getQuatationByNames
(
$coin_names
);
if
(
$coin_infos
)
{
array_shift
(
$select
);
foreach
(
$coin_recommends
as
$key
=>
&
$value
)
{
$temp_key
=
$coin_infos
[
$value
[
'cid'
]][
'name'
];
foreach
(
$select
as
$item
)
{
$value
[
$item
]
=
$coin_infos
[
$value
[
'cid'
]][
$item
];
if
(
$value
[
'platform_id'
]
!=
2
)
{
//国盾币不需要行情
$value
[
'low'
]
=
$coin_quotations
[
$temp_key
][
'low'
];
$value
[
'high'
]
=
$coin_quotations
[
$temp_key
][
'high'
];
$value
[
'last'
]
=
$coin_quotations
[
$temp_key
][
'last'
];
$value
[
'rmb'
]
=
$coin_quotations
[
$temp_key
][
'rmb'
];
}
else
{
$value
[
'low'
]
=
0
;
$value
[
'high'
]
=
0
;
$value
[
'last'
]
=
0
;
$value
[
'rmb'
]
=
0
;
}
}
$value
[
'id'
]
=
$value
[
'cid'
];
$value
[
'sid'
]
=
ucfirst
(
$value
[
'sid'
]);
$value
[
'chain_quotation'
]
=
$coin_quotations
[
$coin_infos
[
$value
[
'cid'
]][
'chain'
]];
unset
(
$value
[
'create_time'
],
$value
[
'update_time'
],
$value
[
'cid'
]);
}
unset
(
$key
,
$value
);
}
return
$result
;
}
return
$datas
;
}
/**
...
...
@@ -91,9 +119,9 @@ class CoinController extends BaseController
//如果coin为null,$coin->minerFee会抛出Trying to get property 'minerFee' of non-object",code=>8
throw
new
Exception
(
'8'
,
'币种不存在'
);
}
$result
=
(
array
)
$miner_fee
->
getAttributes
();
$result
[
'min'
]
=
(
float
)
$result
[
'min'
];
$result
[
'max'
]
=
(
float
)
$result
[
'max'
];
$result
=
(
array
)
$miner_fee
->
getAttributes
();
$result
[
'min'
]
=
(
float
)
$result
[
'min'
];
$result
[
'max'
]
=
(
float
)
$result
[
'max'
];
return
$result
;
}
...
...
@@ -124,10 +152,10 @@ class CoinController extends BaseController
*/
public
function
actionSearchCoinByName
()
{
$request
=
Yii
::
$app
->
request
;
$name
=
$request
->
post
(
'name'
,
''
);
$page
=
$request
->
post
(
'page'
,
1
);
$limit
=
$request
->
post
(
'limit'
,
10
);
$request
=
Yii
::
$app
->
request
;
$name
=
$request
->
post
(
'name'
,
''
);
$page
=
$request
->
post
(
'page'
,
1
);
$limit
=
$request
->
post
(
'limit'
,
10
);
$platform_ids
=
$request
->
post
(
'platform_id'
,
null
);
$condition
=
[[
'!='
,
'chain'
,
'other'
]];
...
...
@@ -136,7 +164,7 @@ class CoinController extends BaseController
}
if
(
$platform_ids
)
{
$platform_id_arr
=
explode
(
','
,
$platform_ids
);
$condition_arr
=
[
'OR'
];
$condition_arr
=
[
'OR'
];
foreach
(
$platform_id_arr
as
$key
=>
$value
)
{
array_push
(
$condition_arr
,
[
'='
,
'platform_id'
,
$value
]);
}
...
...
@@ -176,4 +204,4 @@ class CoinController extends BaseController
}
return
false
;
}
}
\ No newline at end of file
}
backend/assets/CoreAsset.php
View file @
fa7d82c0
...
...
@@ -19,9 +19,9 @@ class CoreAsset extends AssetBundle
];
public
$js
=
[
'global/plugins/bootstrap/js/bootstrap.min.js'
,
//
'global/plugins/bootstrap/js/bootstrap.min.js',
//'global/plugins/js.cookie.min.js',
'global/scripts/app.min.js'
,
//
'global/scripts/app.min.js',
];
public
$depends
=
[
...
...
backend/assets/JqueryAsset.php
View file @
fa7d82c0
...
...
@@ -10,20 +10,20 @@ use yii\web\AssetBundle;
*/
class
JqueryAsset
extends
AssetBundle
{
public
$sourcePath
=
'@common/metronic'
;
public
$sourcePath
=
'@common/metronic'
;
public
$css
=
[
'global/plugins/layui/css/layui.css'
,
];
public
$css
=
[
'global/plugins/layui/css/layui.css'
,
];
public
$js
=
[
'global/plugins/jquery.min.js'
,
'global/plugins/layui/layui.all.js'
,
];
public
$js
=
[
'global/plugins/jquery.min.js'
,
'global/plugins/layui/layui.all.js'
,
];
public
$depends
=
[];
public
$jsOptions
=
[
'position'
=>
\yii\web\View
::
POS_HEAD
,
];
public
$jsOptions
=
[
'position'
=>
\yii\web\View
::
POS_HEAD
,
];
}
backend/assets/LayoutAsset.php
View file @
fa7d82c0
...
...
@@ -24,8 +24,8 @@ class LayoutAsset extends AssetBundle
];
public
$js
=
[
'layouts/layout3/scripts/layout.min.js'
,
'other/js/common.js?01101'
//
'layouts/layout3/scripts/layout.min.js',
//
'other/js/common.js?01101'
];
public
$jsOptions
=
[
...
...
backend/assets/coin/IndexAsset.php
View file @
fa7d82c0
...
...
@@ -14,10 +14,11 @@ use yii\web\View;
class
IndexAsset
extends
AssetBundle
{
public
$sourcePath
=
'@backend/web/js/coin'
;
public
$js
=
[
public
$js
=
[
'index.js'
,
];
public
$jsOptions
=
[
'position'
=>
View
::
POS_END
,
];
}
\ No newline at end of file
backend/controllers/CoinRecommendController.php
0 → 100644
View file @
fa7d82c0
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-9-11
* Time: 下午5:04
*/
namespace
backend\controllers
;
use
common\models\psources\Coin
;
use
common\models\psources\CoinPlatform
;
use
common\models\psources\CoinRecommend
;
use
Yii
;
use
yii\web\Response
;
/**
* Class CoinRecommendController
*
* 推介币种管理
*
* @package backend\controllers
*/
class
CoinRecommendController
extends
BaseController
{
public
function
actionIndex
()
{
if
(
Yii
::
$app
->
request
->
isAjax
)
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$get
=
Yii
::
$app
->
request
->
get
();
$platform
=
$get
[
'platform_id'
]
??
1
;
$page
=
$get
[
'page'
]
??
1
;
$limit
=
$get
[
'limit'
]
??
10
;
$platform_id
=
$get
[
'platform_id'
]
??
''
;
$recommend
=
$get
[
'recommend'
]
??
''
;
$user_platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
if
(
1
!=
$user_platform_id
)
{
$platform_id
=
$user_platform_id
;
}
$condition
=
[];
if
(
!
empty
(
$recommend
))
{
$condition
[
'recommend'
]
=
$recommend
;
}
if
(
!
empty
(
$platform_id
))
{
$condition
[
'platform_id'
]
=
$platform_id
;
}
//todo 获取推介币种
$datas
=
CoinRecommend
::
getList
(
$page
,
$limit
,
$condition
,
[
'sort'
=>
SORT_DESC
]);
return
$datas
;
}
$user_platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
if
(
$user_platform_id
==
1
)
{
$platforms
=
CoinPlatform
::
find
()
->
asArray
()
->
all
();
}
else
{
$platforms
=
CoinPlatform
::
find
()
->
where
([
'id'
=>
$user_platform_id
])
->
asArray
()
->
all
();
}
return
$this
->
render
(
'index'
,
[
'platforms'
=>
$platforms
]);
}
public
function
actionAdd
()
{
if
(
Yii
::
$app
->
request
->
isAjax
)
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$get
=
Yii
::
$app
->
request
->
get
();
$platform_id
=
$get
[
'platform_id'
]
??
1
;
$user_platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
if
(
1
!=
$user_platform_id
&&
$user_platform_id
!=
$platform_id
)
{
return
[
'code'
=>
-
1
,
'msg'
=>
'没有权限修改'
];
}
return
CoinRecommend
::
addRecommendCoin
(
$get
);
}
}
public
function
actionDel
()
{
if
(
Yii
::
$app
->
request
->
isAjax
)
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
null
);
if
(
empty
(
$id
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'删除失败'
];
}
$coin_recommend
=
CoinRecommend
::
findOne
(
$id
);
if
(
empty
(
$coin_recommend
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'推荐币种不存在'
];
}
$coin_platform_id
=
$coin_recommend
->
platform_id
;
$user_platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
if
(
$user_platform_id
==
1
||
$coin_platform_id
==
$user_platform_id
)
{
if
(
$coin_recommend
->
delete
())
{
return
[
'code'
=>
0
,
'msg'
=>
'删除成功'
];
}
}
else
{
return
[
'code'
=>
-
1
,
'msg'
=>
'没有权限'
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'删除失败'
];
}
}
}
backend/views/coin-recommend/index.php
0 → 100644
View file @
fa7d82c0
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-9-11
* Time: 下午5:45
*/
;
?>
<style
type=
"text/css"
>
.layui-form-label
{
width
:
100px
;
}
</style>
<div
class=
"layui-row"
>
<form
class=
"layui-form"
lay-filter=
"form2"
>
<div
class=
"layui-inline"
>
<div
class=
"layui-input-inline"
>
<select
class=
"layui-select"
name=
"platform_id"
>
<option
value=
""
>
选择一个钱包
</option>
<?php
foreach
(
$platforms
as
$key
=>
$value
)
:
?>
<option
value=
"
<?=
$value
[
'id'
]
?>
"
>
<?=
$value
[
'name'
]
?>
</option>
<?php
endforeach
;
?>
</select>
</div>
</div>
<div
class=
"layui-inline"
>
<div
class=
"layui-input-inline"
>
<select
name=
"recommend"
class=
"layui-select"
>
<option
value=
""
>
选择推介类型
</option>
<option
value=
"1"
>
首页推介
</option>
<option
value=
"2"
>
次页推介
</option>
</select>
</div>
</div>
<div
class=
"layui-inline"
>
<button
class=
"layui-btn layui-btn-normal"
lay-submit
lay-filter=
"search"
>
筛选
</button>
<button
class=
"layui-btn layui-btn-normal"
type=
"reset"
>
重置
</button>
</div>
</form>
</div>
<div
class=
"layui-col-md8"
>
<table
class=
"layui-table"
id=
"table1"
lay-filter=
"table1"
></table>
</div>
<div
style=
"display: none; padding: 5px 5px;"
id=
"_form"
>
<form
class=
"layui-form"
id=
"form1"
lay-filter=
"form1"
>
<input
type=
"hidden"
name=
"id"
value=
""
>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
钱包
</label>
<div
class=
"layui-input-inline"
>
<select
class=
"layui-select"
name=
"platform_id"
>
<option
value=
""
>
请选择一个钱包
</option>
<?php
foreach
(
$platforms
as
$key
=>
$value
)
:
?>
<option
value=
"
<?=
$value
[
'id'
]
?>
"
>
<?=
$value
[
'name'
]
?>
</option>
<?php
endforeach
;
?>
</select>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
币种名称
</label>
<div
class=
"layui-input-block"
>
<input
name=
"coin"
class=
"layui-input"
type=
"text"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
推荐类型
</label>
<div
class=
"layui-input-block"
>
<select
name=
"recommend"
class=
"layui-select"
>
<option
value=
"1"
>
首页推介
</option>
<option
value=
"2"
>
次页推介
</option>
</select>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
排序值
</label>
<div
class=
"layui-input-block"
>
<input
name=
"sort"
class=
"layui-input"
type=
"text"
>
</div>
</div>
</form>
</div>
<script
type=
"text/html"
id=
"platform_id_tpl"
>
{{
#
if
(
1
==
d
.
platform_id
){
}}
币钱包
{{
#
}
else
if
(
2
==
d
.
platform_id
){
}}
豆子钱包
{{
#
}
else
if
(
3
==
d
.
platform_id
){
}}
w
钱包
{{
#
}
}}
</script>
<script
type=
"text/html"
id=
"recommend_tpl"
>
{{
#
if
(
1
==
d
.
recommend
){
}}
首页推荐
{{
#
}
else
if
(
2
==
d
.
recommend
){
}}
次页推荐
{{
#
}
}}
</script>
<script
type=
"text/html"
id=
"toolBar"
>
<
button
class
=
"layui-btn layui-btn-xs layui-btn-normal"
lay
-
event
=
"edit"
>
编辑
<
/button
>
<
button
class
=
"layui-btn layui-btn-xs layui-btn-danger"
lay
-
event
=
"del"
>
删除
<
/button
>
</script>
<script
type=
"text/html"
id=
"toolBarTop"
>
<
div
class
=
"layui-btn-container"
>
<
button
class
=
"layui-btn layui-btn-sm"
lay
-
event
=
"recommend_add"
>
添加
<
/button
>
<
/div
>
</script>
<script
type=
"text/javascript"
>
var
table
=
layui
.
table
;
table
.
render
({
elem
:
'#table1'
,
toolbar
:
'#toolBarTop'
,
page
:
true
,
limit
:
10
,
url
:
'/admin/coin-recommend/index'
,
cols
:
[[
{
field
:
'id'
,
title
:
'ID'
},
{
field
:
'platform_id'
,
title
:
'钱包'
,
templet
:
'#platform_id_tpl'
},
{
field
:
'coin'
,
title
:
'币种名称'
},
{
field
:
'recommend'
,
title
:
'推荐类型'
,
templet
:
'#recommend_tpl'
},
{
field
:
'sort'
,
title
:
'排序'
},
{
title
:
'操作'
,
toolbar
:
'#toolBar'
},
]]
});
var
form
=
layui
.
form
;
form
.
render
();
table
.
on
(
'toolbar(table1)'
,
function
(
obj
)
{
var
event
=
obj
.
event
;
if
(
event
==
'recommend_add'
)
{
var
index
=
layer
.
open
({
title
:
'添加推介币种'
,
type
:
1
,
zindex
:
1
,
content
:
$
(
"#_form"
),
btn
:
[
'添加'
,
'取消'
],
scrollbar
:
false
,
success
:
function
()
{
form
.
val
(
"form1"
,
{
id
:
''
,
platform_id
:
''
,
coin
:
''
,
sort
:
''
,
recommend
:
''
});
},
btn1
:
function
()
{
$
.
get
(
'/admin/coin-recommend/add'
,
$
(
"#form1"
).
serialize
(),
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
layer
.
close
(
index
);
$
(
"#_form"
).
css
(
'display'
,
'none'
);
table
.
reload
(
'table1'
,
{
page
:
{
curr
:
1
}
});
}
});
},
btn2
:
function
()
{
$
(
"#_form"
).
css
(
'display'
,
'none'
);
}
});
}
});
table
.
on
(
'tool(table1)'
,
function
(
obj
)
{
var
event
=
obj
.
event
;
var
data
=
obj
.
data
;
if
(
event
==
'edit'
)
{
var
index
=
layer
.
open
({
title
:
'添加推介币种'
,
type
:
1
,
zindex
:
1
,
content
:
$
(
"#_form"
),
btn
:
[
'添加'
,
'取消'
],
scrollbar
:
false
,
success
:
function
()
{
form
.
val
(
"form1"
,
{
id
:
data
.
id
,
platform_id
:
data
.
platform_id
,
coin
:
data
.
coin
,
sort
:
data
.
sort
,
recommend
:
data
.
recommend
});
},
btn1
:
function
()
{
$
.
get
(
'/admin/coin-recommend/add'
,
$
(
"#form1"
).
serialize
(),
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
layer
.
close
(
index
);
$
(
"#_form"
).
css
(
'display'
,
'none'
);
table
.
reload
(
'table1'
,
{
page
:
{
curr
:
1
}
});
}
});
},
btn2
:
function
()
{
layer
.
close
(
index
);
$
(
"#_form"
).
css
(
'display'
,
'none'
);
}
});
}
else
if
(
'del'
==
event
)
{
var
index
=
layer
.
confirm
(
"确认删除?"
,
{
icon
:
3
,
title
:
'删除'
},
function
()
{
$
.
get
(
'/admin/coin-recommend/del'
,
{
id
:
data
.
id
},
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
// layer.close(index);
table
.
reload
(
'table1'
,{
page
:{
curr
:
1
}
});
}
});
});
}
});
form
.
on
(
'submit(search)'
,
function
(
obj
)
{
console
.
log
(
obj
.
field
);
table
.
reload
(
"table1"
,
{
where
:
obj
.
field
,
page
:
{
curr
:
1
}
});
return
false
;
});
</script>
backend/views/coin/add.php
View file @
fa7d82c0
...
...
@@ -53,22 +53,14 @@
<input
type=
"text"
class=
"layui-input"
id=
"time1"
value=
"
<?=
$model
->
release
?>
"
>
</div>
</div>
<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>
<option
value=
"2"
>
次页推荐
</option>
</select>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
合约地址
</label>
<div
class=
"layui-input-block"
>
<input
type=
"text"
class=
"layui-input"
name=
"address"
value=
"
<?=
$model
->
address
?>
"
>
</div>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
精度
</label>
<div
class=
"layui-input-block"
>
...
...
backend/views/coin/edit.php
View file @
fa7d82c0
...
...
@@ -54,25 +54,6 @@
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
推介该币种
</label>
<div
class=
"layui-input-block"
>
<select
name=
"recommend"
>
<option
value=
"0"
<?php
if
(
$model
->
recommend
==
0
)
{
echo
"selected"
;
}
?>
>
否
</option>
<option
value=
"1"
<?php
if
(
$model
->
recommend
==
1
)
{
echo
"selected"
;
}
?>
>
首页推荐
</option>
<option
value=
"2"
<?php
if
(
$model
->
recommend
==
2
)
{
echo
"selected"
;
}
?>
>
次页推荐
</option>
</select>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
合约地址
</label>
<div
class=
"layui-input-block"
>
<input
type=
"text"
class=
"layui-input"
name=
"address"
value=
"
<?=
$model
->
address
?>
"
>
...
...
backend/views/layouts/main.php
View file @
fa7d82c0
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use
common\models\Menu
;
use
backend\assets\AppAsset
;
use
yii\helpers\Html
;
...
...
@@ -11,8 +13,8 @@ AppAsset::register($this);
if
(
!
Yii
::
$app
->
user
->
isGuest
)
{
$user
=
Yii
::
$app
->
user
->
identity
->
username
;
}
else
{
$user
=
'访客'
;
$token
=
null
;
$user
=
'访客'
;
$token
=
null
;
}
/* route */
...
...
@@ -20,7 +22,7 @@ $route = $this->context->id . '/' . $this->context->action->id;
if
(
$route
==
'public/error'
)
{
$this
->
title
=
Yii
::
$app
->
errorHandler
->
exception
->
statusCode
;
}
else
{
$this
->
title
=
Menu
::
find
()
->
select
(
'title'
)
->
where
([
'url'
=>
$route
])
->
scalar
();
$this
->
title
=
Menu
::
find
()
->
select
(
'title'
)
->
where
([
'url'
=>
$route
])
->
scalar
();
}
$picAsset
=
$this
->
getAssetManager
()
->
getBundle
(
AppAsset
::
className
())
->
baseUrl
;
...
...
@@ -34,7 +36,7 @@ $this->beginPage()
<meta
charset=
"
<?=
Yii
::
$app
->
charset
?>
"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<link
rel=
"shortcut icon"
href=
"
<?=
$picAsset
.
'/pages/img/favicon.ico'
?>
"
/>
<link
rel=
"shortcut icon"
href=
"
<?=
$picAsset
.
'/pages/img/favicon.ico'
?>
"
/>
<?=
Html
::
csrfMetaTags
()
?>
<title>
管理后台
<?=
' | '
.
Html
::
encode
(
$this
->
title
)
?>
</title>
<?php
$this
->
head
()
?>
...
...
@@ -51,7 +53,7 @@ $this->beginPage()
<div
class=
"container"
style=
"min-width: 300px"
>
<a
href=
"javascript:;"
class=
"menu-toggler"
></a>
<a
href=
"
<?=
$logout
?>
"
class=
"menu-logout"
>
退出
</a>
<a
href=
"
<?=
$logout
?>
"
class=
"menu-logout"
>
退出
</a>
<span
href=
"javascript:;"
class=
"menu-user"
>
<?=
$user
?>
</span>
</div>
...
...
@@ -69,9 +71,9 @@ $this->beginPage()
<ul
class=
"nav navbar-nav "
>
<?=
\common\widgets\Breadcrumbs
::
widget
([
'homeLink'
=>
false
,
'links'
=>
Menu
::
getBreadcrumbs
(),
'options'
=>
[
//设置html属性
'homeLink'
=>
false
,
'links'
=>
Menu
::
getBreadcrumbs
(),
'options'
=>
[
//设置html属性
'class'
=>
'menu-dropdown classic-menu-dropdown '
],
'active'
=>
Menu
::
find
()
->
select
(
'id, pid, title'
)
...
...
@@ -84,7 +86,7 @@ $this->beginPage()
<div
class=
"page-header-right"
>
<a
href=
"
<?=
\yii\helpers\Url
::
toRoute
(
'login/logout'
)
?>
"
class=
"menu-logout"
>
退出
</a>
<a
href=
"
<?=
\yii\helpers\Url
::
toRoute
(
'login/logout'
)
?>
"
class=
"menu-logout"
>
退出
</a>
<span
class=
"menu-user"
>
<?=
$user
?>
</span>
</div>
...
...
@@ -102,7 +104,7 @@ $this->beginPage()
<div
class=
"layui-row"
>
<div
class=
"col-md-12"
>
<?=
$content
?>
<?=
$content
?>
</div>
</div>
...
...
common/business/ExchangeBusiness.php
View file @
fa7d82c0
...
...
@@ -186,4 +186,32 @@ class ExchangeBusiness
}
return
[];
}
public
static
function
getQuatationByNames
(
$names
)
{
$result
=
[];
foreach
(
$names
as
$key
=>
$value
)
{
$quotation
=
self
::
getquatation
(
$value
);
if
(
!
$quotation
)
{
$quotation
=
[];
//使用Coin服务
try
{
$coinServer
=
CoinFactory
::
createCoin
(
$row
[
'name'
],
$row
[
'id'
],
$row
[
'sid'
]);
$quotation
[
'rmb'
]
=
$coinServer
->
getPrice
();
$quotation
[
'last'
]
=
$coinServer
->
getDollar
();
$quotation
[
'low'
]
=
$coinServer
->
getLow
();
$quotation
[
'high'
]
=
$coinServer
->
getHigh
();
$coinServer
->
__destruct
();
}
catch
(
\Exception
$exception
)
{
$quotation
[
'rmb'
]
=
0
;
$quotation
[
'last'
]
=
0
;
$quotation
[
'low'
]
=
0
;
$quotation
[
'high'
]
=
0
;
\Yii
::
error
(
$exception
->
getMessage
());
}
}
$result
[
$value
]
=
$quotation
;
}
return
$result
;
}
}
common/models/psources/BaseActiveRecord.php
0 → 100644
View file @
fa7d82c0
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-12 14:32:44
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace
common\models\psources
;
use
common\core\BaseActiveRecord
as
CoreBase
;
use
Yii
;
class
BaseActiveRecord
extends
CoreBase
{
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
}
common/models/psources/Coin.php
View file @
fa7d82c0
...
...
@@ -8,8 +8,8 @@
namespace
common\models\psources
;
use
Yii
;
use
common\core\BaseActiveRecord
;
use
Yii
;
/**
* Class Coin
...
...
@@ -20,8 +20,8 @@ use common\core\BaseActiveRecord;
class
Coin
extends
BaseActiveRecord
{
/**
* @return null|object|\yii\db\Connection
* @throws \yii\base\InvalidConfigException
* @return null|object|\yii\db\Connection
*/
public
static
function
getDb
()
{
...
...
@@ -35,9 +35,9 @@ class Coin extends BaseActiveRecord
/**
* 获取币种信息列表
* @param
int
$page
* @param
int
$limit
* @param
array
$condition
* @param
int
$page
* @param
int
$limit
* @param
array
$condition
* @return array|\yii\db\ActiveRecord[]
*/
public
static
function
getList
(
$page
=
1
,
$limit
=
10
,
$condition
=
[])
...
...
@@ -57,9 +57,9 @@ class Coin extends BaseActiveRecord
/**
* 获取币种信息列表
* @param
int
$page
* @param
int
$limit
* @param
array
$condition
* @param
int
$page
* @param
int
$limit
* @param
array
$condition
* @return array|\yii\db\ActiveRecord[]
*/
public
static
function
getSelectList
(
$page
=
1
,
$limit
=
10
,
$columns
=
[],
$condition
=
[])
...
...
@@ -86,7 +86,7 @@ class Coin extends BaseActiveRecord
});
$this
->
setAttributes
(
$params
,
false
);
try
{
return
(
bool
)
$this
->
save
();
return
(
bool
)
$this
->
save
();
}
catch
(
\Exception
$exception
)
{
return
[
'code'
=>
$exception
->
getCode
(),
'message'
=>
$exception
->
getMessage
()];
}
...
...
@@ -112,7 +112,7 @@ class Coin extends BaseActiveRecord
}
$coin
->
setAttributes
(
$params
,
false
);
try
{
return
(
bool
)
$coin
->
save
();
return
(
bool
)
$coin
->
save
();
}
catch
(
\Exception
$exception
)
{
return
[
'code'
=>
$exception
->
getCode
(),
'message'
=>
$exception
->
getMessage
()];
}
...
...
@@ -145,4 +145,31 @@ class Coin extends BaseActiveRecord
$data
=
array_unique
(
array_column
(
$data
,
'chain'
));
return
$data
;
}
}
\ No newline at end of file
/**
* 根据id列表获取币种信息
*
* @param array $ids [description]
* @param array $select [description]
* @param string $sort_by [description]
* @return array [description]
*/
public
static
function
getCoinInfoByIds
(
$ids
,
$select
,
$sort_by
)
{
if
(
!
is_array
(
$ids
))
{
$ids
=
[
$ids
];
}
$query
=
self
::
find
();
if
(
!
empty
(
$select
))
{
$query
=
$query
->
select
(
$select
);
}
$data
=
$query
->
where
([
'in'
,
'id'
,
$ids
])
->
asArray
()
->
all
();
if
(
empty
(
$data
))
{
return
false
;
}
if
(
!
in_array
(
$sort_by
,
$select
))
{
return
$data
;
}
return
array_column
(
$data
,
null
,
'id'
);
}
}
common/models/psources/CoinPlatform.php
0 → 100644
View file @
fa7d82c0
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-12 14:30:49
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace
common\models\psources
;
class
CoinPlatform
extends
BaseActiveRecord
{
public
static
function
tableName
()
{
return
'{{%coin_platform}}'
;
}
}
common/models/psources/CoinRecommend.php
0 → 100644
View file @
fa7d82c0
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-12 10:21:08
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace
common\models\psources
;
use
common\core\BaseActiveRecord
;
use
common\models\psources\Coin
;
use
Yii
;
class
CoinRecommend
extends
BaseActiveRecord
{
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coin_recommend}}'
;
}
/**
* 获取推荐列表
*
* @param integer $page [description]
* @param integer $limit [description]
* @param array $condition [description]
* @param array $order_by [description]
* @return [type] [description]
*/
public
static
function
getList
(
$page
=
1
,
$limit
=
10
,
$condition
=
[],
$order_by
=
[],
$select
=
[])
{
$query
=
self
::
find
();
if
(
!
empty
(
$condition
))
{
$query
=
$query
->
where
(
$condition
);
}
$count
=
$query
->
count
();
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
);
if
(
!
empty
(
$order_by
))
{
# code...
$data
=
$data
->
orderby
(
$order_by
);
}
$data
=
$data
->
asArray
()
->
all
();
//获取币种详情
$coin_ids
=
array_column
(
$data
,
'cid'
);
if
(
empty
(
$select
))
{
$coin_info
=
Coin
::
getCoinInfoByIds
(
$coin_ids
,
[
'id'
,
'name'
],
'id'
);
}
else
{
$coin_info
=
Coin
::
getCoinInfoByIds
(
$coin_ids
,
$select
,
'id'
);
}
foreach
(
$data
as
$key
=>
&
$value
)
{
$value
[
'coin'
]
=
$coin_info
[
$value
[
'cid'
]][
'name'
];
}
unset
(
$key
,
$value
);
// $sql = $query->createCommand()->getSql();
$data
=
[
'count'
=>
$count
,
'data'
=>
$data
];
if
(
$count
>
0
)
{
$data
[
'code'
]
=
0
;
}
else
{
$data
[
'code'
]
=
1
;
$data
[
'msg'
]
=
'数据为空'
;
}
return
$data
;
}
/**
* 添加推介币种
*
* @param [type] $params [description]
*/
public
static
function
addRecommendCoin
(
$params
)
{
$id
=
$params
[
'id'
]
??
null
;
$platform_id
=
$params
[
'platform_id'
]
??
1
;
$coin_name
=
$params
[
'coin'
]
??
''
;
$recommend_type
=
$params
[
'recommend'
]
??
1
;
$sort
=
$params
[
'sort'
]
??
0
;
$coin
=
Coin
::
findOne
([
'name'
=>
strtoupper
(
$coin_name
)]);
if
(
empty
(
$coin
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'币种不存在'
];
}
if
(
!
empty
(
$id
))
{
$coin_recommend
=
CoinRecommend
::
findOne
(
$id
);
}
else
{
$coin_recommend
=
new
CoinRecommend
();
$count
=
self
::
find
()
->
where
([
'cid'
=>
$coin
->
id
,
'platform_id'
=>
$platform_id
])
->
count
();
if
(
$count
>
0
)
{
return
[
'code'
=>
-
1
,
'msg'
=>
'推荐币种已经存在'
];
}
}
$recommend_type
=
$recommend_type
==
1
?
1
:
2
;
$sort
=
(
int
)
$sort
;
$coin_recommend
->
cid
=
$coin
->
id
;
$coin_recommend
->
recommend
=
$recommend_type
;
$coin_recommend
->
platform_id
=
$platform_id
;
$coin_recommend
->
sort
=
$sort
;
if
(
$coin_recommend
->
save
())
{
return
[
'code'
=>
0
,
'msg'
=>
'保存成功'
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'保存失败'
];
}
}
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