{'id'} ==1) { $value->skip = 'skip'; } else { $value->skip = ''; } } return $datum; } protected function _storePost($request) { $name = $request->input('name', ''); $status = $request->input('status', ''); if (empty($name)) { $this->errorMsg = "角色名称必填"; return false; } // 查询角色名称是否存在 $count = Role::where('name', $name)->count(); if ($count > 0) { $this->errorMsg = "角色名称已存在"; return false; } Role::create(['name' => $name,'status'=>$status]); return true; } protected function _updatePost($request, $id) { $name = $request->input('name', ''); $status = $request->input('status', ''); if (empty($name)) { $this->errorMsg = "角色名称必填"; return false; } $model = $this->repository->find($id); if (empty($model)) { $this->errorMsg = "角色不存在"; return false; } // 查询角色名称是否存在 $count = Role::where('name', $name)->where('id','<>',$id)->count(); if ($count > 0) { $this->errorMsg = "角色名称已存在"; return false; } Role::where('id',$id)->update(['name' => $name,'status'=>$status]); return true; } /** * @param Request $request * @param ResponseFactory $response * @param $id * @return \Illuminate\Http\JsonResponse * * 删除一行数据 */ protected function destroy(Request $request, ResponseFactory $response, $id = null) { if ($request->isMethod('post') && $request->ajax()) { $count = DB::table('users')->where('roles_id', $id)->count(); if ($count >= 1) { $data = [ 'status' => 1, 'message' => '当前角色已绑定账号不允许删除' ]; } else { $deleted = $this->repository->delete($id); $deleted === false ? $data = [ 'status' => 1, 'message' => self::ERROR_MSG ] : $data = [ 'status' => 0, 'message' => '' ]; } if ($request->wantsJson()) { return $response->json($data); } } } function getPermissionsView() { $id = request()->input('id'); $role = Role::where('id', $id)->first(); $permission=MenuServer::creatServer()->getPermissionsMenu($role->{'role_p_ids'}); $permission_ids= explode(',', $role->{'role_p_ids'}); if(empty($permission_ids))$permission_ids=[0]; return view('admins.roles.permissions',['permission'=>$permission,'permission_ids'=>$permission_ids,'id'=>$id]); } function setPermissions(){ $permission_ids=request()->input('permission_ids'); $id=request()->input('id'); if(empty($permission_ids)){ return $this->response('请选择权限', 'error'); } $role_p_ids=$permission_ids; if(is_string($permission_ids))$permission_ids=explode(',',$permission_ids); $p_permission_ids= Menu::where('level', 2)->whereIn('id',$permission_ids)->pluck('p_ids'); foreach ($p_permission_ids as $v){ $p_ids= explode(',',$v); $permission_ids=array_merge($permission_ids,$p_ids); } $permission_ids=array_unique($permission_ids); $permission_ids=implode(',',$permission_ids); Role::where('id',$id)->update(['permission_ids'=>$permission_ids,'role_p_ids'=>$role_p_ids]); return $this->response(self::SUCCESS_MSG, 'success', '', ''); } }