This commit is contained in:
make
2025-04-21 17:47:12 +08:00
parent 24cef96a26
commit 7ef217c1b9
523 changed files with 0 additions and 93250 deletions

View File

@@ -1,28 +0,0 @@
<?php
namespace app\services;
use app\model\CategoryModel;
class CategoryService
{
/**
* SiteContext
*
* @var SiteContext
*/
public $SiteContext;
/**
* CategoryModel
*
* @var CategoryModel
*/
public $CategoryModel;
public function __construct(SiteContext $SiteContext)
{
$this->SiteContext = $SiteContext;
$this->CategoryModel = CategoryModel::getInstance();
}
}

View File

@@ -1,291 +0,0 @@
<?php
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
{
/**
* SiteContext
*
* @var SiteContext
*/
public $SiteContext;
/**
* ChapterModel
*
* @var ChapterModel
*/
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;
if (empty($arrFilter['$and'])) {
$arrFilter = [];
}
# 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;
}
$arrChapter = $this->ChapterModel->findPaginatedWithCache(
$arrFilter,
$intPage,
$intLimit,
$arrSort,
$strCacheKey,
$intLifeTime,
);
$arrPager = call_user_func([$this, $Func], $arrParams, $arrSort, $arrChapter);
$arrPager = $arrChapter;
unset($arrPager['data']);
$arrPager['pager'] = call_user_func([$this, $Func], $arrParams, $arrSort, $arrChapter);
$arrResult = [
'data' => $arrChapter['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;
// var_dump($arrChapter['c_name']);exit;
// 更新值
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

@@ -1,722 +0,0 @@
<?php
namespace app\services;
use app\model\CategoryModel;
use app\model\ChapterModel;
use app\model\ConverterMovel;
use app\model\DomainModel;
use app\model\NovelClicksModel;
use app\model\NovelModel;
use template\page\CusteomPage02;
class NovelService
{
/**
* SiteContext
*
* @var SiteContext
*/
public $SiteContext;
/**
* NovelModel
*
* @var NovelModel
*/
public $NovelModel;
/**
* ChapterModel
*
* @var ChapterModel
*/
public $ChapterModel;
/**
* NovelClicksModel
*
* @var NovelClicksModel
*/
public $NovelClicksModel;
public function __construct(SiteContext $SiteContext)
{
$this->SiteContext = $SiteContext;
$this->NovelModel = NovelModel::getInstance();
$this->ChapterModel = ChapterModel::getInstance();
$this->NovelClicksModel = NovelClicksModel::getInstance();
}
/**
* Undocumented function
*
* @param array $arrArgs
* @return string
*/
public function getPageUrl($strKey, array $arrArgs,): string
{
$strSfVal = $this->SiteContext->DomainModel->getFomartSubject($strKey, '', false);
$arrKeys = [];
$arrVals = [];
foreach ($arrArgs as $strKey => $strVal) {
$arrKeys[] = '{' . $strKey . '}';
$arrVals[] = $strVal;
}
return str_replace($arrKeys, $arrVals, $strSfVal);
}
/**
* Undocumented function
*
* @param int $intNId
* @param string $intPinYin
* @return string
*/
public function getNovelInfoUrl($intNId, $intPinYin): string
{
$strKey = 'NOVEL_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
'intNId' => $intNId,
'strPinYin' => $intPinYin
]);
return (string)$strUrl;
}
/**
* Undocumented function
* 伪造小说
* @param int $intNId
* @param string $intPinYin
* @return string
*/
public function getForgeNovelInfoUrl($intNId, $intPinYin, $intNForgeId): string
{
$strKey = 'KAN_NOVEL_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
'intNId' => $intNId,
'strPinYin' => $intPinYin,
'intNForgeId' => $intNForgeId,
]);
return (string)$strUrl;
}
/**
* Undocumented function
*
* @param int $intNId
* @param int $intPinYin
* @param int $intChapterSort
* @param integer $intChapterPage
* @return string
*/
public function getNovelChapterUrl(int $intNId, $intPinYin, $intChapterSort, $intChapterPage = 0): string
{
$strKey = 'CONTENT_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
'intNId' => $intNId,
'strPinYin' => $intPinYin,
'intChapterSort' => $intChapterSort,
'intChapterPage' => $intChapterPage,
]);
return (string)$strUrl;
}
/**
* Undocumented function
*
* @param int $intNId
* @param string $intPinYin
* @return string
*
*/
public function getNovelLasterChapterUrl($intNId, $intPinYin): string
{
$strKey = 'NEWS_CONTENT_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
'intNId' => $intNId,
'strPinYin' => $intPinYin,
]);
return (string)$strUrl;
}
/**
* 小说分类/书库
* Undocumented function
*
* @param [type] $strGender
* @param [type] $strCategory
* @param [type] $strStatus
* @param [type] $strOrder
* @param [type] $intPage
* @return string
*/
public function getNovelCategoryUrl($strGender, $strCategory, $strStatus, $strOrder, $intPage): string
{
$strKey = 'CATEGORY_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
'strGender' => $strGender ?? 'all',
'strCategory' => $strCategory ?? 'all',
'strStatus' => $strStatus ?? 'all',
'strOrder' => $strOrder ?? 'all',
'intPage' => $intPage ?? 1,
]);
$strUrl = preg_replace('#/{2,}#', '/', $strUrl);
return (string)$strUrl;
}
/**
* Undocumented function
* 小说目录
* @param int $intNId
* @param string $intPinYin
* @return string
*
*/
public function getNovelCatalogUrl($intNId, $intPinYin, $strOrder, $intPage = 1): string
{
$strKey = 'NOVEL_CATALOG_URL';
$strUrl = $this->getPageUrl($strKey, [
'intNId' => $intNId,
'strPinYin' => $intPinYin,
'strOrder' => $strOrder,
'intPage' => $intPage,
]);
return (string)$strUrl;
}
/**
* Undocumented function
*
* @param int $intPage
* @param string $strKeyWords
* @return string
*/
public function getNovelSearchUrl($strKeyWords, $intPage = 1): string
{
$strKey = 'SEARCH_INFO_URL';
$strUrl = $this->getPageUrl($strKey, [
'intPage' => $intPage,
'strSearchKeywords' => $strKeyWords
]);
return (string)$strUrl;
}
public $arrSortType = [
'all' => '全部排序',
'news' => '最新入库',
'tuijian' => '推荐',
'update' => '最新更新',
];
public $arrRankSortType = [
'daily' => '天',
'weekly' => '周',
'monthly' => '月',
'total' => '总',
];
public $arrStatus = [
'all' => '所有',
'lianzai' => '连载中',
'wanjie' => '已完结',
];
public $arrSex = [
'all' => '所有',
'man' => '男生',
'women' => '女生',
];
/**
* GetCategoryFilter
*
* @return array
*/
public function getCategoryFilter(string $strNSex = ''): array
{
if ($strNSex == 'man') {
return CategoryModel::$arrCategoryAll['man'];
} else if ($strNSex == 'women') {
return CategoryModel::$arrCategoryAll['women'];
} 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;
}
/**
* 获取小说数据
*
* @param array $arrParams
* @return array
*/
public function getNovelList(array $arrParams): array
{
$intCount = (int)$arrParams['count'] ?? 10;
$strNCategory = $arrParams['n_category'] ?? '';
$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_category filter
if (!empty($strNCategory)) {
$strNCategory = CategoryModel::getZhByPinYin($strNCategory);
if ($strNCategory) {
$arrFilter['n_category'] = $strNCategory;
}
}
# 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'] = $this->arrSex[$strNSex];
break;
case 'women':
$arrFilter['n_category_sex_zh'] = $this->arrSex[$strNSex];
break;
}
}
$arrSort = [];
# sort filter
if (!empty($strSortType)) {
switch ($strSortType) {
case 'news':
$arrSort['created_at'] = -1;
break;
case 'tuijian':
$arrSort['n_level'] = -1;
break;
case 'update':
$arrSort['n_update_time'] = -1;
break;
}
}
$strCacheKey = '';
$intLifeTime = 0;
# cache filter
if ($intCacheLifeTime > 0) {
$strCacheKey = sprintf(
'NovelService:getNovelList:%s:%s:%s:%s:%s',
$this->SiteContext->DomainModel->d_domain,
md5(serialize($arrFilter)),
md5(serialize($arrSort)),
$intCount,
$strDiffKey,
);
$intLifeTime = $intLifeTime;
}
$arrNovel = $this->NovelModel->findManyShuffledWithCache(
$arrFilter,
$intCount,
$arrSort,
$strCacheKey,
$intLifeTime,
);
return $arrNovel;
}
/**
* 获取小说分页数据
*
* @param array $arrParams
* @return array
*/
public function getNovelPager(array $arrParams): array
{
$arrParams = [
'page' => max((int)($arrParams['page'] ?? 1), 1),
'limit' => (int)($arrParams['limit'] ?? 10),
'button_num' => (int)($arrParams['button_num'] ?? 0),
'n_category' => (string)($arrParams['n_category'] ?? ''),
'sort_type' => (string)($arrParams['sort_type'] ?? ''),
'n_status' => (string)($arrParams['n_status'] ?? ''),
'n_sex' => (string)($arrParams['n_sex'] ?? ''),
'diff_key' => (string)($arrParams['diff_key'] ?? ''),
'key' => (string)($arrParams['key'] ?? ''),
'cache_life' => (int)($arrParams['cache_life'] ?? 0),
'func' => (string)($arrParams['func']),
];
$intPage = $arrParams['page'];
$intLimit = $arrParams['limit'];
$strNCategory = $arrParams['n_category'];
$strSortType = $arrParams['sort_type'];
$strNStatus = $arrParams['n_status'];
$strNSex = $arrParams['n_sex'];
$strDiffKey = $arrParams['diff_key'];
$strKey = $arrParams['key'];
$intCacheLifeTime = $arrParams['cache_life'];
$Func = $arrParams['func'];
if ($intPage <= 0) {
$intPage = 1;
}
$arrFilter = [
'$and' => [],
];
# n_category filter
if (!empty($strNCategory)) {
$strNCategory = CategoryModel::getZhByPinYin($strNCategory);
if ($strNCategory) {
$arrFilter['$and'][] = ['n_category' => $strNCategory];
} else {
$arrParams['n_category'] = 'all';
}
}
# n_status filter
if (!empty($strNStatus)) {
switch ($strNStatus) {
case 'lianzai':
$arrFilter['$and'][] = ['n_status' => $this->arrStatus[$strNStatus]];
break;
case 'wanjie':
$arrFilter['$and'][] = ['n_status' => $this->arrStatus[$strNStatus]];
break;
default:
$arrParams['n_status'] = 'all';
break;
}
}
# n_category_sex_zh filter
if (!empty($strNSex)) {
switch ($strNSex) {
case 'man':
$arrFilter['$and'][] = ['n_category_sex_zh' => $this->arrSex[$strNSex]];
break;
case 'women':
$arrFilter['$and'][] = ['n_category_sex_zh' => $this->arrSex[$strNSex]];
break;
default:
$arrParams['n_sex'] = 'all';
break;
}
}
# key filter
if (!empty($strKey)) {
$strKey = mb_substr($strKey, 0, 30);
$arrFilter['$and'][] = [
'$or' => [
['n_name' => ['$regex' => $strKey, '$options' => 'i']],
['n_author' => ['$regex' => $strKey, '$options' => 'i']],
['n_category' => ['$regex' => $strKey, '$options' => 'i']],
['n_description' => ['$regex' => $strKey, '$options' => 'i']],
]
];
$arrParams['key'] = $strKey;
}
$arrSort = [];
# sort filter
if (!empty($strSortType)) {
switch ($strSortType) {
case 'news':
$arrSort['created_at'] = -1;
break;
case 'tuijian':
$arrSort['n_level'] = -1;
break;
case 'update':
$arrSort['n_update_time'] = -1;
break;
default:
$arrParams['sort_type'] = 'all';
break;
}
}
$strCacheKey = '';
$intLifeTime = 0;
# cache filter
if ($intCacheLifeTime > 0) {
$strCacheKey = sprintf(
'NovelService:getNovelList:%s:%s:%s:%s:%s:%s',
$this->SiteContext->DomainModel->d_domain,
md5(serialize($arrFilter)),
md5(serialize($arrSort)),
$intPage,
$intLimit,
$strDiffKey,
);
$intLifeTime = $intLifeTime;
}
if (empty($arrFilter['$and'])) {
$arrFilter = [];
}
$arrNovel = $this->NovelModel->findPaginatedWithCache(
$arrFilter,
$intPage,
$intLimit,
$arrSort,
$strCacheKey,
$intLifeTime,
);
$arrPager = $arrNovel;
unset($arrPager['data']);
$arrPager['pager'] = call_user_func([$this, $Func], $arrParams, $arrSort, $arrNovel);
$arrResult = [
'data' => $arrNovel['data'],
'p_data' => $arrPager,
];
return $arrResult;
}
/**
* 搜索定制分页
*
* @param array $arrFilter 查询条件字段
* @param array $arrSort 查询排序字段
* @param array $arrNovel 查询出来的数据
* @return array
*/
public function generateSearchPager(array $arrParams, array $arrSort, array $arrNovel): array
{
$strKey = $arrParams['key'];
$intPage = $arrNovel['page'];
$intLimit = $arrNovel['limit'];
$intButtomNum = $arrParams['button_num'];
$strBaseUrl = app(NovelService::class)->getNovelSearchUrl($strKey, '{page}');
$arrPaginator = CusteomPage02::generate($intPage, $arrNovel['total'], $intLimit, $strBaseUrl, $intButtomNum);
return $arrPaginator;
}
/**
* 书库/分类定制分页
*
* @param array $arrFilter 查询条件字段
* @param array $arrSort 查询排序字段
* @param array $arrNovel 查询出来的数据
* @return array
*/
public function generateCategoryPager(array $arrParams, array $arrSort, array $arrNovel): array
{
$strGender = $arrParams['n_sex'];
$strCategory = $arrParams['n_category'];
$strStatus = $arrParams['n_status'];
$strOrder = $arrParams['sort_type'];
$intPage = $arrNovel['page'] ?? 1;
$intLimit = $arrNovel['limit'] ?? 10;
$intTotal = $arrNovel['total'] ?? 0;
$intButtomNum = $arrParams['button_num'];
$strBaseUrl = app(NovelService::class)->getNovelCategoryUrl($strGender, $strCategory, $strStatus, $strOrder, '{page}');
$arrPaginator = CusteomPage02::generate($intPage, $intTotal, $intLimit, $strBaseUrl, $intButtomNum);
return $arrPaginator;
}
/**
* 根据NId获取小说详情
*
* @param integer $intNId
* @return void
*/
public function getNovelByNId(int $intNId, int $intNForgeId = 0)
{
// 小说详情
$arrNovel = $this->NovelModel->getNovelByNId($intNId);
if ($intNForgeId > 0) {
foreach ($arrNovel['n_forge_novel'] as $arrForgeNovel) {
if ($arrForgeNovel['n_forge_id'] == $intNForgeId) {
$arrNovel['n_name'] = $arrForgeNovel['n_forge_title'];
break;
}
}
}
// 分类拼音
$arrNovel['n_category_pinyin'] = CategoryModel::getPinYin($arrNovel['n_category']);
$arrNovel['n_category_sex_en'] = $arrNovel['n_category_sex_en'] ?? 'man';
// 最后章节
$arrLatestChapter = $this->ChapterModel->getLatestChapterByNId($intNId);
// 第一章
$arrFirstChapter = $this->ChapterModel->getFirstChapterByNId($intNId, false);
$intFirstChapterSort = null;
if ($arrFirstChapter) {
$intFirstChapterSort = $arrFirstChapter['c_sort_num'];
}
$strFocus = '';
// 要点
if ($arrLatestChapter) {
$strFocus = strip_tags($arrLatestChapter['c_content']);
$intCount = mb_strlen($strFocus);
if ($intCount > 300) {
$strFocus = mb_substr($strFocus, 0, 300);
}
}
// 点击数
$arrNovelClicks = $this->NovelClicksModel->getStats($intNId);
// 推荐小说
$arrRelateveNId = array_column($arrNovel['n_related_novel'], 'n_id');
$arrRelateveNovel = $this->NovelModel->findMany(['n_id' => [
'$in' => $arrRelateveNId,
]], 10);
// 更新值
ConverterMovel::setVal([
'intPage' => 1,
'strNovelName' => $arrNovel['n_name'],
'strNovelAuthor' => $arrNovel['n_author'],
'strNovelCategoryName' => $arrNovel['n_category'],
'strNovelSex' => $arrNovel['n_category_sex_en'] == 'man' ? '男生' : '女生',
'strNovelStatus' => $arrNovel['n_status'],
'strNovelDescription' => $arrNovel['n_description'],
]);
$arrNovel['intFirstChapterSort'] = $intFirstChapterSort;
$arrNovel['arrNovelClicks'] = $arrNovelClicks;
$arrNovel['arrRelateveNovel'] = $arrRelateveNovel;
$arrNovel['strFocus'] = $strFocus;
return $arrNovel;
}
}

