PartnerController.class.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 PartnerController
  19. {
  20. // 返回json类型
  21. private $returnJson = array('type' => 'partner');
  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 getPartnerInfo()
  38. {
  39. $userName = securelyInput('userName');
  40. $projectID = securelyInput('projectID');
  41. if (!preg_match('/^([a-zA-Z][0-9a-zA-Z_]{3,59})$/', $userName)) {
  42. //userName格式非法
  43. $this->returnJson['statusCode'] = '250001';
  44. } else {
  45. $userServer = new UserModule;
  46. $userInfo = $userServer->checkUserExist($userName);
  47. if ($userInfo) {
  48. $partnerServer = new PartnerModule;
  49. if ($partnerServer->checkIsInvited($projectID, $userName)) {
  50. $this->returnJson['statusCode'] = '250007';
  51. $this->returnJson['userInfo']['userName'] = $userName;
  52. $this->returnJson['userInfo']['userNickName'] = $userInfo['userNickName'];
  53. $this->returnJson['userInfo']['isInvited'] = 1;
  54. } else {
  55. $this->returnJson['statusCode'] = '000000';
  56. $this->returnJson['userInfo']['userName'] = $userName;
  57. $this->returnJson['userInfo']['userNickName'] = $userInfo['userNickName'];
  58. $this->returnJson['userInfo']['isInvited'] = 0;
  59. }
  60. } else {
  61. //用户不存在
  62. $this->returnJson['statusCode'] = '250002';
  63. }
  64. }
  65. exitOutput($this->returnJson);
  66. }
  67. /**
  68. * 邀请协作人员
  69. */
  70. public function invitePartner()
  71. {
  72. $userName = securelyInput('userName');
  73. $projectID = securelyInput('projectID');
  74. $module = new ProjectModule();
  75. $userType = $module->getUserType($projectID);
  76. if ($userType < 0 || $userType > 1) {
  77. $this->returnJson['statusCode'] = '120007';
  78. exitOutput($this->returnJson);
  79. }
  80. if (!preg_match('/^([a-zA-Z][0-9a-zA-Z_]{3,59})$/', $userName)) {
  81. //userName格式非法
  82. $this->returnJson['statusCode'] = '250001';
  83. } else {
  84. $userServer = new UserModule;
  85. $userInfo = $userServer->checkUserExist($userName);
  86. if ($userInfo) {
  87. $partnerServer = new PartnerModule;
  88. //检查是否已经被邀请过
  89. if ($partnerServer->checkIsInvited($projectID, $userName)) {
  90. //已被邀请
  91. $this->returnJson['statusCode'] = '250007';
  92. } else {
  93. if ($connID = $partnerServer->invitePartner($projectID, $userInfo['userID'])) {
  94. $this->returnJson['statusCode'] = '000000';
  95. $this->returnJson['connID'] = $connID;
  96. } else {
  97. //添加协作成员失败,成员已经添加
  98. $this->returnJson['statusCode'] = '250003';
  99. }
  100. }
  101. } else {
  102. //用户不存在
  103. $this->returnJson['statusCode'] = '250002';
  104. }
  105. }
  106. exitOutput($this->returnJson);
  107. }
  108. /**
  109. * 移除协作人员
  110. */
  111. public function removePartner()
  112. {
  113. $projectID = securelyInput('projectID');
  114. $module = new ProjectModule();
  115. $userType = $module->getUserType($projectID);
  116. if ($userType < 0 || $userType > 1) {
  117. $this->returnJson['statusCode'] = '120007';
  118. exitOutput($this->returnJson);
  119. }
  120. $connID = securelyInput('connID');
  121. $server = new PartnerModule;
  122. if ($server->removePartner($projectID, $connID)) {
  123. $this->returnJson['statusCode'] = '000000';
  124. } else {
  125. //移除成员失败,成员已经被移出
  126. $this->returnJson['statusCode'] = '250004';
  127. }
  128. exitOutput($this->returnJson);
  129. }
  130. /**
  131. * 获取协作人员列表
  132. */
  133. public function getPartnerList()
  134. {
  135. $projectID = securelyInput('projectID');
  136. $server = new PartnerModule;
  137. $result = $server->getPartnerList($projectID);
  138. if ($result) {
  139. $this->returnJson['statusCode'] = '000000';
  140. $this->returnJson['partnerList'] = $result;
  141. } else {
  142. //协作人员列表为空
  143. $this->returnJson['statusCode'] = '250005';
  144. }
  145. exitOutput($this->returnJson);
  146. }
  147. /**
  148. * 退出协作项目
  149. */
  150. public function quitPartner()
  151. {
  152. $projectID = securelyInput('projectID');
  153. $server = new PartnerModule;
  154. $result = $server->quitPartner($projectID);
  155. if ($result) {
  156. $this->returnJson['statusCode'] = '000000';
  157. } else {
  158. //退出协作项目失败,已退出协作项目
  159. $this->returnJson['statusCode'] = '250006';
  160. }
  161. exitOutput($this->returnJson);
  162. }
  163. /**
  164. * 修改协作成员的昵称
  165. */
  166. public function editPartnerNickName()
  167. {
  168. $projectID = securelyInput('projectID');
  169. $conn_id = securelyInput('connID');
  170. $nick_name = securelyInput('nickName');
  171. $name_length = mb_strlen(quickInput('nickName'), 'utf8');
  172. //判断关联ID是否合法
  173. if (!preg_match('/^[0-9]{1,11}$/', $conn_id)) {
  174. //关联ID格式非法
  175. $this->returnJson['statusCode'] = '250003';
  176. } elseif ($name_length < 1 || $name_length > 32) {
  177. //昵称格式非法
  178. $this->returnJson['statusCode'] = '250004';
  179. } else {
  180. $module = new PartnerModule();
  181. $result = $module->editPartnerNickName($projectID, $conn_id, $nick_name);
  182. if ($result) {
  183. //成功
  184. $this->returnJson['statusCode'] = '000000';
  185. } else {
  186. //失败
  187. $this->returnJson['statusCode'] = '250000';
  188. }
  189. }
  190. exitOutput($this->returnJson);
  191. }
  192. /**
  193. * 修改协作成员的类型
  194. */
  195. public function editPartnerType()
  196. {
  197. $projectID = securelyInput('projectID');
  198. $module = new ProjectModule();
  199. $userType = $module->getUserType($projectID);
  200. if ($userType < 0 || $userType > 1) {
  201. $this->returnJson['statusCode'] = '120007';
  202. exitOutput($this->returnJson);
  203. }
  204. $conn_id = securelyInput('connID');
  205. $user_type = securelyInput('userType');
  206. if (!preg_match('/^[0-9]{1,11}$/', $conn_id)) {
  207. //关联ID格式非法
  208. $this->returnJson['statusCode'] = '250003';
  209. } elseif (!preg_match('/^[1-3]{1}$/', $user_type)) {
  210. //用户类型格式非法
  211. $this->returnJson['statusCode'] = '250005';
  212. } else {
  213. $module = new PartnerModule();
  214. $result = $module->editPartnerType($projectID, $conn_id, $user_type);
  215. if ($result) {
  216. //成功
  217. $this->returnJson['statusCode'] = '000000';
  218. } else {
  219. //失败
  220. $this->returnJson['statusCode'] = '250000';
  221. }
  222. }
  223. exitOutput($this->returnJson);
  224. }
  225. public function getProjectInviteCode()
  226. {
  227. $projectID = securelyInput('projectID');
  228. }
  229. public function joinProjectByInviteCode()
  230. {
  231. $projectID = securelyInput('projectID');
  232. }
  233. }
  234. ?>