SystemRouteCate.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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(0, $this->request->get('app_name', 'adminapi')));
  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. ['path', []],
  69. ['name', ''],
  70. ['sort', 0],
  71. ['app_name', ''],
  72. ]);
  73. if (!$data['name']) {
  74. return app('json')->fail(500037);
  75. }
  76. $data['add_time'] = time();
  77. $data['pid'] = $data['path'][count($data['path']) - 1] ?? 0;
  78. $this->services->save($data);
  79. return app('json')->success(100000);
  80. }
  81. /**
  82. * @param $id
  83. * @return \think\Response
  84. * @author 等风来
  85. * @email 136327134@qq.com
  86. * @date 2023/4/6
  87. */
  88. public function edit($id)
  89. {
  90. return app('json')->success($this->services->getFrom($id, $this->request->get('app_name', 'adminapi')));
  91. }
  92. /**
  93. * @param Request $request
  94. * @param $id
  95. * @return \think\Response
  96. * @author 等风来
  97. * @email 136327134@qq.com
  98. * @date 2023/4/6
  99. */
  100. public function update(Request $request, $id)
  101. {
  102. $data = $request->postMore([
  103. ['path', []],
  104. ['name', ''],
  105. ['sort', 0],
  106. ['app_name', ''],
  107. ]);
  108. if (!$data['name']) {
  109. return app('json')->fail(500037);
  110. }
  111. $data['pid'] = $data['path'][count($data['path']) - 1] ?? 0;
  112. $this->services->update($id, $data);
  113. return app('json')->success(100001);
  114. }
  115. /**
  116. * @param SystemRouteServices $service
  117. * @param $id
  118. * @return \think\Response
  119. * @author 等风来
  120. * @email 136327134@qq.com
  121. * @date 2023/4/6
  122. */
  123. public function delete(SystemRouteServices $service, $id)
  124. {
  125. if (!$id) {
  126. return app('json')->fail(500035);
  127. }
  128. if ($service->count(['cate_id' => $id])) {
  129. return app('json')->fail(500038);
  130. }
  131. $this->services->delete($id);
  132. return app('json')->success(100002);
  133. }
  134. }