ProjectController.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 ProjectController
  19. {
  20. // 返回json类型
  21. private $returnJson = array('type' => 'project');
  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 addProject()
  38. {
  39. $nameLen = mb_strlen(quickInput('projectName'), 'utf8');
  40. $projectName = securelyInput('projectName');
  41. $projectType = securelyInput('projectType');
  42. $projectVersion = quickInput('projectVersion');
  43. $version_len = mb_strlen(quickInput('projectVersion'));
  44. // 验证项目名和项目类型格式
  45. if (!($nameLen >= 1 && $nameLen <= 32 && preg_match('/^[0-3]{1}$/', $projectType))) {
  46. // 项目名或项目类型不合法
  47. $this->returnJson['statusCode'] = '140002';
  48. } elseif ($version_len < 1 || $version_len > 10) {
  49. // 项目版本不合法
  50. $this->returnJson['statusCode'] = '140017';
  51. } else {
  52. // 项目名和项目类型合法
  53. $service = new ProjectModule();
  54. $result = $service->addProject($projectName, $projectType, $projectVersion);
  55. // 判断新建项目是否成功
  56. if ($result) {
  57. // 新建项目成功
  58. $this->returnJson['statusCode'] = '000000';
  59. $this->returnJson['projectInfo'] = $result;
  60. } else
  61. // 新建项目失败
  62. $this->returnJson['statusCode'] = '140001';
  63. }
  64. exitOutput($this->returnJson);
  65. }
  66. /**
  67. * 删除项目
  68. */
  69. public function deleteProject()
  70. {
  71. $projectID = securelyInput('projectID');
  72. $module = new ProjectModule();
  73. $userType = $module->getUserType($projectID);
  74. if ($userType != 0) {
  75. $this->returnJson['statusCode'] = '120007';
  76. exitOutput($this->returnJson);
  77. }
  78. // 判断项目ID是否合法
  79. if (preg_match('/^[0-9]{1,11}$/', $projectID)) {
  80. // 项目ID合法
  81. $service = new ProjectModule();
  82. $result = $service->deleteProject($projectID);
  83. // 判断删除项目是否成功
  84. if ($result)
  85. // 删除项目成功
  86. $this->returnJson['statusCode'] = '000000';
  87. else
  88. // 删除项目失败
  89. $this->returnJson['statusCode'] = '140003';
  90. } else {
  91. // 项目ID不合法
  92. $this->returnJson['statusCode'] = '140004';
  93. }
  94. exitOutput($this->returnJson);
  95. }
  96. /**
  97. * 获取项目列表
  98. */
  99. public function getProjectList()
  100. {
  101. $nameLen = mb_strlen(quickInput('projectName'), 'utf8');
  102. $projectType = securelyInput('projectType');
  103. //$projectName = securelyInput('projectName');
  104. if (!preg_match('/^[0-3]|[-1]{1}$/', $projectType) || ($nameLen != 0 && $nameLen < 1 || $nameLen > 30)) {
  105. // 项目类型或项目名称不合法
  106. $this->returnJson['statusCode'] = '140002';
  107. exitOutput($this->returnJson);
  108. } else {
  109. $service = new ProjectModule();
  110. $result = $service->getProjectList($projectType);
  111. if ($result) {
  112. // 获取项目列表成功
  113. $this->returnJson['statusCode'] = '000000';
  114. $this->returnJson['projectList'] = $result;
  115. } else {
  116. // 项目列表为空
  117. $this->returnJson['statusCode'] = '140005';
  118. }
  119. }
  120. exitOutput($this->returnJson);
  121. }
  122. /**
  123. * 更改项目
  124. */
  125. public function editProject()
  126. {
  127. $nameLen = mb_strlen(quickInput('projectName'), 'utf8');
  128. $projectID = securelyInput('projectID');
  129. $module = new ProjectModule();
  130. $userType = $module->getUserType($projectID);
  131. if ($userType < 0 || $userType > 1) {
  132. $this->returnJson['statusCode'] = '120007';
  133. exitOutput($this->returnJson);
  134. }
  135. $projectType = securelyInput('projectType');
  136. $projectName = securelyInput('projectName');
  137. $projectVersion = quickInput('projectVersion');
  138. $version_len = mb_strlen(quickInput('projectVersion'));
  139. // 判断项目参数格式是否合法
  140. if (!(preg_match('/^[0-9]{1,11}$/', $projectID) && $nameLen >= 1 && $nameLen <= 32 && preg_match('/^[0-3]{1}$/', $projectType))) {
  141. // 项目参数格式不合法
  142. $this->returnJson['statusCode'] = '140007';
  143. } elseif ($version_len < 1 || $version_len > 10) {
  144. // 项目版本不合法
  145. $this->returnJson['statusCode'] = '140017';
  146. } else {
  147. // 项目参数格式合法
  148. $service = new ProjectModule();
  149. $result = $service->editProject($projectID, $projectName, $projectType, $projectVersion);
  150. // 判断修改项目是否成功
  151. if ($result)
  152. // 项目修改成功
  153. $this->returnJson['statusCode'] = '000000';
  154. else
  155. // 项目修改失败
  156. $this->returnJson['statusCode'] = '140006';
  157. }
  158. exitOutput($this->returnJson);
  159. }
  160. /**
  161. * 获取项目信息
  162. */
  163. public function getProject()
  164. {
  165. $projectID = securelyInput('projectID');
  166. if (preg_match('/^[0-9]{1,11}$/', $projectID)) {
  167. $service = new ProjectModule;
  168. $result = $service->getProject($projectID);
  169. if ($result) {
  170. $this->returnJson['statusCode'] = '000000';
  171. $this->returnJson = array_merge($this->returnJson, $result);
  172. } else {
  173. $this->returnJson['statusCode'] = '140005';
  174. }
  175. } else {
  176. $this->returnJson['statusCode'] = '140007';
  177. }
  178. exitOutput($this->returnJson);
  179. }
  180. // /**
  181. // * 获取项目环境列表
  182. // */
  183. // public function getEnvList()
  184. // {
  185. // $projectID = securelyInput('projectID');
  186. //
  187. // if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
  188. // //项目ID不合法
  189. // $this->returnJson['statusCode'] = '140004';
  190. // } else {
  191. // $service = new ProjectModule;
  192. // $result = $service->getEnvList($projectID);
  193. // if ($result) {
  194. // $this->returnJson['statusCode'] = '000000';
  195. // $this->returnJson['envList'] = $result;
  196. // } else {
  197. // //环境列表为空
  198. // $this->returnJson['statusCode'] = '140018';
  199. // }
  200. // }
  201. // exitOutput($this->returnJson);
  202. // }
  203. //
  204. // /**
  205. // * 添加项目环境
  206. // */
  207. // public function addEnv()
  208. // {
  209. // $projectID = securelyInput('projectID');
  210. // $envName = securelyInput('envName');
  211. // $envURI = securelyInput('envURI');
  212. //
  213. // if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
  214. // //项目ID不合法
  215. // $this->returnJson['statusCode'] = '140004';
  216. // } else {
  217. // $service = new ProjectModule;
  218. // $result = $service->addEnv($projectID, $envName, $envURI);
  219. // if ($result) {
  220. // $this->returnJson['statusCode'] = '000000';
  221. // $this->returnJson['envID'] = $result;
  222. // } else {
  223. // $this->returnJson['statusCode'] = '140019';
  224. // }
  225. // }
  226. // exitOutput($this->returnJson);
  227. // }
  228. //
  229. // /**
  230. // * 删除项目环境
  231. // */
  232. // public function deleteEnv()
  233. // {
  234. // $projectID = securelyInput('projectID');
  235. // $envID = securelyInput('envID');
  236. //
  237. // if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
  238. // //项目ID不合法
  239. // $this->returnJson['statusCode'] = '140004';
  240. // } elseif (!preg_match('/^[0-9]{1,11}$/', $envID)) {
  241. // //环境ID不合法
  242. // $this->returnJson['statusCode'] = '140022';
  243. // } else {
  244. // $service = new ProjectModule;
  245. // if ($service->deleteEnv($projectID, $envID)) {
  246. // $this->returnJson['statusCode'] = '000000';
  247. // } else {
  248. // //删除环境失败,projectID与envID不匹配
  249. // $this->returnJson['statusCode'] = '140020';
  250. // }
  251. // }
  252. // exitOutput($this->returnJson);
  253. // }
  254. //
  255. // /**
  256. // * 修改项目环境
  257. // */
  258. // public function editEnv()
  259. // {
  260. // $projectID = securelyInput('projectID');
  261. // $envID = securelyInput('envID');
  262. // $envName = securelyInput('envName');
  263. // $envURI = securelyInput('envURI');
  264. //
  265. // if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
  266. // //项目ID不合法
  267. // $this->returnJson['statusCode'] = '140004';
  268. // } elseif (!preg_match('/^[0-9]{1,11}$/', $envID)) {
  269. // //环境ID不合法
  270. // $this->returnJson['statusCode'] = '140022';
  271. // } else {
  272. // $service = new ProjectModule;
  273. // if ($service->editEnv($projectID, $envID, $envName, $envURI)) {
  274. // $this->returnJson['statusCode'] = '000000';
  275. // } else {
  276. // //修改失败
  277. // $this->returnJson['statusCode'] = '140021';
  278. // }
  279. // }
  280. // exitOutput($this->returnJson);
  281. // }
  282. /**
  283. * 导出项目
  284. */
  285. public function dumpProject()
  286. {
  287. $projectID = securelyInput('projectID');
  288. if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
  289. //项目ID不合法
  290. $this->returnJson['statusCode'] = '140004';
  291. exitOutput($this->returnJson);
  292. }
  293. $service = new ProjectModule;
  294. $fileName = $service->dumpProject($projectID);
  295. if ($fileName) {
  296. $this->returnJson['statusCode'] = '000000';
  297. $this->returnJson['fileName'] = $fileName;
  298. } else {
  299. //修改失败
  300. $this->returnJson['statusCode'] = '140021';
  301. }
  302. exitOutput($this->returnJson);
  303. }
  304. /**
  305. * 获取api数量
  306. */
  307. public function getApiNum()
  308. {
  309. $projectID = securelyInput('projectID');
  310. if (!preg_match('/^[0-9]{1,11}$/', $projectID)) {
  311. //项目ID不合法
  312. $this->returnJson['statusCode'] = '140004';
  313. exitOutput($this->returnJson);
  314. }
  315. $service = new ProjectModule;
  316. $result = $service->getApiNum($projectID);
  317. if ($result) {
  318. $this->returnJson['statusCode'] = '000000';
  319. $this->returnJson['num'] = $result['num'];
  320. } else {
  321. $this->returnJson['statusCode'] = '140023';
  322. }
  323. exitOutput($this->returnJson);
  324. }
  325. /**
  326. * 获取项目动态
  327. */
  328. public function getProjectLogList()
  329. {
  330. //项目ID
  331. $project_id = securelyInput('projectID');
  332. //页码,默认1
  333. $page = securelyInput('page', 1);
  334. //每页的条目数量,默认10
  335. $page_size = securelyInput('pageSize', 15);
  336. if (!preg_match('/^[0-9]{1,11}$/', $project_id)) {
  337. // 项目ID不合法
  338. $this->returnJson['statusCode'] = '140004';
  339. } else {
  340. $service = new ProjectModule();
  341. $result = $service->getProjectLogList($project_id, $page, $page_size);
  342. if ($result) {
  343. //成功
  344. $this->returnJson['statusCode'] = '000000';
  345. $this->returnJson = array_merge($this->returnJson, $result);
  346. } else {
  347. //获取失败,可能数据库出错
  348. $this->returnJson['statusCode'] = '140000';
  349. }
  350. }
  351. exitOutput($this->returnJson);
  352. }
  353. }
  354. ?>