feat: 添加附件(下载管理)回收站分页/恢复/删除接口
This commit is contained in:
@@ -83,11 +83,12 @@ class Attachment
|
||||
{
|
||||
$post = request()->post([
|
||||
'name',
|
||||
'desc',
|
||||
'category_id',
|
||||
'sort',
|
||||
'recommend',
|
||||
'image',
|
||||
'aplicable_to',
|
||||
'applicable_to',
|
||||
'support_platform',
|
||||
'attach',
|
||||
'seo_title',
|
||||
@@ -96,7 +97,8 @@ class Attachment
|
||||
]);
|
||||
$data = array_merge($post, ['language_id' => request()->lang_id]);
|
||||
|
||||
$validate = new AttachmentValidate;
|
||||
$validate = new AttachmentValidate;
|
||||
$data['attach'] = json_decode($data['attach'], true);
|
||||
if (!$validate->scene('create')->check($data)) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
@@ -116,11 +118,12 @@ class Attachment
|
||||
$id = request()->param('id');
|
||||
$put = request()->put([
|
||||
'name',
|
||||
'desc',
|
||||
'category_id',
|
||||
'sort',
|
||||
'recommend',
|
||||
'image',
|
||||
'aplicable_to',
|
||||
'applicable_to',
|
||||
'support_platform',
|
||||
'attach',
|
||||
'seo_title',
|
||||
@@ -128,7 +131,8 @@ class Attachment
|
||||
'seo_desc'
|
||||
]);
|
||||
|
||||
$validate = new AttachmentValidate;
|
||||
$validate = new AttachmentValidate;
|
||||
$put['attach'] = json_decode($put['attach'], true);
|
||||
if (!$validate->scene('update')->check(array_merge($put, ['id' => $id]))) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class AttachmentCategory
|
||||
$data = array_merge($post, ['language_id' => request()->lang_id]);
|
||||
|
||||
$validate = new AttachmentCategoryValidate;
|
||||
if (!$validate->scene('create')->check($post)) {
|
||||
if (!$validate->scene('create')->check($data)) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
|
||||
|
||||
90
app/admin/controller/v1/AttachmentTrash.php
Normal file
90
app/admin/controller/v1/AttachmentTrash.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\controller\v1;
|
||||
|
||||
use app\admin\model\v1\AttachmentModel;
|
||||
|
||||
/**
|
||||
* 附件(下载管理)回收站控制器
|
||||
*/
|
||||
class AttachmentTrash
|
||||
{
|
||||
/**
|
||||
* 分页数据
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$params = request()->param([
|
||||
'name',
|
||||
'category_id',
|
||||
'page/d' => 1,
|
||||
'size/d' => 10
|
||||
]);
|
||||
|
||||
$attachments = AttachmentModel::field([
|
||||
'id',
|
||||
'image',
|
||||
'name',
|
||||
'status',
|
||||
'category_id',
|
||||
'sort',
|
||||
'recommend',
|
||||
'created_at'
|
||||
])
|
||||
->with(['category' => function ($query) {
|
||||
$query->field(['id', 'name' => 'category_name']);
|
||||
}])
|
||||
->withSearch(['name'], [
|
||||
'name' => $params['name']??null
|
||||
])
|
||||
->language(request()->lang_id)
|
||||
->categoryId($params['category_id']??null)
|
||||
->order(['sort' => 'asc', 'id' => 'desc'])
|
||||
->onlyTrashed()
|
||||
->paginate([
|
||||
'list_rows' => $params['size'],
|
||||
'page' => $params['page']
|
||||
])
|
||||
->bindAttr('category', ['category_name'])
|
||||
->hidden(['category_id', 'category']);
|
||||
|
||||
return success('获取成功', $attachments);
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复操作
|
||||
*/
|
||||
public function restore()
|
||||
{
|
||||
$id = request()->param('id');
|
||||
|
||||
$attachment = AttachmentModel::onlyTrashed()->bypk($id)->find();
|
||||
if (empty($attachment)) {
|
||||
return error("请确认操作对象是否正确");
|
||||
}
|
||||
|
||||
if (!$attachment->restore()) {
|
||||
return error("操作失败");
|
||||
}
|
||||
return success("操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除操作
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$id = request()->param('id');
|
||||
|
||||
$attachment = AttachmentModel::onlyTrashed()->bypk($id)->find();
|
||||
if (empty($attachment)) {
|
||||
return error("请确认操作对象是否正确");
|
||||
}
|
||||
|
||||
if (!$attachment->force()->delete()) {
|
||||
return error("操作失败");
|
||||
}
|
||||
return success("操作成功");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user