From 4b97fe8a46ef55f58f7e1757c2dce5c2e4a1634b Mon Sep 17 00:00:00 2001 From: Default Date: Fri, 4 Apr 2025 00:48:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/.example.env | 3 +- code/app/common.php | 6 +- code/app/home/config/router.php | 2 +- code/app/home/controller/Novel.php | 75 +++- code/app/model/CategoryModel.php | 43 +- code/app/model/ChapterModel.php | 4 +- code/app/model/MongoModel.php | 38 ++ code/app/model/NovelModel.php | 669 ++++++++++++++--------------- code/config/view.php | 8 +- 9 files changed, 469 insertions(+), 379 deletions(-) diff --git a/code/.example.env b/code/.example.env index 96c76a3..2a20925 100644 --- a/code/.example.env +++ b/code/.example.env @@ -55,4 +55,5 @@ STORAGE_LOCAL_DIR = /mnt/gluster # VIEW VIEW_DISPLAY_CACHE = false -VIEW_TPL_CACHE = false \ No newline at end of file +VIEW_TPL_CACHE = false +VIEW_DATA_CACHE = false \ No newline at end of file diff --git a/code/app/common.php b/code/app/common.php index 06676fe..36731f2 100644 --- a/code/app/common.php +++ b/code/app/common.php @@ -3,6 +3,9 @@ namespace { + use think\facade\Cache; + + use function MongoDB\object; function getUriByUrl($strUrl) { @@ -852,11 +855,12 @@ namespace { function applyToKeys(null|array &$arrData, array $arrKeys, callable $Callback) { if (empty($arrData)) return; - + foreach ($arrKeys as $strKey) { if (key_exists($strKey, $arrData)) { $arrData[$strKey] = $Callback($arrData[$strKey]); } } } + } diff --git a/code/app/home/config/router.php b/code/app/home/config/router.php index bf201dc..7e4ea5d 100644 --- a/code/app/home/config/router.php +++ b/code/app/home/config/router.php @@ -75,7 +75,7 @@ Route::get('/pc/xiaoshuo/:name-:intNovelId/zhang-:intChapterSort/[:intChapterPag /** * 最新章节-特殊页面处理 */ -Route::get('/pc/books/:name-:n_id/chapter/latest', [Novel::class, 'getNovelNewsChapter']) +Route::get('/pc/books/:name-:n_id/chapter/latest', [Novel::class, 'getNovelLatestChapter']) ->append(['boolIsMobile' => false, 'intUriType' => 1]) ->pattern(['n_id' => '\d+', 'name' => '[\w-]+',]); diff --git a/code/app/home/controller/Novel.php b/code/app/home/controller/Novel.php index ad55d79..60380a7 100644 --- a/code/app/home/controller/Novel.php +++ b/code/app/home/controller/Novel.php @@ -138,7 +138,7 @@ class Novel extends BaseController $NovelModel = new NovelModel; - $arrPage = $NovelModel->getCommonNovelPageOnCache($strKey, $intPage, $intLimit, $intLifeTime, $intGender, $strSearchStatus); + $arrPage = $NovelModel->getCustomPage01($strKey, $intPage, $intLimit, $intLifeTime, $intGender, $strSearchStatus); $strTemplate = ''; @@ -211,7 +211,7 @@ class Novel extends BaseController // 推荐等级为9的,完结的,男生频道/女生频道, 随机8个小说 $strKey = sprintf('%s:PC:Novel:Channel:Hot:%s:%s', $Request->DomainModel->d_domain, $intType, 'Finish'); $intCount = 8; - $strStuatus = '完结'; + $strStuatus = '已完结'; $arrRecommendEndNovel = $NovelModel->getCommonNovelOnCache($strKey, $intLifeTime, $intCount, $intType, $strStuatus); @@ -331,7 +331,7 @@ class Novel extends BaseController $NovelModel = new NovelModel; // 小说详情 - $arrNovel = $NovelModel->getNovelInfo($intNId); + $arrNovel = $NovelModel->getNovelByNId($intNId); // 分品拼音 $arrNovel['category_pinyin'] = CategoryModel::getPinYinByZh($arrNovel['og_novel_category']); @@ -361,7 +361,7 @@ class Novel extends BaseController // 推荐小说 $arrRelateveNId = array_column($arrNovel['n_related_novel'], 'n_id'); - $arrRelateveNovel = $NovelModel->getNovelAll([ + $arrRelateveNovel = $NovelModel->getNovel([ '$in' => $arrRelateveNId, ], 10); @@ -408,7 +408,7 @@ class Novel extends BaseController $NovelModel = new NovelModel; // 小说详情 - $arrNovel = $NovelModel->getNovelInfo($intNId); + $arrNovel = $NovelModel->getNovelByNId($intNId); // 分品拼音 $arrNovel['category_pinyin'] = CategoryModel::getPinYinByZh($arrNovel['og_novel_category']); @@ -442,7 +442,7 @@ class Novel extends BaseController // 推荐小说 $arrRelateveNId = array_column($arrNovel['n_related_novel'], 'n_id'); - $arrRelateveNovel = $NovelModel->getNovelAll([ + $arrRelateveNovel = $NovelModel->getNovel([ '$in' => $arrRelateveNId, ], 10); // echo '
';
@@ -478,7 +478,7 @@ class Novel extends BaseController
      * @param Request $Request
      * @return void
      */
