企微短剧业务系统

RoleController.php 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. * Created by:PhpStorm
  4. * Author:chenzhiyuan
  5. * Date: 2022/4/19
  6. * Time: 7:16 下午
  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 App\Service\Admin\RoleService;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Validation\Rule;
  15. class RoleController extends Controller
  16. {
  17. /**
  18. * 创建角色
  19. * @param Request $request
  20. * @return array
  21. */
  22. public function create_role(Request $request)
  23. {
  24. $support_view_type = AdminService::VIEW_TYPE;
  25. $validator = \Validator::make($request->all(),[
  26. 'name' => 'required',
  27. 'permission_id' => 'required',
  28. 'role_type' => Rule::in([10,20,30])
  29. ]);
  30. if ($validator->fails()) {
  31. return self::returnValue($validator->getMessageBag(), 1102);
  32. }
  33. $view_type = $support_view_type[0];
  34. $admin_id = $request->input('admin_id');
  35. $role_type = $request->input('role_type');
  36. $sys_group_id = $request->input('sys_group_id');
  37. $is_system_admin = $request->input('is_system_admin');
  38. $name = $request->input('name');
  39. $desc = $request->input('desc','');
  40. $permission_id_arr = $request->input('permission_id',[]);
  41. $errno = RoleService::create_role($view_type,$admin_id,$sys_group_id,$is_system_admin,$name,$desc,$role_type,$permission_id_arr);
  42. return self::returnValue([],$errno);
  43. }
  44. /**
  45. * 编辑角色
  46. * @param Request $request
  47. * @return array
  48. */
  49. public function edit_role(Request $request)
  50. {
  51. $support_view_type = AdminService::VIEW_TYPE;
  52. $validator = \Validator::make($request->all(),[
  53. 'id' => 'required|integer',
  54. 'name' => 'required',
  55. 'permission_id' => 'required',
  56. ]);
  57. if ($validator->fails()) {
  58. return self::returnValue($validator->getMessageBag(), 1102);
  59. }
  60. $view_type = $support_view_type[0];
  61. $admin_id = $request->input('admin_id');
  62. $role_type = $request->input('role_type');
  63. $sys_group_id = $request->input('sys_group_id');
  64. $is_system_admin = $request->input('is_system_admin');
  65. $role_id = $request->input("id");
  66. $name = $request->input('name');
  67. $desc = $request->input('desc','');
  68. $permission_id_arr = $request->input('permission_id',[]);
  69. $errNo = RoleService::edit_role(
  70. $view_type,$admin_id,$sys_group_id,$is_system_admin,$role_id,$name,$desc,$role_type,$permission_id_arr
  71. );
  72. return self::returnValue([], $errNo);
  73. }
  74. /**
  75. * 角色列表
  76. * @param Request $request
  77. * @return array
  78. */
  79. public function role_list(Request $request)
  80. {
  81. $support_view_type = AdminService::VIEW_TYPE;
  82. $view_type = $support_view_type[0];
  83. $admin_id = $request->input('admin_id');
  84. $sys_group_id = $request->input('sys_group_id');
  85. $is_system_admin = $request->input('is_system_admin');
  86. $page = $request->input('page',1);
  87. $page_size = $request->input('page_size',20);
  88. $errno = 0;
  89. list($total,$list) = RoleService::role_list($view_type,$admin_id,$sys_group_id,$is_system_admin,$page,$page_size, $errno);
  90. if($errno) return self::returnValue([], $errno);
  91. return self::returnPageValue($list,$total,$page_size,$page);
  92. }
  93. /**
  94. * 角色详情
  95. * @param Request $request
  96. * @return array
  97. */
  98. public function role_info(Request $request)
  99. {
  100. $validator = \Validator::make($request->all(),[
  101. 'id' => 'required|integer',
  102. ]);
  103. if ($validator->fails()) {
  104. return self::returnValue($validator->getMessageBag(), 1102);
  105. }
  106. $role_id = $request->input('id');
  107. $admin_id = $request->input('admin_id');
  108. $sys_group_id = $request->input('sys_group_id');
  109. $is_system_admin = $request->input('is_system_admin');
  110. $errno = 0;
  111. $data = RoleService::role_info($role_id,$admin_id,$sys_group_id,$is_system_admin,$errno);
  112. return self::returnValue($data, $errno);
  113. }
  114. /**
  115. * 获取角色类型
  116. * */
  117. public function role_type(Request $request)
  118. {
  119. $admin_id = $request->input('admin_id');
  120. $sys_group_id = $request->input('sys_group_id');
  121. $is_system_admin = $request->input('is_system_admin');
  122. $errno = 0;
  123. # 获取用户可使用的角色类型
  124. $data = RoleService::role_type($admin_id, $sys_group_id, $is_system_admin, $errno);
  125. return self::returnValue($data, $errno);
  126. }
  127. /**
  128. * 删除角色
  129. * @param Request $request
  130. * @return array
  131. */
  132. public function del_role(Request $request)
  133. {
  134. $validator = \Validator::make($request->all(),[
  135. 'id' => 'required|integer',
  136. ]);
  137. if ($validator->fails()) {
  138. return self::returnValue($validator->getMessageBag(), 1102);
  139. }
  140. $role_id = $request->input('id');
  141. $admin_id = $request->input('admin_id',0);
  142. $sys_group_id = $request->input('sys_group_id',0);
  143. $is_system_admin = $request->input('is_system_admin');
  144. $errno = RoleService::del_role($role_id,$admin_id,$sys_group_id,$is_system_admin);
  145. return self::returnValue([],$errno);
  146. }
  147. }