删除评论
This commit is contained in:
@@ -144,11 +144,12 @@ class PostCommentService
|
|||||||
$where['id'] = $param['id'];
|
$where['id'] = $param['id'];
|
||||||
$comment = PostComment::where($where)->first();
|
$comment = PostComment::where($where)->first();
|
||||||
|
|
||||||
if($scene == 'mini' && $comment['user_id'] != $request->user->uid){
|
$post = Post::where(['id' => $comment['post_id']])->first();
|
||||||
|
|
||||||
|
if($scene == 'mini' && ($comment['user_id'] != $request->user->uid || $post['user_id'] == $request->user->uid)){
|
||||||
throw new \Exception("只能删除本人评论");
|
throw new \Exception("只能删除本人评论");
|
||||||
}
|
}
|
||||||
|
|
||||||
$post = Post::where(['id' => $comment['post_id']])->first();
|
|
||||||
$post['comment'] = $post['comment']-1;
|
$post['comment'] = $post['comment']-1;
|
||||||
$post->save();
|
$post->save();
|
||||||
|
|
||||||
@@ -156,4 +157,26 @@ class PostCommentService
|
|||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除前置处理
|
||||||
|
*/
|
||||||
|
public function beforeServiceDestroy($data, Request $request)
|
||||||
|
{
|
||||||
|
$param = $request->all();
|
||||||
|
|
||||||
|
if (empty($param['id'])) {
|
||||||
|
throw new \Exception("参数错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
$where = [];
|
||||||
|
$where['id'] = $param['id'];
|
||||||
|
$comment = PostComment::where($where)->first();
|
||||||
|
|
||||||
|
$post = Post::where(['id' => $comment['post_id']])->first();
|
||||||
|
$post['comment'] = $post['comment']-1;
|
||||||
|
$post->save();
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user