feat: 产品分类新增设置排序值及是否显示接口

This commit is contained in:
2025-02-12 09:36:59 +08:00
parent bd66d8d61f
commit 3d53547f16
2 changed files with 46 additions and 0 deletions

View File

@@ -170,6 +170,46 @@ class ProductCategory
}
}
/**
* 设置排序值
*/
public function sort()
{
$id = request()->param('id');
$sort = request()->post('sort');
$category = ProductCategoryModel::bypk($id)->find();
if (empty($category)) {
return error('请确认操作对对象是否存在!');
}
if ($sort != $category->sort) {
$category->sort = $sort;
if (!$category->save()) {
return error('操作失败!');
}
}
return success('操作成功!');
}
/**
* 设置是否显示
*/
public function show()
{
$id = request()->param('id');
$category = ProductCategoryModel::bypk($id)->find();
if (empty($category)) {
return error('请确认操作对对象是否存在!');
}
$category->is_show = (int)!$category->is_show;
if (!$category->save()) {
return error('操作失败!');
}
return success('操作成功!');
}
/**
* 删除商品分类
*/

View File

@@ -126,6 +126,12 @@ Route::group('v1', function () {
// 分类更新
Route::put('update/:id', 'ProductCategory/update');
// 设置排序值
Route::post('sort/:id', 'ProductCategory/sort');
// 设置是否显示
Route::get('show/:id', 'ProductCategory/show');
// 分类删除
Route::delete('delete/:id', 'ProductCategory/delete');
});