123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- /**
- * Created by:PhpStorm
- * Author:chenzhiyuan
- * Date: 2022/4/19
- * Time: 2:18 下午
- */
- namespace App\Http\Controllers\Api\Admin;
- use App\Http\Controllers\Controller;
- use App\Service\Admin\AdminService;
- use App\Service\Admin\PermissionService;
- use Illuminate\Http\Request;
- use Illuminate\Validation\Rule;
- class PermissionController extends Controller
- {
- /**
- * 权限树
- * @return array
- */
- public function permission_tree(Request $request)
- {
- $view_type = $request->input("view_type",AdminService::VIEW_TYPE[0]);
- $admin_id = $request->input("admin_id",1);
- $sys_group_id = $request->input('sys_group_id');
- $is_system_admin = $request->input("is_system_admin",0);
- // $res = PermissionService::permission_tree($view_type);
- $res = PermissionService::user_permission($view_type, $admin_id, $is_system_admin,$sys_group_id);
- return self::returnValue($res);
- }
- /**
- * 创建顶级菜单
- * @param Request $request
- * @return array
- */
- public function create_permission_l1(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $validator = \Validator::make($request->all(),[
- 'title' => 'required',
- 'icon' => 'required',
- 'view_type' => Rule::in($support_view_type),
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $view_type = $request->input("view_type",$support_view_type[0]);
- $id = $request->input('id');
- $admin_id = $request->input('admin_id',0);
- $title = $request->input('title');
- $route = $request->input('route','');
- $icon = $request->input('icon');
- $parent_id = 0; //顶级菜单
- $weight = time(); //时间戳,默认新增内容排放在最后
- $ret_code = PermissionService::create_permission($view_type,$admin_id,$parent_id,$title,$route,$weight,$icon);
- return self::returnValue([],$ret_code);
- }
- /***
- * 编辑权限
- * @param Request $request
- */
- public function edit_permission_l1(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $validator = \Validator::make($request->all(),[
- 'id' => 'required',
- 'title' => 'required',
- 'icon' => 'required',
- 'view_type' => Rule::in($support_view_type),
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $view_type = $request->input("view_type",$support_view_type[0]);
- $id = $request->input('id');
- $title = $request->input('title');
- $route = $request->input('route','');
- $icon = $request->input('icon');
- $ret_code = PermissionService::edit_permission_l1($view_type,$id,$title,$route,$icon);
- return self::returnValue([],$ret_code);
- }
- /**
- * 创建非顶级菜单
- * @param Request $request
- * @return array
- */
- public function create_permission_l2(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $validator = \Validator::make($request->all(),[
- 'title' => 'required',
- 'route' => 'required',
- 'parent_id' => 'required',
- 'view_type' => Rule::in($support_view_type),
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $view_type = $request->input("view_type",$support_view_type[0]);
- $admin_id = $request->input('admin_id',0);
- $title = $request->input('title');
- $route = $request->input('route');
- $weight = time(); //时间戳,默认新增内容排放在最后
- $icon = '';
- $parent_id = $request->input("parent_id"); //上级菜单ID
- $ret_code = PermissionService::create_permission($view_type,$admin_id,$parent_id,$title,$route,$weight,$icon);
- return self::returnValue([],$ret_code);
- }
- /***
- * 编辑权限
- * @param Request $request
- */
- public function edit_permission_l2(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $validator = \Validator::make($request->all(),[
- 'id' => 'required',
- 'title' => 'required',
- 'view_type' => Rule::in($support_view_type),
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $view_type = $request->input("view_type",$support_view_type[0]);
- $id = $request->input('id');
- $title = $request->input('title');
- $route = $request->input('route','');
- $ret_code = PermissionService::edit_permission_l2($view_type,$id,$title,$route);
- return self::returnValue([],$ret_code);
- }
- /**
- * 对菜单进行排序设置
- * @param Request $request
- */
- public function be_sort(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $validator = \Validator::make($request->all(),[
- 'p_id' => 'required|array',
- 'parent_id' => 'required',
- 'view_type' => Rule::in($support_view_type),
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $view_type = $request->input("view_type",$support_view_type[0]);
- $admin_id = $request->input('admin_id',0);
- $parent_id = $request->input('parent_id');
- $permission_id_arr = $request->input('p_id');
- $ret_code = PermissionService::be_sort($view_type,$parent_id,$permission_id_arr);
- return self::returnValue([],$ret_code);
- }
- /**
- * 权限列表
- * @param Request $request
- * @return array
- */
- public function permission_list(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $view_type = $request->input("view_type",$support_view_type[0]);
- $parent_id = $request->input('parent_id',0);
- $list = PermissionService::permission_list($view_type,$parent_id);
- return self::returnValue($list,0);
- }
- /**
- * 权限删除
- * @param Request $request
- * @return array
- */
- public function permission_del(Request $request){
- $support_view_type = AdminService::VIEW_TYPE;
- $view_type = $request->input("view_type",$support_view_type[0]);
- $p_id = $request->input('id',0);
- $ret_code = PermissionService::del_permission($view_type,$p_id);
- return self::returnValue([],$ret_code);
- }
- }
|