public function getList($uid, $since_id, $max_id, $count = 20, $page = 1)
 {
     $limit = ($page - 1) * $count . ',' . $count;
     $map['_string'] = "weibo_id IN (SELECT weibo_id FROM {$this->tablePrefix}weibo_favorite WHERE uid={$uid})";
     if ($since_id) {
         $map['weibo_id'] = array('gt', $since_id);
     } else {
         if ($max_id) {
             $map['weibo_id'] = array('lt', $max_id);
         }
     }
     $list = M('weibo')->where($map)->order('weibo_id DESC')->limit($limit)->findAll();
     /*
 	 * 缓存被转发微博的详情, 作者信息, 被转发微博的作者信息
 	 */
     $ids = getSubBeKeyArray($list, 'weibo_id,transpond_id,uid');
     $transpond_list = D('Weibo', 'weibo')->setWeiboObjectCache($ids['transpond_id']);
     // 本页的用户IDs = 作者IDs + 被转发微博的作者IDs
     $ids['uid'] = array_merge($ids['uid'], getSubByKey($transpond_list, 'uid'));
     D('User', 'home')->setUserObjectCache($ids['uid']);
     $weibo_ids = getSubByKey($list, 'weibo_id');
     foreach ($list as $key => $value) {
         $value['favorited'] = D('Favorite', 'weibo')->isFavorited($value['weibo_id'], $uid, $weibo_ids);
         $list[$key] = D('Weibo', 'weibo')->getOneApi('', $value);
     }
 function comments()
 {
     $data['type'] = $_GET['type'] == 'send' ? 'send' : 'receive';
     $data['from_app'] = $_GET['from_app'] == 'other' ? 'other' : 'weibo';
     // 优先展示微博,优先展示有未读from_app
     if (model('UserCount')->getUnreadCount($this->mid, 'comment') <= 0 && model('GlobalComment')->getUnreadCount($this->mid) > 0) {
         $data['from_app'] = 'other';
     }
     if ($data['from_app'] == 'weibo') {
         $data['type'] == 'receive' && model('UserCount')->setZero($this->mid, 'comment');
         //$data['person'] = (in_array( $_GET['person'] , array('all','follow','other')) )?$_GET['person']:'all';
         $data['person'] = 'all';
         $data['list'] = D('Comment', 'weibo')->getCommentList($data['type'], $data['person'], $this->mid);
     } else {
         $dao = model('GlobalComment');
         $data['type'] == 'receive' && $dao->setUnreadCountToZero($this->mid);
         $data['person'] = 'all';
         $data['list'] = $dao->getCommentList($data['type'], $this->mid);
         /*
          * 缓存评论发表者, 被回复的用户,
          */
         $ids = getSubBeKeyArray($data['list']['data'], 'appuid,uid,to_uid');
         D('User', 'home')->setUserObjectCache(array_unique(array_merge($ids['appuid'], $ids['uid'], $ids['to_uid'])));
         foreach ($data['list']['data'] as $k => $v) {
             $data['list']['data'][$k]['data'] = unserialize($v['data']);
         }
     }
     $this->assign('userCount', X('Notify')->getCount($this->mid));
     $this->assign($data);
     $this->setTitle($data['type'] == 'receive' ? L('receive_comment') : L('send_comment'));
     $this->display();
 }
 protected function _doWeiboAndUserCache($weibo_list)
 {
     if (!is_array($weibo_list) || !is_array($weibo_list[0])) {
         return false;
     }
     /*
      * 缓存被转发微博的详情, 作者信息, 被转发微博的作者信息
      */
     $ids = getSubBeKeyArray($weibo_list, 'weibo_id,transpond_id,uid');
     $transpond_list = $this->setWeiboObjectCache($ids['transpond_id']);
     // 本页的用户IDs = 作者IDs + 被转发微博的作者IDs
     $ids['uid'] = array_merge($ids['uid'], getSubByKey($transpond_list, 'uid'));
     D('User', 'home')->setUserObjectCache($ids['uid']);
     return true;
 }
 private function _paramResultData($list, $uid, $page = false)
 {
     if ($page) {
         //取出微博的实际数据
         $weibo_id_list = getSubByKey($list['data'], 'weibo_id');
         $data = $this->getWeiboDetail($weibo_id_list);
     } else {
         //取出微博的实际数据
         $weibo_id_list = getSubByKey($list, 'weibo_id');
         $data = $this->getWeiboDetail($weibo_id_list);
     }
     /*
      * 缓存被转发微博的详情, 被转发微博的作者信息
      */
     $ids = getSubBeKeyArray($data, 'weibo_id,transpond_id');
     $transpond_list = $this->getWeiboDetail($ids['transpond_id']);
     $ids['uid'] = getSubByKey($transpond_list, 'uid');
     D('User', 'home')->setUserObjectCache($ids['uid']);
     $weibo_ids = getSubByKey($data, 'weibo_id');
     foreach ($data as $key => $value) {
         $value['is_favorited'] = D('Favorite', 'weibo')->isFavorited($value['weibo_id'], $uid, $weibo_ids);
         $data[$key] = $this->getOne('', $value);
     }
     if ($page) {
         $list['data'] = $data;
     } else {
         $list = $data;
     }
     return $list;
 }
 function getCommentList($type = 'receive', $person = 'all', $uid)
 {
     if ($type == 'send') {
         // 发出的评论
         if ($person == 'follow') {
             $map = "reply_uid IN (SELECT fid FROM {$this->tablePrefix}weibo_follow where uid={$uid})";
         } else {
             if ($person == 'other') {
                 $map = "reply_uid NOT IN (SELECT fid FROM {$this->tablePrefix}weibo_follow where uid={$uid})";
             } else {
                 $map = '1=1';
             }
         }
         $list = $this->where($map . " AND uid=" . $uid . " AND reply_uid<>{$uid}" . ' AND isdel=0')->order('comment_id DESC')->findPage(10);
     } else {
         // 收到的评论
         if ($person == 'follow') {
             $map = "uid IN (SELECT fid FROM {$this->tablePrefix}weibo_follow where uid={$uid})";
         } else {
             if ($person == 'other') {
                 $map = "uid NOT IN (SELECT fid FROM {$this->tablePrefix}weibo_follow where uid={$uid})";
             } else {
                 $map = 'uid <> ' . $uid;
             }
         }
         //$list = $this->where($map." AND reply_uid=".$uid.' AND isdel=0')->order('comment_id DESC')->findpage(10);
         $list = $this->field('c.*')->table("{$this->tablePrefix}weibo_comment AS c LEFT JOIN {$this->tablePrefix}weibo AS w ON c.weibo_id=w.weibo_id")->where("c.isdel=0 AND w.isdel=0 AND (c.reply_uid={$uid} OR w.uid={$uid} ) and c.uid != {$uid}")->order('comment_id DESC')->findPage(10);
     }
     // 缓存被评论的微博, 被回复的评论, 评论的发表人, 被回复的用户
     $ids = getSubBeKeyArray($list['data'], 'comment_id,reply_comment_id,weibo_id,uid,reply_uid');
     D('Weibo', 'weibo')->setWeiboObjectCache($ids['weibo_id']);
     D('User', 'home')->setUserObjectCache(array_merge($ids['uid'], $ids['reply_uid']));
     $this->setCommentObjectCache(array_merge($ids['comment_id'], $ids['reply_comment_id']));
     foreach ($list['data'] as $key => $value) {
         $list['data'][$key]['mini'] = D('Weibo', 'weibo')->getOneLocation($value['weibo_id'], '', false);
         if (!$value['reply_comment_id']) {
             $list['data'][$key]['reply_uid'] = $list['data'][$key]['mini']['uid'];
             $list['data'][$key]['ismini'] = true;
         } else {
             $list['data'][$key]['comment'] = $this->getCommentDetail($value['reply_comment_id']);
         }
     }
     return $list;
 }