取消点赞,取消收藏

This commit is contained in:
2025-11-26 15:46:51 +08:00
parent 045edc9647
commit 4d11e435be
6 changed files with 82 additions and 3 deletions
+23
View File
@@ -109,4 +109,27 @@ class PostLikeService
$post['like'] = $post['like']+1;
$post->save();
}
/**
* 添加后置处理
*/
public function servicedelete(Request $request)
{
$param = $request->all();
if (empty($param['post_id']) && empty($param['user_id'])) {
throw new \Exception("参数错误");
}
$where = [];
$where['post_id'] = $param['post_id'];
$where['user_id'] = $param['user_id'];
$count = PostLike::where($where)->delete();
$post = Post::where(['id' => $param['post_id']])->first();
$post['like'] = $post['like']-1;
$post->save();
return $count;
}
}