Exemplo n.º 1
0
 public function agree_group()
 {
     $data = $this->get_data();
     $message_id = $data['id'];
     if (empty($message_id)) {
         $this->send_response(400, NULL, '400102:消息id非法');
     }
     $result = $this->model->getNoticeInfo(array('id' => $message_id, 'uid' => $this->user_id), true);
     if (!$result) {
         $this->send_response(400, NULL, '400101:消息体不存在或已经被处理');
     }
     $group_tmp = json_decode($result['title'], true);
     $gid = $group_tmp['group'][0]['id'];
     $gname = $group_tmp['group'][0]['name'];
     $grade = $this->groupModel->getmembergrade($gid, $this->user_id);
     if ($grade > 0) {
         $this->model->putChangeTplByid($this->user_id, $message_id, 1);
         $this->send_response(400, NULL, '400108:您已经是群成员了');
     }
     $group_info = $this->groupModel->getGroupInfo($gid);
     if (!$group_info) {
         $this->model->putChangeTplByid($this->user_id, $message_id, 4);
         $this->send_response(400, NULL, '400109:群不存在');
     }
     //查询群组成员总数是否超出最大限制(暂定100)
     $memberNum = $group_info['member_number'];
     if ($group_info['type'] == Kohana::config('group.type.public')) {
         $maxMemberNum = Kohana::config('group.maxMemberNum.public');
     } else {
         $maxMemberNum = Kohana::config('group.maxMemberNum.private');
     }
     if ($memberNum >= $maxMemberNum) {
         $this->model->putChangeTplByid($this->user_id, $message_id, 3);
         $this->send_response(400, NULL, '400110:群成员人数已满');
     }
     $result = $this->groupModel->addGroupMember($gid, $this->user_id, 1);
     $this->groupModel->addMemberNum($gid);
     $feedModel = new Feed_Model();
     if ($group_info['type'] == Kohana::config('group.type.private')) {
         $dateline = time();
         try {
             //添加群组通讯录联系人
             $this->groupContactModel->addGroupContactByUserCard($gid, $this->user_id, $dateline);
         } catch (Exception $exc) {
             $this->send_response(400, NULL, '400111:导入个人名片到群组通讯录联系人失败');
         }
         $ginfo['modify_time'] = $dateline;
         $ret = $this->groupModel->modifyGroup($gid, $ginfo);
     } else {
         if ($group_info['type'] == Kohana::config('group.type.public')) {
             //发送加入公开群组动态
             $application = array('id' => floatval($gid), 'title' => '查看群组', 'url' => 'group/' . $gid);
             $feedModel->addFeed($this->user_id, 2, $text = '加入了群组:' . $group_info['gname'], $this->get_source(), $application, $at = array(), $images = array(), $sync = array(), $group_type = 0, $group_id = 0, $retweet_id = 0, $allow_rt = 0, $allow_comment = 1, $allow_praise = 1, $allow_del = 1, $allow_hide = 1);
         }
     }
     $commentModel = new Comment_Model();
     if ($group_info['feed_id']) {
         $friendModel = Friend_Model::instance();
         $isFriend = $friendModel->check_isfriend($this->user_id, $group_info['creator_id']);
         if ($isFriend) {
             $commentModel->saveComment($group_info['feed_id'], '加入了本群', $group_info['creator_id']);
         }
     }
     if ($group_info['group_feed_id']) {
         $commentModel->saveComment($group_info['group_feed_id'], '加入了本群', $group_info['creator_id']);
     }
     //添加群到首页tab列表
     $userModel = new User_Model();
     $userModel->insertTag($this->user_id, 7, $gid);
     $feedModel->addTab($gid, $group_info['gname'], 7, $this->user_id);
     //删除邀请表对应的记录
     $this->model->putChangeTplByid($this->user_id, $message_id, 1);
     $this->send_response(200);
 }
Exemplo n.º 2
0
 private function _add_feed_comment($activity, $old_apply_type, $apply_type, $uid)
 {
     $feedModel = new Feed_Model();
     if ($apply_type == Kohana::config('activity.apply_type.join')) {
         $feedStatus = "参加";
         $applyStatus = "参加";
     } else {
         if ($apply_type == Kohana::config('activity.apply_type.interest')) {
             $feedStatus = "关注";
             $applyStatus = "感兴趣";
         }
     }
     if ($activity['gid'] != 0) {
         if ($apply_type != Kohana::config('activity.apply_type.not_join')) {
             $commentModel = new Comment_Model();
             $content = "参与报名:" . $applyStatus;
             if ($activity['feed_id']) {
                 $feed_id = $activity['feed_id'];
                 $feedInfo = $feedModel->getFeedById($feed_id);
                 if ($feedInfo) {
                     $group_type = $feedInfo[$feed_id]['group_type'];
                     $group_id = $feedInfo[$feed_id]['group_id'];
                     $owner_uid = $feedInfo[$feed_id]['owner_uid'];
                     if (!$group_type) {
                         //好友
                         $friendModel = Friend_Model::instance();
                         $isFriend = $friendModel->check_isfriend($owner_uid, $uid);
                         if ($isFriend) {
                             $commentModel->saveComment($feed_id, $content, $owner_uid);
                         }
                     } else {
                         if ($group_type == 1) {
                             //群内
                             $groupModel = Group_Model::instance();
                             $grade = $groupModel->getMemberGrade($group_id, $uid);
                             if ($grade > 0) {
                                 $commentModel->saveComment($feed_id, $content, $owner_uid);
                             }
                         } else {
                             if ($group_type == 2) {
                                 //活动内
                                 $activityModel = Activity_Model::instance();
                                 $apply_type = $activityModel->getActivityApplyType($group_id, $uid);
                                 if ($apply_type > 0) {
                                     $commentModel->saveComment($feed_id, $content, $owner_uid);
                                 }
                             }
                         }
                     }
                 }
             }
             if ($activity['action_feed_id']) {
                 $commentModel->saveComment($activity['action_feed_id'], $content, $activity['creator_id']);
             }
         }
     }
     if (!$old_apply_type && ($apply_type == Kohana::config('activity.apply_type.join') || $apply_type == Kohana::config('activity.apply_type.interest')) && $activity['is_allow_invite']) {
         $application = array('id' => floatval($activity['aid']), 'title' => '查看活动', 'url' => 'action/showblogbox/' . $activity['aid']);
         $feedModel->addFeed($uid, 7, $text = $feedStatus . '了活动:' . $activity['title'], $this->get_source(), $application, $at = array(), $images = array(), $sync = array(), $group_type = 0, $group_id = 0, $retweet_id = 0, $allow_rt = 0, $allow_comment = 1, $allow_praise = 1, $allow_del = 1, $allow_hide = 1);
     }
 }