1、帖子搜索
2、收藏搜索 3、帖子、评论删除
This commit is contained in:
@@ -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