SystemRoute.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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\SystemRouteServices;
  16. use think\facade\App;
  17. /**
  18. * Class SystemRoute
  19. * @author 等风来
  20. * @email 136327134@qq.com
  21. * @date 2023/4/6
  22. * @package app\adminapi\controller\v1\setting
  23. */
  24. class SystemRoute extends AuthController
  25. {
  26. /**
  27. * SystemRoute constructor.
  28. * @param App $app
  29. * @param SystemRouteServices $services
  30. */
  31. public function __construct(App $app, SystemRouteServices $services)
  32. {
  33. parent::__construct($app);
  34. $this->services = $services;
  35. }
  36. /**
  37. * 同步路由权限
  38. * @param string $appName
  39. * @return \think\Response
  40. * @author 等风来
  41. * @email 136327134@qq.com
  42. * @date 2023/4/6
  43. */
  44. public function syncRoute(string $appName = 'adminapi')
  45. {
  46. $this->services->syncRoute($appName);
  47. return app('json')->success(100038);
  48. }
  49. /**
  50. * 列表数据
  51. * @return \think\Response
  52. * @author 等风来
  53. * @email 136327134@qq.com
  54. * @date 2023/4/7
  55. */
  56. public function index()
  57. {
  58. $where = $this->request->getMore([
  59. ['name_like', ''],
  60. ['app_name', 'adminapi']
  61. ]);
  62. return app('json')->success($this->services->getList($where));
  63. }
  64. /**
  65. * tree数据
  66. * @return \think\Response
  67. * @author 等风来
  68. * @email 136327134@qq.com
  69. * @date 2023/4/7
  70. */
  71. public function tree()
  72. {
  73. [$name, $appName] = $this->request->getMore([
  74. ['name_like', ''],
  75. ['app_name', 'adminapi']
  76. ], true);
  77. return app('json')->success($this->services->getTreeList($appName, $name));
  78. }
  79. /**
  80. * @return \think\Response
  81. * @author 等风来
  82. * @email 136327134@qq.com
  83. * @date 2023/4/7
  84. */
  85. public function save($id = 0)
  86. {
  87. $data = $this->request->postMore([
  88. ['cate_id', 0],
  89. ['name', ''],
  90. ['path', ''],
  91. ['method', ''],
  92. ['type', 0],
  93. ['app_name', ''],
  94. ['request', []],
  95. ['response', []],
  96. ['request_example', []],
  97. ['response_example', []],
  98. ['describe', ''],
  99. ]);
  100. // if (!$data['name']) {
  101. // return app('json')->fail(500031);
  102. // }
  103. // if (!$data['path']) {
  104. // return app('json')->fail(500032);
  105. // }
  106. // if (!$data['method']) {
  107. // return app('json')->fail(500033);
  108. // }
  109. // if (!$data['app_name']) {
  110. // return app('json')->fail(500034);
  111. // }
  112. if ($id) {
  113. $this->services->update($id, $data);
  114. } else {
  115. $data['add_time'] = date('Y-m-d H:i:s');
  116. $this->services->save($data);
  117. }
  118. $this->services->cacheDriver()->clear();
  119. return app('json')->success($id ? 100001 : 100021);
  120. }
  121. /**
  122. * @param $id
  123. * @return \think\Response
  124. * @author 等风来
  125. * @email 136327134@qq.com
  126. * @date 2023/4/7
  127. */
  128. public function read($id)
  129. {
  130. return app('json')->success($this->services->getInfo((int)$id));
  131. }
  132. /**
  133. * @param $id
  134. * @return \think\Response
  135. * @author 等风来
  136. * @email 136327134@qq.com
  137. * @date 2023/4/7
  138. */
  139. public function delete($id)
  140. {
  141. if (!$id) {
  142. return app('json')->fail(500035);
  143. }
  144. $this->services->destroy($id);
  145. return app('json')->success(100002);
  146. }
  147. }