SystemRoute.php 4.2 KB

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