fix chapter page
This commit is contained in:
@@ -604,7 +604,32 @@ class Novel extends BaseController
|
||||
|
||||
$ChapterModel = new ChapterModel;
|
||||
|
||||
$strKey = sprintf('Nid:%s:Chapter-Page:%s:Order:%s', $intNId, $intPage, $strOrder);
|
||||
|
||||
$arrFilter = ['n_id' => $intNId, 'c_page' => 0,];
|
||||
$intLimit = 100;
|
||||
$intLifeTime = 12 * 3600;
|
||||
|
||||
if ($strOrder == 'zheng') {
|
||||
$arrSort = ['c_sort_num' => 1];
|
||||
} else {
|
||||
$arrSort = ['c_sort_num' => -1];
|
||||
}
|
||||
|
||||
$arrPage = $ChapterModel->getCommonNovelPageOnCache($strKey, $arrFilter, $intPage, $intLimit, $intLifeTime, $arrSort);
|
||||
|
||||
$intButtomNum = 5;
|
||||
if ($boolIsMobile == false) {
|
||||
$intButtomNum = 10;
|
||||
|
||||
}
|
||||
|
||||
$strBaseUrl = sprintf('/pc/xiaoshuo/%s-%s/mulu/%s/{page}', $arrNovel['og_novel_pin_yin'], $intNId, $strOrder);
|
||||
$arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtomNum);
|
||||
|
||||
// echo '<pre>';
|
||||
// print_r($arrPaginator);
|
||||
// exit;
|
||||
// 章节目录
|
||||
$arrChapter = [
|
||||
['c_sort_num' => 1, 'name' => '第1章', 'created_at' => '作者1'],
|
||||
@@ -614,7 +639,6 @@ class Novel extends BaseController
|
||||
['c_sort_num' => 1, 'name' => '第5章', 'created_at' => '作者1'],
|
||||
['c_sort_num' => 1, 'name' => '第6章', 'created_at' => '作者1'],
|
||||
|
||||
|
||||
];
|
||||
|
||||
View::assign([
|
||||
|
||||
@@ -36,6 +36,75 @@ class ChapterModel extends MongoModel
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $strKey
|
||||
* @param array $arrFilter
|
||||
* @param integer $intPage
|
||||
* @param integer $intLimit
|
||||
* @param integer $intLifeTime
|
||||
* @param array $arrSort
|
||||
* @return array
|
||||
*/
|
||||
public function getCommonNovelPageOnCache(
|
||||
string $strKey,
|
||||
array $arrFilter,
|
||||
int $intPage = 1,
|
||||
int $intLimit = 20,
|
||||
int $intLifeTime = 24 * 3600,
|
||||
array $arrSort = ['c_sort_num' => 1]
|
||||
): array {
|
||||
try {
|
||||
|
||||
$arrResult = Cache::get($strKey);
|
||||
|
||||
// if (empty($arrResult)) {
|
||||
if (true) {
|
||||
$arrOptions = self::$arrChapterOptions;
|
||||
|
||||
$arrOptions = array_merge($arrOptions, [
|
||||
'sort' => $arrSort,
|
||||
// 'limit' => $intCount * 3,
|
||||
'skip' => ($intPage - 1) * $intLimit,
|
||||
'limit' => $intLimit,
|
||||
]);
|
||||
|
||||
|
||||
$Cursor = $this->getCol()->find($arrFilter, $arrOptions);
|
||||
|
||||
$intTotal = $this->getCol()->countDocuments($arrFilter);
|
||||
|
||||
$arrResult = iterator_to_array($Cursor);
|
||||
|
||||
if (!empty($arrResult)) {
|
||||
foreach($arrResult as &$arrChapter){
|
||||
applyToKeys($arrChapter, ['created_at', 'updated_at'], 'formatMongoDate');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$arrResult = [
|
||||
'data' => $arrResult,
|
||||
'total' => $intTotal,
|
||||
'page' => $intPage,
|
||||
'limit' => $intLimit,
|
||||
'pages' => ceil($intTotal / $intLimit)
|
||||
];
|
||||
|
||||
if (!empty($arrResult)) {
|
||||
Cache::set($strKey, $arrResult, $intLifeTime);
|
||||
}
|
||||
}
|
||||
|
||||
return $arrResult;
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user