|
|
@ -31,6 +31,11 @@ class ProductController extends AdminController |
|
|
return Grid::make(new Product(['category:id,name']), function (Grid $grid) { |
|
|
return Grid::make(new Product(['category:id,name']), function (Grid $grid) { |
|
|
$grid->model()->where('supplier_id', Admin::user()->id); |
|
|
$grid->model()->where('supplier_id', Admin::user()->id); |
|
|
|
|
|
|
|
|
|
|
|
$category_id = request()->input('cid'); |
|
|
|
|
|
if ($category_id) { |
|
|
|
|
|
$grid->model()->whereIn('category_id', [$category_id, ...$this->get_category_child_ids($category_id)]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$grid->column('id')->sortable(); |
|
|
$grid->column('id')->sortable(); |
|
|
$grid->column('type')->using(admin_trans('product.options.publish_type')); |
|
|
$grid->column('type')->using(admin_trans('product.options.publish_type')); |
|
|
$grid->column('category.name', '产品分类'); |
|
|
$grid->column('category.name', '产品分类'); |
|
|
@ -63,11 +68,33 @@ class ProductController extends AdminController |
|
|
$filter->equal('id')->width(2); |
|
|
$filter->equal('id')->width(2); |
|
|
$filter->like('title')->width(3); |
|
|
$filter->like('title')->width(3); |
|
|
$filter->equal('status')->select(ProductStatus::array())->width(2); |
|
|
$filter->equal('status')->select(ProductStatus::array())->width(2); |
|
|
|
|
|
|
|
|
|
|
|
$options = array_slice(Category::selectOptions(fn($query) => $query->where('agent_id', 0)), 1, null, true); |
|
|
|
|
|
$filter->equal('cid', '产品分类')->ignore()->select($options)->width(3); |
|
|
$filter->equal('type')->select(admin_trans('product.options.publish_type'))->width(2); |
|
|
$filter->equal('type')->select(admin_trans('product.options.publish_type'))->width(2); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//递归获取指定分类下的所有子分类
|
|
|
|
|
|
private function get_category_child_ids($category_id): array |
|
|
|
|
|
{ |
|
|
|
|
|
static $category = null; |
|
|
|
|
|
if ($category === null) { |
|
|
|
|
|
$category = Category::where('agent_id', 0)->get()->toArray(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$child = []; |
|
|
|
|
|
foreach ($category as $cat) { |
|
|
|
|
|
if ($cat['pid'] == $category_id) { |
|
|
|
|
|
$child[] = $cat['id']; |
|
|
|
|
|
$child = array_merge($child, $this->get_category_child_ids($cat['id'])); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $child; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Make a show builder. |
|
|
* Make a show builder. |
|
|
* |
|
|
* |
|
|
|