Browse Source

feat:limit display

igb 4 months ago
parent
commit
e12a2c60a6

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

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

+ 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('enabled', 1)
             ->with('images') // Eager load images
             ->orderBy('is_pinned', 'desc') // 按 is_pinned 降序排序
             ->paginate(12);

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

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

+ 3 - 1
app/Models/DistProduct.php

@@ -34,7 +34,7 @@ class DistProduct extends Model
     // 静态方法用于查询单个产品
     public static function getProduct($productId)
     {
-        return self::with('images')->find($productId);
+        return self::where('enabled', 1)->with('images')->find($productId);
     }
 
 
@@ -44,6 +44,8 @@ class DistProduct extends Model
     {
         $query = self::query();
 
+        $query->where('enabled', 1);
+
         // 如果提供了分类 ID,添加过滤条件
         if ($categoryId) {
             $query->where('category_id', $categoryId);

+ 1 - 2
app/Models/SitePageTag.php

@@ -10,7 +10,6 @@ class SitePageTag extends Model
     use HasFactory;
     protected $table = 'site_pages_tag';
 
-
     public function pages()
     {
         return $this->belongsToMany(
@@ -18,6 +17,6 @@ class SitePageTag extends Model
             'site_pages_tag_relationship',
             'tag_id',
             'pages_id'
-        );
+        )->where('status', 1);;
     }
 }

+ 1 - 1
app/Services/MenuService.php

@@ -17,7 +17,7 @@ class MenuService
         $menus = SiteMenu::where('show', 1) // 只显示状态为 1 的菜单
             ->where('dist_id', $dist_id)
             ->where('menu_location', $menu_location)
-        ->orderBy('order', 'asc')
+            ->orderBy('order', 'asc')
             ->get();
 
         // 构造多级菜单