/** * 创建活动 */ 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:活动信息非法'); }
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); } }
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); }
/** * * 更新头像接口 * POST update_avatar.json * { * "pid":"原始照片的id", * "middle_content":"大头像base64数据" * "original_content":"原图base64数据" * } */ public function update_avatar() { if ($_POST['data']) { //flash截取头像 $data = json_decode($_POST['data'], TRUE); } else { $data = $this->get_data(); //手机端 } //如果是j2me平台直接取原图 if ($this->get_source() == 6) { $middle_data = @base64_decode($data['original_content']); } else { $middle_data = @base64_decode($data['middle_content']); } $pid = $data['pid']; //原图PID $original_data = @base64_decode($data['original_content']); //原图数据 if ($pid) { $photoModel = new Models\Photo(); if (!$photoModel->findOne($pid)) { $this->response(ResponseType::PHOTO_UPAVATAR_ERROR_INVALID); } } if (!$pid && $original_data) { $tmporigin = Core::tempname(); file_put_contents($tmporigin, $original_data); $uploader = new Uploader(); $uploader->process($tmporigin); //不是图片类型 if ($uploader->getType() !== Uploader::FILETYPE_IMAGE) { $this->response(ResponseType::PHOTO_ERROR_IMAGETYPE); } if ($result = $this->_processUpload($uploader, 1)) { $pid = $result['id']; } else { $this->response(ResponseType::PHOTO_UPAVATAR_ERROR_INVALID); } } if (!$pid || !$middle_data) { $this->response(ResponseType::ERROR_LACKPARAMS); } $tmpfile = Core::tempname(); if (!file_put_contents($tmpfile, $middle_data)) { $this->response(ResponseType::PHOTO_UPAVATAR_ERROR); } $uploader = new Uploader(); $uploader->process($tmpfile); //不是图片类型 if ($uploader->getType() !== Uploader::FILETYPE_IMAGE) { $this->response(ResponseType::PHOTO_ERROR_IMAGETYPE); } $photoModel = new Models\Photo(); $updata['cid'] = 1; //我的头像相册 $updata['oid'] = $pid; $updata['ctrl_type'] = 1; $updata['is_animated'] = 0; $updata['mtime'] = time(); if ($photoModel->create($uploader, $updata)) { $result['id'] = $photoModel->get_pid(); $result['md5'] = $photoModel->md5; $imgurls = $photoModel->geturi($result['id'], 48); $result['src'] = $imgurls[0]; list($set_avatar, $first_time) = $photoModel->setAvatar($photoModel->get_pid(), $updata['oid'], $updata['mtime']); if (!$set_avatar) { $this->response(ResponseType::PHOTO_UPAVATAR_ERROR); } $user_model = User_Model::instance(); $member_field = array('updatetime' => time()); if ($first_time) { $sms_content = '您好,这是您第一次设置头像,系统赠送了100条短信给您'; $user_model->present_sms($this->getUid(), 100, $sms_content, FALSE); $user_info = $user_model->get_user_info($this->getUid()); $member_field['completed'] = $user_info['completed'] + 10; } //发送头像修改动态 $feedModel = new Feed_Model(); $accessory[] = array('id' => $result['id']); $feedModel->addFeed($this->user_id, 3, '更新头像', $this->get_source(), array(), array(), $accessory); //更新memberinfo表 $user_model->update_user_info($this->getUid(), $member_field); $this->response(ResponseType::PHOTO_UPAVATAR_OK, '', $result); unlink($tmpfile); } else { $this->response(ResponseType::PHOTO_UPAVATAR_ERROR); } }