diff --git a/code/app/home/controller/Novel.php b/code/app/home/controller/Novel.php index 3221e82..0c62d81 100644 --- a/code/app/home/controller/Novel.php +++ b/code/app/home/controller/Novel.php @@ -88,7 +88,7 @@ class Novel extends BaseController $boolIsMobile = $Request->param('boolIsMobile'); // 性别 - + $arrSex = [ 'all' => 0, 'nansheng-xiaoshuo' => 1, @@ -110,7 +110,7 @@ class Novel extends BaseController $strCategoryKey = array_search($strCategory, CategoryModel::$arrCategoryPinYin); $strSearchCategory = CategoryModel::$arrCategory[$strCategoryKey]; } - + // 小说状态 $arrStatus = [ 'all' => NULL, @@ -324,22 +324,33 @@ class Novel extends BaseController $boolIsMobile = $Request->param('boolIsMobile'); + $NovelModel = new NovelModel; + // 小说详情 $arrNovel = $NovelModel->getNovelInfo($intNId); + // 最后章节 $ChapterModel = new ChapterModel; - $arrLatestChapter = $ChapterModel->getLatestChapter($intNId); + // 最近五个章节 + $arrChapter = $ChapterModel->getChapterAll([ + 'n_id' => $intNId, + 'c_page' => 0, + ], 5, ['c_sort_num' => -1]); + + // 点击数 $NovelClicksModel = new NovelClicksModel; $arrNovelClicks = $NovelClicksModel->getStats($intNId); + // 推荐小说 + $arrRelateveNId = array_column($arrNovel['n_related_novel'], 'n_id'); + $arrRelateveNovel = $NovelModel->getNovelAll([ + '$in' => $arrRelateveNId, + ], 100); - // echo '
';
- // print_r($arrNovel);
- // exit;
$strNovel = '斗罗大陆';
diff --git a/code/app/model/ChapterModel.php b/code/app/model/ChapterModel.php
index d6c8377..79cd8ca 100644
--- a/code/app/model/ChapterModel.php
+++ b/code/app/model/ChapterModel.php
@@ -68,23 +68,31 @@ class ChapterModel extends MongoModel
* @param integer $intNId
* @return null|array
*/
- public function getChapterAll(array $arrFilter, array $arrOptions = []): null|array
+ public function getChapterAll(array $arrFilter, int $intCount = 10, array $arrSort = ['c_sort_num' => -1], bool $boolReadContent = false): null|array
{
// $arrFilter = ['n_id' => $intNId, 'c_page' => 0];
- // $arrOptions = self::$arrChapterOptions;
+ $arrOptions = self::$arrChapterOptions;
- // $arrOptions['sort'] = ['c_sort_num' => -1];
+ $arrOptions['sort'] = $arrSort;
- // $arrChapter = $this->getOne($arrFilter, $arrOptions);
+ $arrOptions['limit'] = $intCount;
- // if (!empty($arrChapter)) {
- // applyToKeys($arrChapter, ['created_at', 'updated_at'], 'formatMongoDate');
+ $arrFilter = [];
- // $arrChapter['content'] = StorageCore::getInstance()->read($arrChapter['c_content_path']);
- // }
+ $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
+ $arrResult = iterator_to_array($Cursor);
- // return $arrChapter;
+ foreach ($arrResult as &$arrItem) {
+
+ applyToKeys($arrItem, ['created_at', 'updated_at'], 'formatMongoDate');
+ $arrItem['content'] = '';
+ if ($boolReadContent) {
+ $arrItem['content'] = StorageCore::getInstance()->read($arrItem['c_content_path']);
+ }
+ }
+
+ return $arrResult;
}
}
diff --git a/code/app/model/NovelModel.php b/code/app/model/NovelModel.php
index 071624c..cc42988 100644
--- a/code/app/model/NovelModel.php
+++ b/code/app/model/NovelModel.php
@@ -22,6 +22,30 @@ class NovelModel extends MongoModel
*/
protected $strCollection = 'novel';
+ static public $arrNovelOptions = [
+ 'typeMap' => [
+ 'root' => 'array',
+ 'document' => 'array',
+ 'array' => 'array',
+ ],
+ 'projection' => [
+ '_id' => 0,
+ 'og_title' => 0,
+ 'n_site_name' => 0,
+ 'n_site_code' => 0,
+ 'n_site_uuid' => 0,
+ 'n_source_id' => 0,
+ 'n_page_title' => 0,
+ 'og_description' => 0,
+ 'og_novel_latest_chapter_name' => 0,
+ 'og_image' => 0,
+ 'og_novel_latest_chapter_url' => 0,
+ 'og_novel_read_url' => 0,
+ 'og_type' => 0,
+ 'og_url' => 0,
+ ],
+ ];
+
/**
* 根据关键词数组更新小说推荐等级
* @param array $arrKeywords 关键词数组,例如 ["斗罗", "遮天", "凡人"]
@@ -53,29 +77,36 @@ class NovelModel extends MongoModel
return true;
}
- static public $arrNovelOptions = [
- 'typeMap' => [
- 'root' => 'array',
- 'document' => 'array',
- 'array' => 'array',
- ],
- 'projection' => [
- '_id' => 0,
- 'og_title' => 0,
- 'n_site_name' => 0,
- 'n_site_code' => 0,
- 'n_site_uuid' => 0,
- 'n_source_id' => 0,
- 'n_page_title' => 0,
- 'og_description' => 0,
- 'og_novel_latest_chapter_name' => 0,
- 'og_image' => 0,
- 'og_novel_latest_chapter_url' => 0,
- 'og_novel_read_url' => 0,
- 'og_type' => 0,
- 'og_url' => 0,
- ],
- ];
+ /**
+ * Undocumented function
+ *
+ * @param integer $intNId
+ * @return null|array
+ */
+ public function getNovelAll(array $arrFilter, int $intCount = 10, array $arrSort = []): null|array
+ {
+ // $arrFilter = ['n_id' => $intNId, 'c_page' => 0];
+
+ $arrOptions = self::$arrNovelOptions;
+
+ $arrOptions['sort'] = $arrSort;
+
+ $arrOptions['limit'] = $intCount;
+
+ $arrFilter = [];
+
+ $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
+
+ $arrResult = iterator_to_array($Cursor);
+
+ foreach ($arrResult as &$arrItem) {
+
+ applyToKeys($arrItem, ['created_at', 'updated_at'], 'formatMongoDate');
+
+ }
+
+ return $arrResult;
+ }
/**
* Undocumented function
@@ -89,9 +120,6 @@ class NovelModel extends MongoModel
$arrOptions = self::$arrNovelOptions;
$arrNovel = $this->getOne($arrFilter, $arrOptions);
applyToKeys($arrNovel, ['created_at', 'updated_at'], 'formatMongoDate');
-
-
-
return $arrNovel;
}