diff --git a/app/Admin/Controllers/HomeController.php b/app/Admin/Controllers/HomeController.php index a2c02577..d9e166fd 100644 --- a/app/Admin/Controllers/HomeController.php +++ b/app/Admin/Controllers/HomeController.php @@ -17,21 +17,22 @@ class HomeController extends Controller public function index(Content $content) { return $content - ->header('首页') - ->description('首页') - ->body(function (Row $row) { - $row->column(6, function (Column $column) { + ->header('首页') + ->description('首页') + ->body(function (Row $row) { + $user = Admin::user(); + $row->column(6, function (Column $column) use ($user) { $column->row(Dashboard::title()); - if (Admin::user()->can('dcat.admin.home.statistics')) { + if ($user->can('dcat.admin.home.statistics')) { $column->row(new StatisticsTotal()); } }); - $row->column(6, function (Column $column) { - if (Admin::user()->can('dcat.admin.home.new_users')) { + $row->column(6, function (Column $column) use ($user) { + if ($user->can('dcat.admin.home.new_users')) { $column->row(new NewUsers()); } - if (Admin::user()->can('dcat.admin.home.orders')) { + if ($user->can('dcat.admin.home.orders')) { $column->row(new Orders()); } }); diff --git a/app/Admin/Imports/StoreProduct.php b/app/Admin/Imports/StoreProduct.php index 4a12336f..dc4f4799 100644 --- a/app/Admin/Imports/StoreProduct.php +++ b/app/Admin/Imports/StoreProduct.php @@ -27,6 +27,7 @@ class StoreProduct $index = 0; $storeName = $cells[$index];// 店铺名称 $goodsName = $cells[++$index];// 商品名称 + $stock = $cells[++$index];// 库存 $goodsTitle = $cells[++$index];// 商品副标题 $categoryName = $cells[++$index];// 分类名称 $goodsImage = $cells[++$index];// 商品图片 @@ -47,65 +48,62 @@ class StoreProduct // https://qiniu.abcdefg.fun/banner/banner4.png,https://qiniu.abcdefg.fun/banner/banner5.png $goodsContent = $cells[++$index]; - $stock = $cells[++$index];// 库存 - $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)->first(); - if (!$category) { - throw new ImportException('分类 '.$categoryName.' 不存在'); - } - $goods['category_id'] = $category->id; + } - // 图片组 - if ($goodsImage) { - if (Str::startsWith($goodsImage, ['http://', 'https://'])) { - $images = explode(',', $goodsImage); - } else { - $images = $this->getImageUrlFromPath($goodsImage); - } - if (count($images) > 0) { - $goods['cover'] = $images[0]; - $goods['images'] = $images; - } - } - - // 运费模板 - if ($shipTemplate) { - $goods['shipping_template_id'] = $shipTemplate; - } - // 重量 - if ($goodsWeight) { - $goods['weight'] = $goodsWeight; - } - // 详细描述 - if ($goodsContent) { - $description = ''; - foreach(explode(',', $goodsContent) as $item) { - $description .= '

'; - } - $goods['description'] = $description; - } - - $goods = array_merge($goods, [ - 'sell_price' => $salePrice * 100, - 'market_price' => $marketPrice * 100, - 'cost_price' => $costPrice * 100, - 'vip_price' => $vipPrice * 100, - 'sales_value' => $saleValue, - 'stock' => $stock, - ]); - - $product = ProductSpu::where('name', $goods['name'])->first(); + $product = ProductSpu::where('name', $goodsName)->first(); if (!$product) { + $goods = [ + 'name' => $goodsName, + 'subtitle' => $goodsTitle, + 'shipping_template_id' => 1, + ]; + $category = ProductCategory::where('name', $categoryName)->first(); + if (!$category) { + throw new ImportException('分类 '.$categoryName.' 不存在'); + } + $goods['category_id'] = $category->id; + + // 图片组 + if ($goodsImage) { + if (Str::startsWith($goodsImage, ['http://', 'https://'])) { + $images = explode(',', $goodsImage); + } else { + $images = $this->getImageUrlFromPath($goodsImage); + } + if (count($images) > 0) { + $goods['cover'] = $images[0]; + $goods['images'] = $images; + } + } + + // 运费模板 + if ($shipTemplate) { + $goods['shipping_template_id'] = $shipTemplate; + } + // 重量 + if ($goodsWeight) { + $goods['weight'] = $goodsWeight; + } + // 详细描述 + if ($goodsContent) { + $description = ''; + foreach(explode(',', $goodsContent) as $item) { + $description .= '

'; + } + $goods['description'] = $description; + } + + $goods = array_merge($goods, [ + 'sell_price' => $salePrice * 100, + 'market_price' => $marketPrice * 100, + 'cost_price' => $costPrice * 100, + 'vip_price' => $vipPrice * 100, + 'sales_value' => $saleValue, + 'stock' => $stock, + ]); $product = ProductSpu::create($goods); // 属性规格 if ($rowAttrs) { diff --git a/database/seeders/AdminPermissionSeeder.php b/database/seeders/AdminPermissionSeeder.php index 2d46bbac..8b179b26 100644 --- a/database/seeders/AdminPermissionSeeder.php +++ b/database/seeders/AdminPermissionSeeder.php @@ -70,9 +70,9 @@ class AdminPermissionSeeder extends Seeder 'name'=>'主页', 'curd' => false, 'children' =>[ - 'home.statistics'=>['name' =>'统计预览'], - 'home.new_users'=>['name' =>'新注册'], - 'home.orders'=>['name' =>'订单'], + 'statistics'=>['name' =>'统计预览'], + 'new_users'=>['name' =>'新注册'], + 'orders'=>['name' =>'订单'], ], ], 'users'=>[ diff --git a/public/store-goods.xlsx b/public/store-goods.xlsx index d2f90176..d9793d2e 100644 Binary files a/public/store-goods.xlsx and b/public/store-goods.xlsx differ