Esempio n. 1
0
 /**
  * 获取活动详细信息
  */
 public function show($id)
 {
     if ($this->get_method() != 'GET') {
         $this->send_response(405, NULL, '请求的方法不存在');
     } elseif (empty($id)) {
         $this->send_response(400, NULL, '400501:活动ID为空');
     }
     $isShowMember = (int) $this->input->get('member', 0) == 1 ? 1 : 0;
     $webRequest = (int) $this->input->get('web', 0);
     if ($webRequest != 1 && $webRequest != 2) {
         $webRequest = 0;
     }
     $activityInfo = $this->model->getActivityInfo($id);
     if (!$activityInfo) {
         if ($webRequest > 0) {
             echo '活动不存在';
             exit;
         }
         $this->send_response(400, NULL, '400502:活动不存在');
     }
     $permit = $this->_check_activity_view_permission($activityInfo, $this->user_id);
     if (!$permit) {
         if ($webRequest > 0) {
             echo '无权限查看活动信息';
             exit;
         }
         $this->send_response(400, NULL, '400503:无权限查看活动信息');
     }
     $activity = array();
     $aid = $activityInfo['aid'];
     $activity['id'] = floatval($aid);
     $user = array();
     $user['id'] = floatval($activityInfo['creator_id']);
     $userInfo = sns::getuser($activityInfo['creator_id']);
     $user['name'] = $userInfo['realname'];
     $user['avatar'] = sns::getavatar($activityInfo['creator_id']);
     $user['mobile'] = $userInfo['mobile'];
     $activity['user'] = $user;
     unset($userInfo);
     unset($user);
     $organizer = array();
     $organizerList = $this->model->getActivityOrganizer($aid);
     $organizerIdList = array();
     foreach ($organizerList as $value) {
         $user = array();
         $user['id'] = floatval($value['uid']);
         $userInfo = sns::getuser($value['uid']);
         $user['name'] = $userInfo['realname'];
         $user['avatar'] = sns::getavatar($value['uid']);
         $user['mobile'] = $userInfo['mobile'];
         $organizer[] = $user;
         $organizerIdList[] = $user['id'];
         unset($userInfo);
         unset($user);
     }
     $isOrganizer = in_array($this->user_id, $organizerIdList);
     $activity['organizer'] = $organizer;
     $activity['title'] = $activityInfo['title'];
     $nowTime = time();
     if ($activityInfo['end_time'] < $nowTime) {
         $status = Kohana::config('activity.status.end.id');
     } else {
         if ($activityInfo['start_time'] > $nowTime) {
             $status = Kohana::config('activity.status.enroll.id');
         } else {
             $status = Kohana::config('activity.status.working.id');
         }
     }
     $activity['status'] = $status;
     $activity['start_at'] = api::get_date($activityInfo['start_time']);
     $activity['end_at'] = api::get_date($activityInfo['end_time']);
     $activity['spot'] = $activityInfo['spot'];
     $activity['content'] = $activityInfo['content'];
     $activity['type'] = intval($activityInfo['type']);
     $joined = array('number' => 0, 'member' => array());
     $interested = array('number' => 0, 'member' => array());
     $unconfirmed = array('number' => 0, 'member' => array());
     if ($isShowMember) {
         $apply_type = Kohana::config('activity.apply_type.join');
         $joined['number'] = (int) $this->model->getActivityMemberNum($aid, $apply_type);
         $joinedList = $this->model->getActivityMember($aid, $apply_type);
         $joined['member'] = array();
         foreach ($joinedList as $value) {
             $user['id'] = floatval($value['uid']);
             $user['name'] = $value['realname'];
             $user['avatar'] = sns::getavatar($value['uid']);
             $user['mobile'] = "";
             if ($isOrganizer || in_array($user['id'], $organizerIdList)) {
                 $user['mobile'] = $value['mobile'];
             }
             $joined['member'][] = $user;
             unset($user);
         }
         $apply_type = Kohana::config('activity.apply_type.interest');
         $interested['number'] = (int) $this->model->getActivityMemberNum($aid, $apply_type);
         $interestedList = $this->model->getActivityMember($aid, $apply_type);
         $interested['member'] = array();
         foreach ($interestedList as $value) {
             $user['id'] = floatval($value['uid']);
             $user['name'] = $value['realname'];
             $user['avatar'] = sns::getavatar($value['uid']);
             $user['mobile'] = "";
             if ($isOrganizer || in_array($user['id'], $organizerIdList)) {
                 $user['mobile'] = $value['mobile'];
             }
             $interested['member'][] = $user;
             unset($user);
         }
         $apply_type = Kohana::config('activity.apply_type.not_join');
         $notJoined['number'] = (int) $this->model->getActivityMemberNum($aid, $apply_type);
         $notJoinedList = $this->model->getActivityMember($aid, $apply_type);
         $notJoined['member'] = array();
         foreach ($notJoinedList as $value) {
             $user['id'] = floatval($value['uid']);
             $user['name'] = $value['realname'];
             $user['avatar'] = sns::getavatar($value['uid']);
             $user['mobile'] = "";
             if ($isOrganizer || in_array($user['id'], $organizerIdList)) {
                 $user['mobile'] = $value['mobile'];
             }
             $notJoined['member'][] = $user;
             unset($user);
         }
         $unconfirmedList = $this->model->getInviteUnset($aid);
         $unconfirmed['number'] = count($unconfirmedList);
         $unconfirmed['member'] = array();
         foreach ($unconfirmedList as $value) {
             $user['id'] = floatval($value['uid']);
             $user['name'] = $value['realname'];
             $user['avatar'] = sns::getavatar($value['uid']);
             $user['mobile'] = "";
             if ($isOrganizer || in_array($user['id'], $organizerIdList)) {
                 $user['mobile'] = $value['mobile'];
             }
             $unconfirmed['member'][] = $user;
             unset($user);
         }
         $activity['joined'] = $joined;
         $activity['interested'] = $interested;
         $activity['refused'] = $notJoined;
         $activity['unconfirmed'] = $unconfirmed;
     } else {
         $apply_type = Kohana::config('activity.apply_type.join');
         $joined['number'] = (int) $this->model->getActivityMemberNum($aid, $apply_type);
         $joined['member'] = array();
         $apply_type = Kohana::config('activity.apply_type.interest');
         $interested['number'] = (int) $this->model->getActivityMemberNum($aid, $apply_type);
         $interested['member'] = array();
         $apply_type = Kohana::config('activity.apply_type.not_join');
         $notJoined['number'] = (int) $this->model->getActivityMemberNum($aid, $apply_type);
         $notJoined['member'] = array();
         $unconfirmedList = $this->model->getInviteUnset($aid);
         $unconfirmed['number'] = count($unconfirmedList);
         $unconfirmed['member'] = array();
     }
     $activity['joined'] = $joined;
     $activity['interested'] = $interested;
     $activity['refused'] = $notJoined;
     $activity['unconfirmed'] = $unconfirmed;
     if ($webRequest > 0) {
         $types = array_flip(Kohana::config('activity.type'));
         $typeId = $types[$activity['type']];
         $typeNames = Kohana::config('activity.typeName');
         $apply_type = $this->model->getActivityApplyType($activity['id'], $this->user_id);
         $type = $typeNames[$typeId];
         $view = new View('activity/details');
         $view->webRequest = $webRequest;
         $view->type = $type;
         $activityInfo['user'] = $activity['user'];
         $activityInfo['organizer'] = $activity['organizer'];
         $view->activity = $activityInfo;
         $view->apply_type = $apply_type;
         $view->render(true);
         exit;
     }
     $this->send_response(200, $activity);
 }
