feat: 添加附件(下载管理)回收站分页/恢复/删除接口
This commit is contained in:
@@ -83,11 +83,12 @@ class Attachment
|
|||||||
{
|
{
|
||||||
$post = request()->post([
|
$post = request()->post([
|
||||||
'name',
|
'name',
|
||||||
|
'desc',
|
||||||
'category_id',
|
'category_id',
|
||||||
'sort',
|
'sort',
|
||||||
'recommend',
|
'recommend',
|
||||||
'image',
|
'image',
|
||||||
'aplicable_to',
|
'applicable_to',
|
||||||
'support_platform',
|
'support_platform',
|
||||||
'attach',
|
'attach',
|
||||||
'seo_title',
|
'seo_title',
|
||||||
@@ -97,6 +98,7 @@ class Attachment
|
|||||||
$data = array_merge($post, ['language_id' => request()->lang_id]);
|
$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)) {
|
if (!$validate->scene('create')->check($data)) {
|
||||||
return error($validate->getError());
|
return error($validate->getError());
|
||||||
}
|
}
|
||||||
@@ -116,11 +118,12 @@ class Attachment
|
|||||||
$id = request()->param('id');
|
$id = request()->param('id');
|
||||||
$put = request()->put([
|
$put = request()->put([
|
||||||
'name',
|
'name',
|
||||||
|
'desc',
|
||||||
'category_id',
|
'category_id',
|
||||||
'sort',
|
'sort',
|
||||||
'recommend',
|
'recommend',
|
||||||
'image',
|
'image',
|
||||||
'aplicable_to',
|
'applicable_to',
|
||||||
'support_platform',
|
'support_platform',
|
||||||
'attach',
|
'attach',
|
||||||
'seo_title',
|
'seo_title',
|
||||||
@@ -129,6 +132,7 @@ class Attachment
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$validate = new AttachmentValidate;
|
$validate = new AttachmentValidate;
|
||||||
|
$put['attach'] = json_decode($put['attach'], true);
|
||||||
if (!$validate->scene('update')->check(array_merge($put, ['id' => $id]))) {
|
if (!$validate->scene('update')->check(array_merge($put, ['id' => $id]))) {
|
||||||
return error($validate->getError());
|
return error($validate->getError());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class AttachmentCategory
|
|||||||
$data = array_merge($post, ['language_id' => request()->lang_id]);
|
$data = array_merge($post, ['language_id' => request()->lang_id]);
|
||||||
|
|
||||||
$validate = new AttachmentCategoryValidate;
|
$validate = new AttachmentCategoryValidate;
|
||||||
if (!$validate->scene('create')->check($post)) {
|
if (!$validate->scene('create')->check($data)) {
|
||||||
return error($validate->getError());
|
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("操作成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,4 +24,10 @@ class AttachmentCategoryModel extends AttachmentCategoryBaseModel
|
|||||||
{
|
{
|
||||||
return $this->hasMany(AttachmentModel::class, 'category_id', 'id');
|
return $this->hasMany(AttachmentModel::class, 'category_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 语言查询
|
||||||
|
public function scopeLanguage($query, $value)
|
||||||
|
{
|
||||||
|
$query->where('language_id', '=', $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,6 +273,7 @@ Route::group('v1', function () {
|
|||||||
// 产品回收站删除
|
// 产品回收站删除
|
||||||
Route::delete('delete/:id', 'ProductTrash/delete');
|
Route::delete('delete/:id', 'ProductTrash/delete');
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// 附件(下载管理)
|
// 附件(下载管理)
|
||||||
Route::group('attachment', function () {
|
Route::group('attachment', function () {
|
||||||
@@ -289,7 +290,7 @@ Route::group('v1', function () {
|
|||||||
Route::put('update/:id', 'Attachment/update');
|
Route::put('update/:id', 'Attachment/update');
|
||||||
|
|
||||||
// 附件(下载管理)设置排序值
|
// 附件(下载管理)设置排序值
|
||||||
Route::get('sort/:id', 'Attachment/sort');
|
Route::post('sort/:id', 'Attachment/sort');
|
||||||
|
|
||||||
// 附件(下载管理)删除
|
// 附件(下载管理)删除
|
||||||
Route::delete('delete/:id', 'Attachment/delete');
|
Route::delete('delete/:id', 'Attachment/delete');
|
||||||
@@ -314,6 +315,17 @@ Route::group('v1', function () {
|
|||||||
// 附件(下载管理)分类删除
|
// 附件(下载管理)分类删除
|
||||||
Route::delete('delete/:id', 'AttachmentCategory/delete');
|
Route::delete('delete/:id', 'AttachmentCategory/delete');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 附件(下载管理)回收站
|
||||||
|
Route::group('trash', function () {
|
||||||
|
// 附件(下载管理)回收站列表
|
||||||
|
Route::get('index', 'AttachmentTrash/index');
|
||||||
|
|
||||||
|
// 附件(下载管理)回收站还原
|
||||||
|
Route::get('restore/:id', 'AttachmentTrash/restore');
|
||||||
|
|
||||||
|
// 附件(下载管理)回收站删除
|
||||||
|
Route::delete('delete/:id', 'AttachmentTrash/delete');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})->prefix('v1.');
|
})->prefix('v1.');
|
||||||
|
|||||||
@@ -3,13 +3,11 @@ declare (strict_types = 1);
|
|||||||
|
|
||||||
namespace app\common\model;
|
namespace app\common\model;
|
||||||
|
|
||||||
use think\Model;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 附件(下载管理)模型
|
* 附件(下载管理)模型
|
||||||
* @mixin \think\Model
|
* @mixin \think\Model
|
||||||
*/
|
*/
|
||||||
class AttachmentBaseModel extends Model
|
class AttachmentBaseModel extends BaseModel
|
||||||
{
|
{
|
||||||
// 表名
|
// 表名
|
||||||
protected $name = 'attachment';
|
protected $name = 'attachment';
|
||||||
|
|||||||
@@ -3,13 +3,11 @@ declare (strict_types = 1);
|
|||||||
|
|
||||||
namespace app\common\model;
|
namespace app\common\model;
|
||||||
|
|
||||||
use think\Model;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 附件(下载管理)分类模型
|
* 附件(下载管理)分类模型
|
||||||
* @mixin \think\Model
|
* @mixin \think\Model
|
||||||
*/
|
*/
|
||||||
class AttachmentCategoryBaseModel extends Model
|
class AttachmentCategoryBaseModel extends BaseModel
|
||||||
{
|
{
|
||||||
// 表名
|
// 表名
|
||||||
protected $name = 'attachment_category';
|
protected $name = 'attachment_category';
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Phinx\Db\Adapter\MysqlAdapter;
|
||||||
use think\migration\Migrator;
|
use think\migration\Migrator;
|
||||||
|
|
||||||
class CreateAttachment extends Migrator
|
class CreateAttachment extends Migrator
|
||||||
@@ -38,6 +39,7 @@ class CreateAttachment extends Migrator
|
|||||||
->addColumn('attach', 'json', ['null' => false, 'comment' => '附件地址: $[*].file_path为附件地址, $[*].file_ext为文件格式, $[*].btn_name为下载按钮名称'])
|
->addColumn('attach', 'json', ['null' => false, 'comment' => '附件地址: $[*].file_path为附件地址, $[*].file_ext为文件格式, $[*].btn_name为下载按钮名称'])
|
||||||
->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序'])
|
->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序'])
|
||||||
->addColumn('recommend', 'boolean', ['null' => false, 'default' => 0, 'comment' => '是否推荐:1是,0否'])
|
->addColumn('recommend', 'boolean', ['null' => false, 'default' => 0, 'comment' => '是否推荐:1是,0否'])
|
||||||
|
->addColumn('status', MysqlAdapter::PHINX_TYPE_TINY_INTEGER, ['null' => false, 'default' => 1, 'comment' => '状态:1为启用,-1为禁用'])
|
||||||
->addColumn('seo_title', 'string', ['limit' => 255, 'default' => null, 'comment' => 'SEO标题'])
|
->addColumn('seo_title', 'string', ['limit' => 255, 'default' => null, 'comment' => 'SEO标题'])
|
||||||
->addColumn('seo_keywords', 'string', ['limit' => 255, 'default' => null, 'comment' => 'SEO关键字'])
|
->addColumn('seo_keywords', 'string', ['limit' => 255, 'default' => null, 'comment' => 'SEO关键字'])
|
||||||
->addColumn('seo_desc', 'string', ['limit' => 255, 'default' => null, 'comment' => 'SEO描述'])
|
->addColumn('seo_desc', 'string', ['limit' => 255, 'default' => null, 'comment' => 'SEO描述'])
|
||||||
|
|||||||
Reference in New Issue
Block a user