1、帖子搜索
2、收藏搜索 3、帖子、评论删除
This commit is contained in:
@@ -129,12 +129,10 @@ class PostCommentService
|
||||
$post->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 添加后置处理
|
||||
*/
|
||||
public function serviceDelete(Request $request)
|
||||
public function serviceDelete(Request $request,$scene = 'admin')
|
||||
{
|
||||
$param = $request->all();
|
||||
|
||||
@@ -146,6 +144,10 @@ class PostCommentService
|
||||
$where['id'] = $param['id'];
|
||||
$comment = PostComment::where($where)->first();
|
||||
|
||||
if($scene == 'mini' && $comment['user_id'] != $request->user->uid){
|
||||
throw new \Exception("只能删除本人评论");
|
||||
}
|
||||
|
||||
$post = Post::where(['id' => $comment['post_id']])->first();
|
||||
$post['comment'] = $post['comment']-1;
|
||||
$post->save();
|
||||
|
||||
@@ -46,6 +46,25 @@ class PostFavoriteService
|
||||
return $this->postProcess(ucfirst($scene), $result);
|
||||
}
|
||||
|
||||
public function complexQueryIndex(Request $request)
|
||||
{
|
||||
$param = $request->all();
|
||||
$limit = (int)$request->get('size', 15);
|
||||
$page = (int)$request->get('current', 1);
|
||||
$query = PostFavorite::with(['post'])
|
||||
->where('user_id',$request->user->uid)
|
||||
->whereHas('post', function ($q) use ($param) {
|
||||
// 固定过滤 status = 1
|
||||
$q->where('status', 1);
|
||||
|
||||
// 关键字过滤(如果存在)
|
||||
if (!empty($param['keyword'])) {
|
||||
$q->where('content', 'like', "%{$param['keyword']}%");
|
||||
}
|
||||
});
|
||||
return $query->paginate($limit, ['*'], 'page', $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造 CrudUtil 查询配置
|
||||
*/
|
||||
|
||||
@@ -67,9 +67,19 @@ class PostService
|
||||
'between', [$from, $to]
|
||||
];
|
||||
}
|
||||
if (isset($p['keyword']) && $p['keyword']) {
|
||||
$config['where']['content'] = ['like', '%'.$p['keyword'].'%'];
|
||||
}
|
||||
$config['where']['status'] = 1;
|
||||
$config['order']['sort'] = 'desc';
|
||||
$config['order']['id'] = 'desc';
|
||||
|
||||
if (isset($p['order']) && $p['order'] == 'favorite') {
|
||||
$config['order']['favorite'] = 'desc';
|
||||
} elseif (isset($p['order']) && $p['order'] == 'browse') {
|
||||
$config['order']['browse'] = 'desc';
|
||||
} else {
|
||||
$config['order']['id'] = 'desc';
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
@@ -154,6 +164,20 @@ class PostService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function beforeServiceShow($data, Request $request)
|
||||
{
|
||||
$post = Post::find($data['id']);
|
||||
if(!$post){
|
||||
$post->browse = $post->browse+1;
|
||||
$post->save();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function getMediaTypeByUrl(string $url): int
|
||||
{
|
||||
// 提取后缀
|
||||
@@ -172,5 +196,27 @@ class PostService
|
||||
}
|
||||
|
||||
return 0; // 未知类型
|
||||
} /**
|
||||
* 添加后置处理
|
||||
*/
|
||||
public function serviceDelete(Request $request,$scene = 'admin')
|
||||
{
|
||||
$param = $request->all();
|
||||
|
||||
if (empty($param['id'])) {
|
||||
throw new \Exception("参数错误");
|
||||
}
|
||||
|
||||
$where = [];
|
||||
$where['id'] = $param['id'];
|
||||
$post = Post::where($where)->first();
|
||||
|
||||
if($scene == 'mini' && $post['user_id'] != $request->user->uid){
|
||||
throw new \Exception("只能删除本人发布内容");
|
||||
}
|
||||
|
||||
$count = $post->delete();
|
||||
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user