取消点赞,取消收藏
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\common\service;
|
||||
|
||||
use app\common\model\MessageNotice;
|
||||
use app\common\model\Post;
|
||||
use app\common\model\PostLike;
|
||||
use app\common\validate\PostFavoriteValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\PostFavorite;
|
||||
@@ -107,4 +108,28 @@ class PostFavoriteService
|
||||
$post['favorite'] = $post['favorite']+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 = PostFavorite::where($where)->delete();
|
||||
|
||||
$post = PostFavorite::where(['id' => $param['post_id']])->first();
|
||||
$post['favorite'] = $post['favorite']-1;
|
||||
$post->save();
|
||||
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user