Exemplo n.º 1
0
 public static function removeFriend($friend)
 {
     $model = new Friend_Model();
     $id = Session::get('id');
     $x = $model->removeFriend($id, $friend);
     if ($x) {
         header("Location:" . URL . "/friend/getFriends");
         exit;
     }
     echo 'something went wrong';
     die;
 }
Exemplo n.º 2
0
 /**
  * 单例
  * @return Friend_Model
  */
 public static function &instance()
 {
     if (!is_object(Friend_Model::$instances)) {
         // Create a new instance
         Friend_Model::$instances = new Friend_Model();
     }
     return Friend_Model::$instances;
 }
Exemplo n.º 3
0
 private function _user($uid, $avatar_size = 130)
 {
     //外部应用不需获取用户信息
     if ($this->is_app_standalone) {
         return array('id' => $uid, 'name' => '', 'avatar' => '');
     }
     if (!$uid) {
         return array('id' => 0, 'name' => '', 'avatar' => '', 'nick' => array(), 'mobile' => '', 'zone_code' => '');
     }
     if (!$this->_cache_users[$uid]) {
         $user_info = sns::getuser($uid);
         $nicks = Friend_Model::instance()->get_contact_formatted_name($this->uid, $user_info['mobile'], $user_info['zone_code']);
         $mobile = $user_info['mobile'];
         $this->_cache_users[$uid] = array('id' => (int) $uid, 'name' => $user_info['realname'], 'avatar' => sns::getavatar($uid, $avatar_size), 'nick' => $nicks, 'mobile' => $mobile, 'zone_code' => $user_info['zone_code']);
     }
     return $this->_cache_users[$uid];
 }
Exemplo n.º 4
0
 /**
  * Create friendship
  *
  * @param  User_Model  $friend
  */
 public function add_friend(User_Model $friend)
 {
     // don't add duplicate friends or oneself
     if ($this->loaded() && $this->id != $friend->id && !$this->is_friend($friend)) {
         $friendship = new Friend_Model();
         $friendship->user_id = $this->id;
         $friendship->friend_id = $friend->id;
         $friendship->save();
         return true;
     }
     return false;
 }
Exemplo n.º 5
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'];
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
 /**
  *
  * 评论mo短信
  * @param string $feedid
  * @param array $at
  */
 private function mo_sms_comment($commentid, $feedid, $receiver_uid, $receiver_name, $moid = '', $auto)
 {
     $type = $this->format_type($typeid);
     $sender_uid = $this->uid;
     $sender_name = sns::getrealname($this->uid);
     //检查接收者是否在自己联系人中,并且接收者级别<3
     if (Friend_Model::instance()->check_iscontact($sender_uid, $receiver_uid)) {
         $receiver_status = sns::getstatus($receiver_uid);
         if ($receiver_status >= 3 && $auto == true) {
             return false;
         }
     } else {
         return false;
     }
     //接收者的用户基本要<2x
     if (!$this->is_mo_sms_sent('comment', $feedid, $sender_uid, $receiver_uid, $moid)) {
         $receiver_info = sns::getuser($receiver_uid);
         $url_code = Url_Model::instance()->create('status', $sender_uid, $sender_name, $receiver_uid, $receiver_name, $receiver_info['mobile'], $receiver_info['zone_code'], $feedid);
         $short_url = MO_SMS_JUMP . $url_code;
         $comment_row = $this->comment_new->findOne(array('id' => $commentid));
         if ($comment_row) {
             $content = str::cnSubstr($this->feed_at_format($comment_row['content'], $comment_row['at']), 0, 15) . '..';
             $data = array();
             $data['sender']['id'] = $sender_uid;
             $data['sender']['name'] = $sender_name;
             $data['receiver'][] = $receiver_uid;
             $data['timestamp'] = time();
             $data['content']['text'] = $sender_name . '分享了:' . $content . ',点开互动: ' . $short_url;
             $mq_msg = array("kind" => "mobile_sms", "data" => $data);
             $this->mq_send(json_encode($mq_msg), $this->uid, 'momo_im');
             $this->mo_sms_log('comment', $commentid, $feedid, $this->uid, $receiver_uid, $moid);
             if ($moid) {
                 $this->update_my_mo($moid);
             }
             return true;
         }
     }
 }
