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
aa41e653
Commit
aa41e653
authored
Dec 09, 2019
by
孙磊
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'development' of
http://gitlab-ebiz.yiyao365.cn/newshop/newshopback
into development
parents
192b33d0
ec771279
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
290 additions
and
15 deletions
+290
-15
AuthorityNodeController.php
backend/controllers/v1/authority/AuthorityNodeController.php
+224
-0
AuthorityNode.php
backend/models/v1/authority/AuthorityNode.php
+50
-0
ShopRbacNode.php
backend/models/v1/rbacuser/ShopRbacNode.php
+16
-15
No files found.
backend/controllers/v1/authority/AuthorityNodeController.php
0 → 100644
View file @
aa41e653
<?php
namespace
backend\controllers\v1\authority
;
use
app\models\v1\rbacuser\ShopRbacUser
;
use
backend\controllers\v1\BaseController
;
use
Yii
;
use
yii\web\BadRequestHttpException
;
use
yii\web\HttpException
;
use
yii\web\ServerErrorHttpException
;
class
AuthorityNodeController
extends
BaseController
{
public
$modelClass
=
'app\models\v1\authority\AuthorityNode'
;
/**
* 所有action,需要在权限范围内访问
*/
public
function
beforeAction
(
$action
)
{
$_action
=
parent
::
beforeAction
(
$action
);
$userInfo
=
(
new
ShopRbacUser
)
->
getRbacUserInfo
(
Yii
::
$app
->
user
->
identity
->
GUID
);
if
(
$userInfo
[
'ROLE_ID'
]
!=
USER_ROLE_HEADQUARTERS_ADMIN
)
{
throw
new
BadRequestHttpException
(
'没有权限'
);
}
return
$_action
;
}
/**
* 递归实现无限极分类
*
* @param $array 分类数据
* @param $id 主键键名
* @param $pid 父ID键名
* @param $pid 父ID
* @param $level 分类级别
* @return $list 分类好的数组
*/
protected
function
getTree
(
$array
,
$id
=
'ID'
,
$pid
=
'PID'
,
$pid_value
=
0
,
$level
=
0
)
{
//生命静态数组,避免递归调用时,多次声明数组导致覆盖
static
$list
=
[];
foreach
(
$array
as
$key
=>
$value
)
{
//第一次遍历,找到父节点为根节点的节点,也就是pid=0的节点
if
(
$value
[
$pid
]
==
$pid_value
)
{
//父节点为根节点的节点,级别为0,也就是第一极
$value
[
'LEVEL'
]
=
$level
;
$list
[]
=
$value
;
//把这个节点从数组中移除,减少后序递归消耗
unset
(
$array
[
$key
]);
//开始递归,查找父ID为该节点ID的节点,级别则为原级别+1
$this
->
getTree
(
$array
,
$id
,
$pid
,
$value
[
$id
],
$level
+
1
);
}
}
return
$list
;
}
/**
* 生成相应的节点结构
*
* @param $array 节点数据
* @param $level 节点级别
* @param $title 节点名称
* @return $list 生成好的节点结构数组
*/
protected
function
make_tree_node
(
$array
,
$level
=
'LEVEL'
,
$title
=
'TITLE'
)
{
$return
=
array
();
if
(
empty
(
$array
))
return
$return
;
//遍历处理数据
foreach
(
$array
as
$k
=>
$v
)
{
$show_name
=
''
;
switch
(
$v
[
$level
])
{
case
0
:
$show_name
.=
$v
[
$title
];
break
;
case
1
:
$show_name
.=
'|-'
.
$v
[
$title
];
break
;
case
2
:
$show_name
.=
'|    |-'
.
$v
[
$title
];
break
;
}
$return
[
$k
]
=
$v
;
$return
[
$k
][
'SHOW_NAME'
]
=
$show_name
;
}
return
$return
;
}
/**
* @OA\GET(
* path="/backend/web/v1/authority/authority-nodes/node-list",
* tags={"权限管理"},
* summary="权限节点列表(侯贺政)",
* description="权限节点列表",
* @OA\Response(response="200",description="
* ID:节点id,
* NAME:菜单地址,
* TITLE:菜单名称,
* STATUS:菜单状态 0禁用 1启用,
* IS_MENU:是否为菜单(1:是,0:不是),
* IS_TOP_MENU:是否顶部菜单 1是 0否,
* IS_DEFAULT_SHOW:是否进入默认显示页面 1是0否,
* REMARK:描述,
* SORT:菜单排序序号,
* PID:父级菜单ID,
* LEVEL:菜单层级等级(类型-0:项目,1:模块,2:操作),
* SHOW_NAME:显示名称
* "),
* security={{"Authorization":{}}}
* )
*/
public
function
actionNodeList
()
{
$model
=
new
$this
->
modelClass
();
$data
=
$model
->
nodeList
();
if
(
!
$data
)
{
throw
new
BadRequestHttpException
(
'没有您需要的数据'
);
}
$list
=
$this
->
make_tree_node
(
$this
->
getTree
(
$data
));
return
$list
;
}
/**
* @OA\Post(
* path="/backend/web/v1/authority/authority-nodes/node-add",
* tags={"权限管理"},
* summary="添加权限节点(侯贺政)",
* description="添加权限节点",
* @OA\RequestBody(
* required=true,
* description="注:添加权限节点",
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* type="object",
* required={"TITLE","SORT","LEVEL"},
* @OA\Property(property="NAME" ,type="string", description="菜单地址"),
* @OA\Property(property="TITLE" ,type="string", description="菜单名称"),
* @OA\Property(property="LOGO" ,type="string",description="菜单前面的图标url"),
* @OA\Property(property="STATUS", type="int",description="菜单状态(默认1启用,0禁用)"),
* @OA\Property(property="IS_MENU", type="int",description="是否菜单(默认0否,1是)"),
* @OA\Property(property="IS_TOP_MENU", type="int",description="是否顶部菜单(默认0否,1是)"),
* @OA\Property(property="IS_DEFAULT_SHOW", type="int",description="是否进入默认显示页面(默认0否,1是)"),
* @OA\Property(property="REMARK", type="string",description="描述"),
* @OA\Property(property="SORT", type="int",description="菜单排序序号"),
* @OA\Property(property="PID", type="string",description="父级菜单ID(默认无:0)"),
* @OA\Property(property="LEVEL",type="int",description="菜单层级等级(类型-0:项目,1:模块,2:操作)")
* )
* )
* ),
* @OA\Response(
* response=200,
* description="添加成功",
* ),
* @OA\Response(
* response=422,
* description="添加失败,数据验证错误,返回错误信息(数组)。",
* ),
* security={{"Authorization":{}}}
* )
*/
public
function
actionNodeAdd
()
{
$params
=
Yii
::
$app
->
request
->
bodyParams
;
$model
=
new
$this
->
modelClass
();
$model
->
scenario
=
'creation'
;
$model
->
attributes
=
$params
;
$model
->
ORG_GUID
=
isset
(
Yii
::
$app
->
user
->
identity
->
ORG_GUID
)
?
'100'
:
'100'
;
//如果设置了默认显示,先判断是否有其他的默认显示页面,因为只能有一个,所以如果有其他节点是默认显示则将其去除
if
(
$params
[
'IS_DEFAULT_SHOW'
]
==
1
)
{
$model
->
updateAll
(
'IS_DEFAULT_SHOW'
,
'IS_DEFAULT_SHOW=1'
,
[
'IS_DEFAULT_SHOW'
=>
0
]);
}
if
(
!
$model
->
save
())
{
Yii
::
$app
->
response
->
statusCode
=
422
;
return
$model
->
errors
;
}
throw
new
HttpException
(
200
,
'添加成功!'
);
}
/**
* @OA\Delete(
* path="/backend/web/v1/authority/authority-nodes/node-del",
* tags={"权限管理"},
* summary="删除权限节点(侯贺政)",
* description="删除权限节点",
* @OA\Parameter(
* description="要删除的节点GUID",
* in="query",
* name="GUID",
* required=true,
* @OA\Schema(
* type="string",
* )
* ),
* @OA\Response(
* response=200,
* description="删除成功!"
* ),
* security={{"Authorization":{}}}
* )
*/
public
function
actionNodeDel
()
{
$guid
=
Yii
::
$app
->
request
->
get
(
'GUID'
);
$model
=
new
$this
->
modelClass
();
$_model
=
$model
::
findOne
(
$guid
);
if
(
!
$_model
)
{
throw
new
BadRequestHttpException
(
'Requested resource does not exist !'
);
}
if
(
!
$_model
->
delete
())
{
throw
new
ServerErrorHttpException
(
'删除失败!'
);
}
throw
new
HttpException
(
200
,
"删除成功!"
);
}
}
backend/models/v1/authority/AuthorityNode.php
0 → 100644
View file @
aa41e653
<?php
namespace
app\models\v1\authority
;
use
app\models\v1\rbacuser\ShopRbacNode
;
class
AuthorityNode
extends
ShopRbacNode
{
public
$SHOW_NAME
;
//显示名称
/**
* {@inheritdoc}
*/
public
function
fields
()
{
$fields
=
parent
::
fields
();
$fields
[
'SHOW_NAME'
]
=
'SHOW_NAME'
;
$fields
[
'LEVEL'
]
=
function
()
{
switch
(
$this
->
LEVEL
)
{
case
0
:
$level
=
'项目'
;
break
;
case
1
:
$level
=
'模块'
;
break
;
case
2
:
$level
=
'操作'
;
break
;
default
:
$level
=
''
;
break
;
}
return
$level
;
};
return
$fields
;
}
/**
* 节点列表
*
* @return array|null 返回节点列表
*/
public
function
nodeList
()
{
$query
=
static
::
find
()
->
select
([
'ID'
,
'NAME'
,
'TITLE'
,
'STATUS'
,
'IS_MENU'
,
'IS_TOP_MENU'
,
'IS_DEFAULT_SHOW'
,
'REMARK'
,
'SORT'
,
'PID'
,
'LEVEL'
])
->
orderBy
(
"SORT ASC"
)
->
all
();
return
$query
;
}
}
backend/models/v1/rbacuser/ShopRbacNode.php
View file @
aa41e653
...
@@ -3,9 +3,7 @@
...
@@ -3,9 +3,7 @@
namespace
app\models\v1\rbacuser
;
namespace
app\models\v1\rbacuser
;
use
Yii
;
use
Yii
;
use
yii\web\IdentityInterface
;
use
app\models\v1\BaseModel
;
use
app\models\v1\BaseModel
;
use
yii\web\HttpException
;
/**
/**
* This is the model class for table "shop_rbac_node".
* This is the model class for table "shop_rbac_node".
...
@@ -19,10 +17,10 @@ use yii\web\HttpException;
...
@@ -19,10 +17,10 @@ use yii\web\HttpException;
* @property int $IS_MENU 是否为菜单(1:是,0:不是)
* @property int $IS_MENU 是否为菜单(1:是,0:不是)
* @property int $IS_TOP_MENU 是否顶部菜单 1是 0否
* @property int $IS_TOP_MENU 是否顶部菜单 1是 0否
* @property int $IS_DEFAULT_SHOW 是否进入默认显示页面 1是0否
* @property int $IS_DEFAULT_SHOW 是否进入默认显示页面 1是0否
* @property string $REMARK 备注名称
* @property string $REMARK 备注名称
(描述)
* @property int $SORT 菜单排序序号
* @property int $SORT 菜单排序序号
* @property string $PID 父级菜单ID
* @property string $PID 父级菜单ID
* @property int $LEVEL 菜单层级等级
* @property int $LEVEL 菜单层级等级
(0:项目,1:模块,2:操作)
*/
*/
class
ShopRbacNode
extends
BaseModel
class
ShopRbacNode
extends
BaseModel
{
{
...
@@ -45,6 +43,9 @@ class ShopRbacNode extends BaseModel
...
@@ -45,6 +43,9 @@ class ShopRbacNode extends BaseModel
[[
'NAME'
],
'string'
,
'max'
=>
100
],
[[
'NAME'
],
'string'
,
'max'
=>
100
],
[[
'LOGO'
,
'REMARK'
],
'string'
,
'max'
=>
200
],
[[
'LOGO'
,
'REMARK'
],
'string'
,
'max'
=>
200
],
[[
'PID'
],
'string'
,
'max'
=>
11
],
[[
'PID'
],
'string'
,
'max'
=>
11
],
[[
'TITLE'
,
'SORT'
,
'LEVEL'
],
'required'
,
'on'
=>
[
'creation'
]],
[[
'IS_MENU'
,
'IS_TOP_MENU'
,
'IS_DEFAULT_SHOW'
,
'PID'
],
'default'
,
'value'
=>
0
,
'on'
=>
[
'creation'
]],
[
'STATUS'
,
'default'
,
'value'
=>
1
,
'on'
=>
[
'creation'
]]
];
];
}
}
...
@@ -55,18 +56,18 @@ class ShopRbacNode extends BaseModel
...
@@ -55,18 +56,18 @@ class ShopRbacNode extends BaseModel
{
{
return
[
return
[
'ID'
=>
'ID'
,
'ID'
=>
'ID'
,
'ORG_GUID'
=>
'
Org Guid
'
,
'ORG_GUID'
=>
'
组织机构号
'
,
'NAME'
=>
'
Name
'
,
'NAME'
=>
'
菜单地址
'
,
'TITLE'
=>
'
Title
'
,
'TITLE'
=>
'
菜单名称
'
,
'LOGO'
=>
'Logo'
,
'LOGO'
=>
'Logo'
,
'STATUS'
=>
'
Status
'
,
'STATUS'
=>
'
菜单状态
'
,
'IS_MENU'
=>
'
Is Menu
'
,
'IS_MENU'
=>
'
是否为菜单
'
,
'IS_TOP_MENU'
=>
'
Is Top Menu
'
,
'IS_TOP_MENU'
=>
'
是否顶部菜单
'
,
'IS_DEFAULT_SHOW'
=>
'
Is Default Show
'
,
'IS_DEFAULT_SHOW'
=>
'
是否进入默认显示页面
'
,
'REMARK'
=>
'
Remark
'
,
'REMARK'
=>
'
描述
'
,
'SORT'
=>
'
Sort
'
,
'SORT'
=>
'
菜单排序序号
'
,
'PID'
=>
'Pid'
,
'PID'
=>
'Pid'
,
'LEVEL'
=>
'
Level
'
,
'LEVEL'
=>
'
类型
'
,
];
];
}
}
//获取全部的权限节点
//获取全部的权限节点
...
...
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