Browse Source

260302 最新消息列表 新增預計發布時間

OMEGA\lulufj.ho 1 month ago
parent
commit
2be980dac4
1 changed files with 13 additions and 2 deletions
  1. 13
    2
      app/Http/Controllers/Api/NewsController.php

+ 13
- 2
app/Http/Controllers/Api/NewsController.php View File

30
         $month = $request->input("month", -1);
30
         $month = $request->input("month", -1);
31
         $locate = $locate == "tw" ? "zh_TW" : $locate;
31
         $locate = $locate == "tw" ? "zh_TW" : $locate;
32
         $result = [];
32
         $result = [];
33
-
33
+        
34
+        $dateFilter = Carbon::now();
34
         //文章列表
35
         //文章列表
35
         $news = News::where("visible", 1);
36
         $news = News::where("visible", 1);
36
         if($month > 0 || $year > 0){
37
         if($month > 0 || $year > 0){
37
-            $dateFilter = Carbon::now();
38
+            
38
             if($year > 0){
39
             if($year > 0){
39
                 $dateFilter->setYear(intval($year));
40
                 $dateFilter->setYear(intval($year));
40
                 if($month > 0){
41
                 if($month > 0){
43
                 }else{
44
                 }else{
44
                     $news = $news->whereBetween("post_date", [$dateFilter->copy()->startOfYear(), $dateFilter->copy()->endOfYear()]);
45
                     $news = $news->whereBetween("post_date", [$dateFilter->copy()->startOfYear(), $dateFilter->copy()->endOfYear()]);
45
                 }
46
                 }
47
+                
46
             }
48
             }
47
         }
49
         }
50
+
51
+        $news = $news->where(fn($q) =>
52
+            $q->whereNull('start_date')
53
+            ->orWhere('start_date', '<=', $dateFilter)
54
+        )->where(fn($q) =>
55
+            $q->whereNull('end_date')
56
+            ->orWhere('end_date', '>=', $dateFilter)
57
+        );
58
+
48
         $news = $news->orderByDesc("order")->orderByDesc("post_date");
59
         $news = $news->orderByDesc("order")->orderByDesc("post_date");
49
         $result["pagination"] = [
60
         $result["pagination"] = [
50
             "page" => $page,
61
             "page" => $page,