DeptController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace app\admin\controller\sys_manage;
  3. use app\admin\service\sys_manage\DeptService;
  4. use app\admin\validate\sys_manage\DeptValidate;
  5. use app\common\Tree;
  6. use app\controller\Curd;
  7. use app\model\SysDept;
  8. use support\Request;
  9. use support\Response;
  10. class DeptController extends Curd
  11. {
  12. public function __construct()
  13. {
  14. $this->model = new SysDept();
  15. }
  16. /**
  17. * @Desc 部门列表
  18. * @Author Gorden
  19. * @Date 2024/2/21 10:29
  20. *
  21. * @param Request $request
  22. * @return \support\Response
  23. */
  24. public function deptList(Request $request)
  25. {
  26. $page = $request->get('page', 1);
  27. $limit = $request->get('limit', 10);
  28. $keywords = format_string($request->get('keywords', ''));
  29. return DeptService::deptList($page, $limit, $keywords);
  30. }
  31. public function select(Request $request): Response
  32. {
  33. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  34. $format = 'tree';
  35. $order = $request->get('order', 'desc');
  36. $field = $field ?? 'dept_addtimes';
  37. $query = $this->doSelect($where, $field, $order);
  38. return $this->doFormat($query, $format, 1000);
  39. }
  40. protected function formatTree($items): Response
  41. {
  42. $format_items = [];
  43. foreach ($items as $item) {
  44. $format_items[] = [
  45. 'name' => $item->dept_name,
  46. 'value' => (string)$item->dept_id,
  47. 'id' => $item->id ?? $item->dept_id,
  48. 'pid' => $item->pid ?? $item->dept_super_id,
  49. 'dept_id' => $item->dept_id,
  50. 'dept_name' => $item->dept_name,
  51. 'dept_super_id' => $item->dept_super_id,
  52. 'dept_status' => $item->dept_status,
  53. 'dept_category' => $item->dept_category,
  54. 'dept_code' => $item->dept_code,
  55. 'dept_telephone' => $item->dept_telephone,
  56. 'category_addtimes' => $item->category_addtimes,
  57. ];
  58. }
  59. $tree = new Tree($format_items);
  60. return json_success('success', $tree->getTree());
  61. }
  62. public function selectList(Request $request)
  63. {
  64. return DeptService::selectList($request);
  65. }
  66. /**
  67. * @Desc 部门详情
  68. * @Author Gorden
  69. * @Date 2024/2/21 10:35
  70. *
  71. * @param $id
  72. * @return \support\Response
  73. */
  74. public function deptInfo($id)
  75. {
  76. return DeptService::deptInfo($id);
  77. }
  78. /**
  79. * @Desc 创建部门
  80. * @Author Gorden
  81. * @Date 2024/2/21 9:22
  82. *
  83. * @param Request $request
  84. * @return \support\Response
  85. */
  86. public function addDept(Request $request)
  87. {
  88. $validate = new DeptValidate();
  89. if (!$validate->scene('add')->check($request->post())) {
  90. return json_fail($validate->getError());
  91. }
  92. return DeptService::insertDept($request->post());
  93. }
  94. /**
  95. * @Desc 修改部门
  96. * @Author Gorden
  97. * @Date 2024/2/21 10:15
  98. *
  99. * @param $id
  100. * @param Request $request
  101. * @return \support\Response
  102. */
  103. public function updateDept($id, Request $request)
  104. {
  105. $validate = new DeptValidate();
  106. if (!$validate->scene('update')->check($request->post())) {
  107. return json_fail($validate->getError());
  108. }
  109. return DeptService::updateDept($id, $request->post());
  110. }
  111. /**
  112. * @Desc 修改部门状态
  113. * @Author Gorden
  114. * @Date 2024/2/21 10:41
  115. *
  116. * @param $id
  117. * @param $status
  118. * @return \support\Response
  119. */
  120. public function updateStatus($id, Request $request)
  121. {
  122. $validate = new DeptValidate();
  123. if (!$validate->scene('update_status')->check($request->post())) {
  124. return json_fail($validate->getError());
  125. }
  126. return DeptService::updateStatus($id, $request->post('dept_status'));
  127. }
  128. public function delDept($id)
  129. {
  130. return DeptService::delDept($id);
  131. }
  132. }