Exemplo n.º 8
0
 /**
  * 取得列表json数据
  * @method GET
  * 
  * fail=1 失效
  * sale=1 供 dealer=2 求
  * city=城市名(eg:福州)
  * circle:1、好友; 6、熟人; 8、同城
  * cate:1二手物品,2租房,3售房,4团购
  * keyword:用户输入
  * |myfav=1 我的收藏
  * |mytrade=1 我的二手
  * |myrent=1 我的租房
  * |replymy=1 回复我的
  * |hide=1 我的隐藏
  * 
  * @access public
  * @return void
  */
 public function index()
 {
     if ($this->input->get("hide", 0)) {
         $start = (int) $this->input->get('page', 1);
         if ($start <= 0) {
             $this->send_response(400, NULL, "输入有误");
         }
         $pos = (int) $this->input->get('pagesize', 20);
         if ($pos <= 0 || $pos > self::MAX_PAGESIZE) {
             $this->send_response(400, NULL, "输入有误");
         }
         $start = abs(($start - 1) * $pos);
         $result = $this->model->get_hidden_ids($this->user_id, $start, $pos);
         self::get_market_json(array("object_id" => array('$in' => $result), "status" => "all"), "", false);
         return null;
     }
     if ($this->input->get("myfav", 0)) {
         $start = (int) $this->input->get('page', 1);
         if ($start <= 0) {
             $this->send_response(400, NULL, "输入有误");
         }
         $pos = (int) $this->input->get('pagesize', 20);
         if ($pos <= 0 || $pos > self::MAX_PAGESIZE) {
             $this->send_response(400, NULL, "输入有误");
         }
         $start = abs(($start - 1) * $pos);
         $result = $this->model->get_favorite_ids($this->user_id, $start, $pos);
         self::get_market_json(array("object_id" => array('$in' => $result), "status" => "all"), "", false);
         return null;
     }
     if ($this->input->get("mytrade", 0)) {
         self::get_market_json(array("user_id" => (int) $this->user_id, "category" => 1, "status" => "all"), "", false);
         return null;
     }
     if ($this->input->get("myrent", 0)) {
         self::get_market_json(array("user_id" => (int) $this->user_id, "category" => 2, "status" => "all"), "", false);
         return null;
     }
     if ($this->input->get("replymy", 0)) {
         $this->send_response(501, null, "暂不支持");
         return null;
     }
     $fail = $this->input->get("fail", 0);
     $sale = $this->input->get("sale", 0);
     $city = $this->input->get("city", "");
     $circle = $this->input->get("circle", 0);
     $cate = $this->input->get("cate", 0);
     $keyword = $this->input->get("keyword", "");
     $keyword = $keyword ? strtr(trim($keyword), array("." => "", "*" => "", "+" => "", "?" => "", "[" => "", "]" => "", "(" => "", ")" => "", "," => "", "," => "")) : "";
     $where = array();
     if ($fail) {
         $where['status'] = 'all';
     }
     if ($sale && in_array($sale, array('1', '2'))) {
         $where['type'] = (int) $sale;
     }
     if ($city) {
         $where['city'] = $city;
     }
     if ($cate && in_array($cate, array('1', '2', '3', '4', '5'))) {
         $where['category'] = (int) $cate;
     }
     //取得两个月内的隐藏数据
     $lastmonth = mktime(0, 0, 0, date("m") - 2, date("d"), date("Y"));
     $not_id = $this->model->get_hidden_ids($this->uid, null, null, $lastmonth);
     if (!empty($not_id)) {
         $where['object_id'] = array('$nin' => $not_id);
     }
     //权限处理 没选权限默认是同城
     if ($circle && in_array($circle, array('1', '6'))) {
         do {
             $user_ids = array();
             if ($circle == 1) {
                 $user_ids = Friend_Model::instance()->getAllFriendIDs($this->user_id);
                 array_walk($user_ids, function (&$item) {
                     $item = (int) $item;
                 });
                 $user_ids[] = (int) $this->user_id;
                 $where['privacy'] = array('$in' => array(1, 7, 9, 15));
                 break;
             }
             if ($circle == 6) {
                 $sub_model = new Company_Model();
                 $cids = $sub_model->getCompanyList($this->user_id);
                 foreach ($cids as $v) {
                     $uids = $sub_model->getCompanyMemberIds($v["cid"]);
                     $user_ids = array_merge($user_ids, $uids);
                 }
                 $sub_model = new Group_Model();
                 $gids = $sub_model->getUserAllGroupId($this->user_id);
                 foreach ($gids as $v) {
                     $uids = $sub_model->getGroupAllMember($v["gid"]);
                     array_walk($uids, function (&$item) {
                         $item = $item["uid"];
                     });
                     $user_ids = array_merge($user_ids, $uids);
                 }
                 unset($cids, $gids, $sub_model);
                 array_walk($user_ids, function (&$item) {
                     $item = (int) $item;
                 });
                 $user_ids[] = (int) $this->user_id;
                 $user_ids = array_unique($user_ids);
                 $where['privacy'] = array('$in' => array(6, 7, 14, 15));
                 break;
             }
         } while (0);
         $where['user_id'] = array('$in' => $user_ids);
     } else {
         // 同城,(钩上同城选项)或者(好友、群友、同事、在同城)
         $where['privacy'] = array('$in' => array(0, 8, 9, 14, 15));
         if (!$city) {
             $where['city'] = self::city_visitors();
         }
     }
     self::get_market_json($where, $keyword);
 }
