feat: 新增文章回收站分页列表、恢复、删除接口

This commit is contained in:
2025-01-18 10:48:34 +08:00
parent 554ced5380
commit f0fa542ab4
2 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
<?php
declare (strict_types = 1);
namespace app\admin\controller\v1;
use app\admin\model\v1\ArticleModel;
class ArticleTrash
{
// 文章回收站分页列表
public function index()
{
$param = request()->get([
'title',
'category_id',
'page/a' => 1,
'size/a' => 20
]);
$data = ArticleModel::field([
'id',
'category_id',
'title',
'image',
'sort',
'recommend',
'release_time',
'enabled',
])
->with('category')
->language(request()->lang_id)
->categoryNullable($param['category_id']??null)
->withSearch(['title'], ['title' => $param['title']??null])
->onlyTrashed()
->order(['sort' => 'desc', 'id' => 'desc'])
->paginate([
'page' => $param['page'],
'list_rows' => $param['size']
])
->hidden(['category_id', 'category'])
->bindAttr('category', ['category_name' => 'name']);
return success('获取成功', $data);
}
// 恢复
public function restore()
{
$id = request()->param('id');
if (empty($id)) {
return error('参数错误');
}
$article = ArticleModel::onlyTrashed()->id($id)->find();
if (is_null($article)) {
return error('请确认操作对象');
}
if (!$article->restore()) {
return error('操作失败');
}
return success('操作成功');
}
// 删除
public function delete()
{
$id = request()->param('id');
if (empty($id)) {
return error('参数错误');
}
$article = ArticleModel::onlyTrashed()->id($id)->find();
if (is_null($article)) {
return error('请确认操作对象');
}
if (!$article->force()->delete()) {
return error('操作失败');
}
return success('操作成功');
}
}