GroupController.class.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /**
  3. * @name eolinker ams open source,eolinker开源版本
  4. * @link https://www.eolinker.com/
  5. * @package eolinker
  6. * @author www.eolinker.com 广州银云信息科技有限公司 ©2015-2018
  7. * eoLinker是目前全球领先、国内最大的在线API接口管理平台,提供自动生成API文档、API自动化测试、Mock测试、团队协作等功能,旨在解决由于前后端分离导致的开发效率低下问题。
  8. * 如在使用的过程中有任何问题,欢迎加入用户讨论群进行反馈,我们将会以最快的速度,最好的服务态度为您解决问题。
  9. *
  10. * eoLinker AMS开源版的开源协议遵循Apache License 2.0,如需获取最新的eolinker开源版以及相关资讯,请访问:https://www.eolinker.com/#/os/download
  11. *
  12. * 官方网站:https://www.eolinker.com/
  13. * 官方博客以及社区:http://blog.eolinker.com/
  14. * 使用教程以及帮助:http://help.eolinker.com/
  15. * 商务合作邮箱:market@eolinker.com
  16. * 用户讨论QQ群:284421832
  17. */
  18. class GroupController
  19. {
  20. // 返回json类型
  21. private $returnJson = array('type' => 'group');
  22. /**
  23. * 检查登录状态
  24. */
  25. public function __construct()
  26. {
  27. // 身份验证
  28. $server = new GuestModule;
  29. if (!$server->checkLogin()) {
  30. $this->returnJson['statusCode'] = '120005';
  31. exitOutput($this->returnJson);
  32. }
  33. }
  34. /**
  35. * 添加项目api分组
  36. */
  37. public function addGroup()
  38. {
  39. $nameLen = mb_strlen(quickInput('groupName'), 'utf8');
  40. $projectID = securelyInput('projectID');
  41. $module = new ProjectModule();
  42. $userType = $module->getUserType($projectID);
  43. if ($userType < 0 || $userType > 2) {
  44. $this->returnJson['statusCode'] = '120007';
  45. exitOutput($this->returnJson);
  46. }
  47. $groupName = securelyInput('groupName');
  48. $parentGroupID = securelyInput('parentGroupID', NULL);
  49. // 判断项目ID和组名格式是否合法
  50. if (preg_match('/^[0-9]{1,11}$/', $projectID) && $nameLen >= 1 && $nameLen <= 30) {
  51. // 项目ID和组名合法
  52. $service = new GroupModule();
  53. $result = $service->addGroup($projectID, $groupName, $parentGroupID);
  54. // 判断添加项目api分组是否成功
  55. if ($result) {
  56. // 添加项目api分组成功
  57. $this->returnJson['statusCode'] = '000000';
  58. $this->returnJson['groupID'] = $result;
  59. } else
  60. // 添加项目api分组失败
  61. $this->returnJson['statusCode'] = '150001';
  62. } else {
  63. $this->returnJson['statusCode'] = '150002';
  64. }
  65. exitOutput($this->returnJson);
  66. }
  67. /**
  68. * 删除项目api分组
  69. */
  70. public function deleteGroup()
  71. {
  72. $groupID = securelyInput('groupID');
  73. $module = new GroupModule();
  74. $userType = $module->getUserType($groupID);
  75. if ($userType < 0 || $userType > 2) {
  76. $this->returnJson['statusCode'] = '120007';
  77. exitOutput($this->returnJson);
  78. }
  79. // 判断分组ID格式是否合法
  80. if (preg_match('/^[0-9]{1,11}$/', $groupID)) {
  81. // 分组ID格式合法
  82. $service = new GroupModule();
  83. $result = $service->deleteGroup($groupID);
  84. // 判断删除项目api分组是否成功
  85. if ($result)
  86. // 删除项目api分组成功
  87. $this->returnJson['statusCode'] = '000000';
  88. else
  89. // 删除api分组失败
  90. $this->returnJson['statusCode'] = '150003';
  91. } else {
  92. // 分组ID格式不合法
  93. $this->returnJson['statusCode'] = '150004';
  94. }
  95. exitOutput($this->returnJson);
  96. }
  97. /**
  98. * 获取项目api分组列表
  99. */
  100. public function getGroupList()
  101. {
  102. $projectID = securelyInput('projectID');
  103. if (preg_match('/^[0-9]{1,11}$/', $projectID)) {
  104. $service = new GroupModule;
  105. $result = $service->getGroupList($projectID);
  106. $orderList = $service->getGroupOrderList($projectID);
  107. if ($result) {
  108. $this->returnJson['statusCode'] = '000000';
  109. $this->returnJson['groupList'] = $result;
  110. $this->returnJson['groupOrder'] = $orderList;
  111. } else {
  112. $this->returnJson['statusCode'] = '150008';
  113. }
  114. } else {
  115. $this->returnJson['statusCode'] = '150007';
  116. }
  117. exitOutput($this->returnJson);
  118. }
  119. /**
  120. * 修改api分组
  121. */
  122. public function editGroup()
  123. {
  124. $nameLen = mb_strlen(quickInput('groupName'), 'utf8');
  125. $groupID = securelyInput('groupID');
  126. $parentGroupID = securelyInput('parentGroupID');
  127. $module = new GroupModule();
  128. $userType = $module->getUserType($groupID);
  129. if ($userType < 0 || $userType > 2) {
  130. $this->returnJson['statusCode'] = '120007';
  131. exitOutput($this->returnJson);
  132. }
  133. $groupName = securelyInput('groupName');
  134. // 判断分组ID和组名格式是否合法
  135. if (preg_match('/^[0-9]{1,11}$/', $groupID) && $nameLen >= 1 && $nameLen <= 30) {
  136. if ($groupID == $parentGroupID) {
  137. $this->returnJson['statusCode'] = '150008';
  138. exitOutput($this->returnJson);
  139. }
  140. $service = new GroupModule();
  141. $result = $service->editGroup($groupID, $groupName, $parentGroupID);
  142. if ($result)
  143. // 修改api分组成功
  144. $this->returnJson['statusCode'] = '000000';
  145. else
  146. // 修改api分组失败
  147. $this->returnJson['statusCode'] = '150005';
  148. } else {
  149. // 分组ID和组名格式不合法
  150. $this->returnJson['statusCode'] = '150002';
  151. }
  152. exitOutput($this->returnJson);
  153. }
  154. /**
  155. * 修改分组列表排序
  156. */
  157. public function sortGroup()
  158. {
  159. $projectID = securelyInput('projectID');
  160. $module = new ProjectModule();
  161. $userType = $module->getUserType($projectID);
  162. if ($userType < 0 || $userType > 2) {
  163. $this->returnJson['statusCode'] = '120007';
  164. exitOutput($this->returnJson);
  165. }
  166. //排序json字符串
  167. $orderList = quickInput('orderList');
  168. //判断排序格式是否合法
  169. if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
  170. $this->returnJson['statusCode'] = '150007';
  171. } else if (empty($orderList)) {
  172. //排序格式非法
  173. $this->returnJson['statusCode'] = '150004';
  174. } else {
  175. $service = new GroupModule;
  176. $result = $service->sortGroup($projectID, $orderList);
  177. //验证结果
  178. if ($result) {
  179. $this->returnJson['statusCode'] = '000000';
  180. } else {
  181. $this->returnJson['statusCode'] = '150000';
  182. }
  183. }
  184. exitOutput($this->returnJson);
  185. }
  186. /**
  187. * 导出接口分组
  188. */
  189. public function exportGroup()
  190. {
  191. //分组ID
  192. $group_id = securelyInput('groupID');
  193. if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
  194. // 分组ID格式不合法
  195. $this->returnJson['statusCode'] = '150003';
  196. } else {
  197. $service = new GroupModule();
  198. $user_type = $service->getUserType($group_id);
  199. if ($user_type < 0 || $user_type > 2) {
  200. $this->returnJson['statusCode'] = '120007';
  201. } else {
  202. $result = $service->exportGroup($group_id);
  203. if ($result) {
  204. $this->returnJson['statusCode'] = '000000';
  205. $this->returnJson['fileName'] = $result;
  206. } else {
  207. $this->returnJson['statusCode'] = '150000';
  208. }
  209. }
  210. }
  211. exitOutput($this->returnJson);
  212. }
  213. /**
  214. * 导入接口分组
  215. */
  216. public function importGroup()
  217. {
  218. $project_id = securelyInput('projectID');
  219. $json = quickInput('data');
  220. $data = json_decode($json, TRUE);
  221. if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
  222. $this->returnJson['statusCode'] = '150007';
  223. } //判断导入数据是否为空
  224. elseif (empty($data)) {
  225. $this->returnJson['statusCode'] = '150005';
  226. exitOutput($this->returnJson);
  227. } else {
  228. $service = new ProjectModule();
  229. $user_type = $service->getUserType($project_id);
  230. if ($user_type < 0 || $user_type > 2) {
  231. $this->returnJson['statusCode'] = '120007';
  232. }
  233. $server = new GroupModule();
  234. $result = $server->importGroup($project_id, $data);
  235. //验证结果
  236. if ($result) {
  237. $this->returnJson['statusCode'] = '000000';
  238. } else {
  239. $this->returnJson['statusCode'] = '150000';
  240. }
  241. }
  242. exitOutput($this->returnJson);
  243. }
  244. }
  245. ?>