This commit is contained in:
Default
2025-04-18 16:02:44 +08:00
parent 7db551a21b
commit 3e4ec4b1cb
14 changed files with 829 additions and 44 deletions

View File

@@ -204,13 +204,13 @@ class Novel extends BaseController
$arrPage = $NovelModel->getCustomPage01($strKey, $intPage, $intLimit, $intLifeTime, $intGender, $strSearchStatus);
$strTemplate = '';
$intButtomNum = 5;
$intButtonNum = 5;
if ($boolIsMobile == false) {
$intButtomNum = 10;
$intButtonNum = 10;
$strTemplate = 'pc/getLibrary';
}
$arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtomNum);
$arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtonNum);
// 更新值
ConverterMovel::setVal([
@@ -855,13 +855,13 @@ class Novel extends BaseController
$arrPage = $ChapterModel->findPaginatedWithCache($arrFilter, $intPage, $intLimit, $arrSort, $strKey, $intLifeTime);
$intButtomNum = 5;
$intButtonNum = 5;
if ($boolIsMobile == false) {
$intButtomNum = 10;
$intButtonNum = 10;
}
$strBaseUrl = app(NovelService::class)->getNovelCatalogUrl($intNId, $arrNovel['n_name_pinyin'], $strOrder, '{page}');
$arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtomNum);
$arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtonNum);
// 更新值
ConverterMovel::setVal([
@@ -941,11 +941,11 @@ class Novel extends BaseController
$arrPage = $NovelModel->findPaginatedWithCache($arrFilter, $intPage, $intLimit, [], $strKey);
$intButtomNum = 10;
$intButtonNum = 10;
$strBaseUrl = app(NovelService::class)->getNovelSearchUrl($strSearchKeywords, '{page}');
$arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtomNum);
$arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtonNum);
// 更新值
ConverterMovel::setVal([

View File

@@ -1,8 +1,57 @@
{site:grm page_code="fdasfadsf" diff="fadsfdsa" num="10" g_key="arrGrm" /}
{php}var_dump($arrGrm);{/php}
<!-- {chapter:info n_id="1" c_sort_num="200" c_page="0" c_key="arrChapter01" /}
{$arrChapter01.c_name} -->
{novel:info n_id="33" n_key="arrNovel01" n_forge_id="1125940" /}
{$arrNovel01.n_name}
<!-- {chapter:pager page="1" limit="10" n_id="$Request.get.n_id" d_key="d_key" d_val="chapter" cache_life="1000" button_num="3" sort_type="dao" p_val="page_data" func="generateChapterPager"}
<li>
Index: {$d_key}
章节名称: {$chapter.c_name}
章节序号: {$chapter.c_sort_num}
</li>
{/chapter:pager}
{php}var_dump($page_data);{/php} -->
<!-- {chapter:list count="10" n_id="$Request.get.n_id" d_key="d_key" d_val="chapter" cache_life="1000"}
<li>
Index: {$d_key}
章节名称: {$chapter.c_name}
章节序号: {$chapter.c_sort_num}
</li>
{/chapter:list} -->
<!--
{novel:category d_key="key" d_val="val"}
<li>
键: {$key} - 值: {$val}
</li>
{/novel:category} -->
<!-- {novel:sex d_key="key" d_val="val"}
<li>
键: {$key} - 值: {$val}
</li>
{/novel:sex} -->
<!--
{novel:status d_key="key" d_val="val"}
<li>
键: {$key} - 值: {$val}
</li>
{/novel:status} -->
<!--
{novel:sort d_key="key" d_val="val"}
<li>
键: {$key} - 值: {$val}
</li>
{/novel:sort} -->
<!-- {novel:info n_id="33" n_key="arrNovel01" n_forge_id="1125940" /}
{$arrNovel01.n_name} -->
<!-- {$DomainModel->d_domain} -->

View File

@@ -97,6 +97,7 @@ class CategoryModel extends MongoModel
return self::$arrCategory;
}
/**
* Undocumented function
*

View File

@@ -209,6 +209,40 @@ class ChapterModel extends MongoModel
return $arrResult;
}
/**
* Undocumented function
*
* @param array $arrFilter
* @param integer $intCount
* @param array $arrSort
* @param array $arrOptions
* @param boolean $boolReadContent
* @return null|array
*/
public function findManyShuffledWithCache(
array $arrFilter,
int $intCount = 0,
array $arrSort = ['c_sort_num' => -1],
string $strKey = '',
int $intLifeTime = 24 * 3600,
bool $boolReadContent = false
): null|array {
$arrResult = $this->checkCacheByKey($strKey);
if ($arrResult !== NULL) {
return $arrResult;
}
if (empty($arrOptions)) {
$arrOptions = self::$arrChapterOptions;
}
$arrResult = $this->findMany($arrFilter, $intCount, $arrSort, [], $boolReadContent);
$this->setCacheByKey($strKey, $arrResult, $intLifeTime);
return $arrResult;
}
/**
* Undocumented function
*

View File

@@ -204,7 +204,7 @@ class GanRaoMaModel extends MongoModel
* @param string $strPageCode 视图编码
* @param string $strDifference 差异
* @param int $intNum 生成数量
* @return string
* @return array
*/
static public function getGrmCode($strDomain, $strPageCode, $strDifference, $intNum)
{

View File

@@ -149,7 +149,6 @@ class NovelModel extends MongoModel
}
}
/**
* find one novel
*

View File

@@ -3,6 +3,10 @@
namespace app\services;
use app\model\ChapterModel;
use app\model\ConverterMovel;
use app\model\NovelModel;
use template\page\CusteomPage02;
use think\facade\View;
class ChapterService
{
@@ -20,9 +24,259 @@ class ChapterService
*/
public $ChapterModel;
/**
* NovelModel
*
* @var NovelModel
*/
public $NovelModel;
public function __construct(SiteContext $SiteContext)
{
$this->SiteContext = $SiteContext;
$this->NovelModel = NovelModel::getInstance();
$this->ChapterModel = ChapterModel::getInstance();
}
public $arrSortType = [
'zheng' => '正序',
'dao' => '倒叙',
];
/**
* 获取小说数据
*
* @param array $arrParams
* @return array
*/
public function getChapterList(array $arrParams): array
{
$intCount = (int)$arrParams['count'] ?? 10;
$intNId = (int)$arrParams['n_id'] ?? 0;
$strSortType = (string)$arrParams['sort_type'] ?? '';
$strDiffKey = (string) $arrParams['diff_key'] ?? '';
$intCacheLifeTime = (int)$arrParams['cache_life'] ?? 0;
$arrFilter = [
'n_id' => $intNId,
'c_page' => 0,
];
$arrFilter['n_id'] = $intNId;
$arrSort = [];
# sort filter
if (!empty($strSortType)) {
switch ($strSortType) {
case 'zheng':
$arrSort['c_sort_num'] = 1;
break;
case 'dao':
$arrSort['c_sort_num'] = -1;
break;
}
}
$strCacheKey = '';
$intLifeTime = 0;
# cache filter
if ($intCacheLifeTime > 0) {
$strCacheKey = sprintf(
'ChapterService:getChapterList:%s:%s:%s:%s:%s',
$this->SiteContext->DomainModel->d_domain,
md5(serialize($arrFilter)),
md5(serialize($arrSort)),
$intCount,
$strDiffKey,
);
$intLifeTime = $intLifeTime;
}
$arrChapter = $this->ChapterModel->findManyShuffledWithCache(
$arrFilter,
$intCount,
$arrSort,
$strCacheKey,
$intLifeTime,
);
return $arrChapter;
}
/**
* 获取小说分页数据
*
* @param array $arrParams
* @return array
*/
public function getNovelPager(array $arrParams): array
{
$arrParams = [
'page' => max((int)($arrParams['page'] ?? 1), 1),
'limit' => (int)($arrParams['limit'] ?? 10),
'n_id' => (int)($arrParams['n_id'] ?? 0),
'button_num' => (int)($arrParams['button_num'] ?? 0),
'sort_type' => (string)($arrParams['sort_type'] ?? ''),
'diff_key' => (string)($arrParams['diff_key'] ?? ''),
'key' => (string)($arrParams['key'] ?? ''),
'cache_life' => (int)($arrParams['cache_life'] ?? 0),
'func' => (string)($arrParams['func']),
];
if (!in_array($arrParams['sort_type'], array_keys($this->arrSortType))) {
$arrParams['sort_type'] = 'zheng';
}
$intPage = $arrParams['page'];
$intLimit = $arrParams['limit'];
$intNId = $arrParams['n_id'];
$strSortType = $arrParams['sort_type'];
$strDiffKey = $arrParams['diff_key'];
$intCacheLifeTime = $arrParams['cache_life'];
$Func = $arrParams['func'];
if ($intPage <= 0) {
$intPage = 1;
}
$arrFilter = [
'$and' => [],
];
$arrFilter['$and'][] = ['n_id' => $intNId];
$arrFilter['$and'][] = ['c_page' => 0];
$arrSort = [];
# sort filter
if (!empty($strSortType)) {
switch ($strSortType) {
case 'zheng':
$arrSort['c_sort_num'] = 1;
break;
case 'dao':
$arrSort['c_sort_num'] = -1;
break;
}
}
$strCacheKey = '';
$intLifeTime = 0;
# cache filter
if ($intCacheLifeTime > 0) {
$strCacheKey = sprintf(
'Service:getNovelList:%s:%s:%s:%s:%s:%s',
$this->SiteContext->DomainModel->d_domain,
md5(serialize($arrFilter)),
md5(serialize($arrSort)),
$intPage,
$intLimit,
$strDiffKey,
);
$intLifeTime = $intLifeTime;
}
$arrNovel = $this->ChapterModel->findPaginatedWithCache(
$arrFilter,
$intPage,
$intLimit,
$arrSort,
$strCacheKey,
$intLifeTime,
);
$arrPager = call_user_func([$this, $Func], $arrParams, $arrSort, $arrNovel);
$arrResult = [
'data' => $arrNovel['data'],
'p_data' => $arrPager,
];
return $arrResult;
}
/**
* 根据NId获取小说详情
*
* @param integer $intNId
* @return void
*/
public function getChapterInfo(int $intNId, int $intCSortNum, int $intCPage)
{
// 小说详情
$arrNovel = $this->NovelModel->getNovelByNId($intNId);
// 章节
$ChapterModel = ChapterModel::getInstance();
$arrFilter = ['n_id' => $intNId, 'c_sort_num' => $intCSortNum, 'c_page' => $intCPage];
$arrChapter = $ChapterModel->findOne($arrFilter);
$strChapterDescription = '';
// 上一章节和下一章节
$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']);
// 要点-先从章节随机截取后面如果用上ai看看使用ai 提炼 精简内容
$strChapterDescription = strip_tags($arrChapter['c_content']);
$intCount = mb_strlen($strChapterDescription);
$strChapterDescription = ($intCount > 50) ? mb_substr($strChapterDescription, 0, 50) : $strChapterDescription;
$arrChapter['c_content'] = base64_encode($arrChapter['c_content']);
}
$arrChapter['pre_chapter'] = $arrPreChapter;
$arrChapter['next_chapter'] = $arrNextChapter;
// 更新值
ConverterMovel::setVal([
'intPage' => 1,
'strNovelName' => $arrNovel['n_name'],
'strNovelAuthor' => $arrNovel['n_author'],
'strNovelCategoryName' => $arrNovel['n_category'],
'strNovelStatus' => $arrNovel['n_status'],
'strNovelDescription' => $arrNovel['n_description'],
'strChapterDescription' => $strChapterDescription,
'strNovelChapterName' => $arrChapter['c_name'],
'strNovelChapterSort' => $arrChapter['c_sort_num'],
]);
return $arrChapter;
}
/**
* 搜索定制分页
*
* @param array $arrFilter 查询条件字段
* @param array $arrSort 查询排序字段
* @param array $arrChapter 查询出来的数据
* @return array
*/
public function generateChapterPager(array $arrParams, array $arrSort, array $arrChapter): array
{
$arrNovel = $this->NovelModel->getNovelByNId($arrParams['n_id']);
$intButtonNum = $arrParams['button_num'];
$intPage = $arrChapter['page'];
$intLimit = $arrChapter['limit'];
$strBaseUrl = app(NovelService::class)->getNovelCatalogUrl($arrParams['n_id'], $arrNovel['n_name_pinyin'], $arrParams['sort_type'], '{page}');
$arrPaginator = CusteomPage02::generate($intPage, $arrChapter['total'], $intLimit, $strBaseUrl, $intButtonNum);
return $arrPaginator;
}
}

