فهرست منبع

feat: dist_id

igb 4 ماه پیش
والد
کامیت
422f0b758f

+ 7 - 0
app/Helpers/helpers.php

@@ -23,6 +23,13 @@ if (!function_exists('getHost')) {
     }
 }
 
+if (!function_exists('getDistId')) {
+
+    function getDistId() {
+        return app('dist')->id;
+    }
+}
+
 if (!function_exists('formatDirectory')) {
     /**
      * 格式化目录名

+ 2 - 0
app/Http/Controllers/CollectionController.php

@@ -31,9 +31,11 @@ class CollectionController extends Controller
     public function detail($slug)
     {
 
+
         // Find the tag by either slug or id
         $tag = SitePageTag::where('slug', $slug)
             ->orWhere('id', $slug)
+            ->where('dist_id',getDistId())
             ->first();
 
 

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

@@ -22,7 +22,7 @@ class PageController extends Controller
      */
     public function list()
     {
-        $pages = DistPages::paginate(10)->where('status', '1'); // 每页显示10个页面
+        $pages = DistPages::paginate(10)->where('dist_id', getDistId())->where('status', '1'); // 每页显示10个页面
         return $this->liquidRenderer->render('pages.list', ['pages' => $pages]);
     }
 
@@ -35,7 +35,7 @@ class PageController extends Controller
     public function detail($slug)
     {
 
-        $page = DistPages::where('status', '1')->where('slug', $slug)->first();
+        $page = DistPages::where('status', '1')->where('dist_id', getDistId())->where('slug', $slug)->first();
 
         // 如果没有找到且是数字,通过 id 获取页面
         if (!$page) {

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

@@ -38,6 +38,7 @@ class ProductController extends Controller
 
         // 获取分类下的所有产品,并按 is_pinned 排序,然后进行分页
         $products = DistProduct::where('category_id', $category->id)
+            ->where('dist_id', getDistId())
             ->where('enabled', 1)
             ->with('images') // Eager load images
             ->orderBy('is_pinned', 'desc') // 按 is_pinned 降序排序

+ 3 - 3
app/Http/Controllers/SitemapController.php

@@ -15,9 +15,9 @@ class SitemapController extends Controller
     public function index()
     {
         // 获取产品、文章和视频数据
-        $dist_products = DistProduct::where('enabled', 1)->get(); // 获取所有字段
-        $dist_pages = DistPages::where('status', 1)->get(); // 获取所有字段
-        $dist_videos = DistVideo::where('enabled', 1)->get(); // 获取所有字段
+        $dist_products = DistProduct::where('enabled', 1)->where('dist_id', getDistId())->get(); // 获取所有字段
+        $dist_pages = DistPages::where('status', 1)->where('dist_id', getDistId())->get(); // 获取所有字段
+        $dist_videos = DistVideo::where('enabled', 1)->where('dist_id', getDistId())->get(); // 获取所有字段
 
 
         // 创建一个视图来生成 XML

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

@@ -20,7 +20,7 @@ class VideoController extends Controller
      */
     public function index()
     {
-        $videos = Video::paginate(10); // 每页显示10个视频
+        $videos = Video::paginate(10)->where('dist_id', getDistId()); // 每页显示10个视频
         return $this->liquidRenderer->render('videos.index', ['videos' => $videos]);
     }
 

+ 4 - 3
app/Models/DistProduct.php

@@ -34,7 +34,7 @@ class DistProduct extends Model
     // 静态方法用于查询单个产品
     public static function getProduct($productId)
     {
-        return self::where('enabled', 1)->with('images')->find($productId);
+        return self::where('enabled', 1)->where('dist_id', getDistId())->with('images')->find($productId);
     }
 
 
@@ -42,12 +42,13 @@ class DistProduct extends Model
     // 静态方法用于查询多个产品
     public static function getProducts($categoryId = null, $limit = null)
     {
-        $dist=app('dist');
+
 
         $query = self::query();
 
         $query->where('enabled', 1);
-        $query->where('dist_id', $dist->id);
+
+        $query->where('dist_id', getDistId());
 
         // 如果提供了分类 ID,添加过滤条件
         if ($categoryId) {