Exemplo n.º 9
0
 public function agree_group()
 {
     $data = $this->get_data();
     $message_id = $data['id'];
     if (empty($message_id)) {
         $this->send_response(400, NULL, '400102:消息id非法');
     }
     $result = $this->model->getNoticeInfo(array('id' => $message_id, 'uid' => $this->user_id), true);
     if (!$result) {
         $this->send_response(400, NULL, '400101:消息体不存在或已经被处理');
     }
     $group_tmp = json_decode($result['title'], true);
     $gid = $group_tmp['group'][0]['id'];
     $gname = $group_tmp['group'][0]['name'];
     $grade = $this->groupModel->getmembergrade($gid, $this->user_id);
     if ($grade > 0) {
         $this->model->putChangeTplByid($this->user_id, $message_id, 1);
         $this->send_response(400, NULL, '400108:您已经是群成员了');
     }
     $group_info = $this->groupModel->getGroupInfo($gid);
     if (!$group_info) {
         $this->model->putChangeTplByid($this->user_id, $message_id, 4);
         $this->send_response(400, NULL, '400109:群不存在');
     }
     //查询群组成员总数是否超出最大限制(暂定100)
     $memberNum = $group_info['member_number'];
     if ($group_info['type'] == Kohana::config('group.type.public')) {
         $maxMemberNum = Kohana::config('group.maxMemberNum.public');
     } else {
         $maxMemberNum = Kohana::config('group.maxMemberNum.private');
     }
     if ($memberNum >= $maxMemberNum) {
         $this->model->putChangeTplByid($this->user_id, $message_id, 3);
         $this->send_response(400, NULL, '400110:群成员人数已满');
     }
     $result = $this->groupModel->addGroupMember($gid, $this->user_id, 1);
     $this->groupModel->addMemberNum($gid);
     $feedModel = new Feed_Model();
     if ($group_info['type'] == Kohana::config('group.type.private')) {
         $dateline = time();
         try {
             //添加群组通讯录联系人
             $this->groupContactModel->addGroupContactByUserCard($gid, $this->user_id, $dateline);
         } catch (Exception $exc) {
             $this->send_response(400, NULL, '400111:导入个人名片到群组通讯录联系人失败');
         }
         $ginfo['modify_time'] = $dateline;
         $ret = $this->groupModel->modifyGroup($gid, $ginfo);
     } else {
         if ($group_info['type'] == Kohana::config('group.type.public')) {
             //发送加入公开群组动态
             $application = array('id' => floatval($gid), 'title' => '查看群组', 'url' => 'group/' . $gid);
             $feedModel->addFeed($this->user_id, 2, $text = '加入了群组:' . $group_info['gname'], $this->get_source(), $application, $at = array(), $images = array(), $sync = array(), $group_type = 0, $group_id = 0, $retweet_id = 0, $allow_rt = 0, $allow_comment = 1, $allow_praise = 1, $allow_del = 1, $allow_hide = 1);
         }
     }
     $commentModel = new Comment_Model();
     if ($group_info['feed_id']) {
         $friendModel = Friend_Model::instance();
         $isFriend = $friendModel->check_isfriend($this->user_id, $group_info['creator_id']);
         if ($isFriend) {
             $commentModel->saveComment($group_info['feed_id'], '加入了本群', $group_info['creator_id']);
         }
     }
     if ($group_info['group_feed_id']) {
         $commentModel->saveComment($group_info['group_feed_id'], '加入了本群', $group_info['creator_id']);
     }
     //添加群到首页tab列表
     $userModel = new User_Model();
     $userModel->insertTag($this->user_id, 7, $gid);
     $feedModel->addTab($gid, $group_info['gname'], 7, $this->user_id);
     //删除邀请表对应的记录
     $this->model->putChangeTplByid($this->user_id, $message_id, 1);
     $this->send_response(200);
 }
