debug
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 分类拼音
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user