企微短剧业务系统

UserPermissionController.php 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Created by:PhpStorm
  4. * Author:chenzhiyuan
  5. * Date: 2022/4/21
  6. * Time: 2:33 下午
  7. */
  8. namespace App\Http\Controllers\Api\Admin;
  9. use App\Http\Controllers\Controller;
  10. use App\Models\System\Users;
  11. use App\Service\Admin\AdminService;
  12. use App\Service\Admin\PermissionService;
  13. use Illuminate\Http\Request;
  14. class UserPermissionController extends Controller
  15. {
  16. /**
  17. * 获取用户权限列表
  18. * @param Request $request
  19. * @return array
  20. */
  21. public function index(Request $request)
  22. {
  23. $admin_id = $request->input("admin_id");
  24. $sys_group_id = $request->input('sys_group_id');
  25. $is_system_admin = $request->input("is_system_admin");
  26. $view_type = $request->input("view_type",AdminService::VIEW_TYPE[0]);
  27. $res = PermissionService::user_permission($view_type,$admin_id,$is_system_admin,$sys_group_id);
  28. return self::returnValue($res);
  29. }
  30. /**
  31. * 判断用户是否有导出权限
  32. * */
  33. public function exportAuth(Request $request)
  34. {
  35. $admin_id = $request->input("admin_id",1);
  36. $sys_group_id = $request->input('sys_group_id');
  37. $is_system_admin = $request->input("is_system_admin");
  38. # 获取用户是否有导出权限
  39. if($is_system_admin || $admin_id == $sys_group_id) {
  40. $canExport = $adqAuth = $mpAuth = true;
  41. } else {
  42. $authInfo = Users::select('can_export', 'is_all_adq', 'adq_account', 'is_all_mp', 'mp_account')
  43. ->where('enable', 1)->where('id', $admin_id)->first();
  44. if(empty($authInfo)) {
  45. $canExport = $adqAuth = $mpAuth = false;
  46. } else {
  47. $adqAuth = $mpAuth = true;
  48. $canExport = $authInfo->can_export;
  49. if(!$authInfo->is_all_adq && !$authInfo->adq_account) $adqAuth = false;
  50. if(!$authInfo->is_all_mp && !$authInfo->mp_account) $mpAuth = false;
  51. }
  52. }
  53. return self::returnValue(['can_export' => (bool)$canExport, 'adq_auth' => $adqAuth, 'mp_auth' => $mpAuth]);
  54. }
  55. /**
  56. * 用户画像
  57. * @param Request $request
  58. */
  59. public function user_profile(Request $request)
  60. {
  61. $admin_id = $request->input("admin_id");
  62. $sys_group_id = $request->input('sys_group_id');
  63. $is_system_admin = $request->input("is_system_admin");
  64. $manage_mode = [];
  65. if(PermissionService::user_permission(AdminService::VIEW_TYPE[0],$admin_id,$is_system_admin,$sys_group_id)!=[]){
  66. $manage_mode[] = AdminService::VIEW_TYPE[0];
  67. }
  68. if(PermissionService::user_permission(AdminService::VIEW_TYPE[1],$admin_id,$is_system_admin,$sys_group_id)!=[]){
  69. $manage_mode[] = AdminService::VIEW_TYPE[1];
  70. }
  71. $ret_info = [
  72. 'is_system_admin' => $is_system_admin,
  73. 'manage_mode' => $manage_mode,
  74. ];
  75. return self::returnValue($ret_info);
  76. }
  77. }