123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/5
- * Time: 下午5:24
- */
- namespace backend\server;
- use backend\base\Help;
- use Yii;
- use common\models\Sysmenu;
- class Menus
- {
- public $status = [1 => '正常', 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;
- }
- }
|