导入商品
parent
d38169f74b
commit
6e3dc4ad4b
|
|
@ -30,8 +30,13 @@ class Product
|
||||||
$category = ProductCategory::where('name', $cells[2])->firstOrFail();
|
$category = ProductCategory::where('name', $cells[2])->firstOrFail();
|
||||||
$goods['category_id'] = $category->id;
|
$goods['category_id'] = $category->id;
|
||||||
|
|
||||||
|
// 图片组
|
||||||
if ($path = $cells[3]) {
|
if ($path = $cells[3]) {
|
||||||
$images = $this->getImageUrlFromPath($path);
|
if (Str::startsWith($path, ['http://', 'https://'])) {
|
||||||
|
$images = explode(',', $path);
|
||||||
|
} else {
|
||||||
|
$images = $this->getImageUrlFromPath($path);
|
||||||
|
}
|
||||||
if (count($images) > 0) {
|
if (count($images) > 0) {
|
||||||
$goods['cover'] = $images[0];
|
$goods['cover'] = $images[0];
|
||||||
$goods['images'] = $images;
|
$goods['images'] = $images;
|
||||||
|
|
@ -103,7 +108,7 @@ class Product
|
||||||
protected function getImageUrlFromPath($dir)
|
protected function getImageUrlFromPath($dir)
|
||||||
{
|
{
|
||||||
$disk = Storage::disk('public');
|
$disk = Storage::disk('public');
|
||||||
$files = $disk->files('goods/' . $dir);
|
$files = $disk->files($dir);
|
||||||
$images = [];
|
$images = [];
|
||||||
|
|
||||||
foreach($files as $filename) {
|
foreach($files as $filename) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue