From 980ecedcf65449586270b02750b4d2869497d40c Mon Sep 17 00:00:00 2001 From: Default Date: Sat, 29 Mar 2025 22:48:43 +0800 Subject: [PATCH] debug --- code/app/home/config/router.php | 206 +++++++++++++++-------------- code/app/home/controller/Novel.php | 29 +++- code/app/model/NovelModel.php | 105 +++++++++++++-- 3 files changed, 222 insertions(+), 118 deletions(-) diff --git a/code/app/home/config/router.php b/code/app/home/config/router.php index 9329525..2d734e5 100644 --- a/code/app/home/config/router.php +++ b/code/app/home/config/router.php @@ -2,63 +2,65 @@ declare(strict_types=1); +use app\home\controller\Index; use app\home\controller\Novel; +use app\home\controller\User; use think\facade\Route; # 路由别名,可以忽略 // Route::alias("/index.html", "/")->append(['boolIsMobile' => true]); // Route::alias("/pc/index.html", "/")->append(['boolIsMobile' => false]); -Route::get("/", 'Index/index')->ext('html')->append(['boolIsMobile' => true]); -Route::get("/index", 'Index/index')->ext('html')->append(['boolIsMobile' => true]); -Route::get("/pc/index", 'Index/getPcIndex')->ext('html')->append(['boolIsMobile' => false]); -Route::get("/pc/", 'Index/getPcIndex')->append(['boolIsMobile' => false]); +Route::get("/", [Index::class,'index'])->ext('html')->append(['boolIsMobile' => true]); +Route::get("/index", [Index::class,'index'])->ext('html')->append(['boolIsMobile' => true]); +Route::get("/pc/index", [Index::class,'getPcIndex'])->ext('html')->append(['boolIsMobile' => false]); +Route::get("/pc/", [Index::class,'getPcIndex'])->append(['boolIsMobile' => false]); // 书架 -Route::get('bookshelf', 'User/getBookShelf')->ext('html')->append(['boolIsMobile' => true]); -Route::get('/pc/bookshelf', 'User/getBookShelf')->ext('html')->append(['boolIsMobile' => false]); +Route::get('bookshelf', [User::class,'getBookShelf'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('/pc/bookshelf', [User::class,'getBookShelf'])->ext('html')->append(['boolIsMobile' => false]); //排行榜 -Route::get('rank', 'Novel/getNovelRank')->ext('html')->append(['boolIsMobile' => true]); -Route::get("/pc/rank", 'Novel/getNovelRank')->ext('html')->append(['boolIsMobile' => false]); +Route::get('rank', [Novel::class,'getNovelRank'])->ext('html')->append(['boolIsMobile' => true]); +Route::get("/pc/rank", [Novel::class,'getNovelRank'])->ext('html')->append(['boolIsMobile' => false]); // 男生/女生 -Route::get('boy', 'Novel/getNovelChannel')->ext('html')->append(['boolIsMobile' => true, 'strChannel' => 'boys']); -Route::get('pc/boy', 'Novel/getNovelChannel')->ext('html')->append(['boolIsMobile' => false, 'strChannel' => 'boys']); -Route::get('girl', 'Novel/getNovelChannel')->ext('html')->append(['boolIsMobile' => true, 'strChannel' => 'girls']); -Route::get('pc/girl', 'Novel/getNovelChannel')->ext('html')->append(['boolIsMobile' => false, 'strChannel' => 'girls']); -Route::get('novel-boys-channel', 'Novel/getNovelChannel')->ext('html')->append(['boolIsMobile' => true, 'strChannel' => 'boys']); -Route::get('pc/novel-boys-channel', 'Novel/getNovelChannel')->ext('html')->append(['boolIsMobile' => false, 'strChannel' => 'boys']); -Route::get('novel-girls-channel', 'Novel/getNovelChannel')->ext('html')->append(['boolIsMobile' => true, 'strChannel' => 'girls']); -Route::get('pc/novel-girls-channel', 'Novel/getNovelChannel')->ext('html')->append(['boolIsMobile' => false, 'strChannel' => 'girls']); +Route::get('boy', [Novel::class,'getNovelChannel'])->ext('html')->append(['boolIsMobile' => true, 'strChannel' => 'boys']); +Route::get('pc/boy', [Novel::class,'getNovelChannel'])->ext('html')->append(['boolIsMobile' => false, 'strChannel' => 'boys']); +Route::get('girl', [Novel::class,'getNovelChannel'])->ext('html')->append(['boolIsMobile' => true, 'strChannel' => 'girls']); +Route::get('pc/girl', [Novel::class,'getNovelChannel'])->ext('html')->append(['boolIsMobile' => false, 'strChannel' => 'girls']); +Route::get('novel-boys-channel', [Novel::class,'getNovelChannel'])->ext('html')->append(['boolIsMobile' => true, 'strChannel' => 'boys']); +Route::get('pc/novel-boys-channel', [Novel::class,'getNovelChannel'])->ext('html')->append(['boolIsMobile' => false, 'strChannel' => 'boys']); +Route::get('novel-girls-channel', [Novel::class,'getNovelChannel'])->ext('html')->append(['boolIsMobile' => true, 'strChannel' => 'girls']); +Route::get('pc/novel-girls-channel', [Novel::class,'getNovelChannel'])->ext('html')->append(['boolIsMobile' => false, 'strChannel' => 'girls']); //分类 -Route::get('class', 'Novel/getNovelCategory')->ext('html')->append(['boolIsMobile' => true]); -Route::get('/pc/class', 'Novel/getNovelCategory')->ext('html')->append(['boolIsMobile' => false]); +Route::get('class', [Novel::class,'getNovelCategory'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('/pc/class', [Novel::class,'getNovelCategory'])->ext('html')->append(['boolIsMobile' => false]); //分类 使用模板:xmttxs -Route::get('books', 'Novel/getNovelCategory')->ext('html')->append(['boolIsMobile' => true]); -Route::get('/pc/books', 'Novel/getNovelCategory')->ext('html')->append(['boolIsMobile' => false]); -Route::get('/books/[:intCategoryId]-[:intPage]', 'Novel/getNovelCategory')->ext('html')->append(['boolIsMobile' => true]); -Route::get('/pc/books/[:intCategoryId]-[:intPage]', 'Novel/getNovelCategory')->ext('html')->append(['boolIsMobile' => false]); +Route::get('books', [Novel::class,'getNovelCategory'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('/pc/books', [Novel::class,'getNovelCategory'])->ext('html')->append(['boolIsMobile' => false]); +Route::get('/books/[:intCategoryId]-[:intPage]', [Novel::class,'getNovelCategory'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('/pc/books/[:intCategoryId]-[:intPage]', [Novel::class,'getNovelCategory'])->ext('html')->append(['boolIsMobile' => false]); // 书库 -Route::get('library', 'Novel/getLibrary')->ext('html')->append(['boolIsMobile' => true]); -Route::get("pc/library", 'Novel/getLibrary')->ext('html')->append(['boolIsMobile' => false]); -Route::get('shuku', 'Novel/getLibrary')->ext('html')->append(['boolIsMobile' => true]); -Route::get('pc/shuku', 'Novel/getLibrary')->ext('html')->append(['boolIsMobile' => false]); -Route::get('shuku/[:strNovelChannel]-[:intCategoryId]-[:strStatus]-[:strTextNumber]-[:strUpdateTime]-[:strSort]-[:intPage]', 'Novel/getLibrary')->ext('html')->append(['boolIsMobile' => true]); -Route::get('pc/shuku/[:strNovelChannel]-[:intCategoryId]-[:strStatus]-[:strTextNumber]-[:strUpdateTime]-[:strSort]-[:intPage]', 'Novel/getLibrary')->ext('html')->append(['boolIsMobile' => false]); +Route::get('library', [Novel::class,'getLibrary'])->ext('html')->append(['boolIsMobile' => true]); +Route::get("pc/library", [Novel::class,'getLibrary'])->ext('html')->append(['boolIsMobile' => false]); +Route::get('shuku', [Novel::class,'getLibrary'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('pc/shuku', [Novel::class,'getLibrary'])->ext('html')->append(['boolIsMobile' => false]); +Route::get('shuku/[:strNovelChannel]-[:intCategoryId]-[:strStatus]-[:strTextNumber]-[:strUpdateTime]-[:strSort]-[:intPage]', [Novel::class,'getLibrary'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('pc/shuku/[:strNovelChannel]-[:intCategoryId]-[:strStatus]-[:strTextNumber]-[:strUpdateTime]-[:strSort]-[:intPage]', [Novel::class,'getLibrary'])->ext('html')->append(['boolIsMobile' => false]); // 文章 列表 -Route::get('/article/list-[:intCategoryId]-[:intPage]', 'Novel/getArticleList')->ext('html')->append(['boolIsMobile' => true]); -Route::get('/pc/article/list-[:intCategoryId]-[:intPage]', 'Novel/getArticleList')->ext('html')->append(['boolIsMobile' => false]); -Route::get('/article/list', 'Novel/getArticleList')->ext('html')->append(['boolIsMobile' => true]); -Route::get('/pc/article/list', 'Novel/getArticleList')->ext('html')->append(['boolIsMobile' => false]); +Route::get('/article/list-[:intCategoryId]-[:intPage]', [Novel::class,'getArticleList'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('/pc/article/list-[:intCategoryId]-[:intPage]', [Novel::class,'getArticleList'])->ext('html')->append(['boolIsMobile' => false]); +Route::get('/article/list', [Novel::class,'getArticleList'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('/pc/article/list', [Novel::class,'getArticleList'])->ext('html')->append(['boolIsMobile' => false]); // 文章 详情 -Route::get('/article/info-:intArticleId', 'Novel/getArticleInfo')->ext('html')->append(['boolIsMobile' => true]); -Route::get('/pc/article/info-:intArticleId', 'Novel/getArticleInfo')->ext('html')->append(['boolIsMobile' => false]); +Route::get('/article/info-:intArticleId', [Novel::class,'getArticleInfo'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('/pc/article/info-:intArticleId', [Novel::class,'getArticleInfo'])->ext('html')->append(['boolIsMobile' => false]); // 小说详情 Route::get('/info/:intNovelId', [Novel::class, 'getNovelInfo'])->ext('html')->append(['boolIsMobile' => true]); @@ -93,27 +95,27 @@ Route::get('/pc/book-:name-:n_id', [Novel::class, 'getNovelInfo']) // 小说章节 -Route::get('chapter/:intNovelId-:intChapterId-[:intChapterPage]', 'Novel/getNovelChapter')->ext('html')->append(['boolIsMobile' => true]); -Route::get('/pc/chapter/:intNovelId-:intChapterId-[:intChapterPage]', 'Novel/getNovelChapter')->ext('html')->append(['boolIsMobile' => false]); +Route::get('chapter/:intNovelId-:intChapterId-[:intChapterPage]', [Novel::class,'getNovelChapter'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('/pc/chapter/:intNovelId-:intChapterId-[:intChapterPage]', [Novel::class,'getNovelChapter'])->ext('html')->append(['boolIsMobile' => false]); // 小说目录 -Route::get('/chapters/:intNovelId-[:intPage]-[:strSort]', 'Novel/getNovelChapterAll')->ext('html')->append(['boolIsMobile' => true]); -Route::get('pc/chapters/:intNovelId-[:intPage]-[:strSort]', 'Novel/getNovelChapterAll')->ext('html')->append(['boolIsMobile' => false]); -Route::get('/chapters', 'Novel/getNovelChapterAll')->ext('html')->append(['boolIsMobile' => true]); -Route::get('pc/chapters', 'Novel/getNovelChapterAll')->ext('html')->append(['boolIsMobile' => false]); +Route::get('/chapters/:intNovelId-[:intPage]-[:strSort]', [Novel::class,'getNovelChapterAll'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('pc/chapters/:intNovelId-[:intPage]-[:strSort]', [Novel::class,'getNovelChapterAll'])->ext('html')->append(['boolIsMobile' => false]); +Route::get('/chapters', [Novel::class,'getNovelChapterAll'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('pc/chapters', [Novel::class,'getNovelChapterAll'])->ext('html')->append(['boolIsMobile' => false]); // 搜索小说 -Route::get('search', 'Novel/getSearchNovel')->ext('html')->append(['boolIsMobile' => true]); -Route::get('pc/search', 'Novel/getSearchNovel')->ext('html')->append(['boolIsMobile' => false]); +Route::get('search', [Novel::class,'getSearchNovel'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('pc/search', [Novel::class,'getSearchNovel'])->ext('html')->append(['boolIsMobile' => false]); // 小说用户中心 -Route::get('/user', 'User/Index')->ext('html')->append(['boolIsMobile' => true]); -Route::get('/pc/user', 'User/Index')->ext('html')->append(['boolIsMobile' => false]); +Route::get('/user', [User::class,'Index'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('/pc/user', [User::class,'Index'])->ext('html')->append(['boolIsMobile' => false]); // 历史记录 -Route::get('history', 'User/getHistory')->ext('html')->append(['boolIsMobile' => true]); -Route::get('/pc/history', 'User/getHistory')->ext('html')->append(['boolIsMobile' => false]); +Route::get('history', [User::class,'getHistory'])->ext('html')->append(['boolIsMobile' => true]); +Route::get('/pc/history', [User::class,'getHistory'])->ext('html')->append(['boolIsMobile' => false]); @@ -148,112 +150,112 @@ Route::get('/pc/history', 'User/getHistory')->ext('html')->append(['boolIsMobile // $arrRoutes = [ // # 小说推荐 // [ -// 'class'=>'Novel/getRankList', +// 'class'=>[Novel::class,'getRankList'], // 'name'=>'Novel@getTuijianList', // 'path'=>[ -// '/tj/:intTjdj-[:intPage]', -// '/tuijian/:intTjdj-[:intPage]', -// '/recommend/:intTjdj-[:intPage]', -// '/nice/:intTjdj-[:intPage]', -// '/good/:intTjdj-[:intPage]', -// '/推荐/:intTjdj-[:intPage]', +// [::class,'tj/:intTjdj-[:intPage]'], +// [::class,'tuijian/:intTjdj-[:intPage]'], +// [::class,'recommend/:intTjdj-[:intPage]'], +// [::class,'nice/:intTjdj-[:intPage]'], +// [::class,'good/:intTjdj-[:intPage]'], +// [::class,'推荐/:intTjdj-[:intPage]'], // ], // ], // # 小说分类 // [ -// 'class'=>'Novel/getCategoryList', +// 'class'=>[Novel::class,'getCategoryList'], // 'name'=>'Novel@getCategoryList', // 'path'=>[ -// '/list/:intCId-:intSort-:intStatus-[:intPage]', -// '/fenlei/:intCId-:intSort-:intStatus-[:intPage]', -// '/class/:intCId-:intSort-:intStatus-[:intPage]', -// '/type/:intCId-:intSort-:intStatus-[:intPage]', -// '/leixin/:intCId-:intSort-:intStatus-[:intPage]', -// '/小说分类/:intCId-:intSort-:intStatus-[:intPage]', +// [::class,'list/:intCId-:intSort-:intStatus-[:intPage]'], +// [::class,'fenlei/:intCId-:intSort-:intStatus-[:intPage]'], +// [::class,'class/:intCId-:intSort-:intStatus-[:intPage]'], +// [::class,'type/:intCId-:intSort-:intStatus-[:intPage]'], +// [::class,'leixin/:intCId-:intSort-:intStatus-[:intPage]'], +// [::class,'小说分类/:intCId-:intSort-:intStatus-[:intPage]'], // ], // ], // # 小说排行 // [ -// 'class'=>'Novel/getNovelRankList', +// 'class'=>[Novel::class,'getNovelRankList'], // 'name'=>'Novel@getNovelRankList', // 'path'=>[ -// '/paihang/:intCId-:intSort-[:intPage]', -// '/paihanbang/:intCId-:intSort-[:intPage]', -// '/rank/:intCId-:intSort-[:intPage]', -// '/sort/:intCId-:intSort-[:intPage]', -// '/pb/:intCId-:intSort-[:intPage]', -// '/排行榜/:intCId-:intSort-[:intPage]', +// [::class,'paihang/:intCId-:intSort-[:intPage]'], +// [::class,'paihanbang/:intCId-:intSort-[:intPage]'], +// [::class,'rank/:intCId-:intSort-[:intPage]'], +// [::class,'sort/:intCId-:intSort-[:intPage]'], +// [::class,'pb/:intCId-:intSort-[:intPage]'], +// [::class,'排行榜/:intCId-:intSort-[:intPage]'], // ], // ], // # 小说章节 // [ -// 'class'=>'Novel/getReader', +// 'class'=>[Novel::class,'getReader'], // 'name'=>'Novel@getReader', // 'path'=>[ -// '/xq/:intNovelId/:intZhangJiePaiXu-[:strSort]', -// '/xiaoshuo/:intNovelId/:intZhangJiePaiXu-[:strSort]', -// '/novel/:intNovelId/:intZhangJiePaiXu-[:strSort]', -// '/info/:intNovelId/:intZhangJiePaiXu-[:strSort]', -// '/shu/:intNovelId/:intZhangJiePaiXu-[:strSort]', -// '/小说/:intNovelId/:intZhangJiePaiXu-[:strSort]', +// [::class,'xq/:intNovelId/:intZhangJiePaiXu-[:strSort]'], +// [::class,'xiaoshuo/:intNovelId/:intZhangJiePaiXu-[:strSort]'], +// [::class,'novel/:intNovelId/:intZhangJiePaiXu-[:strSort]'], +// [::class,'info/:intNovelId/:intZhangJiePaiXu-[:strSort]'], +// [::class,'shu/:intNovelId/:intZhangJiePaiXu-[:strSort]'], +// [::class,'小说/:intNovelId/:intZhangJiePaiXu-[:strSort]'], -// '/book/:intNovelId/:intZhangJiePaiXu-[:strSort]', -// '/kan/:intNovelId/:intZhangJiePaiXu-[:strSort]', -// '/show/:intNovelId/:intZhangJiePaiXu-[:strSort]', -// '/yuedu/:intNovelId/:intZhangJiePaiXu-[:strSort]', -// '/see/:intNovelId/:intZhangJiePaiXu-[:strSort]', -// '/相关/:intNovelId/:intZhangJiePaiXu-[:strSort]', +// [::class,'book/:intNovelId/:intZhangJiePaiXu-[:strSort]'], +// [::class,'kan/:intNovelId/:intZhangJiePaiXu-[:strSort]'], +// [::class,'show/:intNovelId/:intZhangJiePaiXu-[:strSort]'], +// [::class,'yuedu/:intNovelId/:intZhangJiePaiXu-[:strSort]'], +// [::class,'see/:intNovelId/:intZhangJiePaiXu-[:strSort]'], +// [::class,'相关/:intNovelId/:intZhangJiePaiXu-[:strSort]'], // ], // ], // # 小说详情 // [ -// 'class'=>'Novel/getDetail', +// 'class'=>[Novel::class,'getDetail'], // 'name'=>'Novel@getDetail', // 'path'=>[ -// '/xq/:intNovelId-[:intCurrentPage]-[:strSort]', -// '/xiaoshuo/:intNovelId-[:intCurrentPage]-[:strSort]', -// '/novel/:intNovelId-[:intCurrentPage]-[:strSort]', -// '/info/:intNovelId-[:intCurrentPage]-[:strSort]', -// '/shu/:intNovelId-[:intCurrentPage]-[:strSort]', -// '/小说/:intNovelId-[:intCurrentPage]-[:strSort]', +// [::class,'xq/:intNovelId-[:intCurrentPage]-[:strSort]'], +// [::class,'xiaoshuo/:intNovelId-[:intCurrentPage]-[:strSort]'], +// [::class,'novel/:intNovelId-[:intCurrentPage]-[:strSort]'], +// [::class,'info/:intNovelId-[:intCurrentPage]-[:strSort]'], +// [::class,'shu/:intNovelId-[:intCurrentPage]-[:strSort]'], +// [::class,'小说/:intNovelId-[:intCurrentPage]-[:strSort]'], -// '/book/:intNovelId-[:intCurrentPage]-[:strSort]', -// '/kan/:intNovelId-[:intCurrentPage]-[:strSort]', -// '/show/:intNovelId-[:intCurrentPage]-[:strSort]', -// '/yuedu/:intNovelId-[:intCurrentPage]-[:strSort]', -// '/see/:intNovelId-[:intCurrentPage]-[:strSort]', -// '/相关/:intNovelId-[:intCurrentPage]-[:strSort]', +// [::class,'book/:intNovelId-[:intCurrentPage]-[:strSort]'], +// [::class,'kan/:intNovelId-[:intCurrentPage]-[:strSort]'], +// [::class,'show/:intNovelId-[:intCurrentPage]-[:strSort]'], +// [::class,'yuedu/:intNovelId-[:intCurrentPage]-[:strSort]'], +// [::class,'see/:intNovelId-[:intCurrentPage]-[:strSort]'], +// [::class,'相关/:intNovelId-[:intCurrentPage]-[:strSort]'], // ], // ], // # 搜索 - 小说 // [ -// 'class'=>'Search/getNovel', +// [class'=>'Search::class,'getNovel'], // 'name'=>'Search@getNovel', // 'path'=>[ -// '/search', +// [::class,'search'], // ], // ], // # 书架 // [ -// 'class'=>'Search/getShujia', -// 'name'=>'Search/getShujia', +// [class'=>'Search::class,'getShujia'], +// [name'=>'Search::class,'getShujia'], // 'path'=>[ -// '/shujia', +// [::class,'shujia'], // ], // ], // # 收藏 // [ -// 'class'=>'Search/addSc', -// 'name'=>'Search/addSc', +// [class'=>'Search::class,'addSc'], +// [name'=>'Search::class,'addSc'], // 'path'=>[ -// '/sc', +// [::class,'sc'], // ], // ], // ]; -// // Route::get('/sc', 'Novel/addSc') +// // Route::get('/sc', [Novel::class,'addSc']) // // ->middleware('Throttle:5,60') // 限制 1 分钟内最多 5 次 // // ->name('Novel@addSc'); diff --git a/code/app/home/controller/Novel.php b/code/app/home/controller/Novel.php index e4d95ba..ec6ec0a 100644 --- a/code/app/home/controller/Novel.php +++ b/code/app/home/controller/Novel.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace app\home\controller; use app\home\BaseController; +use app\model\NovelModel; use storage\StorageCore; use think\facade\View; use app\Request; @@ -175,13 +176,27 @@ class Novel extends BaseController } } - // 男生女生频道 + /** + * 男生女生频道 + * + * @param Request $Request + * @return void + */ public function getNovelChannel(Request $Request) { $boolIsMobile = $Request->param('boolIsMobile'); $strNovelChannel = $Request->param('strChannel'); // 区分男生/女生频道 + $NovelModel = new NovelModel; + $intType = ['boys' => 1, 'girls' => 2][$strNovelChannel]; + $intLifeTime = 24 * 3600; + // 模拟数据-推荐等级为9的,连载的,男生频道/女生频道, 随机12个小说 + $strKey = sprintf('%s:PC:Novel:Channel:Hot:%s:%s', $Request->DomainModel->d_domain, $intType, 'Serialized'); + $intCount = 12; + $strStuatus = '连载中'; + + $arrRecommendSerializationNovel = $NovelModel->getCommonNovelOnCache($strKey, $intLifeTime, $intCount, $intType, $strStuatus); $arrRecommendSerializationNovel = [ ['id' => 1, 'name' => '小说1', 'author' => '作者1'], ['id' => 2, 'name' => '小说2', 'author' => '作者2'], @@ -197,6 +212,11 @@ class Novel extends BaseController ['id' => 12, 'name' => '小说3', 'author' => '作者3'], ]; // 模拟数据-推荐等级为9的,完结的,男生频道/女生频道, 随机8个小说 + $strKey = sprintf('%s:PC:Novel:Channel:Hot:%s:%s', $Request->DomainModel->d_domain, $intType, 'Finish'); + $intCount = 8; + $strStuatus = '完结'; + + $arrRecommendEndNovel = $NovelModel->getCommonNovelOnCache($strKey, $intLifeTime, $intCount, $intType, $strStuatus); $arrRecommendEndNovel = [ ['id' => 1, 'name' => '小说1', 'author' => '作者1'], ['id' => 2, 'name' => '小说2', 'author' => '作者2'], @@ -210,6 +230,9 @@ class Novel extends BaseController ]; // 模拟数据-最近更新-随机50 + $strKey = sprintf('%s:PC:Novel:Channel:Latest:%s', $Request->DomainModel->d_domain, $intType); + $intCount = 20; + $arrNewsUpdateNovel = $NovelModel->getCommonNovelOnCache($strKey, $intLifeTime, $intCount, $intType, NULL, ['og_novel_update_time' => -1]); $arrNewsUpdateNovel = [ ['id' => 1, 'name' => '小说1', 'author' => '作者1'], ['id' => 2, 'name' => '小说2', 'author' => '作者2'], @@ -248,7 +271,7 @@ class Novel extends BaseController } // 分类 - public function getNovelCategory(Request $Request,$intCategoryId = null ,$intPage = 1) + public function getNovelCategory(Request $Request, $intCategoryId = null, $intPage = 1) { $boolIsMobile = $Request->param('boolIsMobile'); $strChannel = $Request->param('strChannel'); // 区分男生 / 女生频道 @@ -386,7 +409,7 @@ class Novel extends BaseController } // 小说章节-所有章节 - public function getNovelChapterAll(Request $Request,$intNovelId=null,$intPage=1,$strSort='asc') + public function getNovelChapterAll(Request $Request, $intNovelId = null, $intPage = 1, $strSort = 'asc') { $boolIsMobile = $Request->param('boolIsMobile'); // 模拟数据 diff --git a/code/app/model/NovelModel.php b/code/app/model/NovelModel.php index c9e5b55..ad06778 100644 --- a/code/app/model/NovelModel.php +++ b/code/app/model/NovelModel.php @@ -53,6 +53,82 @@ class NovelModel extends MongoModel return true; } + /** + * Undocumented function + * + * @param string $strKey + * @param int $intLifeTime + * @param integer $intCount + * @param integer $intType + * @param string $strStatus + * @param array $arrSort + * @return array + */ + public function getCommonNovelOnCache( + string $strKey, + int $intLifeTime = 24 * 3600, + int $intCount = 10, + int $intType = 0, + $strStatus = NULL, + array $arrSort = ['n_level' => -1] + ): 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, + 'n_novel_author' => 1, + 'og_novel_category' => 1, + 'og_description' => 1, + 'og_novel_latest_chapter_name' => 1, + 'og_novel_update_time' => 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); + } + } + + return $arrResult; + } catch (\Exception $e) { + return []; + } + } + /** * Undocumented function @@ -63,7 +139,7 @@ class NovelModel extends MongoModel * @param integer $intLevel * @return array */ - public function getHighLevelNovelOnCache(string $strSign, int $intCount = 10, int $intType = 0): array + public function getHighLevelNovelOnCache(string $strSign, int $intCount = 10, int $intType = 0, $strStatus = NULL): array { try { $strKey = sprintf('%s:PC:HOME:FIRST', $strSign); @@ -74,18 +150,21 @@ class NovelModel extends MongoModel // 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 = []; + $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 = [