Role.php 2.4 KB

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