|
@@ -13,6 +13,7 @@ use App\Models\Behavior;
|
|
|
use App\Models\Feed;
|
|
|
use App\Models\PostComment;
|
|
|
use Carbon\Carbon;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
use Tymon\JWTAuth\Facades\JWTAuth;
|
|
@@ -25,9 +26,8 @@ class FeedRepositories
|
|
|
{
|
|
|
use UserTrait;
|
|
|
|
|
|
- public function __construct(Feed $feed, PostRepositories $postRepositories, PostComment $postComment)
|
|
|
+ public function __construct(PostRepositories $postRepositories, PostComment $postComment)
|
|
|
{
|
|
|
- $this->feed = $feed;
|
|
|
$this->postRepositories = $postRepositories;
|
|
|
$this->postComment = $postComment;
|
|
|
}
|
|
@@ -78,6 +78,7 @@ class FeedRepositories
|
|
|
if ($feedType) {
|
|
|
$data = [];
|
|
|
foreach ($fans as $fan) {
|
|
|
+ $number = substr($fan, -1);
|
|
|
$data['uid'] = $fan;
|
|
|
$data['follow_uid'] = $request['target_id'];
|
|
|
$data['follow_username'] = $request['target_username'];
|
|
@@ -111,20 +112,20 @@ class FeedRepositories
|
|
|
Log::debug('创建Feed流-data:' . json_encode($data));
|
|
|
//目前只有评论可以重复出现在别人的feed流中,其他类型如果出现过一次不再产生新的feed信息
|
|
|
if (in_array($feedType, [4])) {
|
|
|
- $this->feed->insert($data);
|
|
|
+ DB::table('feed_'.$number)->insert($data);
|
|
|
} else {
|
|
|
//此处需要优化,如果feed表需要清理历史数据怎么处理
|
|
|
//以下判断可以控制virus的行为,重复不添加feed,但是关注用户不行,关注用户不存在is_existing字段
|
|
|
//if (isset($request['is_existing']) && intval($request['is_existing']) == 0) {
|
|
|
- // $this->feed->insert($data);
|
|
|
+ // DB::table('feed_'.$number)->insert($data);
|
|
|
//}
|
|
|
- $feedRow = $this->feed->where('uid',$data['uid'])
|
|
|
+ $feedRow = DB::table('feed_'.$number)->where('uid',$data['uid'])
|
|
|
->where('follow_uid',$data['follow_uid'])
|
|
|
->where('type',$data['type'])
|
|
|
->where('relate_id',$data['relate_id'])
|
|
|
->first();
|
|
|
- if (empty($feedRow)) {
|
|
|
- $this->feed->insert($data);
|
|
|
+ if(empty($feedRow)){
|
|
|
+ DB::table('feed_'.$number)->insert($data);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -142,7 +143,12 @@ class FeedRepositories
|
|
|
}
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
$where[] = ['uid', $userInfo['uid']];
|
|
|
- $data = $this->feed
|
|
|
+ $number = substr($userInfo['uid'], -1);
|
|
|
+ $table_name = 'feed_'.$number;
|
|
|
+ $feedModel = new Feed();
|
|
|
+ $feedModel->setTable($table_name);
|
|
|
+
|
|
|
+ $data = $feedModel
|
|
|
->where($where)
|
|
|
->orderBy('id', 'desc')
|
|
|
->paginate($perPage);
|
|
@@ -158,10 +164,7 @@ class FeedRepositories
|
|
|
}
|
|
|
if ($value['type'] == 5) {
|
|
|
$value['content'] = null;
|
|
|
- $user = Redis::HGETALL('userInfo:' . $value['relate_id']);
|
|
|
- if (!$user) {
|
|
|
- $user = $this->userInfo($value['relate_id']);
|
|
|
- }
|
|
|
+ $user = $this->userInfo($value['relate_id']);
|
|
|
if ($user) {
|
|
|
Log::debug("测试feed关注状态:uid{$userInfo['uid']}followUid{$value['relate_id']}");
|
|
|
$value['relate_data'] = [
|
|
@@ -201,13 +204,14 @@ class FeedRepositories
|
|
|
if ($followStatus) {
|
|
|
$isFollow = $followStatus;
|
|
|
}
|
|
|
+ $user = $this->userInfo($post['uid']);
|
|
|
return [
|
|
|
'id' => $post['id'],
|
|
|
'type' => $post['type'],
|
|
|
'created_at' => Carbon::parse($post['created_at'])->diffForHumans(),
|
|
|
'uid' => $post['uid'],
|
|
|
- 'username' => $post['username'],
|
|
|
- 'avatar' => $post['avatar'],
|
|
|
+ 'username' => $user['username'],
|
|
|
+ 'avatar' => $user['avatar'],
|
|
|
'topic' => $topic,
|
|
|
'title' => $post['title'],
|
|
|
'content' => $post['content'],
|
|
@@ -232,12 +236,14 @@ class FeedRepositories
|
|
|
|
|
|
public function getPostComment($post_id)
|
|
|
{
|
|
|
- $comments = $this->postComment->where(['post_id' => $post_id, 'parent_id' => 0])->select('id', 'uid', 'username', 'content', 'is_delete')->orderBy('is_delete', 'asc')->orderBy('id', 'desc')->take(2)->get();
|
|
|
+ $comments = $this->postComment->where(['post_id' => $post_id, 'parent_id' => 0])->select('id', 'uid', 'content', 'is_delete')->orderBy('is_delete', 'asc')->orderBy('id', 'desc')->take(2)->get();
|
|
|
foreach ($comments as &$comment) {
|
|
|
if ($comment->is_delete) {
|
|
|
$comment->content = '该评论已被删除';
|
|
|
}
|
|
|
unset($comment->is_delete);
|
|
|
+ $user = $this->userInfo($comment->uid);
|
|
|
+ $comment->username = $user['username'];
|
|
|
}
|
|
|
return $comments;
|
|
|
}
|
|
@@ -248,8 +254,9 @@ class FeedRepositories
|
|
|
*/
|
|
|
public function contentFeedDelete($data)
|
|
|
{
|
|
|
+ $number = substr($data['uid'], -1);
|
|
|
try {
|
|
|
- $this->feed->where('uid', $data['uid'])->where('follow_uid', $data['follow_uid'])->delete();
|
|
|
+ DB::table('feed_'.$number)->where('uid', $data['uid'])->where('follow_uid', $data['follow_uid'])->delete();
|
|
|
Log::debug("取消关注删除对应feed成功uid{$data['uid']}followUid{$data['follow_uid']}");
|
|
|
} catch (\Exception $exception) {
|
|
|
Log::error('取消关注删除对应feed失败' . json_encode($data) . $exception->getMessage());
|
|
@@ -257,4 +264,4 @@ class FeedRepositories
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+}
|