4
0
Fork 0

import goods goods_category

master
panliang 2022-10-08 09:43:16 +08:00
parent bbade99e74
commit c26a77ef5d
2 changed files with 12 additions and 5 deletions

View File

@ -59,7 +59,14 @@ class ImportForm extends Form
if (!$category) {
throw new \Exception('分类必填');
}
$category = GoodsCategory::firstOrCreate(['name' => $category]);
// 分类: 电脑-电脑整机-笔记本
$exts = explode('-', $category);
$category = null;
$level = 1;
foreach($exts as $item) {
$category = GoodsCategory::firstOrCreate(['name' => $item, 'parent_id' => $category ? $category->id : 0, 'level' => $level]);
$level++;
}
if ($brand) {
$brand = GoodsBrand::firstOrCreate(['name' => $brand]);
}
@ -115,7 +122,7 @@ class ImportForm extends Form
return $attr;
}
protected function parseFile($path = null)
protected function parseFile($path = null, $disk = 'public')
{
if (!$path) {
return null;
@ -123,9 +130,9 @@ class ImportForm extends Form
if (Str::startsWith($path, ['http://', 'https://'])) {
return $path;
}
$disk = Storage::disk('public');
$storage = Storage::disk($disk);
return $disk->url($path);
return $storage->url($path);
}
protected function parseFiles($paths = null)

View File

@ -104,7 +104,7 @@ class GoodsController extends AdminController
$grid->selector(function (Selector $selector) {
$brands = GoodsBrand::get();
$types = GoodsType::get();
$categories = GoodsCategory::where('level', 3)->where('path', 'like', '-1-%')->get();
$categories = GoodsCategory::where('level', 3)->get();
$prices = ['0-999', '1000-1999', '2000-4999', '5000+'];
$selector->selectOne('category_id', __('dcat-admin-goods::goods.fields.category_id'), $categories->pluck('name', 'id'));
$selector->selectOne('brand_id', __('dcat-admin-goods::goods.fields.brand_id'), $brands->pluck('name', 'id'));