Exemplo n.º 10
0
 /**
  * 执行清空缓存
  * @return void
  */
 public function do_task()
 {
     if (!empty($this->task_data)) {
         $user_id = $this->task_data['user_id'];
         $added_ids = $this->task_data['added_ids'];
         $updated_ids = $this->task_data['updated_ids'];
         $deleted_ids = $this->task_data['deleted_ids'];
         $recycled_ids = $this->task_data['recycled_ids'];
         $ids = array_merge($added_ids, $updated_ids, $deleted_ids);
         if ($updated_ids or $recycled_ids or $deleted_ids) {
             $this->update_cache($user_id, 'recycled_list_update');
         }
         if (!empty($ids) or $this->is_snapshot) {
             Category_Model::instance()->clear_cache($user_id);
         }
         if (!empty($ids)) {
             foreach ($ids as $id) {
                 $this->cache->delete($this->cache_pre . 'find_by_id_' . $user_id . '_' . $id);
             }
             $this->cache->delete($this->cache_pre . 'get_list_' . $user_id);
             $this->cache->delete($this->cache_pre . 'get_count_' . $user_id);
             Friend_Model::instance()->del_user_link_cache($user_id);
         }
     }
 }
Exemplo n.º 11
0
 /**
  * 检查用户是否有查看活动的权限
  * @param array $activity 
  * @param float $uid
  * return boolean
  */
 private function _check_activity_view_permission($activity, $uid)
 {
     $permit = true;
     if ($activity['gid'] == 0) {
         $permit = false;
         $friendModel = Friend_Model::instance();
         $isFriend = $friendModel->check_isfriend($activity['creator_id'], $uid);
         $fidList = $friendModel->getAllFriendIDs($uid);
         $friendsIsJoin = false;
         if ($fidList) {
             $fids = implode(',', $fidList);
             $friendsIsJoin = $this->model->checkFriendsIsJoined($activity['aid'], $fids);
         }
         $invite = $this->model->getUserInviteUnset($activity['aid'], $uid);
         $isCompanyMember = false;
         if ($activity['belong_type'] == Kohana::config('activity.belongType.company')) {
             $companyModel = new Company_Model();
             $companyId = floatval($activity['belong_id']);
             $isCompanyMember = $companyModel->isCompanyMember($companyId, $uid);
         }
         if ($invite || $isCompanyMember) {
             $permit = true;
         } else {
             if ($activity['is_allow_invite'] && $friendsIsJoin) {
                 $permit = true;
             }
         }
     }
     return $permit;
 }
