123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- /**
- * Created by:PhpStorm
- * Author:chenzhiyuan
- * Date: 2022/4/19
- * Time: 7:16 下午
- */
- namespace App\Http\Controllers\Api\Admin;
- use App\Http\Controllers\Controller;
- use App\Service\Admin\AdminService;
- use App\Service\Admin\PermissionService;
- use App\Service\Admin\RoleService;
- use Illuminate\Http\Request;
- use Illuminate\Validation\Rule;
- class RoleController extends Controller
- {
- /**
- * 创建角色
- * @param Request $request
- * @return array
- */
- public function create_role(Request $request)
- {
- $support_view_type = AdminService::VIEW_TYPE;
- $validator = \Validator::make($request->all(),[
- 'name' => 'required',
- 'permission_id' => 'required',
- 'role_type' => Rule::in([10,20,30])
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $view_type = $support_view_type[0];
- $admin_id = $request->input('admin_id');
- $role_type = $request->input('role_type');
- $sys_group_id = $request->input('sys_group_id');
- $is_system_admin = $request->input('is_system_admin');
- $name = $request->input('name');
- $desc = $request->input('desc','');
- $permission_id_arr = $request->input('permission_id',[]);
- $errno = RoleService::create_role($view_type,$admin_id,$sys_group_id,$is_system_admin,$name,$desc,$role_type,$permission_id_arr);
- return self::returnValue([],$errno);
- }
- /**
- * 编辑角色
- * @param Request $request
- * @return array
- */
- public function edit_role(Request $request)
- {
- $support_view_type = AdminService::VIEW_TYPE;
- $validator = \Validator::make($request->all(),[
- 'id' => 'required|integer',
- 'name' => 'required',
- 'permission_id' => 'required',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $view_type = $support_view_type[0];
- $admin_id = $request->input('admin_id');
- $role_type = $request->input('role_type');
- $sys_group_id = $request->input('sys_group_id');
- $is_system_admin = $request->input('is_system_admin');
- $role_id = $request->input("id");
- $name = $request->input('name');
- $desc = $request->input('desc','');
- $permission_id_arr = $request->input('permission_id',[]);
- $errNo = RoleService::edit_role(
- $view_type,$admin_id,$sys_group_id,$is_system_admin,$role_id,$name,$desc,$role_type,$permission_id_arr
- );
- return self::returnValue([], $errNo);
- }
- /**
- * 角色列表
- * @param Request $request
- * @return array
- */
- public function role_list(Request $request)
- {
- $support_view_type = AdminService::VIEW_TYPE;
- $view_type = $support_view_type[0];
- $admin_id = $request->input('admin_id');
- $sys_group_id = $request->input('sys_group_id');
- $is_system_admin = $request->input('is_system_admin');
- $page = $request->input('page',1);
- $page_size = $request->input('page_size',20);
- $errno = 0;
- list($total,$list) = RoleService::role_list($view_type,$admin_id,$sys_group_id,$is_system_admin,$page,$page_size, $errno);
- if($errno) return self::returnValue([], $errno);
- return self::returnPageValue($list,$total,$page_size,$page);
- }
- /**
- * 角色详情
- * @param Request $request
- * @return array
- */
- public function role_info(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $role_id = $request->input('id');
- $admin_id = $request->input('admin_id');
- $sys_group_id = $request->input('sys_group_id');
- $is_system_admin = $request->input('is_system_admin');
- $errno = 0;
- $data = RoleService::role_info($role_id,$admin_id,$sys_group_id,$is_system_admin,$errno);
- return self::returnValue($data, $errno);
- }
- /**
- * 获取角色类型
- * */
- public function role_type(Request $request)
- {
- $admin_id = $request->input('admin_id');
- $sys_group_id = $request->input('sys_group_id');
- $is_system_admin = $request->input('is_system_admin');
- $errno = 0;
- # 获取用户可使用的角色类型
- $data = RoleService::role_type($admin_id, $sys_group_id, $is_system_admin, $errno);
- return self::returnValue($data, $errno);
- }
- /**
- * 删除角色
- * @param Request $request
- * @return array
- */
- public function del_role(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $role_id = $request->input('id');
- $admin_id = $request->input('admin_id',0);
- $sys_group_id = $request->input('sys_group_id',0);
- $is_system_admin = $request->input('is_system_admin');
- $errno = RoleService::del_role($role_id,$admin_id,$sys_group_id,$is_system_admin);
- return self::returnValue([],$errno);
- }
- }
|