feat: 新增产品回收站相关接口
This commit is contained in:
@@ -83,7 +83,6 @@ class ProductAttr
|
|||||||
]);
|
]);
|
||||||
$attr = array_merge($post, ['language_id' => request()->lang_id]);
|
$attr = array_merge($post, ['language_id' => request()->lang_id]);
|
||||||
|
|
||||||
// $[*].prop_type
|
|
||||||
// $[*].prop_name
|
// $[*].prop_name
|
||||||
// $[*].prop_value
|
// $[*].prop_value
|
||||||
$props = json_decode(request()->post('props/s', ''), true);
|
$props = json_decode(request()->post('props/s', ''), true);
|
||||||
|
|||||||
101
app/admin/controller/v1/ProductTrash.php
Normal file
101
app/admin/controller/v1/ProductTrash.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
declare (strict_types = 1);
|
||||||
|
|
||||||
|
namespace app\admin\controller\v1;
|
||||||
|
|
||||||
|
use app\admin\model\v1\ProductModel;
|
||||||
|
use app\admin\validate\v1\ProductValidate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品回收站管理控制器
|
||||||
|
*/
|
||||||
|
class ProductTrash
|
||||||
|
{
|
||||||
|
// 产品回回站分页列表
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$param = request()->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('操作成功');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -183,6 +183,19 @@ Route::group('v1', function () {
|
|||||||
// 分类删除
|
// 分类删除
|
||||||
Route::delete('delete/:id', 'ProductCategory/delete');
|
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.');
|
})->prefix('v1.');
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,14 @@ class ProductValidate extends Validate
|
|||||||
return $this->only(['categroy_id', 'is_show', 'created_at']);
|
return $this->only(['categroy_id', 'is_show', 'created_at']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回收站分页验证场景
|
||||||
|
*/
|
||||||
|
public function sceneTrash()
|
||||||
|
{
|
||||||
|
return $this->only(['categroy_id']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据更新验证场景
|
* 数据更新验证场景
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user