Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

103 rindas
3.6 KiB

pirms 3 gadiem
  1. <?php
  2. namespace Api\Controller;
  3. use Think\Controller;
  4. class MemberController extends BaseController {
  5. //保存
  6. public function save(){
  7. $member_group_id = I("member_group_id/d");
  8. $item_id = I("item_id/d");
  9. $cat_id = I("cat_id/d") ? I("cat_id/d") : 0 ;
  10. $login_user = $this->checkLogin();
  11. $uid = $login_user['uid'] ;
  12. if(!$this->checkItemCreator($uid , $item_id)){
  13. $this->sendError(10303);
  14. return ;
  15. }
  16. $username = I("username");
  17. $username_array = explode("," , $username) ;
  18. foreach($username_array as $key => $value ){
  19. $member = D("User")->where(" username = '%s' ",array($value))->find();
  20. if(!$member){
  21. continue ;
  22. }
  23. $if_exit = D("ItemMember")->where(" uid = '$member[uid]' and item_id = '$item_id' ")->find();
  24. if ($if_exit) {
  25. continue ;
  26. }
  27. $data = array() ;
  28. $data['username'] = $member['username'] ;
  29. $data['uid'] = $member['uid'] ;
  30. $data['item_id'] = $item_id ;
  31. $data['member_group_id'] = $member_group_id ;
  32. $data['cat_id'] = $cat_id ;
  33. $data['addtime'] = time() ;
  34. $id = D("ItemMember")->add($data);
  35. }
  36. $return = D("ItemMember")->where(" item_member_id = '$id' ")->find();
  37. if (!$return) {
  38. $this->sendError(10101);
  39. }else{
  40. $this->sendResult($return);
  41. }
  42. }
  43. //获取成员列表
  44. public function getList(){
  45. $item_id = I("item_id/d");
  46. $login_user = $this->checkLogin();
  47. $uid = $login_user['uid'] ;
  48. if(!$this->checkItemCreator($uid , $item_id)){
  49. $this->sendError(10303);
  50. return ;
  51. }
  52. if ($item_id > 0 ) {
  53. $ret = D("ItemMember")->where(" item_id = '$item_id' ")->join(" left join user on user.uid = item_member.uid")->field("item_member.* , user.name as name")->order(" addtime asc ")->select();
  54. }
  55. if ($ret) {
  56. foreach ($ret as $key => &$value) {
  57. $value['addtime'] = date("Y-m-d H:i:s",$value['addtime']);
  58. $value['member_group'] = $value['member_group_id'] == 1 ? "编辑" :"只读";
  59. $value['cat_name'] = '所有目录';
  60. if($value['cat_id'] > 0 ){
  61. $row = D("Catalog")->where(" cat_id = '$value[cat_id]' ")->find() ;
  62. if ( $row && $row['cat_name'] ){
  63. $value['cat_name'] = $row['cat_name'] ;
  64. }
  65. }
  66. $value['member_group'] = $value['member_group_id'] == 1 ? "编辑/目录:{$value['cat_name']}" :"只读/目录:{$value['cat_name']}";
  67. }
  68. }
  69. $this->sendResult($ret);
  70. }
  71. //删除成员
  72. public function delete(){
  73. $item_id = I("item_id/d");
  74. $login_user = $this->checkLogin();
  75. $uid = $login_user['uid'] ;
  76. if(!$this->checkItemCreator($uid , $item_id)){
  77. $this->sendError(10303);
  78. return ;
  79. }
  80. $item_member_id = I("item_member_id/d");
  81. if ($item_member_id) {
  82. $member_array = D("ItemMember")->where(" item_id = '%d' and item_member_id = '%d' ",array($item_id,$item_member_id))->find();
  83. $ret = D("ItemMember")->where(" item_id = '%d' and item_member_id = '%d' ",array($item_id,$item_member_id))->delete();
  84. }
  85. if ($ret) {
  86. $this->sendResult($ret);
  87. }else{
  88. $this->sendError(10101);
  89. }
  90. }
  91. }