Esempio n. 1
0
 /**
  * 
  * @return none
  */
 public function personal($id = NULL)
 {
     if ($this->get_method() != 'GET') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     $data = $this->get_data();
     if (empty($id)) {
         $this->send_response(400, NULL, '401307:交易ID为空');
     }
     $id = (int) $id;
     $user_info = sns::getuser($id);
     if (!$user_info) {
         $this->send_response(400, NULL, '401311:用户不存在');
     }
     $stat = $this->model->stat($id);
     $deal_lists = $this->model->personal_lists($id, $this->user_id);
     $this->send_response(200, array('id' => (int) $id, 'name' => $user_info['realname'], 'avatar' => sns::getAvatar($id), 'deal_stat' => array('total' => (int) $stat['total'], 'success' => (int) $stat['success']), 'deal_lists' => $deal_lists, 'relationship' => 0, 'social_account' => array('sina_weibo' => '', 'qq_weibo' => '')));
 }
Esempio n. 2
0
 /**
  * 
  * 活动邀请
  */
 public function invite($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, '400506:活动不存在');
     }
     if (empty($data['user'])) {
         $this->send_response(400, NULL, '400508:活动报名信息为空');
     }
     $return = array();
     $update_apply_type = false;
     $post = new Validation($data);
     $post->add_rules('user', 'required');
     $post->add_callbacks(TRUE, array($this, '_check_user_validation'));
     if ($post->validate()) {
         $form = $post->as_array();
         if (count($form['user'] > 0)) {
             $user_array = $this->_get_event_uid($form['user']);
             $i = 0;
             $cover = Event_Image_Model::instance()->getCover($id);
             $cover = $cover ? $cover : '';
             $opt = array('event' => array('id' => $id, 'name' => $event_info['title'], 'cover' => $cover), 'no_sign' => 1);
             foreach ($user_array as $mobile => $user) {
                 $i++;
                 if ($this->user_id == $user['user_id'] || empty($user['user_id'])) {
                     continue;
                 }
                 $apply_type = $this->model->getApplyType(array('eid' => $id, 'uid' => $user['user_id']));
                 if (!$apply_type || $apply_type == Kohana::config('event.apply_type.refused')) {
                     if ($apply_type == Kohana::config('event.apply_type.refused')) {
                         $update_apply_type = true;
                     }
                     $eventUser = array('eid' => $id, 'pid' => 0, 'uid' => $user['user_id'], 'name' => $user['name'], 'mobile' => $mobile, 'apply_type' => Kohana::config('event.apply_type.unconfirmed'), 'apply_time' => time(), 'invite_by' => $this->user_id, 'grade' => Kohana::config('event.grade.normal'));
                     $this->model->applyEvent($eventUser, $update_apply_type);
                 }
                 if (!in_array($apply_type, array(Kohana::config('event.apply_type.joined'), Kohana::config('event.apply_type.interested')))) {
                     $return[] = array('uid' => $user['user_id'], 'name' => $user['name'], 'mobile' => $mobile, 'avatar' => sns::getAvatar($user['user_id']));
                     $device_id = md5($mobile . '_' . '0');
                     $token = User_Model::instance()->request_access_token(0, $user['user_id'], $device_id, Kohana::config('event.appid'));
                     $event_url = MO_EVENT . 'event/show/' . $id . '?token=' . $token['oauth_token'];
                     $event_short_url = url::getShortUrl($event_url);
                     $content = '邀请你参加活动:' . $event_short_url;
                     $this->send_event_mq($this->user_id, $user['user_id'], $content, $opt);
                 } else {
                     $this->send_response(400, NULL, '400511:该用户已报名');
                 }
             }
             $this->send_response(200, array('num' => $i, 'user' => $return));
         }
     }
     $errors = $post->errors();
     foreach ($errors as $key => $value) {
         switch ($key) {
             case 'user_name_empty':
                 $this->send_response(400, NULL, '400502:名字为空');
                 break;
             case 'user_mobile_empty':
                 $this->send_response(400, NULL, '400503:手机号为空');
                 break;
             case 'user_mobile_format':
                 $this->send_response(400, NULL, '400504:手机号格式不正确');
                 break;
         }
     }
 }