示例#1
0
文件: group.php 项目: momoim/momo-api
 /**
  * 
  * 退出群
  * @param $id
  */
 public function quit($id = 0)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     $groupId = (int) $id;
     if (empty($id)) {
         $this->send_response(400, NULL, '400401:群ID为空');
     }
     $groupInfo = $this->model->getGroupInfo($groupId);
     if (!$groupInfo) {
         $this->send_response(400, NULL, '400402:群不存在');
     }
     $grade = $this->model->getMemberGrade($groupId, $this->user_id);
     if ($grade < Kohana::config('group.grade.normal')) {
         $this->send_response(400, NULL, '400403:你不是该群成员');
     }
     if ($grade == Kohana::config('group.grade.master')) {
         $this->send_response(400, NULL, '400405:群创建者不允许退出群');
     }
     if ($this->model->delGroupMember($groupId, $this->user_id)) {
         $this->send_response(200);
     }
     $this->send_response(400, NULL, '400404:退出群失败');
 }
示例#2
0
 /**
  * 创建活动
  */
 public function create()
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     if (!$data) {
         $this->send_response(400, NULL, '400505:活动信息非法');
     }
     $post = new Validation($data);
     $post->add_rules('title', 'required', 'length[1, 30]');
     $post->add_rules('start_at', 'required', 'numeric');
     $post->add_rules('end_at', 'required', 'numeric');
     $post->add_rules('spot', 'required', 'length[1, 30]');
     $post->add_rules('type', 'required', 'numeric', array($this, '_check_type_validation'));
     $post->add_rules('is_allow_invite', 'required', 'numeric', array($this, '_check_allow_invite_validation'));
     $post->add_rules('content', 'length[0, 300]');
     $post->add_rules('group_ids', array($this, '_check_group_ids_validation'));
     $post->add_callbacks(TRUE, array($this, '_check_time_validation'));
     if ($post->validate()) {
         $activity = array();
         $form = $post->as_array();
         $activity['creator_id'] = $this->user_id;
         $activity['title'] = $form['title'];
         $activity['start_time'] = $form['start_at'];
         $activity['end_time'] = $form['end_at'];
         $nowTime = time();
         $activity['create_time'] = $nowTime;
         $activity['spot'] = $form['spot'];
         $activity['type'] = $form['type'];
         $activity['is_allow_invite'] = $form['is_allow_invite'];
         if (isset($form['content'])) {
             $activity['content'] = $form['content'];
         }
         $groupIds = array();
         if (isset($form['group_ids'])) {
             $groupIds = $form['group_ids'];
         }
         $groupModel = new Group_Model();
         $gidArray = array();
         foreach ($groupIds as $id) {
             $id = floatval($id);
             if ($id != -1) {
                 $groupInfo = $groupModel->getGroupInfo($id);
                 if (!$groupInfo) {
                     $this->send_response(400, NULL, '400506:活动发布到的群不存在');
                 }
                 $grade = $groupModel->getMemberGrade($id, $this->user_id);
                 if ($grade < 1) {
                     $this->send_response(400, NULL, '400507:您不是活动指定发布到群的成员');
                 }
             }
             $gidArray[] = $id;
         }
         if (!$gidArray) {
             $activity['is_publish'] = 0;
         } else {
             $activity['is_publish'] = 1;
         }
         $activity_id = $this->model->add($activity);
         $activityMember = array('aid' => $activity_id, 'uid' => $this->user_id, 'apply_type' => Kohana::config('activity.apply_type.join'), 'apply_time' => $nowTime, 'grade' => Kohana::config('activity.grade.creator'));
         $result = $this->model->applyActivity($activityMember);
         $this->model->addActivityUser($activity_id, $this->user_id);
         $friendModel = new Friend_Model();
         $fidList = $friendModel->getAllFriendIDs($this->user_id, false);
         //活动动态发送到指定momo成员
         foreach ($gidArray as $gid) {
             $this->model->addActivityGroup($activity_id, $gid);
             if ($gid == -1) {
                 $friendModel = new Friend_Model();
                 $fidList = $friendModel->getAllFriendIDs($this->user_id, false);
                 foreach ($fidList as $fid) {
                     $this->model->addActivityUser($activity_id, $fid);
                 }
             } else {
                 $this->model->addActivityGroup($activity_id, $gid);
                 $members = $groupModel->getGroupAllMember($gid);
                 foreach ($members as $value) {
                     $this->model->addActivityUser($activity_id, $value['uid']);
                 }
             }
         }
         $feedModel = new Feed_Model();
         $title = array('uid' => $this->user_id, 'name' => sns::getrealname($this->user_id), 'id' => $activity_id, 'title' => $activity['title']);
         $messageModel = new Message_Model();
         if ($activity['is_publish']) {
             $feedModel->addFeed($this->user_id, 'action_add', Kohana::config('uap.app.action'), $title, array(), $activity_id);
         }
         $this->send_response(200, array('id' => floatval($activity_id)));
     }
     $errors = $post->errors();
     $this->send_response(400, NULL, '400505:活动信息非法');
 }
示例#3
0
 /**
  * 批量获取联系人信息
  * @param int $id 联系人ID
  */
 public function show_batch($id = NULL)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     if (!is_numeric($id) or empty($id)) {
         $this->send_response(400, NULL, '400401:群ID为空');
     }
     $groupModel = new Group_Model();
     $groupInfo = $groupModel->getGroupInfo($id);
     if (!$groupInfo) {
         $this->send_response(400, NULL, '400402:群不存在');
     }
     $grade = $groupModel->getMemberGrade($id, $this->user_id);
     if ($grade < Kohana::config('group.grade.normal')) {
         $this->send_response(400, NULL, '400411:非群成员,无权限查看联系人详细信息');
     }
     $data = $this->get_data();
     $ids = isset($data['ids']) ? $data['ids'] : '';
     if (empty($ids)) {
         $this->send_response(400, NULL, '400215:群联系人ids为空');
     }
     $ids = explode(',', $ids);
     $result = array();
     if (count($ids) > 100) {
         $this->send_response(400, NULL, '400216:群联系人ids超过上限(100个)');
     }
     $contact_ids = array_keys($this->model->get($id));
     $friendModel = new Friend_Model();
     foreach ($ids as $cid) {
         if (in_array($cid, $contact_ids)) {
             $contact = $this->model->get($id, $cid);
             if ($contact !== FALSE) {
                 $contact['is_friend'] = 0;
                 if ($contact['user_id'] > 0) {
                     $isFriend = $friendModel->check_isfriend($this->user_id, $contact['user_id']);
                     if ($isFriend) {
                         $contact['is_friend'] = 1;
                     }
                 }
                 $contact['momo_user_id'] = intval($contact['user_id']);
                 unset($contact['user_id']);
                 $result[] = $contact;
             }
             unset($contact);
         }
     }
     $this->send_response(200, $result);
 }