feat: 产品分类新增设置排序值及是否显示接口
This commit is contained in:
@@ -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('操作成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品分类
|
||||
*/
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user