Esempio n. 2
0
 /**
  * 获取活动成员列表
  */
 public function index($id = 0)
 {
     $data = $this->get_data();
     if ($this->get_method() != 'GET') {
         $this->send_response(405, NULL, '请求的方法不存在');
     } elseif (empty($id)) {
         $this->send_response(400, NULL, '400501:活动ID为空');
     }
     $data = $this->get_data();
     $apply_type = (int) $this->input->get('type', 0);
     $result = array();
     if ($apply_type < -1 || $apply_type > Kohana::config('activity.apply_type.interest')) {
         $this->send_response(400, NULL, '400508:活动报名类型非法');
     }
     $activityInfo = $this->model->getActivityInfo($id);
     if (!$activityInfo) {
         $this->send_response(400, NULL, '400502:活动不存在');
     }
     $grade = $this->model->getMemberGrade($id, $this->user_id);
     if ($grade < Kohana::config('activity.grade.normal')) {
         $this->send_response(400, NULL, '400509:非活动报名者,无权限查看报名成员');
     }
     $invitationList = $this->model->getMembersInviteUser($id);
     $inviteArray = array();
     foreach ($invitationList as $value) {
         if (!array_key_exists($value['uid'], $inviteArray)) {
             $inviteArray[$value['uid']] = array('id' => floatval($value['invite_uid']), 'name' => $value['realname']);
         }
     }
     if ($apply_type == -1) {
         //未确认成员
         $memberList = $this->model->getInviteUnset($id);
     } else {
         if ($apply_type == 0) {
             //全部成员
             $apply_member = $this->model->getActivityAllMember($id);
             $invite_member = $this->model->getInviteUnset($id);
             $memberList = array_merge($apply_member, $invite_member);
         } else {
             //各报名类型成员
             $memberList = $this->model->getActivityMember($id, $apply_type);
         }
     }
     foreach ($memberList as $value) {
         $member = array();
         $user = array();
         $user['id'] = floatval($value['uid']);
         $user['name'] = $value['realname'];
         $user['avatar'] = sns::getavatar($value['uid']);
         $user['mobile'] = "";
         $userGrade = intval($value['grade']);
         if ($grade > Kohana::config('activity.grade.normal') || $userGrade > Kohana::config('activity.grade.normal')) {
             $user['mobile'] = $value['mobile'];
         }
         $member['user'] = $user;
         $invite_user = array();
         if (array_key_exists($value['uid'], $inviteArray)) {
             $invite_user = $inviteArray[$value['uid']];
         }
         $member['invite_user'] = $invite_user;
         $member['apply_type'] = intval($value['apply_type']);
         $member['grade'] = $userGrade;
         $result[] = $member;
         unset($user);
         unset($member);
     }
     $this->send_response(200, $result);
 }