Work.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * 项目管理控制器
  4. *
  5. * @author qifan
  6. * @date 2020-12-17
  7. */
  8. namespace app\admin\controller;
  9. use app\admin\logic\WorkLogic;
  10. use think\Hook;
  11. use think\Request;
  12. class Work extends ApiCommon
  13. {
  14. /**
  15. * 用于判断权限
  16. * @permission 无限制
  17. * @allow 登录用户可访问
  18. * @other 其他根据系统设置
  19. **/
  20. public function _initialize()
  21. {
  22. $action = [
  23. 'permission' => [''],
  24. 'allow' => ['rules', 'roles', 'saverole', 'readrole', 'updaterole', 'deleterole']
  25. ];
  26. Hook::listen('check_auth',$action);
  27. $request = Request::instance();
  28. $a = strtolower($request->action());
  29. if (!in_array($a, $action['permission'])) {
  30. parent::_initialize();
  31. }
  32. }
  33. /**
  34. * 规则列表
  35. *
  36. * @param WorkLogic $workLogic
  37. * @return \think\response\Json
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @throws \think\exception\DbException
  41. */
  42. public function rules(WorkLogic $workLogic)
  43. {
  44. $data = $workLogic->getRules();
  45. $result = [
  46. 'menu_id' => 0,
  47. 'menu_name' => "项目管理",
  48. 'menu_type' => 1,
  49. 'parent_id' => 0,
  50. 'realm' => 'work',
  51. 'children' => []
  52. ];
  53. $result['children'][] = ['id' => 0, 'title' => '项目', 'name' => 'work', 'children' => $data];
  54. return resultArray(['data' => $result]);
  55. }
  56. /**
  57. * 获取角色
  58. *
  59. * @param WorkLogic $workLogic
  60. * @return \think\response\Json
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. * @throws \think\exception\DbException
  64. */
  65. public function roles(WorkLogic $workLogic)
  66. {
  67. $data = $workLogic->getRoles();
  68. return resultArray(['data' => $data]);
  69. }
  70. /**
  71. * 创建角色
  72. *
  73. * @param WorkLogic $workLogic
  74. * @return \think\response\Json
  75. */
  76. public function saveRole(WorkLogic $workLogic)
  77. {
  78. $userInfo=$this->userInfo;
  79. if (empty($this->param['title'])) return resultArray(['error' => '请填写权限名称!']);
  80. $data=$workLogic->saveRole($this->param);
  81. if (!$data) return resultArray(['操作失败!']);
  82. # 添加系统操作日志
  83. SystemActionLog($userInfo['id'], 'admin_group','project', $data, 'save',$this->param['title'] , '', '','添加了项目管理权限:'.$this->param['title']);
  84. return resultArray(['data' => '操作成功!']);
  85. }
  86. /**
  87. * 权限角色详情
  88. *
  89. * @param WorkLogic $workLogic
  90. * @return \think\response\Json
  91. * @throws \think\db\exception\DataNotFoundException
  92. * @throws \think\db\exception\ModelNotFoundException
  93. * @throws \think\exception\DbException
  94. */
  95. public function readRole(WorkLogic $workLogic)
  96. {
  97. if (empty($this->param['id'])) return resultArray(['error' => '请选择权限角色!']);
  98. $data = $workLogic->readRole($this->param['id']);
  99. return resultArray(['data' => $data]);
  100. }
  101. /**
  102. * 编辑权限角色
  103. *
  104. * @param WorkLogic $workLogic
  105. * @return \think\response\Json
  106. * @throws \think\Exception
  107. * @throws \think\exception\PDOException
  108. */
  109. public function updateRole(WorkLogic $workLogic)
  110. {
  111. if (empty($this->param['id'])) return resultArray(['error' => '请选择要编辑的权限角色!']);
  112. if (empty($this->param['title'])) return resultArray(['error' => '请填写权限名称!']);
  113. $userInfo=$this->userInfo;
  114. $this->param['user_id']=$userInfo['id'];
  115. $data=$workLogic->updateRole($this->param);
  116. if ($data!==false)return resultArray(['data' => '操作成功!']);
  117. return resultArray(['error' => '操作失败!']);
  118. }
  119. /**
  120. * 删除权限角色
  121. *
  122. * @param WorkLogic $workLogic
  123. * @return \think\response\Json
  124. * @throws \think\Exception
  125. * @throws \think\exception\PDOException
  126. */
  127. public function deleteRole(WorkLogic $workLogic)
  128. {
  129. if (empty($this->param['id'])) return resultArray(['error' => '请选择要删除的权限角色!']);
  130. $userInfo=$this->userInfo;
  131. $result = $workLogic->deleteRole($this->param['id'],$userInfo['id']);
  132. if (empty($result['status'])) return resultArray(['error' => $result['error']]);
  133. return resultArray(['data' => '操作成功!']);
  134. }
  135. }