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
96a66170
Commit
96a66170
authored
Sep 13, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
币种权限控制
parent
8d008f67
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
125 additions
and
64 deletions
+125
-64
AdminController.php
backend/controllers/AdminController.php
+0
-1
CoinController.php
backend/controllers/CoinController.php
+58
-44
index.php
backend/views/coin/index.php
+2
-2
CoinBusiness.php
common/business/CoinBusiness.php
+42
-16
Coin.php
common/models/psources/Coin.php
+23
-1
No files found.
backend/controllers/AdminController.php
View file @
96a66170
...
...
@@ -61,7 +61,6 @@ class AdminController extends BaseController
$model
->
generateAuthKey
();
$model
->
setPassword
(
$data
[
'password'
]);
$model
->
group
=
$role
;
$model
->
platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
/* 保存用户数据到数据库 */
if
(
$model
->
save
())
{
...
...
backend/controllers/CoinController.php
View file @
96a66170
...
...
@@ -8,12 +8,12 @@
namespace
backend\controllers
;
use
Yii
;
use
common\models\psources\Coin
;
use
backend\models\coin\CoinForm
;
use
yii\web\UploadedFile
;
use
yii\validators\ImageValidator
;
use
common\business\CoinBusiness
;
use
common\models\psources\Coin
;
use
Yii
;
use
yii\validators\ImageValidator
;
use
yii\web\UploadedFile
;
/**
* 币种管理控制器
...
...
@@ -29,27 +29,32 @@ class CoinController extends BaseController
$page
=
$request
->
get
(
'page'
,
1
);
$limit
=
$request
->
get
(
'limit'
,
10
);
$name
=
$request
->
get
(
'name'
,
null
);
$platform
=
$request
->
get
(
'platform'
,
'all'
);
$recommend
=
$request
->
get
(
'recommend'
,
'all'
);
$platform
=
$request
->
get
(
'platform'
,
''
);
$recommend
=
$request
->
get
(
'recommend'
,
''
);
$condition
=
[];
if
(
$name
)
{
$condition
[]
=
[
'like'
,
'name'
,
$name
];
}
if
(
$platform
!=
'
all
'
)
{
if
(
$platform
!=
''
)
{
$condition
[]
=
[
'chain'
=>
$platform
];
}
if
(
$recommend
!=
'all'
)
{
$
recommend
=
$recommend
?
1
:
0
;
$condition
[]
=
[
'
recommend'
=>
$recommend
];
if
(
Yii
::
$app
->
user
->
id
!=
Yii
::
$app
->
params
[
'admin'
]
)
{
$
platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
$condition
[]
=
[
'
>'
,
"find_in_set(
$platform_id
, platform_id)"
,
0
];
}
if
(
Yii
::
$app
->
user
->
identity
->
group
!=
'administrator'
)
{
$condition
[]
=
[
'OR'
,
[
'group'
=>
Yii
::
$app
->
user
->
identity
->
group
],
[
'>'
,
'recommend'
,
0
]];
if
(
!
empty
(
$recommend
))
{
//使用连表查询推荐币种
$data
=
CoinBusiness
::
getRecommendList
(
$page
,
$limit
,
$condition
);
}
else
{
$data
=
CoinBusiness
::
getList
(
$page
,
$limit
,
$condition
);
}
$data
=
CoinBusiness
::
getList
(
$page
,
$limit
,
$condition
);
$data
[
'code'
]
=
0
;
//ajax return
Yii
::
$app
->
response
->
format
=
'json'
;
return
$data
;
}
$platforms
=
Coin
::
getChainList
();
return
$this
->
render
(
'index'
,
[
'platforms'
=>
$platforms
]);
...
...
@@ -66,7 +71,7 @@ class CoinController extends BaseController
* @var $coin \common\models\psources\Coin
*/
$coin
=
Yii
::
createObject
(
Coin
::
className
());
$data
=
array_merge
(
$request
->
post
(),
[
'
group'
=>
Yii
::
$app
->
user
->
identity
->
group
]);
$data
=
array_merge
(
$request
->
post
(),
[
'
platform_id'
=>
Yii
::
$app
->
user
->
identity
->
platform_id
]);
unset
(
$data
[
'id'
]);
$result
=
$coin
->
addOne
(
$data
);
if
(
$result
===
true
)
{
...
...
@@ -96,23 +101,26 @@ class CoinController extends BaseController
$req
=
Yii
::
$app
->
request
;
Yii
::
$app
->
response
->
format
=
'json'
;
if
(
$model
->
load
(
$req
->
post
())
&&
$model
->
validate
())
{
$role
=
Yii
::
$app
->
user
->
identity
->
group
;
if
(
'administrator'
!=
$role
)
{
$coin
=
Coin
::
find
()
->
select
([
'group'
])
->
where
([
'id'
=>
$req
->
post
(
'id'
)])
->
one
();
if
(
$role
==
$coin
->
group
)
{
$coin
=
Yii
::
createObject
(
Coin
::
className
());
$result
=
$coin
->
updateOne
(
$req
->
post
());
if
(
$result
===
true
)
{
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
}
}
else
{
return
[
'code'
=>
-
1
,
'msg'
=>
'没有权限修改'
];
$platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
$can
=
false
;
if
(
Yii
::
$app
->
params
[
'admin'
]
!=
Yii
::
$app
->
user
->
id
)
{
$coin
=
Coin
::
find
()
->
where
([
'id'
=>
$req
->
post
(
'id'
),
'platform_id'
=>
$platform_id
])
->
one
();
if
(
$coin
)
{
$can
=
true
;
}
}
else
{
$can
=
true
;
}
$coin
=
Yii
::
createObject
(
Coin
::
className
());
$result
=
$coin
->
updateOne
(
$req
->
post
());
if
(
$result
===
true
)
{
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
if
(
$can
)
{
$coin
=
Yii
::
createObject
(
Coin
::
className
());
$result
=
$coin
->
updateOne
(
$req
->
post
());
if
(
$result
===
true
)
{
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
}
}
else
{
return
[
'code'
=>
-
1
,
'msg'
=>
'没有权限修改'
];
}
}
$errors
=
$model
->
errors
;
...
...
@@ -164,23 +172,30 @@ class CoinController extends BaseController
public
function
actionDelete
()
{
Yii
::
$app
->
response
->
format
=
'json'
;
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
0
);
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
0
);
if
(
$id
)
{
$model
=
Coin
::
findOne
([
'id'
=>
$id
]);
if
(
$model
)
{
$role
=
Yii
::
$app
->
user
->
identity
->
group
;
if
(
'administrator'
!=
$role
)
{
$coin
=
Coin
::
find
()
->
select
([
'group'
])
->
where
([
'id'
=>
$id
])
->
one
();
if
(
$role
==
$coin
->
group
)
{
try
{
$model
->
delete
();
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
}
catch
(
\Throwable
$t
)
{
}
catch
(
\Exception
$e
)
{
}
}
else
{
return
[
'code'
=>
-
1
,
'msg'
=>
'没有权限修改'
];
$platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
$can
=
false
;
if
(
Yii
::
$app
->
params
[
'admin'
]
!=
Yii
::
$app
->
user
->
id
)
{
$coin
=
Coin
::
find
()
->
where
([
'id'
=>
$id
,
'platform_id'
=>
$platform_id
])
->
one
();
if
(
$coin
)
{
$can
=
true
;
}
}
else
{
$can
=
true
;
}
if
(
$can
)
{
try
{
$model
->
delete
();
return
[
'code'
=>
0
,
'msg'
=>
'succeed'
];
}
catch
(
\Throwable
$t
)
{
return
[
'code'
=>
$t
->
getCode
(),
'msg'
=>
$t
->
getMessage
()];
}
}
else
{
return
[
'code'
=>
-
1
,
'msg'
=>
'没有权限修改'
];
}
}
}
...
...
@@ -197,4 +212,4 @@ class CoinController extends BaseController
$this
->
layout
=
false
;
return
$this
->
render
(
'exchange'
,
[
'exchanges'
=>
$exchanges
]);
}
}
\ No newline at end of file
}
backend/views/coin/index.php
View file @
96a66170
...
...
@@ -35,7 +35,7 @@ IndexAsset::register($this);
<label
class=
"layui-form-label"
style=
"margin-bottom: 0; width: 100px;"
>
类型
</label>
<div
class=
"layui-input-inline"
>
<select
name=
"platform"
>
<option
value=
"
all
"
>
全部
</option>
<option
value=
""
>
全部
</option>
<?php
foreach
(
$platforms
as
$platform
)
:
?>
<option
value=
"
<?=
$platform
?>
"
>
<?=
$platform
?>
</option>
<?php
endforeach
;
?>
...
...
@@ -46,7 +46,7 @@ IndexAsset::register($this);
<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=
""
>
全部
</option>
<option
value=
"0"
>
否
</option>
<option
value=
"1"
>
是
</option>
</select>
...
...
common/business/CoinBusiness.php
View file @
96a66170
...
...
@@ -21,9 +21,9 @@ class CoinBusiness
{
/**
* 管理员后台获取币种列表
* @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
=
[])
...
...
@@ -34,7 +34,34 @@ class CoinBusiness
foreach
(
$datas
as
$key
=>
$value
)
{
//获取交易所信息
try
{
$coin
=
CoinFactory
::
createCoin
(
$value
[
'name'
],
$value
[
'id'
],
$value
[
'sid'
]);
$coin
=
CoinFactory
::
createCoin
(
$value
[
'name'
],
$value
[
'id'
],
$value
[
'sid'
]);
$rows
[
'data'
][
$key
][
'exchange'
]
=
$coin
->
exchange_count
();
}
catch
(
\Exception
$exception
)
{
$rows
[
'data'
][
$key
][
'exchange'
]
=
0
;
}
}
}
return
$rows
;
}
/**
* 管理员后台获取币种列表
* @param int $page
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord[]
*/
public
static
function
getRecommendList
(
$page
=
1
,
$limit
=
10
,
$condition
=
[])
{
$rows
=
Coin
::
getRecommendList
(
$page
,
$limit
,
$condition
);
if
(
$rows
[
'count'
]
>
0
)
{
$datas
=
$rows
[
'data'
];
foreach
(
$datas
as
$key
=>
$value
)
{
//获取交易所信息
try
{
$coin
=
CoinFactory
::
createCoin
(
$value
[
'name'
],
$value
[
'id'
],
$value
[
'sid'
]);
$rows
[
'data'
][
$key
][
'exchange'
]
=
$coin
->
exchange_count
();
}
catch
(
\Exception
$exception
)
{
$rows
[
'data'
][
$key
][
'exchange'
]
=
0
;
...
...
@@ -47,7 +74,7 @@ class CoinBusiness
/**
* 返回交易所列表
*
* @param $id
* @param
$id
* @return array
*/
public
static
function
getExchangeListById
(
$id
=
0
)
...
...
@@ -68,9 +95,9 @@ class CoinBusiness
/**
* api获取行情列表
* @param
int
$page
* @param
int
$limit
* @param
array
$condition
* @param
int
$page
* @param
int
$limit
* @param
array
$condition
* @return array
*/
public
static
function
getApiList
(
$page
=
1
,
$limit
=
10
,
$condition
=
[])
...
...
@@ -104,7 +131,7 @@ class CoinBusiness
/**
* 根据name返回币种信息
* @param
array
$condition 需要的币种sid列表
* @param
array
$condition 需要的币种sid列表
* @return array
*/
public
static
function
getApiListForIndex
(
$condition
=
[])
...
...
@@ -126,9 +153,9 @@ class CoinBusiness
/**
* 根据名称搜索
* @param
int
$page
* @param
int
$limit
* @param
array
$condition
* @param
int
$page
* @param
int
$limit
* @param
array
$condition
* @return array|\yii\db\ActiveRecord|\yii\db\ActiveRecord[]
*/
public
static
function
SearchByName
(
$page
=
1
,
$limit
=
10
,
$condition
=
[])
...
...
@@ -150,7 +177,7 @@ class CoinBusiness
/**
* 获取币种的所有信息
* @param integer $id
* @param
integer $id
* @return array
*/
public
static
function
getCoinAllById
(
$id
)
...
...
@@ -172,7 +199,7 @@ class CoinBusiness
if
(
empty
(
$row
[
'introduce'
]))
{
$row
[
'introduce'
]
=
''
;
}
$row
[
'price'
]
=
sprintf
(
"%s"
,(
double
)
$row
[
'price'
]);
$row
[
'price'
]
=
sprintf
(
"%s"
,
(
double
)
$row
[
'price'
]);
$coin
=
CoinFactory
::
createCoin
(
$row
[
'name'
],
$row
[
'id'
],
$row
[
'sid'
]);
$row
[
'quotation'
]
=
$coin
->
quotation
();
$row
[
'exchange_count'
]
=
$coin
->
exchange_count
();
...
...
@@ -180,4 +207,4 @@ class CoinBusiness
}
return
$row
?
[
$row
]
:
[];
}
}
\ No newline at end of file
}
common/models/psources/Coin.php
View file @
96a66170
...
...
@@ -50,7 +50,6 @@ class Coin extends BaseActiveRecord
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
foreach
(
$data
as
$key
=>
$item
)
{
$data
[
$key
][
'price'
]
=
sprintf
(
"%0.6f"
,
$item
[
'price'
]);
// $data[$key]['release'] = date('Y-m-d', $item['release']);
}
return
[
'count'
=>
$count
,
'data'
=>
$data
];
}
...
...
@@ -194,4 +193,27 @@ class Coin extends BaseActiveRecord
}
return
array_column
(
$data
,
null
,
'id'
);
}
/**
* 获取推介币种信息列表
*
* @param int $page
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord[]
*/
public
static
function
getRecommendList
(
$page
=
1
,
$limit
=
10
,
$condition
=
[])
{
$query
=
self
::
find
();
foreach
(
$condition
as
$item
)
{
$query
=
$query
->
andWhere
(
$item
);
}
$query
=
$query
->
rightJoin
(
'coin_recommend'
,
'coin.id=coin_recommend.cid'
);
$count
=
$query
->
count
();
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
foreach
(
$data
as
$key
=>
$item
)
{
$data
[
$key
][
'price'
]
=
sprintf
(
"%0.6f"
,
$item
[
'price'
]);
}
return
[
'count'
=>
$count
,
'data'
=>
$data
];
}
}
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