-    public function getNovelNewsChapter(Request $Request)
+    public function getNovelLatestChapter(Request $Request)
     {
 
         $boolIsMobile = $Request->param('boolIsMobile');
@@ -487,15 +487,20 @@ class Novel extends BaseController
 
         // 小说详情
         $NovelModel = new NovelModel;
-        $arrNovel = $NovelModel->getNovelInfo($intNId);
+        $arrNovel = $NovelModel->getNovelByNId($intNId);
 
         // 最新章节
         $ChapterModel = new ChapterModel;
         $arrChapter = $ChapterModel->getLatestChapter($intNId);
 
         // 上一章节和下一章节
-        $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']);
+        $arrPreChapter  = $arrNextChapter = [];
+
+        if ($arrChapter) {
+            $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']);
+        }
+
 
         $arrCategoryAll = CategoryModel::$arrCategoryAll;
 
@@ -520,6 +525,17 @@ class Novel extends BaseController
             'arrNewsNovel' => $arrNewsNovel,
             'strPageCode' => 'boy'
         ]);
+        View::assign([
+            'arrNovel' => $arrNovel,
+            'arrCategoryAll' => $arrCategoryAll,
+            'arrChapter' => $arrChapter,
+            'arrPreChapter' => $arrPreChapter,
+            'arrNextChapter' => $arrNextChapter,
+            'strPageCode' => 'boy',
+            'intNovelId' => $intNId,
+            'intChapterSort' => $arrChapter['c_sort_num'] ?? 0,
+            'intChapterPage' => $arrChapter['c_page'] ?? 0,
+        ]);
         if ($boolIsMobile) {
             return View::fetch('getNovelChapter');
         } else {
@@ -544,7 +560,7 @@ class Novel extends BaseController
         // 小说详情
         $NovelModel = new NovelModel;
         $intNId = $intNovelId;
-        $arrNovel = $NovelModel->getNovelInfo($intNId);
+        $arrNovel = $NovelModel->getNovelByNId($intNId);
 
         // 章节
         $ChapterModel = new ChapterModel;
@@ -597,7 +613,7 @@ class Novel extends BaseController
         // 小说详情
         $NovelModel = new NovelModel;
         $intNId = $intNovelId;
-        $arrNovel = $NovelModel->getNovelInfo($intNId);
+        $arrNovel = $NovelModel->getNovelByNId($intNId);
 
         $ChapterModel = new ChapterModel;
 
@@ -613,7 +629,7 @@ class Novel extends BaseController
             $arrSort = ['c_sort_num' => -1];
         }
 
-        $arrPage = $ChapterModel->getCommonNovelPageOnCache($strKey, $arrFilter, $intPage, $intLimit, $intLifeTime, $arrSort);
+        $arrPage = $ChapterModel->getCommonPageOnCache($strKey, $arrFilter, $intPage, $intLimit, $intLifeTime, $arrSort);
 
         $intButtomNum = 5;
         if ($boolIsMobile == false) {
@@ -652,8 +668,6 @@ class Novel extends BaseController
         }
     }
 
-
-
     /**
      * 小说-搜索
      *
@@ -664,6 +678,35 @@ class Novel extends BaseController
     {
         $boolIsMobile = $Request->param('boolIsMobile');
 
+        $strKeywords = (string)$Request->get('q');
+        $intPage = (int)$Request->get('page', 1);
+        $intLimit = 20;
+
+        $strKey = sprintf('%s:PC:Novel:Search:%s:Page:%s:Limit:%s', $Request->DomainModel->d_domain,  $strKeywords, $intPage, $intLimit);
+
+        if (empty($strKeywords)) {
+            return response('请输入搜索的关键字', 400);
+        }
+
+        $NovelModel = new NovelModel;
+
+        $arrFilter = [
+            '$or' => [
+                ['og_novel_book_name' => ['$regex' => $strKeywords, '$options' => 'i']],
+                ['og_novel_author' => ['$regex' => $strKeywords, '$options' => 'i']],
+                ['og_novel_category' => ['$regex' => $strKeywords, '$options' => 'i']],
+                ['og_description' => ['$regex' => $strKeywords, '$options' => 'i']],
+            ]
+        ];
+
+
+        $arrPage = $NovelModel->getCommonPageOnCache($arrFilter, $intPage, $intLimit, [], $strKey);
+
+        $intButtomNum = 10;
+
+        $strBaseUrl = sprintf('/pc/search.html?q=%s&page={page}', $strKeywords);
+        $arrPaginator = CusteomPage02::generate($intPage,  $arrPage['total'], $intLimit, $strBaseUrl, $intButtomNum);
+
         // 模拟数据
         $arrSearchNovel = [
             ['id' => 1, 'name' => '小说1', 'author' => '作者1'],
@@ -677,6 +720,8 @@ class Novel extends BaseController
         ];
 
         View::assign([
+            'strKeywords' => $strKeywords,
+            'intPage' => $intPage,
             'arrSearchNovel' => $arrSearchNovel,
             'strPageCode' => 'search'
         ]);
diff --git a/code/app/model/CategoryModel.php b/code/app/model/CategoryModel.php
index 2166ea6..664ed00 100644
--- a/code/app/model/CategoryModel.php
+++ b/code/app/model/CategoryModel.php
@@ -44,17 +44,6 @@ class CategoryModel extends MongoModel
         ]
     ];
 
-    /**
-     * Undocumented function
-     *
-     * @param string $strName
-     * @return string
-     */
-    static public function checkSex(string $strName): string
-    {
-        return in_array($strName, self::$arrMan) ? 'man' : 'women';
-    }
-
     static $arrCategoryPinYin = [
         1 => 'xuanhuan-xiuzhen',      // 玄幻-修真
         2 => 'junshi-xiaoshuo',       // 军史-小说
@@ -83,24 +72,56 @@ class CategoryModel extends MongoModel
     ];
 
 
