diff --git a/app/common/service/PostCommentService.php b/app/common/service/PostCommentService.php index dbf4fb8..9fcf9d1 100644 --- a/app/common/service/PostCommentService.php +++ b/app/common/service/PostCommentService.php @@ -144,11 +144,12 @@ class PostCommentService $where['id'] = $param['id']; $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("只能删除本人评论"); } - $post = Post::where(['id' => $comment['post_id']])->first(); $post['comment'] = $post['comment']-1; $post->save(); @@ -156,4 +157,26 @@ class PostCommentService 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; + } } \ No newline at end of file