コード例 #1
0
ファイル: event.php プロジェクト: momoim/momo-api
 /**
  * 
  * 修改成员状态
  * @param $id
  */
 public function user_update($id = NULL)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     if (empty($id)) {
         $this->send_response(400, NULL, '400501:活动ID为空');
     }
     $data = $this->get_data();
     if (!$data) {
         $this->send_response(400, NULL, '400412:活动信息非法');
     }
     $event_info = $this->model->get($id);
     if (!$event_info) {
         $this->send_response(400, NULL, '400502:活动不存在');
     }
     if ($this->user_id != $event_info['organizer']) {
         $this->send_response(400, NULL, '400512:限活动创建者使用');
     }
     $type_array = Kohana::config('event.apply_type');
     if (!$data['user']) {
         $this->send_response(400, NULL, '400415:用户数据非法');
     }
     foreach ($data['user'] as $user) {
         if (!in_array($user['apply_type'], $type_array)) {
             $this->send_response(400, NULL, '400504:活动类型非法');
         }
         $a = array('eid' => $id, 'uid' => $user['id']);
         $apply_doc = $user['apply_doc'] ? $user['apply_doc'] : array();
         $dependent = $user['dependent'] ? $user['dependent'] : array();
         $apply_type = $this->model->getApplyType(array('eid' => $id, 'uid' => $user['id']));
         if ($event_info['organizer'] == $user['id'] && $user['apply_type'] == Kohana::config('event.apply_type.refused')) {
             $this->send_response(400, NULL, '400507:活动创建者不能改状态为不参加');
         }
         $user_update = array('apply_type' => $user['apply_type']);
         if ($apply_doc) {
             $user_update['apply_doc'] = serialize($apply_doc);
         }
         if (!empty($apply_doc)) {
             if (!$this->_check_user_apply_doc_valid($id, $apply_doc)) {
                 $this->send_response(400, NULL, '400531:报名信息非法');
             }
             $this->model->addUserApplyDoc($id, $user['id'], 0, '', $apply_doc);
         }
         $this->model->updateApplyEvent($id, $user['id'], $user_update);
         $this->_dependent_apply_event($dependent, $id, $user['id'], $user['apply_type']);
         if (Tab_Model::instance()->get($user['id'], Kohana::config('group.type.event'), $id)) {
             if ($user['apply_type'] == Kohana::config('event.apply_type.refused')) {
                 $this->_del_group_user($id, $user['id']);
             }
         } else {
             $this->_add_group_user($id, $user['id'], Kohana::config('group.grade.normal'));
         }
     }
     $this->send_response(200);
 }