'正常', 2 => '禁用']; public function Create() { $models = new Sysmenu(); $models->scenario = 'add'; $model = $models->Authenticator(Yii::$app->request->post('data')); if (!empty($model->pid)) { $model->id = $model->pid; $row = $model->FindById(); $model->path = $row->path . $row->id . ','; unset($model['id']); } if (is_object($model)) { if ($model->insert() == true) return true; } return $model; } public function Edit() { $model = new Sysmenu(); $model = $model->Authenticator(Yii::$app->request->post('data')); if (is_object($model)) { $model->id = Yii::$app->request->post('data')['id']; $row = $model->FindById(); $row->name = $model->name; $row->url = $model->url; $row->sort = $model->sort; $row->status = $model->status; $row->icon = $model->icon; if ($row->update() == true) return true; } return $model; } public function getchildren() { $model = new Sysmenu(); $modela = new Checkauthority(); $arrId = $modela->MenuAccess(); if (Yii::$app->session['user_info']['user'] != Yii::$app->params['UserSuperadministrator']) { $model->id = $arrId; } $model->pid = Yii::$app->request->post('pid'); $model->status = 1; $row = $model->MultipleConditionQuery('id,name as title,icon, url as href,pid'); //2级目录 if ($row == null) return false; $model->pid = array_column($row, 'id');; $list = $model->MultipleConditionQuery('id,name as title,icon, url as href,pid'); //三级目录 //重组三级菜单 if ($list != null) { foreach ($list as $key => $val) { $arr[$val['pid']][] = $val; } } foreach ($row as $k => $v) { if (!empty($arr[$v['id']])) { $row[$k]['children'] = $arr[$v['id']]; } } //重组返回数据 [父菜单ID]=>子菜单 $brr = []; $brr[Yii::$app->request->post('pid')] = $row; return $brr; } public function MenuListSorting() { $model = new Sysmenu(); // $model->status = 1; $rows = $model->getList(Yii::$app->request->post()); foreach ($rows['data'] as $key => $val) { $num = substr_count(trim($val['paths'], ','), ','); $rows['data'][$key]['name'] = '|' . str_repeat('___', $num) . $val['name']; // $rows['data'][$key]['status'] = $this->status[$val['status']]; $rows['data'][$key]['level'] = substr_count(trim($val['paths'], ','), ','); } return $rows; } public function TopMenu() { $Sysmenu = new Sysmenu(); $Sysmenu->pid = 0; if (Yii::$app->session['user_info']['user'] != Yii::$app->params['UserSuperadministrator']) { $model = new Checkauthority(); $Sysmenu->id = $model->MenuAccess(); } $Sysmenu->status = 1; $row = $Sysmenu->MultipleConditionQuery(['id', 'name', 'pid', 'path', 'url', 'sort', 'status']); return $row; } public function Del() { $model = new Sysmenu(); $model->pid = Yii::$app->request->post('id'); $row = $model->OneFind(); if ($row != null) return '请按层级关系逐个删除'; $model->pid = ''; $model->id = Yii::$app->request->post('id'); $one = $model->OneFind(); if ($one != null) { if ($one->delete() == true) return true; } return false; } /** *修改菜单栏状态 **/ public function EditMenuStatus() { $Menu_id = intval(Yii::$app->request->post('menuid')); $res = intval(Yii::$app->request->post('res')); $model = new Sysmenu(); $model->id = $Menu_id; $row = $model->FindById(); $row->status = $res; if ($row->update() == true) return true; return false; } /*更改排序*/ public function SetSortH() { $input = Yii::$app->request->post(); $rows = Sysmenu::findOne($input['id']); $rows->sort = $input['sort']; if($rows->update()) return true; return false; } }