View File

@@ -1,263 +0,0 @@
<?php
namespace app\services;
use app\model\ConverterMovel;
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;
use think\facade\View;
class SiteContext
{
/**
* Request
*
* @var \think\Request
*/
public $Request;
/**
* DomainModel
*
* @var DomainModel
*/
public $DomainModel;
/**
* TemplatesModel
*
* @var TemplatesModel
*/
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();
}
/**
* GetViewConfig
*
* @return array
*/
public function getViewConfig(): array
{
$strDomain = $this->Request->rootDomain();
$this->DomainModel = DomainModel::getDomainOnCacheByDomain($strDomain);
if (empty($this->DomainModel)) {
throw new HttpException(404, 'Site config not Found');
}
$this->TemplatesModel = TemplatesModel::getTemplateOnCacheByTId($this->DomainModel->t_id);
if (empty($this->DomainModel)) {
throw new HttpException(500, 'Site template not Found');
}
$this->Request->DomainModel = $this->DomainModel;
$this->Request->TemplatesModel = $this->TemplatesModel;
return [
'type' => 'Think',
'auto_rule' => 3,
'view_dir_name' => 'view',
'view_suffix' => 'html',
'view_path' => root_path(ltrim($this->TemplatesModel->t_path, '/')),
];
}
/**
* 初始化网站基本信息到全局替换类里
*
* @return void
*/
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);
$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('Request', $this->Request);
View::assign('DomainModel', $this->DomainModel);
View::assign('TemplatesModel', $this->TemplatesModel);
ConverterMovel::setVal([
'strSiteName' => $this->DomainModel->d_name,
'strSiteDomain' => $this->DomainModel->d_domain,
'strSiteKeywords' => $this->DomainModel->d_keywords,
'strSiteDescription' => $this->DomainModel->d_description,
'strIndexTitle' => $this->DomainModel->d_index_title,
'strIndexKeywords' => $this->DomainModel->d_index_keywords,
'strIndexDescription' => $this->DomainModel->d_index_description,
]);
}
/**
* 变量转换
*
* @param string $strCode
* @return string
*/
public function converterTemplate(string $strCode): string
{
$strTitleTemplate = $this->DomainModel->getFomartSubject($strCode);
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);
}
/**
* get home view
*
* @return string
*/
public function getHomeView(string $strPlatform): string
{
if ($strPlatform == 'h5') {
if ($this->DomainModel->info_id > 0) {
$strView = 'novel/getNovelInfo.html';
} else {
$strView = 'index/index.html';
}
} else {
if ($this->DomainModel->info_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;
}
}