Browse Source

feat: 增加限定

igb 4 months ago
parent
commit
eb4f13088e

+ 1 - 1
app/Http/Controllers/PageController.php

@@ -46,7 +46,7 @@ class PageController extends Controller
                 $page = SitePage::where('status', '1')->where('dist_id', getDistId())->where('id', $slug)->firstOrFail();
             }
             else{
-                abort(404);
+                abort(403);
             }
         }
 

+ 12 - 1
app/Http/Controllers/ProductController.php

@@ -34,7 +34,13 @@ class ProductController extends Controller
 //        return $this->liquidRenderer->render('products_categories.liquid', ['products' => $products]);
 
         // 获取分类信息
-        $category = DistProductCategory::findOrFail($slug);
+        // 获取分类信息,并限定 dist_id
+        $category = DistProductCategory::where(function ($query) use ($slug) {
+            $query->where('id', $slug)
+                ->orWhere('slug', $slug);
+        })
+            ->where('dist_id', getDistId())
+            ->firstOrFail();
 
         // 获取分类下的所有产品,并按 is_pinned 排序,然后进行分页
         $products = DistProduct::where('category_id', $category->id)
@@ -93,6 +99,11 @@ class ProductController extends Controller
     {
         $product = DistProduct::getProduct($id);
 
+        if(!$product)
+        {
+            abort('404');
+        }
+
         // 构建导航数据 开始
         $breadcrumbs = [
             [

+ 14 - 3
app/Http/Controllers/VideoController.php

@@ -31,7 +31,13 @@ class VideoController extends Controller
 
 
         // 获取分类信息
-        $category = DistVideoCategory::findOrFail($slug);
+        $category = DistVideoCategory::where(function ($query) use ($slug) {
+            $query->where('id', $slug)
+                ->orWhere('slug', $slug);
+        })
+            ->where('dist_id', getDistId())
+            ->firstOrFail();
+
         // 获取分类下的所有产品,并按 is_pinned 排序,然后进行分页
         $videos = DistVideo::where('category_id', $category->id)
             ->where('dist_id', getDistId())
@@ -87,8 +93,13 @@ class VideoController extends Controller
     public function detail($slug)
     {
 
-        $video = DistVideo::where('dist_id', getDistId())->where('slug', $slug)->orWhere('id', $slug)->first();
-
+        // 获取视频信息,并确保 dist_id 符合 getDistId() 的要求
+        $video = DistVideo::where('dist_id', getDistId())
+            ->where(function ($query) use ($slug) {
+                $query->where('slug', $slug)
+                    ->orWhere('id', $slug);
+            })
+            ->firstOrFail();
 
         // 构建导航数据 开始
         $breadcrumbs = [