Site.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\site;
  12. use app\dict\site\SiteDict;
  13. use app\service\admin\auth\AuthSiteService;
  14. use app\service\admin\site\SiteService;
  15. use core\base\BaseAdminController;
  16. use think\Response;
  17. class Site extends BaseAdminController
  18. {
  19. /**
  20. * 站点列表
  21. * @return Response
  22. */
  23. public function lists()
  24. {
  25. $data = $this->request->params([
  26. ['keyword', ''],
  27. ['status', ''],
  28. ['group_id', 0],
  29. ['create_time', []],
  30. ['expire_time', []],
  31. ['app', ''],
  32. ['site_domain', '']
  33. ]);
  34. return success((new SiteService())->getPage($data));
  35. }
  36. /**
  37. * 站点详情
  38. * @param int $id
  39. * @return Response
  40. */
  41. public function info(int $id)
  42. {
  43. return success((new SiteService())->getInfo($id));
  44. }
  45. /**
  46. * 添加站点
  47. * ['site_name' => '', 'username' => '', 'head_img' => '', 'real_name' => '', 'password' => '', 'expire_time' => 0]
  48. * @return Response
  49. */
  50. public function add()
  51. {
  52. $data = $this->request->params([
  53. ['site_name', ''],
  54. ['uid', 0],
  55. ['username', ''],
  56. ['real_name', ''],
  57. ['password', ''],
  58. ['group_id', 0],
  59. ['expire_time', 0],
  60. ['site_domain', ''],
  61. ]);
  62. $this->validate($data, 'app\validate\site\Site.add');
  63. if (empty($data['uid'])) $this->validate($data, 'app\validate\sys\User.add');
  64. $site_id = (new SiteService())->add($data);
  65. return success('ADD_SUCCESS', ['site_id' => $site_id]);
  66. }
  67. /**
  68. * 站点状态
  69. * @return Response
  70. */
  71. public function getStatusList()
  72. {
  73. return success(SiteDict::getStatus());
  74. }
  75. /**
  76. * 站点菜单
  77. * @return Response
  78. */
  79. public function menu()
  80. {
  81. return success((new AuthSiteService())->getMenuList(1, 1, 'all', 0));
  82. }
  83. /**
  84. * 关闭站点
  85. */
  86. public function closeSite($id)
  87. {
  88. $data = $this->request->params([
  89. ['status', SiteDict::CLOSE],
  90. ]);
  91. (new SiteService())->edit($id, $data);
  92. return success();
  93. }
  94. /**
  95. * 菜单或接口更新
  96. */
  97. public function edit($id)
  98. {
  99. $data = $this->request->params([
  100. ['site_name', ''],
  101. ['expire_time', 0],
  102. ['group_id',0],
  103. ['site_domain', ''],
  104. ]);
  105. $this->validate(array_merge($data, ['site_id' => $id]), 'app\validate\site\Site.edit');
  106. (new SiteService())->edit($id, $data);
  107. return success('MODIFY_SUCCESS');
  108. }
  109. /**
  110. * 删除站点
  111. * @param $id
  112. * @return Response
  113. */
  114. public function del($id) {
  115. (new SiteService())->del($id);
  116. return success('DELETE_SUCCESS');
  117. }
  118. /**
  119. * 开启站点
  120. */
  121. public function openSite($id)
  122. {
  123. $data = $this->request->params([
  124. ['status', SiteDict::ON],
  125. ]);
  126. (new SiteService())->edit($id, $data);
  127. return success();
  128. }
  129. public function indexConfig()
  130. {
  131. }
  132. /**
  133. * 获取站点拥有的应用
  134. * @return Response
  135. */
  136. public function addons() {
  137. $data = $this->request->params([
  138. ['title', ''],
  139. ]);
  140. $data = (new SiteService())->getSiteAddons($data);
  141. return success(data:$data);
  142. }
  143. }