+    /**
+     * get category of the novels
+     *
+     * @return array
+     */
     static public function getCategory(): array
     {
         return self::$arrCategory;
     }
 
+    /**
+     * get a category of  man's novels
+     *
+     * @return array
+     */
     static public function getManCategory(): array
     {
         return self::$arrMan;
     }
 
+    /**
+     * get a category of the woman novels
+     *
+     * @return array
+     */
     static public function getWomenCategory(): array
     {
         return self::$arrWomen;
     }
 
+    /**
+     * get pinyin based on chinese characters
+     *
+     * @param string $strZh
+     * @return string
+     */
     static public function getPinYinByZh(string $strZh)
     {
         $intKey = array_search($strZh, self::$arrCategory);
         return self::$arrCategoryPinYin[$intKey];
     }
+
+    /**
+     * determine the gender of the novel category
+     *
+     * @param string $strName
+     * @return string
+     */
+    static public function checkSex(string $strName): string
+    {
+        return in_array($strName, self::$arrMan) ? 'man' : 'women';
+    }
 }
diff --git a/code/app/model/ChapterModel.php b/code/app/model/ChapterModel.php
index f95ade6..7cbafc2 100644
--- a/code/app/model/ChapterModel.php
+++ b/code/app/model/ChapterModel.php
@@ -49,7 +49,7 @@ class ChapterModel extends MongoModel
      * @param array $arrSort
      * @return array
      */
-    public function getCommonNovelPageOnCache(
+    public function getCommonPageOnCache(
         string $strKey,
         array $arrFilter,
         int $intPage = 1,
@@ -149,7 +149,7 @@ class ChapterModel extends MongoModel
             $arrChapter['content'] = StorageCore::getInstance()->read($arrChapter['c_content_path']);
         }
 
-        return  $arrChapter;
+        return  $arrChapter??[];
     }
 
     /**
diff --git a/code/app/model/MongoModel.php b/code/app/model/MongoModel.php
index bc3c6c9..cd3980d 100644
--- a/code/app/model/MongoModel.php
+++ b/code/app/model/MongoModel.php
@@ -7,6 +7,7 @@ namespace app\model;
 use db\mongo\MongoBase;
 use ddl\DDLManage;
 use MongoDB\Collection;
+use think\facade\Cache;
 
 /**
  * @mixin think\Model
@@ -77,4 +78,41 @@ abstract class MongoModel
     {
         return $this->getCol()->findOne($arrFilter, $arrOptions);
     }
+
+    /**
+     * Undocumented function
+     *
+     * @param string $strKey
+     * @return array|object|NULL
+     */
+    public function checkCacheByKey(string $strKey): array|object|NULL
+    {
+
+        if (config('view.view_data_cache') == false) {
+            return NULL;
+        }
+
+        if (!empty($strKey)) {
+            $arrResult = Cache::get($strKey);
+            if (!empty($arrResult)) {
+                return  $arrResult;
+            }
+        }
+        return NULL;
+    }
+
+    /**
+     * Undocumented function
+     *
+     * @param string $strKey
+     * @param mixed $mixedData
+     * @param integer $intLifeTime
+     * @return void
+     */
+    public function setCacheByKey(string $strKey, mixed $mixedData, int $intLifeTime)
+    {
+        if (!empty($strKey) && !empty($mixedData)) {
+            Cache::set($strKey, $mixedData, $intLifeTime);
+        }
+    }
 }
diff --git a/code/app/model/NovelModel.php b/code/app/model/NovelModel.php
index 422e3ba..ecd5507 100644
--- a/code/app/model/NovelModel.php
+++ b/code/app/model/NovelModel.php
@@ -68,9 +68,8 @@ class NovelModel extends MongoModel
                 ['$set' => ['n_level' => $intLevel]]
             );
 
-            $intUpdateNum = $UpdateResult->getModifiedCount();
+            $UpdateResult->getModifiedCount();
         } catch (Exception $e) {
-
             return false;
         }
 
@@ -78,15 +77,13 @@ class NovelModel extends MongoModel
     }
 
     /**
-     * Undocumented function
+     * 直接读库查询大量小说
      *
      * @param integer $intNId
      * @return null|array
      */
