SystemRouteCate.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\setting;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\system\SystemRouteCateServices;
  14. use app\services\system\SystemRouteServices;
  15. use think\facade\App;
  16. use think\Request;
  17. /**
  18. * Class SystemRouteCate
  19. * @author 等风来
  20. * @email 136327134@qq.com
  21. * @date 2023/4/6
  22. * @package app\adminapi\controller\v1\setting
  23. */
  24. class SystemRouteCate extends AuthController
  25. {
  26. /**
  27. * SystemRouteCate constructor.
  28. * @param App $app
  29. * @param SystemRouteCateServices $services
  30. */
  31. public function __construct(App $app, SystemRouteCateServices $services)
  32. {
  33. parent::__construct($app);
  34. $this->services = $services;
  35. }
  36. /**
  37. * @return \think\Response
  38. * @author 等风来
  39. * @email 136327134@qq.com
  40. * @date 2023/4/6
  41. */
  42. public function index()
  43. {
  44. return app('json')->success($this->services->getAllList());
  45. }
  46. /**
  47. * @return \think\Response
  48. * @author 等风来
  49. * @email 136327134@qq.com
  50. * @date 2023/4/6
  51. */
  52. public function create()
  53. {
  54. return app('json')->success($this->services->getFrom(0, $this->request->get('app_name', 'adminapi')));
  55. }
  56. /**
  57. * @param Request $request
  58. * @return \think\Response
  59. * @author 等风来
  60. * @email 136327134@qq.com
  61. * @date 2023/4/6
  62. */
  63. public function save(Request $request)
  64. {
  65. $data = $request->postMore([
  66. ['path', []],
  67. ['name', ''],
  68. ['sort', 0],
  69. ['app_name', ''],
  70. ]);
  71. if (!$data['name']) {
  72. return app('json')->fail('接口分类名称不能为空');
  73. }
  74. $data['add_time'] = time();
  75. $data['pid'] = $data['path'][count($data['path']) - 1] ?? 0;
  76. $this->services->save($data);
  77. return app('json')->success('保存成功');
  78. }
  79. /**
  80. * @param $id
  81. * @return \think\Response
  82. * @author 等风来
  83. * @email 136327134@qq.com
  84. * @date 2023/4/6
  85. */
  86. public function edit($id)
  87. {
  88. return app('json')->success($this->services->getFrom($id, $this->request->get('app_name', 'adminapi')));
  89. }
  90. /**
  91. * @param Request $request
  92. * @param $id
  93. * @return \think\Response
  94. * @author 等风来
  95. * @email 136327134@qq.com
  96. * @date 2023/4/6
  97. */
  98. public function update(Request $request, $id)
  99. {
  100. $data = $request->postMore([
  101. ['path', []],
  102. ['name', ''],
  103. ['sort', 0],
  104. ['app_name', ''],
  105. ]);
  106. if (!$data['name']) {
  107. return app('json')->fail('接口分类名称不能为空');
  108. }
  109. $data['pid'] = $data['path'][count($data['path']) - 1] ?? 0;
  110. $this->services->update($id, $data);
  111. return app('json')->success('修改成功');
  112. }
  113. /**
  114. * @param SystemRouteServices $service
  115. * @param $id
  116. * @return \think\Response
  117. * @author 等风来
  118. * @email 136327134@qq.com
  119. * @date 2023/4/6
  120. */
  121. public function delete(SystemRouteServices $service, $id)
  122. {
  123. if (!$id) {
  124. return app('json')->fail('接口不存在');
  125. }
  126. if ($service->count(['cate_id' => $id])) {
  127. return app('json')->fail('该分类下有接口,无法删除');
  128. }
  129. $this->services->delete($id);
  130. return app('json')->success('删除成功');
  131. }
  132. }