示例#1
0
 public static function &instance()
 {
     if (!is_object(Company_Model::$instances)) {
         // Create a new instance
         Company_Model::$instances = new Company_Model();
     }
     return Company_Model::$instances;
 }
示例#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
 /**
  * 检查用户是否有查看活动的权限
  * @param array $activity 
  * @param float $uid
  * return boolean
  */
 private function _check_activity_view_permission($activity, $uid)
 {
     $permit = true;
     $apply_type = $this->model->getActivityApplyType($activity['aid'], $uid);
     if ($activity['gid'] == 0 && $apply_type == 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;
 }
示例#4
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);
 }