From 1ffbbe8dc9e44b342e5d039eb6b5f2f1c9df4583 Mon Sep 17 00:00:00 2001 From: jsasg Date: Mon, 17 Feb 2025 15:26:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E5=9B=9E=E6=94=B6=E7=AB=99=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/v1/ProductAttr.php | 1 - app/admin/controller/v1/ProductTrash.php | 101 ++++++++++++++++++++++ app/admin/route/v1.php | 13 +++ app/admin/validate/v1/ProductValidate.php | 8 ++ 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 app/admin/controller/v1/ProductTrash.php diff --git a/app/admin/controller/v1/ProductAttr.php b/app/admin/controller/v1/ProductAttr.php index f51b9e3f..b1cdae7a 100644 --- a/app/admin/controller/v1/ProductAttr.php +++ b/app/admin/controller/v1/ProductAttr.php @@ -83,7 +83,6 @@ class ProductAttr ]); $attr = array_merge($post, ['language_id' => request()->lang_id]); - // $[*].prop_type // $[*].prop_name // $[*].prop_value $props = json_decode(request()->post('props/s', ''), true); diff --git a/app/admin/controller/v1/ProductTrash.php b/app/admin/controller/v1/ProductTrash.php new file mode 100644 index 00000000..85cab381 --- /dev/null +++ b/app/admin/controller/v1/ProductTrash.php @@ -0,0 +1,101 @@ +param([ + 'name', + 'spu', + 'category_id', + 'page/d' => 1, + 'size/d' => 10 + ]); + + $validate = new ProductValidate(); + if (!$validate->scene('trash')->check($param)) { + return error($validate->getError()); + } + + $products = ProductModel::field([ + 'id', + 'name', + 'cover_image', + 'spu', + 'category_id', + 'sort', + 'is_new', + 'is_sale', + 'stock_qty', + 'status', + 'created_at', + 'deleted_at' + ]) + ->with(['category']) + ->language(request()->lang_id) + ->withSearch(['name_nullable', 'spu_nullable'], [ + 'name_nullable' => $param['name']??null, + 'spu_nullable' => $param['spu']??null, + ]) + ->categoryNullable($param['category_id']??null) + ->onlyTrashed() + ->order(['sort' => 'asc', 'id' => 'desc']) + ->paginate([ + 'list_rows' => $param['size'], + 'page' => $param['page'], + ]) + ->bindAttr('category', ['category_name' => 'name']) + ->hidden(['category_id', 'category']); + + return success('获取成功', $products); + } + + // 恢复 + public function restore() + { + $id = request()->param('id'); + if (!$id) { + return error('参数错误'); + } + + $product = ProductModel::onlyTrashed()->bypk($id)->find(); + if (is_null($product)) { + return error('请确认操作对象'); + } + + if (!$product->restore()) { + return error('操作失败'); + } + + return success('操作成功'); + } + + // 删除 + public function delete() + { + $id = request()->param('id'); + if (!$id) { + return error('参数错误'); + } + + $product = ProductModel::onlyTrashed()->bypk($id)->find(); + if (is_null($product)) { + return error('请确认操作对象'); + } + if (!$product->force()->delete()) { + return error('操作失败'); + } + + return success('操作成功'); + } +} diff --git a/app/admin/route/v1.php b/app/admin/route/v1.php index 823d3b98..742469d1 100644 --- a/app/admin/route/v1.php +++ b/app/admin/route/v1.php @@ -183,6 +183,19 @@ Route::group('v1', function () { // 分类删除 Route::delete('delete/:id', 'ProductCategory/delete'); }); + + // 产品回收站 + Route::group('trash', function () { + // 产品回收站列表 + Route::get('index', 'ProductTrash/index'); + + // 产品回收站还原 + Route::get('restore/:id', 'ProductTrash/restore'); + + // 产品回收站删除 + Route::delete('delete/:id', 'ProductTrash/delete'); + }); + }); })->prefix('v1.'); diff --git a/app/admin/validate/v1/ProductValidate.php b/app/admin/validate/v1/ProductValidate.php index dce02abe..b45546fd 100644 --- a/app/admin/validate/v1/ProductValidate.php +++ b/app/admin/validate/v1/ProductValidate.php @@ -91,6 +91,14 @@ class ProductValidate extends Validate return $this->only(['categroy_id', 'is_show', 'created_at']); } + /** + * 回收站分页验证场景 + */ + public function sceneTrash() + { + return $this->only(['categroy_id']); + } + /** * 数据更新验证场景 */