优化代码
This commit is contained in:
@@ -55,4 +55,5 @@ STORAGE_LOCAL_DIR = /mnt/gluster
|
|||||||
|
|
||||||
# VIEW
|
# VIEW
|
||||||
VIEW_DISPLAY_CACHE = false
|
VIEW_DISPLAY_CACHE = false
|
||||||
VIEW_TPL_CACHE = false
|
VIEW_TPL_CACHE = false
|
||||||
|
VIEW_DATA_CACHE = false
|
||||||
@@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
use think\facade\Cache;
|
||||||
|
|
||||||
|
use function MongoDB\object;
|
||||||
|
|
||||||
function getUriByUrl($strUrl)
|
function getUriByUrl($strUrl)
|
||||||
{
|
{
|
||||||
@@ -852,11 +855,12 @@ namespace {
|
|||||||
function applyToKeys(null|array &$arrData, array $arrKeys, callable $Callback)
|
function applyToKeys(null|array &$arrData, array $arrKeys, callable $Callback)
|
||||||
{
|
{
|
||||||
if (empty($arrData)) return;
|
if (empty($arrData)) return;
|
||||||
|
|
||||||
foreach ($arrKeys as $strKey) {
|
foreach ($arrKeys as $strKey) {
|
||||||
if (key_exists($strKey, $arrData)) {
|
if (key_exists($strKey, $arrData)) {
|
||||||
$arrData[$strKey] = $Callback($arrData[$strKey]);
|
$arrData[$strKey] = $Callback($arrData[$strKey]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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])
|
->append(['boolIsMobile' => false, 'intUriType' => 1])
|
||||||
->pattern(['n_id' => '\d+', 'name' => '[\w-]+',]);
|
->pattern(['n_id' => '\d+', 'name' => '[\w-]+',]);
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ class Novel extends BaseController
|
|||||||
|
|
||||||
|
|
||||||
$NovelModel = new NovelModel;
|
$NovelModel = new NovelModel;
|
||||||
$arrPage = $NovelModel->getCommonNovelPageOnCache($strKey, $intPage, $intLimit, $intLifeTime, $intGender, $strSearchStatus);
|
$arrPage = $NovelModel->getCustomPage01($strKey, $intPage, $intLimit, $intLifeTime, $intGender, $strSearchStatus);
|
||||||
|
|
||||||
|
|
||||||
$strTemplate = '';
|
$strTemplate = '';
|
||||||
@@ -211,7 +211,7 @@ class Novel extends BaseController
|
|||||||
// 推荐等级为9的,完结的,男生频道/女生频道, 随机8个小说
|
// 推荐等级为9的,完结的,男生频道/女生频道, 随机8个小说
|
||||||
$strKey = sprintf('%s:PC:Novel:Channel:Hot:%s:%s', $Request->DomainModel->d_domain, $intType, 'Finish');
|
$strKey = sprintf('%s:PC:Novel:Channel:Hot:%s:%s', $Request->DomainModel->d_domain, $intType, 'Finish');
|
||||||
$intCount = 8;
|
$intCount = 8;
|
||||||
$strStuatus = '完结';
|
$strStuatus = '已完结';
|
||||||
|
|
||||||
$arrRecommendEndNovel = $NovelModel->getCommonNovelOnCache($strKey, $intLifeTime, $intCount, $intType, $strStuatus);
|
$arrRecommendEndNovel = $NovelModel->getCommonNovelOnCache($strKey, $intLifeTime, $intCount, $intType, $strStuatus);
|
||||||
|
|
||||||
@@ -331,7 +331,7 @@ class Novel extends BaseController
|
|||||||
$NovelModel = new NovelModel;
|
$NovelModel = new NovelModel;
|
||||||
|
|
||||||
// 小说详情
|
// 小说详情
|
||||||
$arrNovel = $NovelModel->getNovelInfo($intNId);
|
$arrNovel = $NovelModel->getNovelByNId($intNId);
|
||||||
|
|
||||||
// 分品拼音
|
// 分品拼音
|
||||||
$arrNovel['category_pinyin'] = CategoryModel::getPinYinByZh($arrNovel['og_novel_category']);
|
$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');
|
$arrRelateveNId = array_column($arrNovel['n_related_novel'], 'n_id');
|
||||||
|
|
||||||
$arrRelateveNovel = $NovelModel->getNovelAll([
|
$arrRelateveNovel = $NovelModel->getNovel([
|
||||||
'$in' => $arrRelateveNId,
|
'$in' => $arrRelateveNId,
|
||||||
], 10);
|
], 10);
|
||||||
|
|
||||||
@@ -408,7 +408,7 @@ class Novel extends BaseController
|
|||||||
$NovelModel = new NovelModel;
|
$NovelModel = new NovelModel;
|
||||||
|
|
||||||
// 小说详情
|
// 小说详情
|
||||||
$arrNovel = $NovelModel->getNovelInfo($intNId);
|
$arrNovel = $NovelModel->getNovelByNId($intNId);
|
||||||
|
|
||||||
// 分品拼音
|
// 分品拼音
|
||||||
$arrNovel['category_pinyin'] = CategoryModel::getPinYinByZh($arrNovel['og_novel_category']);
|
$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');
|
$arrRelateveNId = array_column($arrNovel['n_related_novel'], 'n_id');
|
||||||
|
|
||||||
$arrRelateveNovel = $NovelModel->getNovelAll([
|
$arrRelateveNovel = $NovelModel->getNovel([
|
||||||
'$in' => $arrRelateveNId,
|
'$in' => $arrRelateveNId,
|
||||||
], 10);
|
], 10);
|
||||||
// echo '<pre>';
|
// echo '<pre>';
|
||||||
@@ -478,7 +478,7 @@ class Novel extends BaseController
|
|||||||
* @param Request $Request
|
* @param Request $Request
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function getNovelNewsChapter(Request $Request)
|
public function getNovelLatestChapter(Request $Request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$boolIsMobile = $Request->param('boolIsMobile');
|
$boolIsMobile = $Request->param('boolIsMobile');
|
||||||
@@ -487,15 +487,20 @@ class Novel extends BaseController
|
|||||||
|
|
||||||
// 小说详情
|
// 小说详情
|
||||||
$NovelModel = new NovelModel;
|
$NovelModel = new NovelModel;
|
||||||
$arrNovel = $NovelModel->getNovelInfo($intNId);
|
$arrNovel = $NovelModel->getNovelByNId($intNId);
|
||||||
|
|
||||||
// 最新章节
|
// 最新章节
|
||||||
$ChapterModel = new ChapterModel;
|
$ChapterModel = new ChapterModel;
|
||||||
$arrChapter = $ChapterModel->getLatestChapter($intNId);
|
$arrChapter = $ChapterModel->getLatestChapter($intNId);
|
||||||
|
|
||||||
// 上一章节和下一章节
|
// 上一章节和下一章节
|
||||||
$arrPreChapter = $ChapterModel->getPreChapter($arrChapter['n_id'], $arrChapter['c_sort_num'], $arrChapter['c_page']);
|
$arrPreChapter = $arrNextChapter = [];
|
||||||
$arrNextChapter = $ChapterModel->getNextChapter($arrChapter['n_id'], $arrChapter['c_sort_num'], $arrChapter['c_page']);
|
|
||||||
|
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;
|
$arrCategoryAll = CategoryModel::$arrCategoryAll;
|
||||||
|
|
||||||
@@ -520,6 +525,17 @@ class Novel extends BaseController
|
|||||||
'arrNewsNovel' => $arrNewsNovel,
|
'arrNewsNovel' => $arrNewsNovel,
|
||||||
'strPageCode' => 'boy'
|
'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) {
|
if ($boolIsMobile) {
|
||||||
return View::fetch('getNovelChapter');
|
return View::fetch('getNovelChapter');
|
||||||
} else {
|
} else {
|
||||||
@@ -544,7 +560,7 @@ class Novel extends BaseController
|
|||||||
// 小说详情
|
// 小说详情
|
||||||
$NovelModel = new NovelModel;
|
$NovelModel = new NovelModel;
|
||||||
$intNId = $intNovelId;
|
$intNId = $intNovelId;
|
||||||
$arrNovel = $NovelModel->getNovelInfo($intNId);
|
$arrNovel = $NovelModel->getNovelByNId($intNId);
|
||||||
|
|
||||||
// 章节
|
// 章节
|
||||||
$ChapterModel = new ChapterModel;
|
$ChapterModel = new ChapterModel;
|
||||||
@@ -597,7 +613,7 @@ class Novel extends BaseController
|
|||||||
// 小说详情
|
// 小说详情
|
||||||
$NovelModel = new NovelModel;
|
$NovelModel = new NovelModel;
|
||||||
$intNId = $intNovelId;
|
$intNId = $intNovelId;
|
||||||
$arrNovel = $NovelModel->getNovelInfo($intNId);
|
$arrNovel = $NovelModel->getNovelByNId($intNId);
|
||||||
|
|
||||||
$ChapterModel = new ChapterModel;
|
$ChapterModel = new ChapterModel;
|
||||||
|
|
||||||
@@ -613,7 +629,7 @@ class Novel extends BaseController
|
|||||||
$arrSort = ['c_sort_num' => -1];
|
$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;
|
$intButtomNum = 5;
|
||||||
if ($boolIsMobile == false) {
|
if ($boolIsMobile == false) {
|
||||||
@@ -652,8 +668,6 @@ class Novel extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小说-搜索
|
* 小说-搜索
|
||||||
*
|
*
|
||||||
@@ -664,6 +678,35 @@ class Novel extends BaseController
|
|||||||
{
|
{
|
||||||
$boolIsMobile = $Request->param('boolIsMobile');
|
$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 = [
|
$arrSearchNovel = [
|
||||||
['id' => 1, 'name' => '小说1', 'author' => '作者1'],
|
['id' => 1, 'name' => '小说1', 'author' => '作者1'],
|
||||||
@@ -677,6 +720,8 @@ class Novel extends BaseController
|
|||||||
];
|
];
|
||||||
|
|
||||||
View::assign([
|
View::assign([
|
||||||
|
'strKeywords' => $strKeywords,
|
||||||
|
'intPage' => $intPage,
|
||||||
'arrSearchNovel' => $arrSearchNovel,
|
'arrSearchNovel' => $arrSearchNovel,
|
||||||
'strPageCode' => 'search'
|
'strPageCode' => 'search'
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -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 = [
|
static $arrCategoryPinYin = [
|
||||||
1 => 'xuanhuan-xiuzhen', // 玄幻-修真
|
1 => 'xuanhuan-xiuzhen', // 玄幻-修真
|
||||||
2 => 'junshi-xiaoshuo', // 军史-小说
|
2 => 'junshi-xiaoshuo', // 军史-小说
|
||||||
@@ -83,24 +72,56 @@ class CategoryModel extends MongoModel
|
|||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get category of the novels
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
static public function getCategory(): array
|
static public function getCategory(): array
|
||||||
{
|
{
|
||||||
return self::$arrCategory;
|
return self::$arrCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a category of man's novels
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
static public function getManCategory(): array
|
static public function getManCategory(): array
|
||||||
{
|
{
|
||||||
return self::$arrMan;
|
return self::$arrMan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a category of the woman novels
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
static public function getWomenCategory(): array
|
static public function getWomenCategory(): array
|
||||||
{
|
{
|
||||||
return self::$arrWomen;
|
return self::$arrWomen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get pinyin based on chinese characters
|
||||||
|
*
|
||||||
|
* @param string $strZh
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
static public function getPinYinByZh(string $strZh)
|
static public function getPinYinByZh(string $strZh)
|
||||||
{
|
{
|
||||||
$intKey = array_search($strZh, self::$arrCategory);
|
$intKey = array_search($strZh, self::$arrCategory);
|
||||||
return self::$arrCategoryPinYin[$intKey];
|
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';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class ChapterModel extends MongoModel
|
|||||||
* @param array $arrSort
|
* @param array $arrSort
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getCommonNovelPageOnCache(
|
public function getCommonPageOnCache(
|
||||||
string $strKey,
|
string $strKey,
|
||||||
array $arrFilter,
|
array $arrFilter,
|
||||||
int $intPage = 1,
|
int $intPage = 1,
|
||||||
@@ -149,7 +149,7 @@ class ChapterModel extends MongoModel
|
|||||||
$arrChapter['content'] = StorageCore::getInstance()->read($arrChapter['c_content_path']);
|
$arrChapter['content'] = StorageCore::getInstance()->read($arrChapter['c_content_path']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $arrChapter;
|
return $arrChapter??[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace app\model;
|
|||||||
use db\mongo\MongoBase;
|
use db\mongo\MongoBase;
|
||||||
use ddl\DDLManage;
|
use ddl\DDLManage;
|
||||||
use MongoDB\Collection;
|
use MongoDB\Collection;
|
||||||
|
use think\facade\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mixin think\Model
|
* @mixin think\Model
|
||||||
@@ -77,4 +78,41 @@ abstract class MongoModel
|
|||||||
{
|
{
|
||||||
return $this->getCol()->findOne($arrFilter, $arrOptions);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,9 +68,8 @@ class NovelModel extends MongoModel
|
|||||||
['$set' => ['n_level' => $intLevel]]
|
['$set' => ['n_level' => $intLevel]]
|
||||||
);
|
);
|
||||||
|
|
||||||
$intUpdateNum = $UpdateResult->getModifiedCount();
|
$UpdateResult->getModifiedCount();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,15 +77,13 @@ class NovelModel extends MongoModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* 直接读库查询大量小说
|
||||||
*
|
*
|
||||||
* @param integer $intNId
|
* @param integer $intNId
|
||||||
* @return null|array
|
* @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 = self::$arrNovelOptions;
|
||||||
|
|
||||||
$arrOptions['sort'] = $arrSort;
|
$arrOptions['sort'] = $arrSort;
|
||||||
@@ -100,7 +97,6 @@ class NovelModel extends MongoModel
|
|||||||
$arrResult = iterator_to_array($Cursor);
|
$arrResult = iterator_to_array($Cursor);
|
||||||
|
|
||||||
foreach ($arrResult as &$arrItem) {
|
foreach ($arrResult as &$arrItem) {
|
||||||
|
|
||||||
applyToKeys($arrItem, ['created_at', 'updated_at'], 'formatMongoDate');
|
applyToKeys($arrItem, ['created_at', 'updated_at'], 'formatMongoDate');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,12 +106,12 @@ class NovelModel extends MongoModel
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* 根据小说ID查询指定小说
|
||||||
*
|
*
|
||||||
* @param integer $intNId
|
* @param integer $intNId
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getNovelInfo(int $intNId): null|array
|
public function getNovelByNId(int $intNId): null|array
|
||||||
{
|
{
|
||||||
$arrFilter = ['n_id' => $intNId];
|
$arrFilter = ['n_id' => $intNId];
|
||||||
$arrOptions = self::$arrNovelOptions;
|
$arrOptions = self::$arrNovelOptions;
|
||||||
@@ -131,7 +127,7 @@ class NovelModel extends MongoModel
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* 查询符合条件的随机多条小说
|
||||||
*
|
*
|
||||||
* @param string $strKey
|
* @param string $strKey
|
||||||
* @param integer $intCount
|
* @param integer $intCount
|
||||||
@@ -143,42 +139,42 @@ class NovelModel extends MongoModel
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$arrResult = Cache::get($strKey);
|
$arrResult = $this->checkCacheByKey($strKey);
|
||||||
|
if ($arrResult !== NULL) {
|
||||||
// if (empty($arrResult)) {
|
return $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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$pipeline = [
|
||||||
|
['$match' => $arrFilter],
|
||||||
|
['$sample' => ['size' => $intCount]]
|
||||||
|
];
|
||||||
|
|
||||||
|
$Novel = $this->getCol()->aggregate($pipeline);
|
||||||
|
|
||||||
|
$arrResult = iterator_to_array($Novel);
|
||||||
|
|
||||||
|
$this->setCacheByKey($strKey, $arrResult, $intLifeTime);
|
||||||
|
|
||||||
return $arrResult;
|
return $arrResult;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* 用于Home下的书库分页
|
||||||
*
|
*
|
||||||
* @param string $strKey
|
* @param string $strKey
|
||||||
|
* @param integer $intPage
|
||||||
|
* @param integer $intLimit
|
||||||
* @param int $intLifeTime
|
* @param int $intLifeTime
|
||||||
* @param integer $intCount
|
|
||||||
* @param integer $intType
|
* @param integer $intType
|
||||||
* @param string $strStatus
|
* @param string $strStatus
|
||||||
* @param array $arrSort
|
* @param array $arrSort
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getCommonNovelPageOnCache(
|
public function getCustomPage01(
|
||||||
string $strKey,
|
string $strKey,
|
||||||
int $intPage = 1,
|
int $intPage = 1,
|
||||||
int $intLimit = 20,
|
int $intLimit = 20,
|
||||||
@@ -186,71 +182,89 @@ class NovelModel extends MongoModel
|
|||||||
int $intType = 0,
|
int $intType = 0,
|
||||||
$strStatus = NULL,
|
$strStatus = NULL,
|
||||||
array $arrSort = ['n_level' => -1]
|
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 {
|
): array {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$arrResult = Cache::get($strKey);
|
$arrResult = $this->checkCacheByKey($strKey);
|
||||||
|
if ($arrResult !== NULL) {
|
||||||
// if (empty($arrResult)) {
|
return $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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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;
|
return $arrResult;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return [];
|
return [];
|
||||||
@@ -279,56 +293,54 @@ class NovelModel extends MongoModel
|
|||||||
): array {
|
): array {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$arrResult = Cache::get($strKey);
|
$arrResult = $this->checkCacheByKey($strKey);
|
||||||
|
if ($arrResult !== NULL) {
|
||||||
// if (empty($arrResult)) {
|
return $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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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;
|
return $arrResult;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return [];
|
return [];
|
||||||
@@ -352,54 +364,51 @@ class NovelModel extends MongoModel
|
|||||||
|
|
||||||
$intLifeTime = 24 * 3600;
|
$intLifeTime = 24 * 3600;
|
||||||
|
|
||||||
$arrResult = Cache::get($strKey);
|
$arrResult = $this->checkCacheByKey($strKey);
|
||||||
|
if ($arrResult !== NULL) {
|
||||||
// if (empty($arrResult)) {
|
return $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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$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;
|
return $arrResult;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -422,40 +431,37 @@ class NovelModel extends MongoModel
|
|||||||
|
|
||||||
$intLifeTime = 24 * 3600;
|
$intLifeTime = 24 * 3600;
|
||||||
|
|
||||||
$arrResult = Cache::get($strKey);
|
$arrResult = $this->checkCacheByKey($strKey);
|
||||||
|
if ($arrResult !== NULL) {
|
||||||
// if (empty($arrResult)) {
|
return $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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$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;
|
return $arrResult;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -479,52 +485,49 @@ class NovelModel extends MongoModel
|
|||||||
|
|
||||||
$intLifeTime = 24 * 3600;
|
$intLifeTime = 24 * 3600;
|
||||||
|
|
||||||
$arrResult = Cache::get($strKey);
|
$arrResult = $this->checkCacheByKey($strKey);
|
||||||
|
if ($arrResult !== NULL) {
|
||||||
// if (empty($arrResult)) {
|
return $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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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;
|
return $arrResult;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -554,74 +557,69 @@ class NovelModel extends MongoModel
|
|||||||
|
|
||||||
$intLifeTime = 24 * 3600;
|
$intLifeTime = 24 * 3600;
|
||||||
|
|
||||||
$arrResult = Cache::get($strKey);
|
$arrResult = $this->checkCacheByKey($strKey);
|
||||||
|
if ($arrResult !== NULL) {
|
||||||
|
return $arrResult;
|
||||||
|
}
|
||||||
|
$arrFilter = [
|
||||||
|
'nc_type' => $strDateType,
|
||||||
|
];
|
||||||
|
|
||||||
// if (empty($arrResult)) {
|
if ($strStatus !== NULL) {
|
||||||
if (true) {
|
$arrFilter['og_novel_status'] = $strStatus;
|
||||||
$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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
} catch (\Exception $e) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -643,22 +641,5 @@ class NovelModel extends MongoModel
|
|||||||
'strPinYin' => $intPinYin
|
'strPinYin' => $intPinYin
|
||||||
]);
|
]);
|
||||||
return (string)$strUrl;
|
return (string)$strUrl;
|
||||||
|
|
||||||
// $Request = request();
|
|
||||||
// $strFomart = $Request->DomainModel->d_novel_info_url_fomart;
|
|
||||||
|
|
||||||
// return str_replace(
|
|
||||||
// [
|
|
||||||
// '{intNId}',
|
|
||||||
// '{strPinYin}',
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// $intNId,
|
|
||||||
// $intPinYin
|
|
||||||
// ],
|
|
||||||
// $strFomart
|
|
||||||
// );
|
|
||||||
|
|
||||||
// return $strUrl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ return [
|
|||||||
'display_cache' => env('VIEW_DISPLAY_CACHE', false),
|
'display_cache' => env('VIEW_DISPLAY_CACHE', false),
|
||||||
|
|
||||||
// 是否开启模板编译缓存,设为false则每次都会重新编译
|
// 是否开启模板编译缓存,设为false则每次都会重新编译
|
||||||
'tpl_cache' => env('VIEW_TPL_CACHE', true),
|
'tpl_cache' => env('VIEW_TPL_CACHE', false),
|
||||||
|
|
||||||
|
//页面数据缓存,实际是控制器数据缓存
|
||||||
|
'view_data_cache' => env('VIEW_DATA_CACHE', false),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user