SystemRoute.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\setting;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\system\SystemRouteServices;
  14. use crmeb\services\CacheService;
  15. use think\facade\App;
  16. /**
  17. * Class SystemRoute
  18. * @author 等风来
  19. * @email 136327134@qq.com
  20. * @date 2023/4/6
  21. * @package app\adminapi\controller\v1\setting
  22. */
  23. class SystemRoute extends AuthController
  24. {
  25. /**
  26. * SystemRoute constructor.
  27. * @param App $app
  28. * @param SystemRouteServices $services
  29. */
  30. public function __construct(App $app, SystemRouteServices $services)
  31. {
  32. parent::__construct($app);
  33. $this->services = $services;
  34. }
  35. /**
  36. * 同步路由权限
  37. * @param string $appName
  38. * @return \think\Response
  39. * @author 等风来
  40. * @email 136327134@qq.com
  41. * @date 2023/4/6
  42. */
  43. public function syncRoute(string $appName = 'adminapi')
  44. {
  45. $this->services->syncRoute($appName);
  46. return app('json')->success('同步成功');
  47. }
  48. /**
  49. * 列表数据
  50. * @return \think\Response
  51. * @author 等风来
  52. * @email 136327134@qq.com
  53. * @date 2023/4/7
  54. */
  55. public function index()
  56. {
  57. $where = $this->request->getMore([
  58. ['name_like', ''],
  59. ['app_name', 'adminapi']
  60. ]);
  61. return app('json')->success($this->services->getList($where));
  62. }
  63. /**
  64. * tree数据
  65. * @return \think\Response
  66. * @author 等风来
  67. * @email 136327134@qq.com
  68. * @date 2023/4/7
  69. */
  70. public function tree()
  71. {
  72. [$name, $appName] = $this->request->getMore([
  73. ['name_like', ''],
  74. ['app_name', 'adminapi']
  75. ], true);
  76. return app('json')->success($this->services->getTreeList($appName, $name));
  77. }
  78. /**
  79. * @return \think\Response
  80. * @author 等风来
  81. * @email 136327134@qq.com
  82. * @date 2023/4/7
  83. */
  84. public function save($id = 0)
  85. {
  86. $data = $this->request->postMore([
  87. ['cate_id', 0],
  88. ['name', ''],
  89. ['path', ''],
  90. ['method', ''],
  91. ['type', 0],
  92. ['app_name', ''],
  93. ['query', []],
  94. ['header', []],
  95. ['request', []],
  96. ['response', []],
  97. ['request_example', []],
  98. ['response_example', []],
  99. ['describe', ''],
  100. ['error_code', []],
  101. ]);
  102. // if (!$data['name']) {
  103. // return app('json')->fail('接口名不能为空');
  104. // }
  105. // if (!$data['path']) {
  106. // return app('json')->fail('接口地址不能为空');
  107. // }
  108. // if (!$data['method']) {
  109. // return app('json')->fail('请求方式不能为空');
  110. // }
  111. // if (!$data['app_name']) {
  112. // return app('json')->fail('模块分类不能为空');
  113. // }
  114. if ($id) {
  115. $this->services->update($id, $data);
  116. } else {
  117. $data['add_time'] = date('Y-m-d H:i:s');
  118. $this->services->save($data);
  119. }
  120. CacheService::clear();
  121. return app('json')->success($id ? '修改成功' : '添加成功');
  122. }
  123. /**
  124. * @param $id
  125. * @return \think\Response
  126. * @author 等风来
  127. * @email 136327134@qq.com
  128. * @date 2023/4/7
  129. */
  130. public function read($id)
  131. {
  132. return app('json')->success($this->services->getInfo((int)$id));
  133. }
  134. /**
  135. * @param $id
  136. * @return \think\Response
  137. * @author 等风来
  138. * @email 136327134@qq.com
  139. * @date 2023/4/7
  140. */
  141. public function delete($id)
  142. {
  143. if (!$id) {
  144. return app('json')->fail('接口不存在');
  145. }
  146. $this->services->destroy($id);
  147. return app('json')->success('删除成功');
  148. }
  149. }