-    public function getNovelAll(array $arrFilter, int $intCount = 10, array $arrSort =  []): null|array
+    public function getNovel(array $arrFilter, int $intCount = 10, array $arrSort =  []): null|array
     {
-        // $arrFilter = ['n_id' => $intNId, 'c_page' => 0];
-
         $arrOptions = self::$arrNovelOptions;
 
         $arrOptions['sort'] = $arrSort;
@@ -100,7 +97,6 @@ class NovelModel extends MongoModel
         $arrResult = iterator_to_array($Cursor);
 
         foreach ($arrResult as &$arrItem) {
-
             applyToKeys($arrItem, ['created_at', 'updated_at'], 'formatMongoDate');
         }
 
@@ -110,12 +106,12 @@ class NovelModel extends MongoModel
 
 
     /**
-     * Undocumented function
+     * 根据小说ID查询指定小说
      *
      * @param integer $intNId
      * @return array
      */
-    public function getNovelInfo(int $intNId): null|array
+    public function getNovelByNId(int $intNId): null|array
     {
         $arrFilter = ['n_id' => $intNId];
         $arrOptions = self::$arrNovelOptions;
@@ -131,7 +127,7 @@ class NovelModel extends MongoModel
 
 
     /**
-     * Undocumented function
+     * 查询符合条件的随机多条小说
      *
      * @param string $strKey
      * @param integer $intCount
@@ -143,42 +139,42 @@ class NovelModel extends MongoModel
     {
         try {
 
-            $arrResult = Cache::get($strKey);
-
-            // if (empty($arrResult)) {
-            if (true) {
-
-                $pipeline = [
-                    ['$match' => $arrFilter],
-                    ['$sample' => ['size' => $intCount]]
-                ];
-
-                $Novel = $this->getCol()->aggregate($pipeline);
-
-                $arrResult =  iterator_to_array($Novel);
-                if (!empty($arrResult)) {
-                    Cache::set($strKey, $arrResult, $intLifeTime);
-                }
+            $arrResult =  $this->checkCacheByKey($strKey);
+            if ($arrResult !== NULL) {
+                return $arrResult;
             }
 
+            $pipeline = [
+                ['$match' => $arrFilter],
+                ['$sample' => ['size' => $intCount]]
+            ];
+
+            $Novel = $this->getCol()->aggregate($pipeline);
+
+            $arrResult =  iterator_to_array($Novel);
+
+            $this->setCacheByKey($strKey, $arrResult, $intLifeTime);
+
             return $arrResult;
         } catch (\Exception $e) {
             return [];
         }
     }
 
+
     /**
-     * Undocumented function
+     * 用于Home下的书库分页
      *
      * @param string $strKey
+     * @param integer $intPage
+     * @param integer $intLimit
      * @param int $intLifeTime
-     * @param integer $intCount
      * @param integer $intType
      * @param string $strStatus
      * @param array $arrSort
      * @return array
      */
-    public function getCommonNovelPageOnCache(
+    public function getCustomPage01(
         string $strKey,
         int $intPage = 1,
         int $intLimit = 20,
@@ -186,71 +182,89 @@ class NovelModel extends MongoModel
         int $intType = 0,
         $strStatus = NULL,
         array $arrSort = ['n_level' => -1]
+    ): array {
+        $arrFilter = [];
+
+        switch ($intType) {
+            case 1:
+                $arrCategory = array_values(CategoryModel::getManCategory());
+                $arrFilter['og_novel_category'] = ['$in' => $arrCategory];
+                break;
+            case 2:
+                $arrCategory = array_values(CategoryModel::getWomenCategory());
+                $arrFilter['og_novel_category'] =  ['$in' => $arrCategory];
+                break;
+        }
+
+        if ($strStatus !== NULL) {
+            $arrFilter['og_novel_status'] = $strStatus;
+        }
+        return $this->getCommonPageOnCache($arrFilter, $intPage, $intLimit,  $arrSort, $strKey, $intLifeTime,);
+    }
+
+    /**
+     * 通用小说分页
+     *
+     * @param array $arrFilter
+     * @param integer $intPage
+     * @param integer $intLimit
+     * @param array $arrSort
+     * @param string $strKey
+     * @param int $intLifeTime
+     * @return array
+     */
+    public function getCommonPageOnCache(
+        array $arrFilter,
+        int $intPage = 1,
+        int $intLimit = 20,
+        array $arrSort = ['n_level' => -1],
+        string $strKey = '',
+        int $intLifeTime = 24 * 3600,
     ): array {
         try {
 
-            $arrResult = Cache::get($strKey);
-
-            // if (empty($arrResult)) {
-            if (true) {
-                $arrFilter = [];
-
-                switch ($intType) {
-                    case 1:
-                        $arrCategory = array_values(CategoryModel::getManCategory());
-                        $arrFilter['og_novel_category'] = ['$in' => $arrCategory];
-                        break;
-                    case 2:
-                        $arrCategory = array_values(CategoryModel::getWomenCategory());
-                        $arrFilter['og_novel_category'] =  ['$in' => $arrCategory];
-                        break;
-                }
-
-                if ($strStatus !== NULL) {
-                    $arrFilter['og_novel_status'] = $strStatus;
-                }
-
-                $arrOptions = [
-                    'sort' => $arrSort,
-                    // 'limit' => $intCount * 3,
-                    'skip' => ($intPage - 1) * $intLimit,
-                    'limit' => $intLimit,
-                    'projection' => [
-                        'n_id' => 1,
-                        'og_novel_book_name' => 1,
-                        'og_novel_pin_yin' => 1,
-                        'n_cover_path' => 1,
-                        'og_novel_author' => 1,
-                        'og_novel_category' => 1,
-                        'og_description' => 1,
-                        'og_novel_latest_chapter_name' => 1,
-                        'og_novel_update_time' => 1,
-                        'og_novel_status' => 1,
-                    ],
-                ];
-
-
-                $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
-
-                $intTotal =  $this->getCol()->countDocuments($arrFilter);
-
-                $arrResult = iterator_to_array($Cursor);
-
-                shuffle($arrResult);
-
-                $arrResult = [
-                    'data' => $arrResult,
-                    'total' => $intTotal,
-                    'page' => $intPage,
-                    'limit' => $intLimit,
-                    'pages' => ceil($intTotal / $intLimit)
-                ];
-
-                if (!empty($arrResult)) {
-                    Cache::set($strKey, $arrResult, $intLifeTime);
-                }
+            $arrResult = $this->checkCacheByKey($strKey);
+            if ($arrResult !== NULL) {
+                return  $arrResult;
             }
 
+            $arrOptions = [
+                'sort' => $arrSort,
+                'skip' => ($intPage - 1) * $intLimit,
+                'limit' => $intLimit,
+                'projection' => [
+                    'n_id' => 1,
+                    'og_novel_book_name' => 1,
+                    'og_novel_pin_yin' => 1,
+                    'n_cover_path' => 1,
+                    'og_novel_author' => 1,
+                    'og_novel_category' => 1,
+                    'og_description' => 1,
+                    'og_novel_latest_chapter_name' => 1,
+                    'og_novel_update_time' => 1,
+                    'og_novel_status' => 1,
+                ],
+            ];
+
+
+            $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
+
+            $intTotal =  $this->getCol()->countDocuments($arrFilter);
+
+            $arrResult = iterator_to_array($Cursor);
+
+            shuffle($arrResult);
+
+            $arrResult = [
+                'data' => $arrResult,
+                'total' => $intTotal,
+                'page' => $intPage,
+                'limit' => $intLimit,
+                'pages' => ceil($intTotal / $intLimit)
+            ];
+
+            $this->setCacheByKey($strKey, $arrResult, $intLifeTime);
+
             return $arrResult;
         } catch (\Exception $e) {
             return [];
@@ -279,56 +293,54 @@ class NovelModel extends MongoModel
     ): array {
         try {
 
-            $arrResult = Cache::get($strKey);
-
-            // if (empty($arrResult)) {
-            if (true) {
-                $arrFilter = [];
-
-                switch ($intType) {
-                    case 1:
-                        $arrCategory = array_values(CategoryModel::getManCategory());
-                        $arrFilter['og_novel_category'] = ['$in' => $arrCategory];
-                        break;
-                    case 2:
-                        $arrCategory = array_values(CategoryModel::getWomenCategory());
-                        $arrFilter['og_novel_category'] =  ['$in' => $arrCategory];
-                        break;
-                }
-
-                if ($strStatus !== NULL) {
-                    $arrFilter['og_novel_status'] = $strStatus;
-                }
-
-                $arrOptions = [
-                    'sort' => $arrSort,
-                    'limit' => $intCount * 3,
-                    'projection' => [
-                        'n_id' => 1,
-                        'og_novel_book_name' => 1,
-                        'og_novel_pin_yin' => 1,
-                        'n_cover_path' => 1,
-                        'og_novel_author' => 1,
-                        'og_novel_category' => 1,
-                        'og_description' => 1,
-                        'og_novel_latest_chapter_name' => 1,
-                        'og_novel_update_time' => 1,
-                        'og_novel_status' => 1,
-                    ],
-                ];
-
-                $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
-                $arrResult = iterator_to_array($Cursor);
-
-                shuffle($arrResult);
-
-                $arrResult = array_slice($arrResult, 0, $intCount);
-
-                if (!empty($arrResult)) {
-                    Cache::set($strKey, $arrResult, $intLifeTime);
-                }
+            $arrResult =  $this->checkCacheByKey($strKey);
+            if ($arrResult !== NULL) {
+                return $arrResult;
             }
 
+            $arrFilter = [];
+
+            switch ($intType) {
+                case 1:
+                    $arrCategory = array_values(CategoryModel::getManCategory());
+                    $arrFilter['og_novel_category'] = ['$in' => $arrCategory];
+                    break;
+                case 2:
+                    $arrCategory = array_values(CategoryModel::getWomenCategory());
+                    $arrFilter['og_novel_category'] =  ['$in' => $arrCategory];
+                    break;
+            }
+
+            if ($strStatus !== NULL) {
+                $arrFilter['og_novel_status'] = $strStatus;
+            }
+
+            $arrOptions = [
+                'sort' => $arrSort,
+                'limit' => $intCount * 3,
+                'projection' => [
+                    'n_id' => 1,
+                    'og_novel_book_name' => 1,
+                    'og_novel_pin_yin' => 1,
+                    'n_cover_path' => 1,
+                    'og_novel_author' => 1,
+                    'og_novel_category' => 1,
+                    'og_description' => 1,
+                    'og_novel_latest_chapter_name' => 1,
+                    'og_novel_update_time' => 1,
+                    'og_novel_status' => 1,
+                ],
+            ];
+
+            $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
+            $arrResult = iterator_to_array($Cursor);
+
+            shuffle($arrResult);
+
+            $arrResult = array_slice($arrResult, 0, $intCount);
+
+            $this->setCacheByKey($strKey, $arrResult, $intLifeTime);
+
             return $arrResult;
         } catch (\Exception $e) {
             return [];
@@ -352,54 +364,51 @@ class NovelModel extends MongoModel
 
             $intLifeTime = 24 * 3600;
 
-            $arrResult = Cache::get($strKey);
-
-            // if (empty($arrResult)) {
-            if (true) {
-                $arrFilter = [];
-
-                switch ($intType) {
-                    case 1:
-                        $arrCategory = array_values(CategoryModel::getManCategory());
-                        $arrFilter['og_novel_category'] = ['$in' => $arrCategory];
-                        break;
-                    case 2:
-                        $arrCategory = array_values(CategoryModel::getWomenCategory());
-                        $arrFilter['og_novel_category'] =  ['$in' => $arrCategory];
-                        break;
-                }
-
-                if ($strStatus !== NULL) {
-                    $arrFilter['og_novel_status'] = $strStatus;
-                }
-
-                $arrOptions = [
-                    'sort' => ['n_level' => -1],
-                    'limit' => $intCount * 3,
-                    'projection' => [
-                        'n_id' => 1,
-                        'og_novel_book_name' => 1,
-                        'og_novel_pin_yin' => 1,
-                        'n_cover_path' => 1,
-                        'n_novel_author' => 1,
-                        'og_novel_category' => 1,
-                        'og_description' => 1,
-                        'og_novel_status' => 1,
-                    ],
-                ];
-
-
-                $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
-                $arrResult = iterator_to_array($Cursor);
-
-                shuffle($arrResult);
-
-                $arrResult = array_slice($arrResult, 0, $intCount);
-
-                if (!empty($arrResult)) {
-                    Cache::set($strKey, $arrResult, $intLifeTime);
-                }
+            $arrResult =  $this->checkCacheByKey($strKey);
+            if ($arrResult !== NULL) {
+                return $arrResult;
             }
+            $this->setCacheByKey($strKey, $arrResult, $intLifeTime);
+
+            switch ($intType) {
+                case 1:
+                    $arrCategory = array_values(CategoryModel::getManCategory());
+                    $arrFilter['og_novel_category'] = ['$in' => $arrCategory];
+                    break;
+                case 2:
+                    $arrCategory = array_values(CategoryModel::getWomenCategory());
+                    $arrFilter['og_novel_category'] =  ['$in' => $arrCategory];
+                    break;
+            }
+
+            if ($strStatus !== NULL) {
+                $arrFilter['og_novel_status'] = $strStatus;
+            }
+
+            $arrOptions = [
+                'sort' => ['n_level' => -1],
+                'limit' => $intCount * 3,
+                'projection' => [
+                    'n_id' => 1,
+                    'og_novel_book_name' => 1,
+                    'og_novel_pin_yin' => 1,
+                    'n_cover_path' => 1,
+                    'n_novel_author' => 1,
+                    'og_novel_category' => 1,
+                    'og_description' => 1,
+                    'og_novel_status' => 1,
+                ],
+            ];
+
+
+            $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
+            $arrResult = iterator_to_array($Cursor);
+
+            shuffle($arrResult);
+
+            $arrResult = array_slice($arrResult, 0, $intCount);
+
+            $this->setCacheByKey($strKey, $arrResult, $intLifeTime);
 
             return $arrResult;
         } catch (\Exception $e) {
@@ -422,40 +431,37 @@ class NovelModel extends MongoModel
 
             $intLifeTime = 24 * 3600;
 
-            $arrResult = Cache::get($strKey);
-
-            // if (empty($arrResult)) {
-            if (true) {
-                $arrFilter = [
-                    'og_novel_status' => "已完结",
-                ];
-
-                $arrOptions = [
-                    'sort' => ['og_novel_update_time' => -1],
-                    'limit' => $intCount * 3,
-                    'projection' => [
-                        'n_id' => 1,
-                        'og_novel_book_name' => 1,
-                        'og_novel_pin_yin' => 1,
-                        'n_cover_path' => 1,
-                        'og_novel_author' => 1,
-                        'og_novel_category' => 1,
-                        'og_description' => 1,
-                        'og_novel_status' => 1,
-                    ],
-                ];
-
-                $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
-                $arrResult = iterator_to_array($Cursor);
-
-                shuffle($arrResult);
-
-                $arrResult = array_slice($arrResult, 0, $intCount);
-
-                if (!empty($arrResult)) {
-                    Cache::set($strKey, $arrResult, $intLifeTime);
-                }
+            $arrResult =  $this->checkCacheByKey($strKey);
+            if ($arrResult !== NULL) {
+                return $arrResult;
             }
+            $arrFilter = [
+                'og_novel_status' => "已完结",
+            ];
+
+            $arrOptions = [
+                'sort' => ['og_novel_update_time' => -1],
+                'limit' => $intCount * 3,
+                'projection' => [
+                    'n_id' => 1,
+                    'og_novel_book_name' => 1,
+                    'og_novel_pin_yin' => 1,
+                    'n_cover_path' => 1,
+                    'og_novel_author' => 1,
+                    'og_novel_category' => 1,
+                    'og_description' => 1,
+                    'og_novel_status' => 1,
+                ],
+            ];
+
+            $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
+            $arrResult = iterator_to_array($Cursor);
+
+            shuffle($arrResult);
+
+            $arrResult = array_slice($arrResult, 0, $intCount);
+
+            $this->setCacheByKey($strKey, $arrResult, $intLifeTime);
 
             return $arrResult;
         } catch (\Exception $e) {
@@ -479,52 +485,49 @@ class NovelModel extends MongoModel
 
             $intLifeTime = 24 * 3600;
 
-            $arrResult = Cache::get($strKey);
-
-            // if (empty($arrResult)) {
-            if (true) {
-                if ($intType == 1) {
-                    $arrCategory = array_values(CategoryModel::getManCategory());
-                    $arrFilter = [
-                        'og_novel_category' => ['$in' => $arrCategory]
-                    ];
-                } elseif ($intType == 2) {
-                    $arrCategory = array_values(CategoryModel::getWomenCategory());
-                    $arrFilter = [
-                        'og_novel_category' => ['$in' => $arrCategory]
-                    ];
-                } else {
-                    $arrFilter = [];
-                }
-
-                $arrOptions = [
-                    'sort' => ['og_novel_update_time' => -1],
-                    'limit' => $intCount * 3,
-                    'projection' => [
-                        'n_id' => 1,
-                        'og_novel_book_name' => 1,
-                        'og_novel_pin_yin' => 1,
-                        'n_cover_path' => 1,
-                        'og_novel_author' => 1,
-                        'og_novel_category' => 1,
-                        'og_description' => 1,
-                        'og_novel_update_time' => 1,
-                        'og_novel_latest_chapter_name' => 1,
-                        'og_novel_status' => 1,
-                    ],
-                ];
-
-                $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
-                $arrResult = iterator_to_array($Cursor);
-
-                shuffle($arrResult);
-
-                $arrResult = array_slice($arrResult, 0, $intCount);
-
-                if (!empty($arrResult)) {
-                    Cache::set($strKey, $arrResult, $intLifeTime);
-                }
+            $arrResult =  $this->checkCacheByKey($strKey);
+            if ($arrResult !== NULL) {
+                return $arrResult;
             }
+            if ($intType == 1) {
+                $arrCategory = array_values(CategoryModel::getManCategory());
+                $arrFilter = [
+                    'og_novel_category' => ['$in' => $arrCategory]
+                ];
+            } elseif ($intType == 2) {
+                $arrCategory = array_values(CategoryModel::getWomenCategory());
+                $arrFilter = [
+                    'og_novel_category' => ['$in' => $arrCategory]
+                ];
+            } else {
+                $arrFilter = [];
+            }
+
+            $arrOptions = [
+                'sort' => ['og_novel_update_time' => -1],
+                'limit' => $intCount * 3,
+                'projection' => [
+                    'n_id' => 1,
+                    'og_novel_book_name' => 1,
+                    'og_novel_pin_yin' => 1,
+                    'n_cover_path' => 1,
+                    'og_novel_author' => 1,
+                    'og_novel_category' => 1,
+                    'og_description' => 1,
+                    'og_novel_update_time' => 1,
+                    'og_novel_latest_chapter_name' => 1,
+                    'og_novel_status' => 1,
+                ],
+            ];
+
+            $Cursor = $this->getCol()->find($arrFilter, $arrOptions);
+            $arrResult = iterator_to_array($Cursor);
+
+            shuffle($arrResult);
+
+            $arrResult = array_slice($arrResult, 0, $intCount);
+
+            $this->setCacheByKey($strKey, $arrResult, $intLifeTime);
 
             return $arrResult;
         } catch (\Exception $e) {
@@ -554,74 +557,69 @@ class NovelModel extends MongoModel
 
             $intLifeTime = 24 * 3600;
 
-            $arrResult = Cache::get($strKey);
+            $arrResult =  $this->checkCacheByKey($strKey);
+            if ($arrResult !== NULL) {
+                return $arrResult;
+            }
+            $arrFilter = [
+                'nc_type' => $strDateType,
+            ];
 
-            // if (empty($arrResult)) {
-            if (true) {
-                $arrFilter = [
-                    'nc_type' => $strDateType,
-                ];
-
-                if ($strStatus !== NULL) {
-                    $arrFilter['og_novel_status'] = $strStatus;
-                }
-
-                if ($intType == 1) {
-                    $arrCategory = array_values(CategoryModel::getManCategory());
-                    $arrFilter['n_category'] = ['$in' => $arrCategory];
-                } elseif ($intType == 2) {
-                    $arrCategory = array_values(CategoryModel::getWomenCategory());
-                    $arrFilter['n_category'] = ['$in' => $arrCategory];
-                }
-
-
-                $arrOptions = [
-                    'sort' => ['nc_clicks' => -1],
-                    'limit' => $intCount * 3,
-                    'projection' => [
-                        'n_id' => 1,
-                    ],
-                ];
-
-                $NovelClicksModel = new NovelClicksModel;
-
-                $Cursor =  $NovelClicksModel->getCol()->find($arrFilter, $arrOptions);
-
-                $arrNId = [];
-                foreach ($Cursor as $Doc) {
-                    $arrNId[] = $Doc['n_id'];
-                }
-
-                $Cursor = $this->getCol()->find(
-                    ['n_id' => ['$in' => $arrNId]],
-                    [
-                        'projection' => [
-                            'n_id' => 1,
-                            'og_novel_book_name' => 1,
-                            'og_novel_pin_yin' => 1,
-                            'n_cover_path' => 1,
-                            'n_novel_author' => 1,
-                            'og_novel_category' => 1,
-                            'og_description' => 1, 
-                            'og_novel_status' => 1,
-                        ],
-                    ]
-                );
-     
-
-
-                $arrResult = iterator_to_array($Cursor);
-
-                shuffle($arrResult);
-
-                $arrResult = array_slice($arrResult, 0, $intCount);
-
-                if (!empty($arrResult)) {
-                    Cache::set($strKey, $arrResult, $intLifeTime);
-                }
+            if ($strStatus !== NULL) {
+                $arrFilter['og_novel_status'] = $strStatus;
             }
 
-            return $arrResult;
+            if ($intType == 1) {
+                $arrCategory = array_values(CategoryModel::getManCategory());
+                $arrFilter['n_category'] = ['$in' => $arrCategory];
+            } elseif ($intType == 2) {
+                $arrCategory = array_values(CategoryModel::getWomenCategory());
+                $arrFilter['n_category'] = ['$in' => $arrCategory];
+            }
+
+
+            $arrOptions = [
+                'sort' => ['nc_clicks' => -1],
+                'limit' => $intCount * 3,
+                'projection' => [
+                    'n_id' => 1,
+                ],
+            ];
+
+            $NovelClicksModel = new NovelClicksModel;
+
+            $Cursor =  $NovelClicksModel->getCol()->find($arrFilter, $arrOptions);
+
+            $arrNId = [];
+            foreach ($Cursor as $Doc) {
+                $arrNId[] = $Doc['n_id'];
+            }
+
+            $Cursor = $this->getCol()->find(
+                ['n_id' => ['$in' => $arrNId]],
+                [
+                    'projection' => [
+                        'n_id' => 1,
+                        'og_novel_book_name' => 1,
+                        'og_novel_pin_yin' => 1,
+                        'n_cover_path' => 1,
+                        'n_novel_author' => 1,
+                        'og_novel_category' => 1,
+                        'og_description' => 1,
+                        'og_novel_status' => 1,
+                    ],
+                ]
+            );
+
+            $arrResult = iterator_to_array($Cursor);
+
+            shuffle($arrResult);
+
+            $arrResult = array_slice($arrResult, 0, $intCount);
+
+            $this->setCacheByKey($strKey, $arrResult, $intLifeTime);
+
+            return    $arrResult;
         } catch (\Exception $e) {
             return [];
         }
@@ -643,22 +641,5 @@ class NovelModel extends MongoModel
             'strPinYin' => $intPinYin
         ]);
         return  (string)$strUrl;
-
-        // $Request = request();
-        // $strFomart = $Request->DomainModel->d_novel_info_url_fomart;
-
-        // return str_replace(
-        //     [
-        //         '{intNId}',
-        //         '{strPinYin}',
-        //     ],
-        //     [
-        //         $intNId,
-        //         $intPinYin
-        //     ],
-        //     $strFomart
-        // );
-
-        // return $strUrl;
     }
 }
diff --git a/code/config/view.php b/code/config/view.php
index f008513..d1ce0ca 100644
--- a/code/config/view.php
+++ b/code/config/view.php
@@ -31,8 +31,8 @@ return [
     'display_cache' => env('VIEW_DISPLAY_CACHE', false),
 
     // 是否开启模板编译缓存,设为false则每次都会重新编译
-    'tpl_cache' =>  env('VIEW_TPL_CACHE', true),
+    'tpl_cache' =>  env('VIEW_TPL_CACHE', false),
+
+    //页面数据缓存,实际是控制器数据缓存
+    'view_data_cache' =>  env('VIEW_DATA_CACHE', false),
 ];
-
-
-