Blame view

application/admin/controller/antis/department/Role.php 2.39 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  <?php
  
  namespace app\admin\controller\antis\department;
  
  use addons\antis\model\StaffRole;
  use addons\antis\model\StaffRule;
  use app\admin\controller\antis\Base;
  use addons\antis\model\Staff;
  
  /**
   * 角色管理
   */
  class Role extends Base
  {
      /**
       * @var \addons\antis\model\StaffRole
       */
      protected $model = null;
  
      public function _initialize()
      {
          parent::_initialize();
          $this->model = new StaffRole();
      }
  
      /**
       * 权限配置
       * @return string
       */
      public function rule($ids=null)
      {
          $map['id'] = $ids;
          if ($this->request->isAjax()) {
              $data   = $this->request->post('row/a');
  
              $result = $this->model->save(['rules'=>$data['rules'],'role_type'=>$data['role_type'],'is_sale'=>$data['is_sale'],'is_cost'=>$data['is_cost']], $map);
  
              if (!$result) {
                  $this->error('修改失败');
              }
              $this->success('修改成功');
          }
          $row=$this->model->get($ids);
          if(empty($row)){
              $this->error('信息不存在');
          }
          $rule=[1=>'本人',2=>'本人及下属',3=>'本部门',4=>'仅下属部门',5=>'本部门及下属部门',6=>'全部'];
  
          $this->view->assign('row',$row);
          $this->view->assign('rule',$rule);
          return $this->view->fetch();
      }
  
      /**
       * 获取菜单
       * @param null $ids
       */
      public function roletree($ids=null){
  
          $data = $this->model::where(['id'=>intval($ids)])->find();
          if(empty($data)){
              $this->error('数据不存在');
          }
          $rules=explode(',',$data['rules']??'');
          $staffRules=StaffRule::where([])->order('weigh desc,id asc')->select();
          $roleList=[];
          foreach ($staffRules as $v) {
            if(empty($roleList)){
                $roleList[] = [
                    'id' => $v['pid'],
                    'parent' => '#',
                    'text' => '全部',
                    'type' => 'menu',
                    'state' => ['opened' => true],
                ];
            }
              $roleList[] = array(
                  'id' => $v['id'],
                  'parent' => $v['pid'] ?? '#',
                  'text' => __($v['title']),
                  'type' => 'menu',
                  'state' => ['selected' => in_array($v['id'], $rules) ? true : false, 'opened' => true]
              );
          }
          $this->success('', null, $roleList);
      }
  }