DatabaseTableFieldController.class.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 DatabaseTableFieldController
  19. {
  20. //返回Json类型
  21. private $returnJson = array('type' => 'database_table_field');
  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 addField()
  38. {
  39. $tableID = securelyInput('tableID');
  40. $module = new DatabaseTableModule();
  41. $userType = $module->getUserType($tableID);
  42. if ($userType < 0 || $userType > 2) {
  43. $this->returnJson['statusCode'] = '120007';
  44. exitOutput($this->returnJson);
  45. }
  46. $nameLen = mb_strlen(quickInput('fieldName', 'utf8'));
  47. $fieldName = securelyInput('fieldName');
  48. $typeLen = mb_strlen(quickInput('fieldType', 'utf8'));
  49. $fieldType = securelyInput('fieldType');
  50. $fieldLength = securelyInput('fieldLength');
  51. $isNotNull = securelyInput('isNotNull');
  52. $isPrimaryKey = securelyInput('isPrimaryKey');
  53. $descLen = mb_strlen(quickInput('fieldDescription', 'utf8'));
  54. $fieldDescription = securelyInput('fieldDescription');
  55. $fieldDefaultValue = securelyInput('defaultValue');
  56. if (!preg_match('/^[0-9]{1,11}$/', $tableID)) {
  57. $this->returnJson['statusCode'] = '240001';
  58. } elseif (!($nameLen >= 1 && $nameLen <= 255)) {
  59. // 字段名长度不合法
  60. $this->returnJson['statusCode'] = '240002';
  61. } elseif (!($typeLen >= 1 && $typeLen <= 255)) {
  62. $this->returnJson['statusCode'] = '240003';
  63. } elseif (!preg_match('/^[0-9]{1}$/', $isNotNull) || !preg_match('/^[0-9]{1}$/', $isPrimaryKey)) {
  64. $this->returnJson['statusCode'] = '240004';
  65. } elseif (!($descLen >= 0 && $descLen <= 255)) {
  66. // 字段描述长度不合法
  67. $this->returnJson['statusCode'] = '240005';
  68. } else {
  69. $service = new DatabaseTableFieldModule;
  70. $result = $service->addField($tableID, $fieldName, $fieldType, $fieldLength, $isNotNull, $isPrimaryKey, $fieldDescription, $fieldDefaultValue);
  71. if ($result) {
  72. $this->returnJson['statusCode'] = '000000';
  73. $this->returnJson['fieldID'] = $result;
  74. } else {
  75. $this->returnJson['statusCode'] = '240006';
  76. }
  77. }
  78. exitOutput($this->returnJson);
  79. }
  80. /**
  81. * 删除字段
  82. */
  83. public function deleteField()
  84. {
  85. $fieldID = securelyInput('fieldID');
  86. $module = new DatabaseTableFieldModule();
  87. $userType = $module->getUserType($fieldID);
  88. if ($userType < 0 || $userType > 2) {
  89. $this->returnJson['statusCode'] = '120007';
  90. exitOutput($this->returnJson);
  91. }
  92. if (!preg_match('/^[0-9]{1,11}$/', $fieldID)) {
  93. $this->returnJson['statusCode'] = '240007';
  94. } else {
  95. $service = new DatabaseTableFieldModule;
  96. $result = $service->deleteField($fieldID);
  97. if ($result) {
  98. $this->returnJson['statusCode'] = '000000';
  99. } else {
  100. $this->returnJson['statusCode'] = '240008';
  101. }
  102. }
  103. exitOutput($this->returnJson);
  104. }
  105. /**
  106. * 获取字段列表
  107. */
  108. public function getField()
  109. {
  110. $tableID = securelyInput('tableID');
  111. if (!preg_match('/^[0-9]{1,11}$/', $tableID)) {
  112. $this->returnJson['statusCode'] = '240001';
  113. } else {
  114. $service = new DatabaseTableFieldModule;
  115. $result = $service->getField($tableID);
  116. if ($result) {
  117. $this->returnJson['statusCode'] = '000000';
  118. $this->returnJson['fieldList'] = $result;
  119. } else {
  120. $this->returnJson['statusCode'] = '240009';
  121. }
  122. }
  123. exitOutput($this->returnJson);
  124. }
  125. /**
  126. * 修改字段
  127. */
  128. public function editField()
  129. {
  130. $fieldID = securelyInput('fieldID');
  131. $module = new DatabaseTableFieldModule();
  132. $userType = $module->getUserType($fieldID);
  133. if ($userType < 0 || $userType > 2) {
  134. $this->returnJson['statusCode'] = '120007';
  135. exitOutput($this->returnJson);
  136. }
  137. $nameLen = mb_strlen(quickInput('fieldName', 'utf8'));
  138. $fieldName = securelyInput('fieldName');
  139. $typeLen = mb_strlen(quickInput('fieldType', 'utf8'));
  140. $fieldType = securelyInput('fieldType');
  141. $fieldLength = securelyInput('fieldLength');
  142. $isNotNull = securelyInput('isNotNull');
  143. $isPrimaryKey = securelyInput('isPrimaryKey');
  144. $descLen = mb_strlen(quickInput('fieldDescription', 'utf8'));
  145. $fieldDescription = securelyInput('fieldDescription');
  146. $fieldDefaultValue = securelyInput('defaultValue');
  147. if (!preg_match('/^[0-9]{1,11}$/', $fieldID)) {
  148. $this->returnJson['statusCode'] = '240007';
  149. } elseif (!($nameLen >= 1 && $nameLen <= 255)) {
  150. // 字段名长度不合法
  151. $this->returnJson['statusCode'] = '240002';
  152. } elseif (!($typeLen >= 1 && $typeLen < 255)) {
  153. $this->returnJson['statusCode'] = '240003';
  154. } elseif (!preg_match('/^[0-9]{1}$/', $isNotNull) || !preg_match('/^[0-9]{1}$/', $isPrimaryKey)) {
  155. $this->returnJson['statusCode'] = '240004';
  156. } elseif (!($descLen >= 0 && $descLen <= 255)) {
  157. // 字段描述长度不合法
  158. $this->returnJson['statusCode'] = '240005';
  159. } else {
  160. $service = new DatabaseTableFieldModule;
  161. $result = $service->editField($fieldID, $fieldName, $fieldType, $fieldLength, $isNotNull, $isPrimaryKey, $fieldDescription, $fieldDefaultValue);
  162. if ($result) {
  163. $this->returnJson['statusCode'] = '000000';
  164. } else {
  165. $this->returnJson['statusCode'] = '240010';
  166. }
  167. }
  168. exitOutput($this->returnJson);
  169. }
  170. }
  171. ?>