View File

@@ -209,27 +209,36 @@ class NovelService
}
protected $arrSortType = [
public $arrSortType = [
'all' => '全部排序',
'news' => '最新入库',
'tuijian' => '推荐',
'update' => '最新更新',
];
protected $arrStatus = [
public $arrStatus = [
'all' => '所有',
'lianzai' => '连载中',
'wanjie' => '已完结',
];
protected $arrSex = [
public $arrSex = [
'all' => '所有',
'man' => '男生',
'women' => '女生',
];
/**
* GetCategoryFilter
*
* @return array
*/
public function getCategoryFilter(): array
{
return array_combine(CategoryModel::$arrCategoryPinYin, CategoryModel::$arrCategory);
}
/**
* 获取小说数据
*
@@ -511,14 +520,13 @@ class NovelService
// 小说详情
$arrNovel = $this->NovelModel->getNovelByNId($intNId);
if( $intNForgeId>0){
if ($intNForgeId > 0) {
foreach ($arrNovel['n_forge_novel'] as $arrForgeNovel) {
if ($arrForgeNovel['n_forge_id'] == $intNForgeId) {
$arrNovel['n_name'] = $arrForgeNovel['n_forge_title'];
break;
}
}
}
// 分类拼音

View File

@@ -4,6 +4,7 @@ namespace app\services;
use app\model\ConverterMovel;
use app\model\DomainModel;
use app\model\GanRaoMaModel;
use app\model\TemplatesModel;
use think\facade\Request;
use think\facade\Config;
@@ -109,4 +110,19 @@ class SiteContext
return ConverterMovel::convert($strTitleTemplate);
}
/**
* 获取干扰码
*
* @param string $strPageCode
* @param string $strDiff
* @param integer $intNum
* @return array
*/
public function generateGrm(string $strPageCode, string $strDiff, int $intNum): array
{
$strDomain = $this->DomainModel->d_domain;
return GanRaoMaModel::getGrmCode($strDomain, $strPageCode, $strDiff, $intNum);
}
}