Esempio n. 1
0
 public static function &instance()
 {
     if (!is_object(Activity_Invite_Model::$instances)) {
         // Create a new instance
         Activity_Invite_Model::$instances = new Activity_Invite_Model();
     }
     return Activity_Invite_Model::$instances;
 }
Esempio n. 2
0
 public function invite_create()
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     $invite_code = trim($data['invite_code']);
     if (strlen($invite_code) != 32 || !preg_match('/^[0-9A-Za-z]{32}$/', $invite_code)) {
         $this->send_response(400, NULL, '活动邀请链接无效');
     }
     $activityInviteModel = Activity_Invite_Model::instance();
     $invite_info = $activityInviteModel->getInvitationInfo($invite_code);
     if (!$invite_info) {
         $this->send_response(400, NULL, '活动邀请链接无效');
     }
     $aid = $invite_info['aid'];
     $activity = $this->model->getActivityInfo($aid);
     if (!$activity) {
         $this->send_response(400, NULL, '400502:活动不存在');
     }
     $now_time = time();
     if ($now_time > $activity['end_time']) {
         $this->send_response(400, NULL, '400502:活动已结束');
     }
     $applyResult = $this->model->getActivityApplyType($aid, $this->user_id);
     if ($applyResult > 0) {
         $this->send_response(400, NULL, '你已经报名了该活动');
     }
     $activityMember['aid'] = $aid;
     $activityMember['uid'] = $this->user_id;
     $activityMember['apply_type'] = Kohana::config('activity.apply_type.join');
     $activityMember['apply_time'] = $now_time;
     $activityMember['grade'] = Kohana::config('activity.grade.normal');
     $this->model->applyActivity($activityMember);
     $userModel = User_Model::instance();
     $userModel->insertTag($this->user_id, 15, $aid);
     $apply_type = Kohana::config('activity.apply_type.join');
     $this->_add_feed_comment($activity, 0, $apply_type, $this->user_id);
     $feedModel = Feed_Model::instance();
     $feedModel->addTab($aid, $activity['title'], 15, $this->user_id);
     $this->send_response(200);
 }