Exemplo n.º 12
0
 /**
  * 决定是否显示评论框
  * @param int $vuid 登录者id
  * @param int $uid 所有者id
  */
 public function retrunAllow($vuid, $uid)
 {
     if ($vuid == $uid) {
         return 1;
     }
     $right = User_Model::instance()->getRights($uid, 'allowcomment');
     if ($right == 0) {
         //任何人可以访问
         return 1;
     } elseif ($right == 1) {
         //仅好友
         $return = Friend_Model::instance()->getCheckIsFriend($vuid, $uid);
         if ($return) {
             //如果是好友返回1
             return 1;
         } else {
             //如果不是好友返回2
             return 2;
         }
     } else {
         return 0;
     }
 }
Exemplo n.º 13
0
 /**
  * 检查用户查看权限
  * @return <type>
  */
 public function checkPermission($fid, $content)
 {
     if ($this->uid != $fid) {
         $friendModel = Friend_Model::instance();
         if (!$friendModel->check_isfriend($this->uid, $fid)) {
             return '对方不是你的好友,无权限查看源内容';
         }
     }
     return $content;
 }
Exemplo n.º 14
0
 /**
  * 
  * 获取用户的mix_id
  */
 private function get_user_mix_ids()
 {
     $uids = array();
     //联系人
     $uids = Friend_Model::instance()->get_user_link_cache($this->user_id);
     //群组
     $group_array = Group_Model::instance()->getUserAllGroupId($this->user_id);
     if ($group_array) {
         foreach ($group_array as $group) {
             $uids[] = '1_' . $group['gid'];
         }
     }
     array_push($uids, $this->user_id);
     return $uids;
 }
Exemplo n.º 15
0
 /**
  * 
  * @param $user_id
  * @return unknown_type
  */
 private function _get_relation_contact_uids($user_id)
 {
     $contact_uids = array();
     $contact_uids = Friend_Model::instance()->get_user_link_cache($user_id);
     return $contact_uids;
 }
Exemplo n.º 16
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:活动信息非法');
 }
Exemplo n.º 17
0
 public function __construct()
 {
     parent::__construct();
     $this->model = User_Model::instance();
     $this->friend_model = Friend_Model::instance();
 }
Exemplo n.º 18
0
 /**
  * 批量获取联系人信息
  * @param int $id 联系人ID
  */
 public function show_batch($id = NULL)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     }
     if (!is_numeric($id) or empty($id)) {
         $this->send_response(400, NULL, '400401:群ID为空');
     }
     $groupModel = new Group_Model();
     $groupInfo = $groupModel->getGroupInfo($id);
     if (!$groupInfo) {
         $this->send_response(400, NULL, '400402:群不存在');
     }
     $grade = $groupModel->getMemberGrade($id, $this->user_id);
     if ($grade < Kohana::config('group.grade.normal')) {
         $this->send_response(400, NULL, '400411:非群成员,无权限查看联系人详细信息');
     }
     $data = $this->get_data();
     $ids = isset($data['ids']) ? $data['ids'] : '';
     if (empty($ids)) {
         $this->send_response(400, NULL, '400215:群联系人ids为空');
     }
     $ids = explode(',', $ids);
     $result = array();
     if (count($ids) > 100) {
         $this->send_response(400, NULL, '400216:群联系人ids超过上限(100个)');
     }
     $contact_ids = array_keys($this->model->get($id));
     $friendModel = new Friend_Model();
     foreach ($ids as $cid) {
         if (in_array($cid, $contact_ids)) {
             $contact = $this->model->get($id, $cid);
             if ($contact !== FALSE) {
                 $contact['is_friend'] = 0;
                 if ($contact['user_id'] > 0) {
                     $isFriend = $friendModel->check_isfriend($this->user_id, $contact['user_id']);
                     if ($isFriend) {
                         $contact['is_friend'] = 1;
                     }
                 }
                 $contact['momo_user_id'] = intval($contact['user_id']);
                 unset($contact['user_id']);
                 $result[] = $contact;
             }
             unset($contact);
         }
     }
     $this->send_response(200, $result);
 }