SystemRouteCate.php 4.1 KB

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