select('post.*') ->find($id); } //获取内容话题 public function getTopic($topic_ids) { $ids = explode(',', $topic_ids); $topic = []; foreach($ids as $id){ $name = $topicNameArray = Redis::ZRANGEBYSCORE('topic.name', $id, $id); if($name && isset($name[0])){ $topic[] = [ 'id' => intval($id), 'name' => $name[0], ]; } } return $topic; } //获取内容详情 public function getPostInfo($id, $type = 0) { if($type){ $res = Redis::SISMEMBER('delete_post_ids', $id); if($res){ return []; } } $data = Redis::HGETALL('post_info_'.$id); if($data){ $data['praise_count'] = intval($data['praise_count']); $data['comment_count'] = intval($data['comment_count']); $data['collect_count'] = intval($data['collect_count']); $data['available_bean'] = intval($data['available_bean']); $data['collect_bean'] = intval($data['collect_bean']); $data['will_collect_bean'] = $data['will_collect_bean'] + 3 * $data['pv']; $data['imgs'] = json_decode($data['imgs'], true); } return $data; } //获取内容最新评论 public function getNewComment($id) { $comment = []; $commentKey = 'post_new_comment_'.$id; $commentData = Redis::GET($commentKey); if($commentData){ $comment = json_decode($commentData); }else{ $comments = PostComment::where('post_id', $id)->where('parent_id', 0)->orderBy('is_delete', 'asc')->orderBy('id', 'desc')->limit(2)->get(); foreach($comments as $item){ $userComment = $this->userInfo($item->uid); $comment[] = [ 'id' => $item->id, 'username' => $userComment['username'], 'content' => $item->is_delete?'该评论已被删除':$item->content, 'is_delete' => $item->is_delete, ]; } Redis::SET($commentKey, json_encode($comment)); Redis::EXPIRE($commentKey, 300); } return $comment; } }