diff --git a/code/app/home/controller/Novel.php b/code/app/home/controller/Novel.php index ae24415..59b1386 100644 --- a/code/app/home/controller/Novel.php +++ b/code/app/home/controller/Novel.php @@ -469,7 +469,7 @@ class Novel extends BaseController /** - * 小说章节 + * 章节详情 * * @param Request $Request * @param integer $intNovelId 小说id @@ -481,6 +481,24 @@ class Novel extends BaseController { $boolIsMobile = $Request->param('boolIsMobile'); + + // 小说详情 + $NovelModel = new NovelModel; + $intNId = $intNovelId; + $arrNovel = $NovelModel->getNovelInfo($intNId); + + // 章节 + $ChapterModel = new ChapterModel; + $arrFilter = ['n_id' => $intNId, 'c_sort_num' => $intChapterSort, 'c_page' => $intChapterPage]; + + $arrChapter = $ChapterModel->getChapter($arrFilter); + + // 上一章节和下一章节 + $arrPreChapter = $ChapterModel->getPreChapter($arrChapter['n_id'], $arrChapter['c_sort_num'], $arrChapter['c_page']); + $arrNextChapter = $ChapterModel->getNextChapter($arrChapter['n_id'], $arrChapter['c_sort_num'], $arrChapter['c_page']); + + + // 模拟数据 $arrNewsNovel = [ ['id' => 1, 'name' => '小说1', 'author' => '作者1'], diff --git a/code/app/model/ChapterModel.php b/code/app/model/ChapterModel.php index c8588c3..0e3dc33 100644 --- a/code/app/model/ChapterModel.php +++ b/code/app/model/ChapterModel.php @@ -36,6 +36,28 @@ class ChapterModel extends MongoModel ], ]; + /** + * Undocumented function + * + * @param array $arrFilter + * @return null|array + */ + public function getChapter(array $arrFilter): null|array + { + + $arrOptions = self::$arrChapterOptions; + + $arrChapter = $this->getOne($arrFilter, $arrOptions); + + if (!empty($arrChapter)) { + applyToKeys($arrChapter, ['created_at', 'updated_at'], 'formatMongoDate'); + + $arrChapter['content'] = StorageCore::getInstance()->read($arrChapter['c_content_path']); + } + + return $arrChapter; + } + /** * Undocumented function * @@ -110,13 +132,13 @@ class ChapterModel extends MongoModel ['c_sort_num' => ['$lt' => $intCSortNum]], [ '$and' => [ - ['c_sort_num' => ['$eq' => $intCSortNum]], - ['c_page' => ['$lt' => $intCPage]] + ['c_sort_num' => ['$eq' => $intCSortNum]], + ['c_page' => ['$lt' => $intCPage]] ] ] ] ], - ['n_id' => $intNId] + ['n_id' => $intNId] ] ]; @@ -125,7 +147,9 @@ class ChapterModel extends MongoModel 'c_sort_num' => -1, 'c_page' => -1, ]; - return $this->getChapterAll($arrFilter, 1, $arrSort); + + $arrChapterAll = $this->getChapterAll($arrFilter, 1, $arrSort); + return $arrChapterAll[0] ?? []; } /** @@ -145,13 +169,13 @@ class ChapterModel extends MongoModel ['c_sort_num' => ['$gt' => $intCSortNum]], [ '$and' => [ - ['c_sort_num' => ['$eq' => $intCSortNum]], - ['c_page' => ['$gt' => $intCPage]] + ['c_sort_num' => ['$eq' => $intCSortNum]], + ['c_page' => ['$gt' => $intCPage]] ] ] ] ], - ['n_id' => $intNId] + ['n_id' => $intNId] ] ]; @@ -160,6 +184,8 @@ class ChapterModel extends MongoModel 'c_sort_num' => 1, 'c_page' => 1, ]; - return $this->getChapterAll($arrFilter, 1, $arrSort); + + $arrChapterAll = $this->getChapterAll($arrFilter, 1, $arrSort); + return $arrChapterAll[0] ?? []; } }