SystemRoute.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. ['error_code', []],
  103. ]);
  104. // if (!$data['name']) {
  105. // return app('json')->fail(500031);
  106. // }
  107. // if (!$data['path']) {
  108. // return app('json')->fail(500032);
  109. // }
  110. // if (!$data['method']) {
  111. // return app('json')->fail(500033);
  112. // }
  113. // if (!$data['app_name']) {
  114. // return app('json')->fail(500034);
  115. // }
  116. if ($id) {
  117. $this->services->update($id, $data);
  118. } else {
  119. $data['add_time'] = date('Y-m-d H:i:s');
  120. $this->services->save($data);
  121. }
  122. CacheService::clear();
  123. return app('json')->success($id ? 100001 : 100021);
  124. }
  125. /**
  126. * @param $id
  127. * @return \think\Response
  128. * @author 等风来
  129. * @email 136327134@qq.com
  130. * @date 2023/4/7
  131. */
  132. public function read($id)
  133. {
  134. return app('json')->success($this->services->getInfo((int)$id));
  135. }
  136. /**
  137. * @param $id
  138. * @return \think\Response
  139. * @author 等风来
  140. * @email 136327134@qq.com
  141. * @date 2023/4/7
  142. */
  143. public function delete($id)
  144. {
  145. if (!$id) {
  146. return app('json')->fail(500035);
  147. }
  148. $this->services->destroy($id);
  149. return app('json')->success(100002);
  150. }
  151. }