12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- /**
- * Created by:PhpStorm
- * Author:chenzhiyuan
- * Date: 2022/4/21
- * Time: 2:33 下午
- */
- namespace App\Http\Controllers\Api\Admin;
- use App\Http\Controllers\Controller;
- use App\Models\System\Users;
- use App\Service\Admin\AdminService;
- use App\Service\Admin\PermissionService;
- use Illuminate\Http\Request;
- class UserPermissionController extends Controller
- {
- /**
- * 获取用户权限列表
- * @param Request $request
- * @return array
- */
- public function index(Request $request)
- {
- $admin_id = $request->input("admin_id");
- $sys_group_id = $request->input('sys_group_id');
- $is_system_admin = $request->input("is_system_admin");
- $view_type = $request->input("view_type",AdminService::VIEW_TYPE[0]);
- $res = PermissionService::user_permission($view_type,$admin_id,$is_system_admin,$sys_group_id);
-
- return self::returnValue($res);
- }
- /**
- * 判断用户是否有导出权限
- * */
- public function exportAuth(Request $request)
- {
- $admin_id = $request->input("admin_id",1);
- $sys_group_id = $request->input('sys_group_id');
- $is_system_admin = $request->input("is_system_admin");
- # 获取用户是否有导出权限
- if($is_system_admin || $admin_id == $sys_group_id) {
- $canExport = $adqAuth = $mpAuth = true;
- } else {
- $authInfo = Users::select('can_export', 'is_all_adq', 'adq_account', 'is_all_mp', 'mp_account')
- ->where('enable', 1)->where('id', $admin_id)->first();
- if(empty($authInfo)) {
- $canExport = $adqAuth = $mpAuth = false;
- } else {
- $adqAuth = $mpAuth = true;
- $canExport = $authInfo->can_export;
- if(!$authInfo->is_all_adq && !$authInfo->adq_account) $adqAuth = false;
- if(!$authInfo->is_all_mp && !$authInfo->mp_account) $mpAuth = false;
- }
- }
- return self::returnValue(['can_export' => (bool)$canExport, 'adq_auth' => $adqAuth, 'mp_auth' => $mpAuth]);
- }
- /**
- * 用户画像
- * @param Request $request
- */
- public function user_profile(Request $request)
- {
- $admin_id = $request->input("admin_id");
- $sys_group_id = $request->input('sys_group_id');
- $is_system_admin = $request->input("is_system_admin");
- $manage_mode = [];
- if(PermissionService::user_permission(AdminService::VIEW_TYPE[0],$admin_id,$is_system_admin,$sys_group_id)!=[]){
- $manage_mode[] = AdminService::VIEW_TYPE[0];
- }
- if(PermissionService::user_permission(AdminService::VIEW_TYPE[1],$admin_id,$is_system_admin,$sys_group_id)!=[]){
- $manage_mode[] = AdminService::VIEW_TYPE[1];
- }
- $ret_info = [
- 'is_system_admin' => $is_system_admin,
- 'manage_mode' => $manage_mode,
- ];
- return self::returnValue($ret_info);
- }
- }
|