|
@@ -16,6 +16,7 @@ use App\Models\PostComment;
|
|
|
use App\Models\PostData;
|
|
|
use App\Models\PostImgs;
|
|
|
use App\Models\PostLike;
|
|
|
+use App\Models\PostShare;
|
|
|
use App\Models\Topic;
|
|
|
use App\Service\DetectionService;
|
|
|
use App\Service\RabbitMqUtil;
|
|
@@ -35,6 +36,8 @@ class PostRepositories
|
|
|
PostData $postData,
|
|
|
PostImgs $postImgs,
|
|
|
PostComment $postComment,
|
|
|
+ PostCollect $postCollect,
|
|
|
+ PostShare $postShare,
|
|
|
DetectionService $detectionService,
|
|
|
RabbitMqUtil $rabbitMqUtil,
|
|
|
Topic $topic)
|
|
@@ -43,6 +46,8 @@ class PostRepositories
|
|
|
$this->postData = $postData;
|
|
|
$this->postImgs = $postImgs;
|
|
|
$this->postComment = $postComment;
|
|
|
+ $this->postCollect = $postCollect;
|
|
|
+ $this->postShare = $postShare;
|
|
|
$this->detectionService = $detectionService;
|
|
|
$this->rabbitMqUtil = $rabbitMqUtil;
|
|
|
$this->topic = $topic;
|
|
@@ -255,12 +260,12 @@ class PostRepositories
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
try{
|
|
|
- $this->postComment->create($data);
|
|
|
+ $comment = $this->postComment->create($data);
|
|
|
$post->data->comment_count += 1;
|
|
|
$post->data->save();
|
|
|
|
|
|
DB::commit();
|
|
|
- return jsonSuccess();
|
|
|
+ return jsonSuccess(['id' => $comment->id], '评论成功');
|
|
|
|
|
|
}catch (QueryException $exception){
|
|
|
DB::rollBack();
|
|
@@ -285,10 +290,71 @@ class PostRepositories
|
|
|
->orWhere('content', 'like', "%{$request['keyword']}%");
|
|
|
}
|
|
|
})
|
|
|
+ ->where(function($query) use ($request){
|
|
|
+ if(isset($request['topic_ids'])){
|
|
|
+ $topicIds = json_decode($request['topic_ids'], true);
|
|
|
+ foreach ($topicIds as $key=>$id) {
|
|
|
+ if ($key==0) {
|
|
|
+ $query->whereRaw('FIND_IN_SET('.$id.', post.topic_ids)');
|
|
|
+ } else {
|
|
|
+ $query->orWhereRaw('FIND_IN_SET('.$id.', post.topic_ids)');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->orderBy('weight','desc')
|
|
|
+ ->paginate($perPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 视频列表
|
|
|
+ */
|
|
|
+ public function video($request)
|
|
|
+ {
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if(isset($request['id'])){
|
|
|
+ $where[] = ['post.id', '<>', $request['id']];
|
|
|
+ }
|
|
|
+ $where[] = ['type', 'video'];
|
|
|
+ return $this->post
|
|
|
+ ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
+ ->select('post.*')
|
|
|
+ ->where($where)
|
|
|
->orderBy('weight','desc')
|
|
|
->paginate($perPage);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 个人中心内容列表
|
|
|
+ */
|
|
|
+ public function MyPost($type, $uid)
|
|
|
+ {
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if($type == 'create'){
|
|
|
+ $where[] = ['post.uid', $uid];
|
|
|
+ $post = $this->post;
|
|
|
+ $order = 'post.id';
|
|
|
+ }elseif($type == 'collect'){
|
|
|
+ $post = $this->post->join('post_collect', 'post_collect.post_id', '=', 'post.id');
|
|
|
+ $where[] = ['post_collect.uid', $uid];
|
|
|
+ $order = 'post_collect.id';
|
|
|
+ }else{
|
|
|
+ $post = $this->post->join('post_share', 'post_share.post_id', '=', 'post.id');
|
|
|
+ $where[] = ['post_share.uid', $uid];
|
|
|
+ $order = 'post_share.updated_at';
|
|
|
+ }
|
|
|
+ return $post
|
|
|
+ ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
+ ->select('post.*')
|
|
|
+ ->where($where)
|
|
|
+ ->orderBy($order,'desc')
|
|
|
+ ->paginate($perPage);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 内容详情
|
|
|
*/
|
|
@@ -314,6 +380,21 @@ class PostRepositories
|
|
|
->paginate($perPage);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 话题内容
|
|
|
+ */
|
|
|
+ public function topicPost($request)
|
|
|
+ {
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
+
|
|
|
+ return $this->post
|
|
|
+ ->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
+ ->select('post.*')
|
|
|
+ ->whereRaw('FIND_IN_SET(' . $request['id'] . ',post.topic_ids)')
|
|
|
+ ->orderBy('id','desc')
|
|
|
+ ->paginate($perPage);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 评论列表
|
|
@@ -342,6 +423,29 @@ class PostRepositories
|
|
|
->paginate($perPage);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 话题列表
|
|
|
+ */
|
|
|
+ public function topicList($request)
|
|
|
+ {
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if(isset($request['category_id'])){
|
|
|
+ $topic = $this->topic->join('category_topic', 'category_topic.topic_id', '=', 'topic.id')->select('topic.*');
|
|
|
+ $where[] = ['category_topic.category_id', $request['category_id']];
|
|
|
+ }else{
|
|
|
+ $topic = $this->topic;
|
|
|
+ }
|
|
|
+ if(isset($request['is_suggest'])){
|
|
|
+ $where[] = ['topic.is_suggest', $request['is_suggest']];
|
|
|
+ }
|
|
|
+ return $topic
|
|
|
+ ->where($where)
|
|
|
+ ->orderBy('id','desc')
|
|
|
+ ->paginate($perPage);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 更新帖子统计数量
|
|
@@ -350,7 +454,11 @@ class PostRepositories
|
|
|
*/
|
|
|
public function updatePostData($request)
|
|
|
{
|
|
|
- $postId = $request['post_id'];
|
|
|
+ $postId = isset($request['post_id'])?$request['post_id']:0;
|
|
|
+ if(empty($postId)){
|
|
|
+ Log::debug("非帖子类操作,不操作帖子统计数量".json_encode($request));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
$post = PostData::where('post_id', $postId)->first();
|
|
|
if (isset($request['behavior_flag']) && $request['behavior_flag'] == 'read') {
|
|
|
$post->pv += 1;
|
|
@@ -374,6 +482,12 @@ class PostRepositories
|
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'forward') {
|
|
|
$post->share_count += 1;
|
|
|
$post->share_real_count += 1;
|
|
|
+ $shareRow = PostShare::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->first();
|
|
|
+ if($shareRow){
|
|
|
+ PostShare::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->update(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
|
|
|
+ }else{
|
|
|
+ PostShare::create(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
|
|
|
+ }
|
|
|
Log::debug("帖子:".$postId."被分享,share_count +1");
|
|
|
} elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'comment') {
|
|
|
$post->comment_count += 1;
|
|
@@ -408,4 +522,14 @@ class PostRepositories
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 话题详情
|
|
|
+ */
|
|
|
+ public function topicDetail($id)
|
|
|
+ {
|
|
|
+ return $this->topic
|
|
|
+ ->find($id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|