This commit is contained in:
Default
2025-04-21 11:56:50 +08:00
parent 3216cffb5e
commit 65b8710bff
17 changed files with 2432 additions and 55 deletions

View File

@@ -216,6 +216,13 @@ class NovelService
'update' => '最新更新',
];
public $arrRankSortType = [
'daily' => '天',
'weekly' => '周',
'monthly' => '月',
'total' => '总',
];
public $arrStatus = [
'all' => '所有',
'lianzai' => '连载中',
@@ -234,18 +241,108 @@ class NovelService
*
* @return array
*/
public function getCategoryFilter(string $n_sex=''): array
public function getCategoryFilter(string $strNSex = ''): array
{
if($n_sex == 'man'){
if ($strNSex == 'man') {
return CategoryModel::$arrCategoryAll['man'];
}else if($n_sex == 'women'){
} else if ($strNSex == 'women') {
return CategoryModel::$arrCategoryAll['women'];
}else{
} else {
return array_combine(CategoryModel::$arrCategoryPinYin, CategoryModel::$arrCategory);
}
}
/**
* 获取排行榜小说
*
* @param array $arrParams
* @return array
*/
public function getRankList(array $arrParams): array
{
$intCount = (int)$arrParams['count'] ?? 10;
$strSortType = (string)$arrParams['sort_type'] ?? '';
$strNStatus = (string) $arrParams['n_status'] ?? '';
$strNSex = (string) $arrParams['n_sex'] ?? '';
$strDiffKey = (string) $arrParams['diff_key'] ?? '';
$intCacheLifeTime = (int)$arrParams['cache_life'] ?? 0;
$arrFilter = [];
# n_status filter
if (!empty($strNStatus)) {
switch ($strNStatus) {
case 'lianzai':
$arrFilter['n_status'] = $this->arrStatus[$strNStatus];
break;
case 'wanjie':
$arrFilter['n_status'] = $this->arrStatus[$strNStatus];
break;
}
}
# n_category_sex_zh filter
if (!empty($strNSex)) {
switch ($strNSex) {
case 'man':
$arrFilter['n_category_sex_zh'] = 1;
break;
case 'women':
$arrFilter['n_category_sex_zh'] = 2;
break;
}
}
$arrSort = [];
# sort filter
if (!empty($strSortType)) {
switch ($strSortType) {
case 'daily':
$arrSort['n_sort_type'] = 'daily';
break;
case 'weekly':
$arrSort['n_sort_type'] = 'weekly';
break;
case 'monthly':
$arrSort['n_sort_type'] = 'monthly';
break;
case 'total':
$arrSort['n_sort_type'] = 'total';
break;
}
}
$strCacheKey = '';
$intLifeTime = 0;
# cache filter
if ($intCacheLifeTime > 0) {
$strCacheKey = sprintf(
'NovelService:getRankList:%s:%s:%s:%s:%s',
$this->SiteContext->DomainModel->d_domain,
md5(serialize($arrFilter)),
md5(serialize($arrSort)),
$intCount,
$strDiffKey,
);
$intLifeTime = $intLifeTime;
}
$arrNovel = $this->NovelModel->getRankNovelOnCache(
$strCacheKey,
$intCount,
$arrFilter['n_category_sex_zh'] ?? 0,
$arrSort['n_sort_type'] ?? 'daily',
$arrFilter['n_status'] ?? NULL,
$intLifeTime,
);
return $arrNovel;
}
/**
* 获取小说数据
*
@@ -319,7 +416,7 @@ class NovelService
# cache filter
if ($intCacheLifeTime > 0) {
$strCacheKey = sprintf(
'Service:getNovelList:%s:%s:%s:%s:%s',
'NovelService:getNovelList:%s:%s:%s:%s:%s',
$this->SiteContext->DomainModel->d_domain,
md5(serialize($arrFilter)),
md5(serialize($arrSort)),
@@ -464,7 +561,7 @@ class NovelService
# cache filter
if ($intCacheLifeTime > 0) {
$strCacheKey = sprintf(
'Service:getNovelList:%s:%s:%s:%s:%s:%s',
'NovelService:getNovelList:%s:%s:%s:%s:%s:%s',
$this->SiteContext->DomainModel->d_domain,
md5(serialize($arrFilter)),
md5(serialize($arrSort)),
@@ -619,4 +716,7 @@ class NovelService
return $arrNovel;
}
}

View File

@@ -7,6 +7,9 @@ use app\model\DomainModel;
use app\model\GanRaoMaModel;
use app\model\TemplatesModel;
use app\model\CategoryModel;
use app\model\ChapterModel;
use app\model\NovelClicksModel;
use app\model\NovelModel;
use think\facade\Request;
use think\facade\Config;
use think\exception\HttpException;
@@ -35,9 +38,32 @@ class SiteContext
*/
public $TemplatesModel;
/**
* NovelModel
*
* @var NovelModel
*/
public $NovelModel;
/**
* ChapterModel
*
* @var ChapterModel
*/
public $ChapterModel;
/**
* NovelClicksModel
*
* @var NovelClicksModel
*/
public $NovelClicksModel;
public function __construct()
{
$this->Request = request();
$this->NovelModel = NovelModel::getInstance();
$this->ChapterModel = ChapterModel::getInstance();
$this->NovelClicksModel = NovelClicksModel::getInstance();
}
/**
@@ -81,32 +107,32 @@ class SiteContext
*/
public function initCfg()
{
// 全局使用的URL模板
$strPcUrlTemp = $this->DomainModel->getFomartSubject('PC_URL_PATH','',false);
$strNanUrlTemp = $this->DomainModel->getFomartSubject('NAN_SHENG_URL','',false);
$strNvUrlTemp = $this->DomainModel->getFomartSubject('NV_SHENG_URL','',false);
$strCategoryIndexUrlTemp = $this->DomainModel->getFomartSubject('CATEGORY_INDEX_URL','',false);
$strRankUrlTemp = $this->DomainModel->getFomartSubject('RANK_INFO_URL','',false);
$strSearchIndexUrlTemp = $this->DomainModel->getFomartSubject('SEARCH_INDEX_URL','',false);
$strHistoryUrlTemp = $this->DomainModel->getFomartSubject('HISTORY_INFO_URL','',false);
$strBookShelfUrlTemp = $this->DomainModel->getFomartSubject('SHUJIA_INFO_URL','',false);
$strUserUrlTemp = $this->DomainModel->getFomartSubject('USER_INFO_URL','',false);
// 全局使用的URL模板
$strPcUrlTemp = $this->DomainModel->getFomartSubject('PC_URL_PATH', '', false);
$strNanUrlTemp = $this->DomainModel->getFomartSubject('NAN_SHENG_URL', '', false);
$strNvUrlTemp = $this->DomainModel->getFomartSubject('NV_SHENG_URL', '', false);
$strCategoryIndexUrlTemp = $this->DomainModel->getFomartSubject('CATEGORY_INDEX_URL', '', false);
$strRankUrlTemp = $this->DomainModel->getFomartSubject('RANK_INFO_URL', '', false);
$strSearchIndexUrlTemp = $this->DomainModel->getFomartSubject('SEARCH_INDEX_URL', '', false);
$strHistoryUrlTemp = $this->DomainModel->getFomartSubject('HISTORY_INFO_URL', '', false);
$strBookShelfUrlTemp = $this->DomainModel->getFomartSubject('SHUJIA_INFO_URL', '', false);
$strUserUrlTemp = $this->DomainModel->getFomartSubject('USER_INFO_URL', '', false);
$strNanUrl = str_replace("/", "", $strNanUrlTemp);
$strNvUrl = str_replace("/", "", $strNvUrlTemp);
View::assign("strPcPath", $strPcUrlTemp);
View::assign("strNanUrlTemp", $strNanUrlTemp);
View::assign("strNvUrlTemp", $strNvUrlTemp);
View::assign("strNanUrl", $strNanUrl);
View::assign("strNvUrl", $strNvUrl);
View::assign("strCategoryIndexUrlTemp", $strCategoryIndexUrlTemp);
View::assign("strRankUrlTemp", $strRankUrlTemp);
View::assign("strSearchIndexUrlTemp", $strSearchIndexUrlTemp);
View::assign("strHistoryUrlTemp", $strHistoryUrlTemp);
View::assign("strBookShelfUrlTemp", $strBookShelfUrlTemp);
View::assign("strUserUrlTemp", $strUserUrlTemp);
View::assign("strPcPath", $strPcUrlTemp);
View::assign("strNanUrlTemp", $strNanUrlTemp);
View::assign("strNvUrlTemp", $strNvUrlTemp);
View::assign("strNanUrl", $strNanUrl);
View::assign("strNvUrl", $strNvUrl);
View::assign("strCategoryIndexUrlTemp", $strCategoryIndexUrlTemp);
View::assign("strRankUrlTemp", $strRankUrlTemp);
View::assign("strSearchIndexUrlTemp", $strSearchIndexUrlTemp);
View::assign("strHistoryUrlTemp", $strHistoryUrlTemp);
View::assign("strBookShelfUrlTemp", $strBookShelfUrlTemp);
View::assign("strUserUrlTemp", $strUserUrlTemp);
View::assign('Request', $this->Request);
View::assign('DomainModel', $this->DomainModel);
View::assign('TemplatesModel', $this->TemplatesModel);
@@ -166,14 +192,72 @@ class SiteContext
} else {
$strView = 'index/index.html';
}
}else{
} else {
if ($this->DomainModel->n_id > 0) {
$strView = 'pc/getNovelInfo.html';
} else {
$strView = 'pc/index.html';
}
}
return $strView;
}
/**
* 获取伪造小说列表
*
* @param array $arrParams
* @return array
*/
public function getForgeList(array $arrParams): array
{
$intCount = (int)$arrParams['count'] ?? 10;
$strDiffKey = (string) $arrParams['diff_key'] ?? '';
$intCacheLifeTime = (int)$arrParams['cache_life'] ?? 0;
$arrFilter = [
'n_forge_novel' => [
'$ne' => null, // 不为 null
'$ne' => '', // 不为空字符串
'$ne' => [], // 不为空数组
'$exists' => true // 确保字段存在
],
];
$strCacheKey = '';
$intLifeTime = 0;
# cache filter
if ($intCacheLifeTime > 0) {
$strCacheKey = sprintf(
'SiteContext:getForgeList:%s:%s:%s:%s',
$this->DomainModel->d_domain,
md5(serialize($arrFilter)),
$intCount,
$strDiffKey,
);
$intLifeTime = $intLifeTime;
}
$arrAllNovel = $this->NovelModel->getRandNovelWithCache(
$arrFilter,
$intCount,
$strCacheKey,
$intLifeTime,
);
$arrResult = [];
foreach ($arrAllNovel as $arrNovel) {
$arrResult[] = [
'n_id' => $arrNovel['n_id'],
'n_name_pinyin' => $arrNovel['n_name_pinyin'],
'n_forge_id' => $arrNovel['n_forge_novel'][0]->n_forge_id,
'n_forge_title' => $arrNovel['n_forge_novel'][0]->n_forge_title,
];
}
return $arrResult;
}
}