'正常',2=>'禁用']; public function Create() { $models = new Frontend(); //$models->scenario = 'add'; $model = $models->Authenticator(Yii::$app->request->post()); if(!empty($model->pid)) { $model->id = $model->pid; $row = $model->FindById(); $model->path = $row->path.$row->id.','; unset($model['id']); }else{ $model->id = $model->pid; $model->path = '0'.','; } if(is_object($model)) { $url = Yii::$app->params['img_url']['city']; $icon = UploadFile::InstanceImgName('img',$url); if (is_string($icon)) { $model->icon = $icon; } if($model->insert() == true) return true; } return $model; } public function Edit() { /*$model = new Frontend(); $model = $model->Authenticator(Yii::$app->request->post()); if(is_object($model)) { $model->id = Yii::$app->request->post('data')['id']; $row = $model->FindById(); if(!empty($row)) { $row = Help::SetAttr(Yii::$app->request->post(),$model,$row); $url = Yii::$app->params['img_url']['city']; $img = UploadFile::InstanceImgName('img',$url); if(is_string($img)) { UploadFile::delImg($url,$row->icon); $row->icon = $img; $row->name = $model->name; $row->url = $model->url; $row->sort = $model->sort; $row->status = $model->status; } } if($row->save(false)) return true; } return $model;*/ $model = new Frontend(); $input = Yii::$app->request->post(); $setAttribute = $model->Authenticator($input); if(is_object($setAttribute)) { $model->id = $input['id']; $row = $model->FindById(); if($row != null) { $row = Help::SetAttr($input,$model,$row); $url = Yii::$app->params['img_url']['city']; $img = UploadFile::InstanceImgName('img',$url); if(is_string($img)) { UploadFile::delImg($url,$row->icon); $row->icon = $img; } if($row->save(false)) return true; } // return true; } return false; } public function getchildren() { $model = new Frontend(); $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 Frontend(); $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]['position'] = $val['position'] ==1 ? '首页' : '内页'; $rows['data'][$key]['level'] = substr_count(trim($val['paths'],','),','); } return $rows; } public function TopMenu() { $Sysmenu = new Frontend(); $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 Frontend(); $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; } }