优化代码
This commit is contained in:
@@ -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-]+',]);
|
||||
|
||||
|
||||
@@ -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 '<pre>';
|
||||
@@ -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'
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user