SystemRouteCate.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. $data['add_time'] = time();
  77. $res = $this->services->save($data);
  78. $path = $this->services->getPathValue($data['pid']);
  79. $path = $this->services->setPathValue($path, $res->id);
  80. $res->path = $path;
  81. $res->save();
  82. return app('json')->success('保存成功');
  83. }
  84. /**
  85. * @param $id
  86. * @return \think\Response
  87. * @author 等风来
  88. * @email 136327134@qq.com
  89. * @date 2023/4/6
  90. */
  91. public function edit($id)
  92. {
  93. return app('json')->success($this->services->getFrom($id));
  94. }
  95. /**
  96. * @param Request $request
  97. * @param $id
  98. * @return \think\Response
  99. * @author 等风来
  100. * @email 136327134@qq.com
  101. * @date 2023/4/6
  102. */
  103. public function update(Request $request, $id)
  104. {
  105. $data = $request->postMore([
  106. ['pid', 0],
  107. ['name', ''],
  108. ['sort', 0],
  109. ['app_name', ''],
  110. ]);
  111. if (!$data['name']) {
  112. return app('json')->fail('缺少分类名称');
  113. }
  114. $pid = $this->services->value($id, 'pid');
  115. if ($data['pid'] != $pid) {
  116. $path = $this->services->getPathValue($data['pid']);
  117. $data['path'] = $this->services->setPathValue($path, $id);
  118. }
  119. $this->services->update($id, $data);
  120. return app('json')->success('修改成功');
  121. }
  122. /**
  123. * @param SystemRouteServices $service
  124. * @param $id
  125. * @return \think\Response
  126. * @author 等风来
  127. * @email 136327134@qq.com
  128. * @date 2023/4/6
  129. */
  130. public function delete(SystemRouteServices $service, $id)
  131. {
  132. if (!$id) {
  133. return app('json')->fail('缺少参数');
  134. }
  135. if ($service->count(['cate_id' => $id])) {
  136. return app('json')->fail('请先删除分类下的接口');
  137. }
  138. $this->services->delete($id);
  139. return app('json')->success('删除成功');
  140. }
  141. }