From e6984bbf5dd6e860c2273d9d6f9a04246bd16f67 Mon Sep 17 00:00:00 2001 From: leo108 Date: Sat, 22 Dec 2018 14:51:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=95=8C=E9=9D=A2=20-=20?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ProductsController.php | 10 ++ resources/sass/app.scss | 120 ++++++++++++++++++++ resources/views/products/index.blade.php | 10 +- resources/views/products/show.blade.php | 77 +++++++++++++ routes/web.php | 2 + 5 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 resources/views/products/show.blade.php diff --git a/app/Http/Controllers/ProductsController.php b/app/Http/Controllers/ProductsController.php index 50852d77..9afb19b9 100644 --- a/app/Http/Controllers/ProductsController.php +++ b/app/Http/Controllers/ProductsController.php @@ -49,4 +49,14 @@ public function index(Request $request) ], ]); } + + public function show(Product $product, Request $request) + { + // 判断商品是否已经上架,如果没有上架则抛出异常。 + if (!$product->on_sale) { + throw new \Exception('商品未上架'); + } + + return view('products.show', ['product' => $product]); + } } diff --git a/resources/sass/app.scss b/resources/sass/app.scss index f4d6c52b..612dfb46 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -124,3 +124,123 @@ body { border-bottom: 1px solid #eee; } } + +.products-show-page { + .cover { + width: 100%; + border: solid 1px #eee; + padding: 30px 0; + } + .title { + font-size: 24px; + font-weight: bold; + margin-bottom: 10px; + } + .price { + label { + width: 69px; + color: #999; + font-size: 12px; + padding-left: 10px; + } + em { + font-family: Arial; + font-size: 18px; + font-style: normal; + text-decoration: none; + vertical-align: middle; + } + span { + font-family: Arial; + font-size: 24px; + font-weight: bolder; + text-decoration: none; + vertical-align: middle; + } + line-height: 30px; + background-color: #e9e9e9; + color: red; + font-size: 20px; + } + .sales_and_reviews { + border-top: 1px dotted #c9c9c9; + border-bottom: 1px dotted #c9c9c9; + margin: 5px 0 10px; + display: flex; + flex-direction: row; + font-size: 12px; + &>div { + &.sold_count,&.review_count { + border-right: 1px dotted #c9c9c9; + } + width: 33%; + text-align: center; + padding: 5px; + .count { + color: #FF0036; + font-weight: 700; + } + } + } + .skus { + &>label { + color: #999; + font-size: 12px; + padding: 0 10px 0 10px; + } + .btn-group { + margin-left: -10px; + label { + border-radius: 0 !important; + margin: 1px 5px; + padding: 2px 5px; + font-size: 12px; + } + .btn { + border: 1px solid #ccc; + } + .btn.active, .btn:hover { + margin-top: 0px !important; + background: #fff !important; + border: 2px solid red !important; + } + .btn.focus { + outline: 0 !important; + } + } + } + .cart_amount { + label { + color: #999; + font-size: 12px; + padding: 0 10px 0 10px; + } + font-size: 12px; + color: #888; + margin: 10px 0 20px; + input { + width: 50px; + display: inline-block; + border-radius: 0 !important; + } + span { + color: #999; + font-size: 12px; + padding-left: 10px; + } + } + .buttons { + padding-left: 44px; + } + + .product-detail { + .nav.nav-tabs > li > a { + border-radius: 0 !important; + } + margin: 20px 0; + .tab-content { + border: 1px solid #eee; + padding: 20px; + } + } + } diff --git a/resources/views/products/index.blade.php b/resources/views/products/index.blade.php index abca8ccd..ca6c7373 100644 --- a/resources/views/products/index.blade.php +++ b/resources/views/products/index.blade.php @@ -34,9 +34,15 @@
-
+
+ + + +
{{ $product->price }}
-
{{ $product->title }}
+
销量 {{ $product->sold_count }}笔
diff --git a/resources/views/products/show.blade.php b/resources/views/products/show.blade.php new file mode 100644 index 00000000..0468fbbb --- /dev/null +++ b/resources/views/products/show.blade.php @@ -0,0 +1,77 @@ +@extends('layouts.app') +@section('title', $product->title) + +@section('content') +
+
+
+
+
+
+ +
+
+
{{ $product->title }}
+
{{ $product->price }}
+
+
累计销量 {{ $product->sold_count }}
+
累计评价 {{ $product->review_count }}
+
评分 {{ str_repeat('★', floor($product->rating)) }}{{ str_repeat('☆', 5 - floor($product->rating)) }}
+
+
+ +
+ @foreach($product->skus as $sku) + + @endforeach +
+
+
+
+ + +
+
+
+
+ +
+
+ {!! $product->description !!} +
+
+
+
+
+
+
+
+
+@endsection + +@section('scriptsAfterJs') + +@endsection diff --git a/routes/web.php b/routes/web.php index 03d994af..476f2738 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,6 +13,8 @@ Route::redirect('/', '/products')->name('root'); Route::get('products', 'ProductsController@index')->name('products.index'); +Route::get('products', 'ProductsController@index')->name('products.index'); +Route::get('products/{product}', 'ProductsController@show')->name('products.show'); Auth::routes(['verify' => true]);