You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.0 KiB

пре 3 година
  1. <?php
  2. namespace Api\Controller;
  3. use Think\Controller;
  4. /*
  5. 团队成员管理
  6. */
  7. class TeamMemberController extends BaseController {
  8. //添加和编辑
  9. public function save(){
  10. $login_user = $this->checkLogin();
  11. $member_username = I("member_username");
  12. $team_id = I("team_id/d");
  13. $teamInfo = D("Team")->where(" id = '$team_id' and uid = '$login_user[uid]' ")->find();
  14. if (!$teamInfo) {
  15. $this->sendError(10209,"无此团队或者你无管理此团队的权限");
  16. return ;
  17. }
  18. $member_username_array = explode("," , $member_username) ;
  19. foreach($member_username_array as $key => $value ){
  20. $memberInfo = D("User")->where(" username = '%s' ",array($value))->find();
  21. if (!$memberInfo) {
  22. continue ;
  23. }
  24. $if_exit = D("TeamMember")->where(" member_uid = '$memberInfo[uid]' and team_id = '$team_id' ")->find();
  25. if ($if_exit) {
  26. continue ;
  27. }
  28. $data = array() ;
  29. $data['team_id'] = $team_id ;
  30. $data['member_uid'] = $memberInfo['uid'] ;
  31. $data['member_username'] = $memberInfo['username'] ;
  32. $data['addtime'] = time() ;
  33. $id = D("TeamMember")->add($data);
  34. //检查该团队已经加入了哪些项目
  35. $teamItems = D("TeamItem")->where(" team_id = '$team_id' ")->select() ;
  36. if ($teamItems) {
  37. foreach ($teamItems as $key2 => $value2) {
  38. $data= array(
  39. "team_id"=>$team_id,
  40. "member_uid"=>$memberInfo['uid'],
  41. "member_username"=>$memberInfo['username'],
  42. "item_id"=>$value2['item_id'],
  43. "member_group_id"=>1, //默认添加的权限为1,即编辑权限
  44. "addtime"=>time()
  45. );
  46. D("TeamItemMember")->add($data);
  47. }
  48. }
  49. }
  50. $return = D("TeamMember")->where(" id = '$id' ")->find();
  51. if (!$return) {
  52. $return['error_code'] = 10103 ;
  53. $return['error_message'] = 'request fail' ;
  54. }
  55. $this->sendResult($return);
  56. }
  57. //获取列表
  58. public function getList(){
  59. $login_user = $this->checkLogin();
  60. $team_id = I("team_id/d");
  61. $teamInfo = D("Team")->where(" id = '$team_id' and uid = '$login_user[uid]' ")->find();
  62. if (!$teamInfo) {
  63. $this->sendError(102099,"无此团队或者你无管理此团队的权限");
  64. return ;
  65. }
  66. if ($login_user['uid'] > 0 ) {
  67. $ret = D("TeamMember")->where(" team_id = '$team_id' ")->join(" left join user on user.uid = team_member.member_uid")->field("team_member.* , user.name as name")->order(" addtime desc ")->select();
  68. }
  69. if ($ret) {
  70. foreach ($ret as $key => &$value) {
  71. $value['addtime'] = date("Y-m-d H:i:s" , $value['addtime']);
  72. }
  73. $this->sendResult($ret);
  74. }else{
  75. $this->sendResult(array());
  76. }
  77. }
  78. //删除
  79. public function delete(){
  80. $login_user = $this->checkLogin();
  81. $id = I("id/d")? I("id/d") : 0;
  82. $teamMemberInfo = D("TeamMember")->where(" id = '$id' ")->find();
  83. $team_id = $teamMemberInfo['team_id'] ;
  84. $teamInfo = D("Team")->where(" id = '$team_id' and uid = '$login_user[uid]' ")->find();
  85. if (!$teamInfo) {
  86. $this->sendError(102099,"无此团队或者你无管理此团队的权限");
  87. return ;
  88. }
  89. $ret = D("TeamItemMember")->where(" member_uid = '$teamMemberInfo[member_uid]' and team_id = '$team_id' ")->delete();
  90. $ret = D("TeamMember")->where(" id = '$id' ")->delete();
  91. if ($ret) {
  92. $this->sendResult($ret);
  93. }else{
  94. $return['error_code'] = 10103 ;
  95. $return['error_message'] = 'request fail' ;
  96. $this->sendResult($return);
  97. }
  98. }
  99. }