diff --git a/app/Admin/Imports/StoreProduct.php b/app/Admin/Imports/StoreProduct.php index 8c443823..09902257 100644 --- a/app/Admin/Imports/StoreProduct.php +++ b/app/Admin/Imports/StoreProduct.php @@ -49,14 +49,20 @@ class StoreProduct $stock = $cells[++$index];// 库存 - $store = Store::where(['title' => $storeName])->firstOrFail(); + $store = Store::where(['title' => $storeName])->first(); + if (!$store) { + throw new ImportException('门店 '.$storeName.' 不存在'); + } $goods = [ 'name' => $goodsName, 'subtitle' => $goodsTitle, 'shipping_template_id' => 1, ]; - $category = ProductCategory::where('name', $categoryName)->firstOrFail(); + $category = ProductCategory::where('name', $categoryName)->first(); + if (!$category) { + throw new ImportException('分类 '.$categoryName.' 不存在'); + } $goods['category_id'] = $category->id; // 图片组