public function getAllRoleMenuRoleKey() { $secuityUrlKey = $this->secuityUrlKey(); $role_ids = $this->getAllRoleIds(); //var_dump($role_ids); $role_menu_keys = []; if (!empty($role_ids)) { foreach ($role_ids as $role_id) { $d_menu_ids = AdminRoleMenu::find()->asArray()->select(['menu_id'])->where(['role_id' => $role_id])->all(); $role_keys = []; $menu_ids = []; if (!empty($d_menu_ids)) { foreach ($d_menu_ids as $d) { $menu_ids[] = $d['menu_id']; } } if ($menu_ids) { $menus = AdminMenu::find()->asArray()->where(['in', 'id', $menu_ids])->all(); // var_dump(['in','id',$menu_ids]); if (!empty($menus)) { foreach ($menus as $menu) { $role_keys[] = $menu['role_key']; } $role_menu_key[$role_id] = array_merge($role_keys, $secuityUrlKey); } } else { $role_menu_key[$role_id] = $secuityUrlKey; } } } return $role_menu_key; }
public function getActiveMenuIds() { if ($this->_active_menu_ids === null) { $user = Yii::$app->user->identity; $user_id = $user['id']; $roles = AdminUserRole::find()->asArray()->where(['user_id' => $user_id])->all(); $role_ids = []; if (!empty($roles)) { foreach ($roles as $one) { $role_ids[] = $one['role_id']; } } //var_dump($user);exit; $menu_ids = []; if (!empty($role_ids)) { $AdminRoleMenus = AdminRoleMenu::find()->asArray()->select(['menu_id'])->where(['in', 'role_id', $role_ids])->all(); if (!empty($AdminRoleMenus)) { foreach ($AdminRoleMenus as $menu) { $menu_ids[] = $menu['menu_id']; } } } $menu_ids = array_unique($menu_ids); $this->_active_menu_ids = $menu_ids; } return $this->_active_menu_ids; }
public function getActiveMenuIds() { if ($this->_active_menu_ids === null) { $user = Yii::$app->user->identity; //var_dump($user);exit; $menu_ids = []; if ($role_id = $user->role) { $AdminRoleMenus = AdminRoleMenu::find()->asArray()->select(['menu_id'])->where(['role_id' => $role_id])->all(); if (!empty($AdminRoleMenus)) { foreach ($AdminRoleMenus as $menu) { $menu_ids[] = $menu['menu_id']; } } } $this->_active_menu_ids = $menu_ids; } return $this->_active_menu_ids; }
public function delete() { //$request_param = CRequest::param(); //$this->_param = $request_param; //$this->initParam(); if ($role_id = CRequest::param($this->_paramKey)) { $model = AdminRole::findOne([$this->_paramKey => $role_id]); if ($model->role_id) { $innerTransaction = Yii::$app->db->beginTransaction(); try { $model->delete(); # 删除这个role 对应的所有关联的菜单 AdminRoleMenu::deleteAll(['role_id' => $role_id]); $innerTransaction->commit(); } catch (Exception $e) { $innerTransaction->rollBack(); } echo json_encode(["statusCode" => "200", "message" => 'Delete Success!']); exit; } else { echo json_encode(["statusCode" => "300", "message" => "role_id => {$role_id} , is not exist"]); exit; } } else { if ($ids = CRequest::param($this->_paramKey . 's')) { $id_arr = explode(",", $ids); $innerTransaction = Yii::$app->db->beginTransaction(); try { AdminRole::deleteAll(['in', 'role_id', $id_arr]); # 删除这个role 对应的所有关联的菜单 AdminRoleMenu::deleteAll(['in', 'role_id', $id_arr]); $innerTransaction->commit(); } catch (Exception $e) { $innerTransaction->rollBack(); } echo json_encode(["statusCode" => "200", "message" => "{$ids} Delete Success!"]); exit; } } echo json_encode(["statusCode" => "300", "message" => "role_id or ids Param is not Exist!"]); exit; }
public function deleteMenu() { $id = CRequest::param("id"); if (!$id) { echo json_encode(["statusCode" => "300", "message" => "id can not empty"]); exit; } else { $one = AdminMenu::find()->where(" id = " . $id . " AND can_delete = 2 ")->one(); //echo $one->id; if ($one->id) { $ids = $this->getMenuAllChildId($id); $ids[] = $id; # 1. 删除当前分类对应的所有子分类 # 2. 删除在menu_id 对应到权限中的所有menu_id $innerTransaction = Yii::$app->db->beginTransaction(); try { AdminRoleMenu::deleteAll(['in', 'menu_id', $ids]); $idsStr = implode(",", $ids); $one->deleteAll(" id in (" . $idsStr . ") AND can_delete = 2"); $innerTransaction->commit(); echo json_encode(["statusCode" => "200", "message" => "delete menu success! MENU NAME:" . $one->name]); } catch (Exception $e) { $innerTransaction->rollBack(); } exit; } else { echo json_encode(["statusCode" => "300", "message" => "the menu can not delete"]); exit; } } }