|
@@ -18,6 +18,7 @@ use App\Models\PostImgs;
|
|
use App\Models\PostLike;
|
|
use App\Models\PostLike;
|
|
use App\Models\Topic;
|
|
use App\Models\Topic;
|
|
use App\Service\DetectionService;
|
|
use App\Service\DetectionService;
|
|
|
|
+use App\Service\RabbitMqUtil;
|
|
use App\Traits\PostTrait;
|
|
use App\Traits\PostTrait;
|
|
use App\Traits\UserTrait;
|
|
use App\Traits\UserTrait;
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Database\QueryException;
|
|
@@ -34,6 +35,7 @@ class PostRepositories
|
|
PostImgs $postImgs,
|
|
PostImgs $postImgs,
|
|
PostComment $postComment,
|
|
PostComment $postComment,
|
|
DetectionService $detectionService,
|
|
DetectionService $detectionService,
|
|
|
|
+ RabbitMqUtil $rabbitMqUtil,
|
|
Topic $topic)
|
|
Topic $topic)
|
|
{
|
|
{
|
|
$this->post = $post;
|
|
$this->post = $post;
|
|
@@ -41,6 +43,7 @@ class PostRepositories
|
|
$this->postImgs = $postImgs;
|
|
$this->postImgs = $postImgs;
|
|
$this->postComment = $postComment;
|
|
$this->postComment = $postComment;
|
|
$this->detectionService = $detectionService;
|
|
$this->detectionService = $detectionService;
|
|
|
|
+ $this->rabbitMqUtil = $rabbitMqUtil;
|
|
$this->topic = $topic;
|
|
$this->topic = $topic;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -151,6 +154,112 @@ class PostRepositories
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 评论&回复
|
|
|
|
+ */
|
|
|
|
+ public function comment($request)
|
|
|
|
+ {
|
|
|
|
+ //验证小号
|
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
|
+ if (empty($userInfo)) {
|
|
|
|
+ Log::info('获取用户信息失败');
|
|
|
|
+ return jsonError('获取用户信息失败');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $detectionTextResult = $this->detectionService->checkText($request['content']);
|
|
|
|
+ if ($detectionTextResult['code']<0) {
|
|
|
|
+ return jsonError('内容违规,请修正哦');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $post = $this->post->find($request['post_id']);
|
|
|
|
+ if(!$post){
|
|
|
|
+ return jsonError('获取内容信息失败');
|
|
|
|
+ }
|
|
|
|
+ $data = [
|
|
|
|
+ 'uid' => $userInfo['uid'],
|
|
|
|
+ 'post_id' => $request['post_id'],
|
|
|
|
+ 'parent_id' => 0,
|
|
|
|
+ 'username' => $userInfo['username'],
|
|
|
|
+ 'reply_uid' => 0,
|
|
|
|
+ 'reply_username' => '',
|
|
|
|
+ 'avatar' => $userInfo['avatar']??'',
|
|
|
|
+ 'content' => $request['content'],
|
|
|
|
+ 'is_delete' => 0,
|
|
|
|
+ ];
|
|
|
|
+ if(isset($request['parent_id']) && $request['parent_id'] != 0){
|
|
|
|
+ $comment = $this->postComment->find($request['parent_id']);
|
|
|
|
+ if(!$comment){
|
|
|
|
+ return jsonError('获取评论信息失败');
|
|
|
|
+ }
|
|
|
|
+ if($comment->parent_id){
|
|
|
|
+ return jsonError('只能回复评论');
|
|
|
|
+ }
|
|
|
|
+ $data['parent_id'] = $request['parent_id'];
|
|
|
|
+
|
|
|
|
+ if(isset($request['reply_uid']) && isset($request['reply_username'])){
|
|
|
|
+ $data['reply_uid'] = 0;
|
|
|
|
+ $data['reply_username'] = $request['reply_username'];
|
|
|
|
+ $this->rabbitMqUtil->push('add_message', [
|
|
|
|
+ 'uid' => $request['reply_uid'],
|
|
|
|
+ 'message_show_type' => 'post_reply_main',
|
|
|
|
+ 'param' => [
|
|
|
|
+ 'uid' => $userInfo['uid'],
|
|
|
|
+ 'username' => $userInfo['username'],
|
|
|
|
+ ]
|
|
|
|
+ ]);
|
|
|
|
+ }else{
|
|
|
|
+ $data['reply_uid'] = 0;
|
|
|
|
+ $data['reply_username'] = '';
|
|
|
|
+ $this->rabbitMqUtil->push('add_message', [
|
|
|
|
+ 'uid' => $comment->uid,
|
|
|
|
+ 'message_show_type' => 'post_reply',
|
|
|
|
+ 'param' => [
|
|
|
|
+ 'uid' => $userInfo['uid'],
|
|
|
|
+ 'username' => $userInfo['username'],
|
|
|
|
+ 'post_id' => $post->id,
|
|
|
|
+ 'content' => subtext($request['content'], 20),
|
|
|
|
+ ]
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ $this->rabbitMqUtil->push('add_message', [
|
|
|
|
+ 'uid' => $comment->uid,
|
|
|
|
+ 'message_show_type' => 'post_reply_main',
|
|
|
|
+ 'param' => [
|
|
|
|
+ 'uid' => $userInfo['uid'],
|
|
|
|
+ 'username' => $userInfo['username'],
|
|
|
|
+ 'post_id' => $post->id,
|
|
|
|
+ 'content' => subtext($request['content'], 20),
|
|
|
|
+ ]
|
|
|
|
+ ]);
|
|
|
|
+ }else{
|
|
|
|
+ $this->rabbitMqUtil->push('add_message', [
|
|
|
|
+ 'uid' => $post->uid,
|
|
|
|
+ 'message_show_type' => 'post_comment',
|
|
|
|
+ 'param' => [
|
|
|
|
+ 'uid' => $userInfo['uid'],
|
|
|
|
+ 'username' => $userInfo['username'],
|
|
|
|
+ 'post_id' => $post->id,
|
|
|
|
+ 'content' => subtext($request['content'], 20),
|
|
|
|
+ ]
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try{
|
|
|
|
+ $this->postComment->create($data);
|
|
|
|
+ $post->data->comment_count += 1;
|
|
|
|
+ $post->data->save();
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
|
|
+ return jsonSuccess();
|
|
|
|
+
|
|
|
|
+ }catch (QueryException $exception){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ Log::debug('评论内容失败:'.$exception->getMessage());
|
|
|
|
+ return jsonError('评论内容失败,请重试');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 内容列表
|
|
* 内容列表
|
|
*/
|
|
*/
|