Exemplo n.º 1
0
 /**
  * 删除群
  * @param int $id 群组ID
  */
 public function destroy($id = NULL)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     } elseif (empty($id)) {
         $this->send_response(400, NULL, '400401:群ID为空');
     }
     $groupInfo = $this->model->getGroupInfo($id);
     if (!$groupInfo) {
         $this->send_response(400, NULL, '400402:群不存在');
     }
     $grade = $this->model->getMemberGrade($id, $this->user_id);
     if ($grade < Kohana::config('group.grade.master')) {
         $this->send_response(400, NULL, '400413:非群主,无权限删除群');
     }
     $memberList = $this->model->getGroupAllMember($id);
     $result = $this->model->delete($id);
     if ($result) {
         $feedModel = Feed_Model::instance();
         $userModel = User_Model::instance();
         $content = '您加入的群"' . $groupInfo['gname'] . '"已解散';
         foreach ($memberList as $value) {
             $feedModel->deleteItem($id, 32, $value['uid']);
             $userModel->present_mo_notice(Kohana::config('uap.xiaomo'), $value['uid'], $content);
         }
         $this->send_response(200);
     }
     $this->send_response(400, NULL, '删除群失败');
 }
Exemplo n.º 2
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.º 3
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);
 }