StatusCodeGroupController.class.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 StatusCodeGroupController
  19. {
  20. // 返回json类型
  21. private $returnJson = array('type' => 'status_code_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. * 添加分组
  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. if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
  50. //项目ID格式不合法
  51. $this->returnJson['statusCode'] = '180005';
  52. } elseif (!($nameLen >= 1 && $nameLen <= 32)) {
  53. //分组名称不合法
  54. $this->returnJson['statusCode'] = '180004';
  55. } else {
  56. $service = new StatusCodeGroupModule;
  57. $result = $service->addGroup($projectID, $groupName, $parentGroupID);
  58. if ($result) {
  59. //添加分组成功
  60. $this->returnJson['statusCode'] = '000000';
  61. $this->returnJson['statusGroupID'] = $result;
  62. } else {
  63. //添加分组失败
  64. $this->returnJson['statusCode'] = '180002';
  65. }
  66. }
  67. exitOutput($this->returnJson);
  68. }
  69. /**
  70. * 删除分组
  71. */
  72. public function deleteGroup()
  73. {
  74. $groupID = securelyInput('groupID');
  75. $module = new StatusCodeGroupModule();
  76. $userType = $module->getUserType($groupID);
  77. if ($userType < 0 || $userType > 2) {
  78. $this->returnJson['statusCode'] = '120007';
  79. exitOutput($this->returnJson);
  80. }
  81. if (!preg_match('/^[0-9]{1,11}$/', $groupID)) {
  82. //分组ID格式不合法
  83. $this->returnJson['statusCode'] = '180003';
  84. } else {
  85. $service = new StatusCodeGroupModule;
  86. $result = $service->deleteGroup($groupID);
  87. if ($result) {
  88. $this->returnJson['statusCode'] = '000000';
  89. } else {
  90. $this->returnJson['statusCode'] = '180006';
  91. }
  92. }
  93. exitOutput($this->returnJson);
  94. }
  95. /**
  96. * 获取分组列表
  97. */
  98. public function getGroupList()
  99. {
  100. $projectID = securelyInput('projectID');
  101. if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
  102. //项目ID格式不合法
  103. $this->returnJson['statusCode'] = '180005';
  104. } else {
  105. $service = new StatusCodeGroupModule;
  106. $result = $service->getGroupList($projectID);
  107. if ($result) {
  108. $this->returnJson['statusCode'] = '000000';
  109. $this->returnJson = array_merge($this->returnJson, $result);
  110. } else {
  111. $this->returnJson['statusCode'] = '180001';
  112. }
  113. }
  114. exitOutput($this->returnJson);
  115. }
  116. /**
  117. * 修改分组
  118. */
  119. public function editGroup()
  120. {
  121. $nameLen = mb_strlen(quickInput('groupName'), 'utf8');
  122. $groupID = securelyInput('groupID');
  123. $parentGroupID = securelyInput('parentGroupID');
  124. $module = new StatusCodeGroupModule();
  125. $userType = $module->getUserType($groupID);
  126. if ($userType < 0 || $userType > 2) {
  127. $this->returnJson['statusCode'] = '120007';
  128. exitOutput($this->returnJson);
  129. }
  130. $groupName = securelyInput('groupName');
  131. if (!preg_match('/^[0-9]{1,11}$/', $groupID) || ($parentGroupID != NULL && !preg_match('/^[0-9]{1,11}$/', $parentGroupID))) {
  132. //项目ID格式不合法
  133. $this->returnJson['statusCode'] = '180003';
  134. } elseif (!($nameLen >= 1 && $nameLen <= 32)) {
  135. //分组名称不合法
  136. $this->returnJson['statusCode'] = '180004';
  137. } elseif ($groupID == $parentGroupID) {
  138. $this->returnJson['statusCode'] = '180009';
  139. } else {
  140. $service = new StatusCodeGroupModule;
  141. $result = $service->editGroup($groupID, $groupName, $parentGroupID);
  142. if ($result) {
  143. $this->returnJson['statusCode'] = '000000';
  144. } else {
  145. $this->returnJson['statusCode'] = '180007';
  146. }
  147. }
  148. exitOutput($this->returnJson);
  149. }
  150. /**
  151. * 修改状态码分组列表排序
  152. */
  153. public function sortGroup()
  154. {
  155. $projectID = securelyInput('projectID');
  156. $module = new ProjectModule();
  157. $userType = $module->getUserType($projectID);
  158. if ($userType < 0 || $userType > 2) {
  159. $this->returnJson['statusCode'] = '120007';
  160. exitOutput($this->returnJson);
  161. }
  162. //排序json字符串
  163. $orderList = quickInput('orderList');
  164. //判断排序格式是否合法
  165. if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
  166. $this->returnJson['statusCode'] = '180005';
  167. } else if (empty($orderList)) {
  168. //排序格式非法
  169. $this->returnJson['statusCode'] = '180008';
  170. } else {
  171. $service = new StatusCodeGroupModule();
  172. $result = $service->sortGroup($projectID, $orderList);
  173. //验证结果
  174. if ($result) {
  175. $this->returnJson['statusCode'] = '000000';
  176. } else {
  177. $this->returnJson['statusCode'] = '180000';
  178. }
  179. }
  180. exitOutput($this->returnJson);
  181. }
  182. /**
  183. * 导出分组
  184. */
  185. public function exportGroup()
  186. {
  187. //分组ID
  188. $group_id = securelyInput('groupID');
  189. if (!preg_match('/^[0-9]{1,11}$/', $group_id)) {
  190. // 分组ID格式不合法
  191. $this->returnJson['statusCode'] = '180003';
  192. } else {
  193. $service = new StatusCodeGroupModule();
  194. $user_type = $service->getUserType($group_id);
  195. if ($user_type < 0 || $user_type > 2) {
  196. $this->returnJson['statusCode'] = '120007';
  197. } else {
  198. $result = $service->exportGroup($group_id);
  199. if ($result) {
  200. $this->returnJson['statusCode'] = '000000';
  201. $this->returnJson['fileName'] = $result;
  202. } else {
  203. $this->returnJson['statusCode'] = '180000';
  204. }
  205. }
  206. }
  207. exitOutput($this->returnJson);
  208. }
  209. /**
  210. * 导入分组
  211. */
  212. public function importGroup()
  213. {
  214. $project_id = securelyInput('projectID');
  215. $json = quickInput('data');
  216. $data = json_decode($json, TRUE);
  217. if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
  218. $this->returnJson['statusCode'] = '180007';
  219. } //判断导入数据是否为空
  220. elseif (empty($data)) {
  221. $this->returnJson['statusCode'] = '180005';
  222. exitOutput($this->returnJson);
  223. } else {
  224. $service = new ProjectModule();
  225. $user_type = $service->getUserType($project_id);
  226. if ($user_type < 0 || $user_type > 2) {
  227. $this->returnJson['statusCode'] = '120007';
  228. }
  229. $server = new StatusCodeGroupModule();
  230. $result = $server->importGroup($project_id, $data);
  231. //验证结果
  232. if ($result) {
  233. $this->returnJson['statusCode'] = '000000';
  234. } else {
  235. $this->returnJson['statusCode'] = '180000';
  236. }
  237. }
  238. exitOutput($this->returnJson);
  239. }
  240. }
  241. ?>