Пример #1
0
 public function message_opt_friend_apply($data, $message_id, $mini)
 {
     $location = '';
     $sex = 0;
     $together_count = 0;
     $same_friend = array();
     $result = $this->getNoticeInfo(array('id' => $message_id, 'authorid' => $this->uid), true);
     if ($result) {
         $tmp = $result['body'] ? json_decode($result['body'], true) : array("explain" => "");
         //取得共同好友
         $friendModel = new Friend_Model();
         $ffids = $friendModel->getAllFriendIDs($result['authorid'], false);
         $mfids = $friendModel->getAllFriendIDs($this->uid, false);
         $together = array_intersect($ffids, $mfids);
         $data = sns::getuser($result['authorid']);
         $tmp['reside'] = '';
         if ($data['resideprovince'] || $data['residecity']) {
             $config = Kohana::config_load('cityarray');
             //加载城市数组
             $province = isset($data['resideprovince']) ? isset($config['province'][$data['resideprovince']]) ? $config['province'][$data['resideprovince']] : '' : "";
             $city = isset($data['residecity']) ? isset($config['city'][$data['residecity']]) ? $config['city'][$data['residecity']] : '' : "";
             $location = $province . " " . $city;
         }
         $sex = $data['sex'] == 1 ? "男" : "女";
         $tmp['fid'] = $result['authorid'];
         $tmp['explain'] = $tmp['explain'] ? str::unhtmlspecialchars($tmp['explain']) : '';
         unset($data, $ffids, $mfids, $config);
         $str = "";
         $urlpre = url::base();
         $avatar = sns::getavatar($result['authorid']);
         if (!empty($together)) {
             $together_count = count($together);
             $i = 0;
             foreach ($together as $val) {
                 $item = array();
                 $item['id'] = $val;
                 $item['name'] = sns::getrealname($val);
                 $same_friend[] = $item;
                 if (9 < ++$i) {
                     break;
                 }
             }
         }
     }
     return array('location' => $location, 'sex' => $sex, 'together_count' => $together_count, 'together' => $same_friend);
 }
Пример #2
0
 public function userAboutActivityNum($uid, $end = 0)
 {
     $groupModel = new Group_Model();
     $gidList = $groupModel->getUserAllGroupId($uid);
     $gids = '';
     $separator = '';
     foreach ($gidList as $value) {
         $gids .= $separator . $value['gid'];
         $separator = ',';
     }
     $friendModel = new Friend_Model();
     $fidList = $friendModel->getAllFriendIDs($uid);
     $fids = '';
     if ($fidList) {
         $fids = implode(',', $fidList);
     }
     $applyAids = $this->getApplyAids($uid);
     $companyModel = Company_Model::instance();
     $companyList = $companyModel->getCompanyList($uid);
     $companyIds = "";
     $separator = '';
     foreach ($companyList as $value) {
         $companyIds .= $separator . $value['cid'];
         $separator = ',';
     }
     $belongType = Kohana::config('activity.belongType.company');
     if (!empty($companyIds)) {
         if (empty($applyAids)) {
             $separator = '';
         } else {
             $separator = ',';
         }
         $activityList = $this->getBelongActivityList($belongType, $companyIds);
         foreach ($activityList as $value) {
             $applyAids .= $separator . $value['aid'];
             $separator = ',';
         }
     }
     if ($fids) {
         $where = "(gid = -1 AND creator_id in ({$fids}))";
         $friendApplyaids = $this->getFriendsApplyAids($fids);
         if ($friendApplyaids) {
             $where .= " OR (is_allow_invite = 1 AND aid IN ({$friendApplyaids}))";
         }
     }
     if ($gids) {
         if ($where) {
             $where .= " OR gid in ({$gids})";
         } else {
             $where .= "gid in ({$gids})";
         }
     }
     if ($applyAids) {
         if ($where) {
             $where .= " OR aid in ({$applyAids})";
         } else {
             $where .= "aid in ({$applyAids})";
         }
     }
     if (!$where) {
         return 0;
     }
     if ($end == 0) {
         //未结束的活动
         $nowTime = time();
         $where = "{$nowTime} < end_time AND " . "({$where})";
     }
     $query = $this->db->query("SELECT COUNT(DISTINCT aid) AS num FROM action WHERE {$where}");
     $result = $query->result_array(FALSE);
     return (int) $result[0]['num'];
 }
Пример #3
0
 /**
  * 创建活动
  */
 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:活动信息非法');
 }