You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
395 lines
15 KiB
395 lines
15 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
/**
|
|
* Created by 安徽云掌.
|
|
* User: 云掌.帮德
|
|
* Date: 2020/3/8 22:30
|
|
* Desc: 角色权限类
|
|
*/
|
|
|
|
namespace app\api\controller;
|
|
|
|
use auth\PermissAuth;
|
|
use think\App;
|
|
|
|
/**
|
|
* Manager类添加、修改等公共请求参数
|
|
* @OA\Schema (
|
|
* schema = "GroupField",
|
|
* required={"id","username","password","sex","phone"},
|
|
* @OA\Property(property="title",type="string",minLength=1,maxLength=100,mock={"mock":"@cname"},default="商务部",description="用户组中文名称"),
|
|
* @OA\Property(property="role_code",type="string",minLength=1,maxLength=100,mock={"mock":"@name"},default="bussiness ",description="角色标识"),
|
|
* @OA\Property(property="remark",type="string",minLength=1,maxLength=100,mock={"mock":"@string"},default="",description="备注"),
|
|
* ),
|
|
*/
|
|
class Group extends Common
|
|
{
|
|
public $model = null;
|
|
|
|
public function __construct(App $app)
|
|
{
|
|
parent::__construct($app);
|
|
|
|
}
|
|
|
|
/**
|
|
* @OA\Get (
|
|
* path="group/index",tags={"角色管理"},summary="获取角色管理",description="根据相关参数获取角色管理",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\Parameter(name="title",in="query",description="角色名称",@OA\Schema (type="string")),
|
|
* @OA\Parameter(name="role_code",in="query",description="角色标识",@OA\Schema (type="string")),
|
|
* @OA\Parameter (name="page",in="query",description="当前页码",@OA\Schema (type="integer",format="int15")),
|
|
* @OA\Parameter (name="limit",in="query",description="分页数量",@OA\Schema (type="integer",format="int15")),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="返回管理员用户数据信息",
|
|
* @OA\JsonContent(ref="#/components/schemas/GroupMsgExport"),
|
|
* ),
|
|
* )
|
|
*/
|
|
public function index()
|
|
{
|
|
//接受参数
|
|
$_get = $this->request->get();
|
|
|
|
//验证参数
|
|
validate(\app\api\validate\Group::class)->scene('lists')->check($_get);
|
|
|
|
$_data = (PermissAuth::getInstance())->getGroups();
|
|
//返回数据
|
|
return send_http_status($_data);
|
|
}
|
|
|
|
/**
|
|
* @OA\Get (
|
|
* path="group/getGroupRule",tags={"角色管理"},summary="查询角色权限",description="查询角色所有的权限菜单,并进行标记checked",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\Parameter(name="role_id",in="path",required=true,description="角色ID",@OA\Schema (type="integer",format="int32")),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="返回管理员用户数据信息",
|
|
* @OA\JsonContent(ref="#/components/schemas/MenuMsgExport"),
|
|
* ),
|
|
* )
|
|
*/
|
|
public function getGroupRule()
|
|
{
|
|
//接受参数
|
|
$_get = $this->request->param('role_id', 0, 'int');
|
|
// //验证参数
|
|
// validate(\app\api\validate\Group::class)->scene('lists')->check($_get);
|
|
|
|
$_data = (PermissAuth::getInstance())->getGroupRule($_get);
|
|
//返回数据
|
|
return send_http_status($_data);
|
|
}
|
|
|
|
|
|
public function getUserGroups()
|
|
{
|
|
$_data = (PermissAuth::getInstance())->getUserGroups(UID);
|
|
//返回数据
|
|
return send_http_status($_data);
|
|
}
|
|
|
|
/**
|
|
* @OA\Post (path="group/add",tags={"角色管理"},summary="添加角色数据",description="添加后台角色数据",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema(ref="#/components/schemas/GroupField"),
|
|
* ),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="添加成功",
|
|
* @OA\JsonContent(type="object",
|
|
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
|
|
* @OA\Property(property="msg", type="string",description="提示信息"),
|
|
* @OA\Property(property="count", type="integer",format="int32",description="记录总数"),
|
|
* @OA\Property(property="data", type="integer",format="int32",description="添加成功的的数据ID"),
|
|
* ),
|
|
* ),
|
|
* )
|
|
* @Log [sys_name] 在 [sys_time] 创建了用户角色:[title]
|
|
*/
|
|
public function add()
|
|
{
|
|
//接收参数
|
|
$_post = $this->request->post();
|
|
|
|
//验证参数
|
|
validate(\app\api\validate\Group::class)->check($_post);
|
|
|
|
//处理并返回参数
|
|
$insertId = (PermissAuth::getInstance())->addGroup($_post);
|
|
return send_http_status($insertId, $insertId ? 201 : 202);
|
|
}
|
|
|
|
/**
|
|
* @OA\Post (path="group/addGroupRule/role_id/{role_id}",tags={"角色管理"},summary="添加角色权限",description="添加后台角色权限",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema (
|
|
* required={"menu_id"},
|
|
* @OA\Property(property="menu_id",type="string",description="数据ID或数据ID集合 id=1或 id=1,2,8"),
|
|
* ),
|
|
* ),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="添加成功",
|
|
* @OA\JsonContent(type="object",
|
|
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
|
|
* @OA\Property(property="msg", type="string",description="提示信息"),
|
|
* @OA\Property(property="count", type="integer",format="int32",description="记录总数"),
|
|
* @OA\Property(property="data", type="integer",format="int32",description="添加成功的的数据ID"),
|
|
* ),
|
|
* ),
|
|
* )
|
|
* @param int $role_id
|
|
* @Log [sys_name] 在 [sys_time] 编辑了用户角色:[title]的权限菜单:
|
|
*/
|
|
public function addGroupRule($role_id = 0)
|
|
{
|
|
//接收参数
|
|
$menu_id = $this->request->param('menu_id', '', 'string');
|
|
$menu_id = implode(',', $menu_id);
|
|
//验证参数
|
|
$_rules = [
|
|
'role_id|用户角色ID' => 'require|length:1,100',
|
|
'menu_id|菜单id' => 'require|length:1,10000',
|
|
];
|
|
validate($_rules)->check(['role_id' => $role_id, 'menu_id' => $menu_id]);
|
|
|
|
//处理并返回参数
|
|
$insertId = (PermissAuth::getInstance())->addGroupRule((int)$role_id, $menu_id);
|
|
return send_http_status($insertId, $insertId ? 201 : 202);
|
|
}
|
|
|
|
/**
|
|
* @param int $id 角色ID
|
|
*/
|
|
public function readRule($id = '')
|
|
{
|
|
//验证参数
|
|
validate(\app\api\validate\Demo::class)->scene('read')->check(['id' => $id]);
|
|
|
|
//处理数据
|
|
$_data = (PermissAuth::getInstance())->getGroupRule((int)$id);
|
|
if (!empty($_data)) {
|
|
$_data = get_tree($_data);
|
|
}
|
|
|
|
//返回数据
|
|
return send_http_status($_data);
|
|
}
|
|
|
|
/**
|
|
* @OA\Post (path="group/edit/id/{id}",tags={"角色管理"},summary="修改角色数据",description="修改角色数据",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema(ref="#/components/schemas/GroupField"),
|
|
* ),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="修改数据状态",
|
|
* @OA\JsonContent(type="object",
|
|
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
|
|
* @OA\Property(property="msg", type="string",description="提示信息"),
|
|
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
|
|
* @OA\Property(property="data", type="string",description="不返回"),
|
|
* ),
|
|
* ),
|
|
* )
|
|
* @Log [sys_name]在[sys_time]修改了用户角色:[title]
|
|
*/
|
|
public function edit($id = 0)
|
|
{
|
|
//接收参数
|
|
$_post['title'] = $this->request->post('title', '');
|
|
$_post['role_code'] = $this->request->post('role_code', '');
|
|
$_post['remark'] = $this->request->post('remark', '');
|
|
$_post['id'] = $id; //安全赋值,以免客户端没传id,修改需要id字段
|
|
|
|
//验证参数
|
|
validate(\app\api\validate\Group::class)->check($_post);
|
|
|
|
//处理并返回数据
|
|
return send_http_status('', (PermissAuth::getInstance())->editGroup($_post) ? 203 : 204);
|
|
}
|
|
|
|
/**
|
|
* @OA\Post (
|
|
* path="group/status",tags={"角色管理"},summary="更新角色状态",description="根据ID及status更新角色状态",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema (
|
|
* required={"id","status"},
|
|
* @OA\Property(property="id",type="string",description="数据ID或数据ID集合 id=1或 id=1,2,8"),
|
|
* @OA\Property(property="status",type="integer",format="int15",description="数据状态 0禁用 1启用"),
|
|
* ),
|
|
* ),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="删除数据状态",
|
|
* @OA\JsonContent(type="object",
|
|
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
|
|
* @OA\Property(property="msg", type="string",description="提示信息"),
|
|
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
|
|
* @OA\Property(property="data", type="string",description="不返回"),
|
|
* ),
|
|
* ),
|
|
* )
|
|
* @Log [sys_name] 在 [sys_time] [dictionary_status]了用户角色:[title]
|
|
*/
|
|
public function status()
|
|
{
|
|
//接收参数
|
|
$ids = $this->request->param('id');
|
|
$status = $this->request->param('status', 1, 'int');
|
|
|
|
//验证参数
|
|
$_rules = [
|
|
'ids|id' => 'require|length:1,100',
|
|
'status|状态值' => 'require|number|length:1',
|
|
];
|
|
validate($_rules)->check(['ids' => $ids, 'status' => $status]);
|
|
|
|
//处理并返回数据
|
|
return send_http_status('', PermissAuth::getInstance()->statusGroup($ids, $status) !== false ? 207 : 208);
|
|
}
|
|
|
|
/**
|
|
* @OA\Post (
|
|
* path="group/delete",tags={"角色管理"},summary="删除角色数据",description="根据ID删除角色数据",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema (
|
|
* required={"id"},
|
|
* @OA\Property(property="id",type="string",description="数据ID或数据ID集合 id=1或 id=1,2,8"),
|
|
* ),
|
|
* ),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="删除数据状态",
|
|
* @OA\JsonContent(type="object",
|
|
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
|
|
* @OA\Property(property="msg", type="string",description="提示信息"),
|
|
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
|
|
* @OA\Property(property="data", type="string",description="不返回"),
|
|
* ),
|
|
* ),
|
|
* )
|
|
* @Log [sys_name] 在 [sys_time] 删除了用户角色:[title]
|
|
*/
|
|
public function delete()
|
|
{
|
|
//接收参数
|
|
$ids = $this->request->post('id');
|
|
|
|
//验证参数
|
|
validate(['ids|id' => 'require|length:1,100'])->check(['ids' => $ids]);
|
|
|
|
$affected = (PermissAuth::getInstance())->deleteGroup($ids);
|
|
|
|
//处理并返回数据
|
|
return send_http_status('', $affected ? 205 : 206);
|
|
}
|
|
|
|
/**
|
|
* swagger response返回数据引用
|
|
* @OA\Schema(
|
|
* schema="GroupMsgExport",
|
|
* required={"code","msg","count","data"},
|
|
* @OA\Property(
|
|
* property="code",
|
|
* type="integer",
|
|
* format="int32",
|
|
* description="状态码"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="msg",
|
|
* type="string",
|
|
* description="提示消息"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="count",
|
|
* type="integer",
|
|
* format="int32",
|
|
* description="记录总数",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="data",
|
|
* type="array",
|
|
* description="请求结果",
|
|
* @OA\Items(
|
|
* @OA\Property(
|
|
* property="id",
|
|
* type="integer",
|
|
* description="ID"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="site_id",
|
|
* type="integer",
|
|
* description="站点ID"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="remark",
|
|
* type="string",
|
|
* description="备注",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="title",
|
|
* type="string",
|
|
* description="用户组中文名称"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="role_code",
|
|
* type="string",
|
|
* description="角色标识"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="status",
|
|
* type="integer",
|
|
* description="状态:为1正常,为0禁用"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="rules",
|
|
* type="string",
|
|
* description="用户组拥有的规则id, 多个规则,隔开"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="type",
|
|
* type="integer",
|
|
* description="组的类型 1:共用 2:个人"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="delete_time",
|
|
* type="integer",
|
|
* description="是否删除 null:未删除"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="update_time",
|
|
* type="integer",
|
|
* description="更新时间"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="create_time",
|
|
* type="integer",
|
|
* description="创建时间"
|
|
* ),
|
|
* )
|
|
* ),
|
|
*
|
|
* ),
|
|
*/
|
|
}
|
|
|