Role.php 2.5 KB

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