Browse Source

章节获取优化

wangzq 2 years ago
parent
commit
0d9a3311e9

+ 3 - 1
app/Http/Controllers/QuickApp/Book/ChapterController.php

@@ -196,6 +196,7 @@ class ChapterController extends BaseController
         $this->book_info = $book_info;
         $this->book_info = $book_info;
         //获取章节信息
         //获取章节信息
         $chapter = ChapterService::getChapterNameById($cid, $bid);
         $chapter = ChapterService::getChapterNameById($cid, $bid);
+
         if (!$chapter) {
         if (!$chapter) {
             //短推长
             //短推长
             $combination_chapter = $this->chapterNotExists($bid,$cid);
             $combination_chapter = $this->chapterNotExists($bid,$cid);
@@ -209,6 +210,7 @@ class ChapterController extends BaseController
                 return response()->error('QAPP_SYS_ERROR');
                 return response()->error('QAPP_SYS_ERROR');
             }
             }
         }
         }
+
         list($is_split,$is_change_chapter_name) = BookService::splitContent($bid);
         list($is_split,$is_change_chapter_name) = BookService::splitContent($bid);
         if($is_split && ($book_info->channel_name == '男频' || $is_change_chapter_name) ){
         if($is_split && ($book_info->channel_name == '男频' || $is_change_chapter_name) ){
             $chapter->name = '第'.$chapter->sequence.'章';
             $chapter->name = '第'.$chapter->sequence.'章';
@@ -243,7 +245,7 @@ class ChapterController extends BaseController
                 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
                 'uid' => $this->uid, 'bid' => $bid, 'book_name' => $book_info->book_name,
                 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
                 'cid' => $cid, 'chapter_name' => $chapter->name, 'sequence' => $chapter->sequence
             ]);
             ]);
-            return response()->item(new ChapterTransformer, $this->getChapter($bid, $cid, $chapter));
+            return response()->item(new ChapterTransformer, $this->getChapter($bid, $chapter->id, $chapter));
         }
         }
 
 
         // 书籍是否限免
         // 书籍是否限免

+ 25 - 2
app/Modules/Book/Services/ChapterService.php

@@ -110,8 +110,12 @@ class ChapterService
     public static function getChapterNameById($chapter_id,$bid)
     public static function getChapterNameById($chapter_id,$bid)
     {
     {
         $chapter = Chapter::getChapterNameById($chapter_id);
         $chapter = Chapter::getChapterNameById($chapter_id);
-        if($chapter && $chapter->bid == $bid){
-            return $chapter;
+        if ($chapter){
+            if ($chapter->bid == $bid){
+                return $chapter;
+            }else if (abs($chapter->bid) == $bid && $chapter->bid != $bid){
+                return  self::realChapterNameById($chapter,$bid);
+            }
         }
         }
         return false;
         return false;
     }
     }
@@ -427,4 +431,23 @@ class ChapterService
         }
         }
     }
     }
 
 
+    /***
+     * 根据章节序号获取章节信息没有内容
+     * name: realChapterNameById
+     * @param $chapter
+     * @param $bid
+     * @return false
+     * date 2022/08/24 11:00
+     */
+    private static function realChapterNameById($chapter, $bid)
+    {
+        $sequence = $chapter['sequence'] ?? 0;
+        $new_chapter = Chapter::where('bid',$bid)->where('sequence','>=',$sequence)->orderBy('sequence','asc')->select('id','bid','name','sequence','size','is_vip','prev_cid','next_cid','recent_update_at')->first();
+        if ($new_chapter){
+            return $new_chapter;
+        }
+        return  false;
+    }
+
+
 }
 }