feat: 新增产品分类用于下拉框场景列表树接口

This commit is contained in:
2025-03-28 16:57:23 +08:00
parent 1d22d80add
commit e46f14006c
3 changed files with 19 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ class ProductCategory
public function index()
{
$params = request()->param([
'is_show',
'keywords' => '',
]);
@@ -30,8 +31,13 @@ class ProductCategory
])
->language(request()->lang_id)
->withSearch(['name_nullable'], [
'name_nullable' => $params['keywords']
'name_nullable' => $params['keywords']??null
])
->where(function($query) use($params) {
if (!empty($params['is_show'])) {
$query->where('is_show', '=', $params['is_show']);
}
})
->select();
if ($ret->isEmpty()) {
return success('获取成功');

View File

@@ -29,9 +29,17 @@ class ProductCategoryModel extends ProductCategoryBaseModel
$query->where('language_id', '=', $value);
}
// 根据是否显示查询
public function scopeIsShow($query, bool $value)
/**
* 根据是否显示查询
* @param $query
* @param \Closure:bool|bool $value
*/
public function scopeIsShow($query, \Closure|bool $value)
{
if (is_callable($value)) {
$query->where('is_show', '=', $value());
return;
}
$query->where('is_show', '=', (int)$value);
}

View File

@@ -201,7 +201,7 @@ Route::group('v1', function () {
Route::group('banner', function() {
// 横幅(分类)列表
Route::get('list', 'Banner/list');
// 横幅(分类)分页
Route::get('index', 'Banner/index');
@@ -286,6 +286,7 @@ Route::group('v1', function () {
});
// 产品分类
Route::get('categorys', 'ProductCategory/index')->append(['is_show' => '1']);
Route::group('category', function () {
// tco分类树
Route::get('tco/tree', 'ProductTcoCategory/tree');