企微短剧业务系统

PermissionController.php 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /**
  3. * Created by:PhpStorm
  4. * Author:chenzhiyuan
  5. * Date: 2022/4/19
  6. * Time: 2:18 下午
  7. */
  8. namespace App\Http\Controllers\Api\Admin;
  9. use App\Http\Controllers\Controller;
  10. use App\Service\Admin\AdminService;
  11. use App\Service\Admin\PermissionService;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Validation\Rule;
  14. class PermissionController extends Controller
  15. {
  16. /**
  17. * 权限树
  18. * @return array
  19. */
  20. public function permission_tree(Request $request)
  21. {
  22. $view_type = $request->input("view_type",AdminService::VIEW_TYPE[0]);
  23. $admin_id = $request->input("admin_id",1);
  24. $sys_group_id = $request->input('sys_group_id');
  25. $is_system_admin = $request->input("is_system_admin",0);
  26. // $res = PermissionService::permission_tree($view_type);
  27. $res = PermissionService::user_permission($view_type, $admin_id, $is_system_admin,$sys_group_id);
  28. return self::returnValue($res);
  29. }
  30. /**
  31. * 创建顶级菜单
  32. * @param Request $request
  33. * @return array
  34. */
  35. public function create_permission_l1(Request $request){
  36. $support_view_type = AdminService::VIEW_TYPE;
  37. $validator = \Validator::make($request->all(),[
  38. 'title' => 'required',
  39. 'icon' => 'required',
  40. 'view_type' => Rule::in($support_view_type),
  41. ]);
  42. if ($validator->fails()) {
  43. return self::returnValue($validator->getMessageBag(), 1102);
  44. }
  45. $view_type = $request->input("view_type",$support_view_type[0]);
  46. $id = $request->input('id');
  47. $admin_id = $request->input('admin_id',0);
  48. $title = $request->input('title');
  49. $route = $request->input('route','');
  50. $icon = $request->input('icon');
  51. $parent_id = 0; //顶级菜单
  52. $weight = time(); //时间戳,默认新增内容排放在最后
  53. $ret_code = PermissionService::create_permission($view_type,$admin_id,$parent_id,$title,$route,$weight,$icon);
  54. return self::returnValue([],$ret_code);
  55. }
  56. /***
  57. * 编辑权限
  58. * @param Request $request
  59. */
  60. public function edit_permission_l1(Request $request){
  61. $support_view_type = AdminService::VIEW_TYPE;
  62. $validator = \Validator::make($request->all(),[
  63. 'id' => 'required',
  64. 'title' => 'required',
  65. 'icon' => 'required',
  66. 'view_type' => Rule::in($support_view_type),
  67. ]);
  68. if ($validator->fails()) {
  69. return self::returnValue($validator->getMessageBag(), 1102);
  70. }
  71. $view_type = $request->input("view_type",$support_view_type[0]);
  72. $id = $request->input('id');
  73. $title = $request->input('title');
  74. $route = $request->input('route','');
  75. $icon = $request->input('icon');
  76. $ret_code = PermissionService::edit_permission_l1($view_type,$id,$title,$route,$icon);
  77. return self::returnValue([],$ret_code);
  78. }
  79. /**
  80. * 创建非顶级菜单
  81. * @param Request $request
  82. * @return array
  83. */
  84. public function create_permission_l2(Request $request){
  85. $support_view_type = AdminService::VIEW_TYPE;
  86. $validator = \Validator::make($request->all(),[
  87. 'title' => 'required',
  88. 'route' => 'required',
  89. 'parent_id' => 'required',
  90. 'view_type' => Rule::in($support_view_type),
  91. ]);
  92. if ($validator->fails()) {
  93. return self::returnValue($validator->getMessageBag(), 1102);
  94. }
  95. $view_type = $request->input("view_type",$support_view_type[0]);
  96. $admin_id = $request->input('admin_id',0);
  97. $title = $request->input('title');
  98. $route = $request->input('route');
  99. $weight = time(); //时间戳,默认新增内容排放在最后
  100. $icon = '';
  101. $parent_id = $request->input("parent_id"); //上级菜单ID
  102. $ret_code = PermissionService::create_permission($view_type,$admin_id,$parent_id,$title,$route,$weight,$icon);
  103. return self::returnValue([],$ret_code);
  104. }
  105. /***
  106. * 编辑权限
  107. * @param Request $request
  108. */
  109. public function edit_permission_l2(Request $request){
  110. $support_view_type = AdminService::VIEW_TYPE;
  111. $validator = \Validator::make($request->all(),[
  112. 'id' => 'required',
  113. 'title' => 'required',
  114. 'view_type' => Rule::in($support_view_type),
  115. ]);
  116. if ($validator->fails()) {
  117. return self::returnValue($validator->getMessageBag(), 1102);
  118. }
  119. $view_type = $request->input("view_type",$support_view_type[0]);
  120. $id = $request->input('id');
  121. $title = $request->input('title');
  122. $route = $request->input('route','');
  123. $ret_code = PermissionService::edit_permission_l2($view_type,$id,$title,$route);
  124. return self::returnValue([],$ret_code);
  125. }
  126. /**
  127. * 对菜单进行排序设置
  128. * @param Request $request
  129. */
  130. public function be_sort(Request $request){
  131. $support_view_type = AdminService::VIEW_TYPE;
  132. $validator = \Validator::make($request->all(),[
  133. 'p_id' => 'required|array',
  134. 'parent_id' => 'required',
  135. 'view_type' => Rule::in($support_view_type),
  136. ]);
  137. if ($validator->fails()) {
  138. return self::returnValue($validator->getMessageBag(), 1102);
  139. }
  140. $view_type = $request->input("view_type",$support_view_type[0]);
  141. $admin_id = $request->input('admin_id',0);
  142. $parent_id = $request->input('parent_id');
  143. $permission_id_arr = $request->input('p_id');
  144. $ret_code = PermissionService::be_sort($view_type,$parent_id,$permission_id_arr);
  145. return self::returnValue([],$ret_code);
  146. }
  147. /**
  148. * 权限列表
  149. * @param Request $request
  150. * @return array
  151. */
  152. public function permission_list(Request $request){
  153. $support_view_type = AdminService::VIEW_TYPE;
  154. $view_type = $request->input("view_type",$support_view_type[0]);
  155. $parent_id = $request->input('parent_id',0);
  156. $list = PermissionService::permission_list($view_type,$parent_id);
  157. return self::returnValue($list,0);
  158. }
  159. /**
  160. * 权限删除
  161. * @param Request $request
  162. * @return array
  163. */
  164. public function permission_del(Request $request){
  165. $support_view_type = AdminService::VIEW_TYPE;
  166. $view_type = $request->input("view_type",$support_view_type[0]);
  167. $p_id = $request->input('id',0);
  168. $ret_code = PermissionService::del_permission($view_type,$p_id);
  169. return self::returnValue([],$ret_code);
  170. }
  171. }