Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
newShopBack
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
newshop
newShopBack
Commits
9a417526
Commit
9a417526
authored
Dec 09, 2019
by
孙磊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
权限角色列表和添加角色
Signed-off-by:
sunlei
<
sunlei@romens.cn
>
parent
043d58f2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
204 additions
and
0 deletions
+204
-0
AuthorityRoleController.php
backend/controllers/v1/authority/AuthorityRoleController.php
+204
-0
No files found.
backend/controllers/v1/authority/AuthorityRoleController.php
0 → 100644
View file @
9a417526
<?php
namespace
backend\controllers\v1\authority
;
use
Yii
;
use
backend\controllers\v1\BaseController
;
use
app\models\v1\rbacuser\ShopRbacUser
;
use
backend\helpers\Func
;
use
yii\web\BadRequestHttpException
;
use
yii\web\ServerErrorHttpException
;
use
app\models\v1\rbacuser\ShopRbacRoleAccess
;
use
app\models\v1\rbacuser\ShopRbacNode
;
class
AuthorityRoleController
extends
BaseController
{
public
$modelClass
=
'app\models\v1\rbacuser\ShopRbacRole'
;
/**
* @OA\Get(
* path="/backend/web/v1/authority/authority-roles/authority-role-list",
* tags={"权限管理"},
* description="角色列表",
* summary="角色列表(孙磊)",
* @OA\Parameter(name="page",in="query",description="分页页码",@OA\Schema(type="int")),
* @OA\Response(response="200",description="
* ID:主键ID,
* PID:上级管理组ID,
* STATUS:状态,1:启用,
* NAME:角色名称,
* REMARK:描述,
* SORT:排序
* "),
* security={{"Authorization": {}}}
* )
*/
public
function
actionAuthorityRoleList
()
{
$model
=
new
$this
->
modelClass
;
$params
=
Yii
::
$app
->
request
->
queryParams
;
//权限信息
$rbac
=
new
ShopRbacUser
();
$userGuid
=
Yii
::
$app
->
user
->
identity
->
GUID
;
$userinfo
=
$rbac
->
getRbacUserInfo
(
$userGuid
);
if
(
$userinfo
[
'ROLE_ID'
]
!=
USER_ROLE_HEADQUARTERS_ADMIN
){
throw
new
BadRequestHttpException
(
'您没有查看角色列表的权限,请联系管理员'
);
}
$model
->
attributes
=
$params
;
if
(
$model
->
validate
())
{
//所有输入数据都有效 all inputs are valid
$info
=
$model
->
getAuthorityRoles
(
$params
);
if
(
!
$info
->
getModels
())
{
throw
new
BadRequestHttpException
(
'未找到符合的角色信息'
);
}
return
$info
;
}
else
{
//验证失败:$errors 是一个包含错误信息的数组
Yii
::
$app
->
response
->
statusCode
=
422
;
return
$model
->
errors
;
}
}
/**
* @OA\Get(
* path="/backend/web/v1/authority/authority-roles/authority-role-detail",
* tags={"权限管理"},
* description="角色详情",
* summary="角色详情(孙磊)",
* @OA\Parameter(name="ID",in="query",description="角色主键ID",@OA\Schema(type="int")),
* @OA\Response(response="200",description="
* ID:主键ID,
* STATUS:状态,1:启用,
* NAME:角色组名称,
* REMARK:描述,
* SORT:显示排序
* "),
* security={{"Authorization": {}}}
* )
*/
public
function
actionAuthorityRoleDetail
()
{
$model
=
new
$this
->
modelClass
();
//用户输入数据赋值到模型属性
$ID
=
$model
->
ID
=
Yii
::
$app
->
request
->
get
(
'ID'
);
if
(
$model
->
validate
())
{
//获取角色详情
$info
=
$model
->
getAuthorityRoles
(
$ID
);
if
(
!
$info
->
getModels
())
{
throw
new
BadRequestHttpException
(
'未找到符合的权限角色信息'
);
}
return
$info
;
}
else
{
//验证失败:$errors 是一个包含错误信息的数组
Yii
::
$app
->
response
->
statusCode
=
422
;
return
$model
->
errors
;
}
}
/**
* @OA\POST(
* path="/backend/web/v1/authority/authority-roles/add-authority-role",
* tags={"权限管理"},
* description="添加角色",
* summary="添加角色(孙磊)",
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* type="object",
* required={"NAME"},
* @OA\Property(property="NAME",description="角色组名称,最长30字",type="string"),
* @OA\Property(property="STATUS",description="状态",type="int"),
* @OA\Property(property="SORT",description="显示排序",type="int"),
* @OA\Property(property="REMARK",description="描述",type="string"),
* )
* )
* ),
* @OA\Response(response=201,description="添加角色成功"),
* security={{"Authorization": {}}}
* )
*/
public
function
actionAddAuthorityRole
()
{
//权限信息
$rbac
=
new
ShopRbacUser
();
$userGuid
=
Yii
::
$app
->
user
->
identity
->
GUID
;
$userinfo
=
$rbac
->
getRbacUserInfo
(
$userGuid
);
if
(
$userinfo
[
'ROLE_ID'
]
!=
USER_ROLE_HEADQUARTERS_ADMIN
){
throw
new
BadRequestHttpException
(
'您没有添加角色的权限,请联系管理员'
);
}
$params
=
Yii
::
$app
->
getRequest
()
->
post
();
$model
=
new
$this
->
modelClass
();
$other_param
=
array
(
//'ID'=>Func::create_guid(),
'ORG_GUID'
=>
Yii
::
$app
->
user
->
identity
->
ORG_GUID
);
$model
->
setAttributes
(
$other_param
);
$model
->
setAttributes
(
$params
);
if
(
$model
->
save
())
{
Yii
::
$app
->
getResponse
()
->
setStatusCode
(
201
);
}
elseif
(
!
$model
->
hasErrors
())
{
throw
new
ServerErrorHttpException
(
'Failed to create the object for unknown reason.'
);
}
return
$model
;
}
/**
* @OA\PUT(
* path="/backend/web/v1/authority/authority-roles/revise-authority-role",
* tags={"权限管理"},
* description="修改角色",
* summary="修改角色(孙磊)",
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* type="object",
* required={"ID","NAME","SORT"},
* @OA\Property(property="ID",description="角色主键ID",type="string"),
* @OA\Property(property="NAME",description="角色组名称,最长30字",type="string"),
* @OA\Property(property="STATUS",description="状态",type="int"),
* @OA\Property(property="SORT",description="显示排序",type="int"),
* @OA\Property(property="REMARK",description="描述",type="string"),
* )
* )
* ),
* @OA\Response(response=202,description="修改角色成功"),
* security={{"Authorization": {}}}
* )
*/
public
function
actionReviseAuthorityRole
()
{
//权限信息
$rbac
=
new
ShopRbacUser
();
$userGuid
=
Yii
::
$app
->
user
->
identity
->
GUID
;
$userinfo
=
$rbac
->
getRbacUserInfo
(
$userGuid
);
if
(
$userinfo
[
'ROLE_ID'
]
!=
USER_ROLE_HEADQUARTERS_ADMIN
){
throw
new
BadRequestHttpException
(
'您没有修改角色的权限,请联系管理员'
);
}
$id
=
Yii
::
$app
->
getRequest
()
->
post
(
'ID'
);
$model
=
$this
->
modelClass
::
findOne
(
$id
);
if
(
!
$model
){
throw
new
BadRequestHttpException
(
'没有找到要修改的记录'
);
}
//修改人信息
$other_param
=
array
(
'UPDATE_TIME'
=>
date
(
'Y-m-d H:i:s'
,
time
()),
'UPDATE_USER_CODE'
=>
Yii
::
$app
->
user
->
identity
->
CODE
);
$model
->
setAttributes
(
$other_param
);
$model
->
setAttributes
(
Yii
::
$app
->
getRequest
()
->
post
());
if
(
$model
->
save
()
===
false
&&
!
$model
->
hasErrors
())
{
throw
new
ServerErrorHttpException
(
'Failed to update the object for unknown reason.'
);
}
Yii
::
$app
->
getResponse
()
->
setStatusCode
(
202
);
return
$model
;
}
}
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