This commit is contained in:
Default
2025-04-19 16:50:08 +08:00
parent aafd25260a
commit 4299706868
7 changed files with 300 additions and 216 deletions

View File

@@ -808,4 +808,22 @@ namespace {
}
}
}
/**
* generate string
*
* @param integer $length
* @return string
*/
function randomString(int $length): string {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$max = 51; // 字符集长度减1 (0-51)
$result = '';
for ($i = 0; $i < $length; $i++) {
$result .= $chars[random_int(0, $max)];
}
return $result;
}
}

View File

@@ -9,9 +9,9 @@ use app\services\SiteContext;
use think\facade\Route;
// Route::get('/article/fenlei/:category', function (\think\Request $Request, SiteContext $SiteContext) {
// return view($SiteContext->getHomeView());
// });
Route::get('/article/fenlei/:category', function (\think\Request $Request, SiteContext $SiteContext) {
return view('test/test01/index.html');
});

View File

@@ -1,3 +1,24 @@
{novel:pagerexp page="1" limit="10" n_category="$Request.route.category" d_key="d_key" d_val="novel" p_val="page_data"
cache_life="1000" func="generateSearchPager" export_name="fadfads" /}
{php}var_dump($fadfads['p_data']);{/php}
<!-- {novel:pager page="1" limit="10" n_category="$Request.route.category" d_key="d_key" d_val="novel" p_val="page_data"
cache_life="1000" func="generateSearchPager"}
<li>
Index: {$d_key}
Title: {$novel.n_name}
Author: {$novel.n_category}
</li>
{/novel:pager}
{php}var_dump($page_data);{/php} -->
<!-- {site:grm page_code="fdasfadsf" diff="fadsfdsa" num="10" g_key="arrGrm" /}
{php}var_dump($arrGrm);{/php} -->
@@ -49,9 +70,9 @@
{/novel:sort} -->
<!--
{novel:info n_id="33" n_key="arrNovel01" n_forge_id="1125940" /}
{$arrNovel01.n_name}
{$arrNovel01.n_name} -->
<!-- {$DomainModel->d_domain} -->
@@ -66,17 +87,3 @@
</li>
{/novel:list} -->
<!--
{novel:pager page="1" limit="10" n_category="$Request.route.category" d_key="d_key" d_val="novel" p_val="page_data"
cache_life="1000" func="generateSearchPager"}
<li>
Index: {$d_key}
Title: {$novel.n_name}
Author: {$novel.n_category}
</li>
{/novel:pager}
{php}var_dump($page_data);{/php}
-->

View File

@@ -168,7 +168,7 @@ class ChapterService
$strCacheKey = '';
$intLifeTime = 0;
if (empty($arrFilter['$and'])) {
$arrFilter = [];
}
@@ -188,7 +188,7 @@ class ChapterService
$intLifeTime = $intLifeTime;
}
$arrNovel = $this->ChapterModel->findPaginatedWithCache(
$arrChapter = $this->ChapterModel->findPaginatedWithCache(
$arrFilter,
$intPage,
$intLimit,
@@ -197,10 +197,14 @@ class ChapterService
$intLifeTime,
);
$arrPager = call_user_func([$this, $Func], $arrParams, $arrSort, $arrNovel);
$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' => $arrNovel['data'],
'data' => $arrChapter['data'],
'p_data' => $arrPager,
];
@@ -218,7 +222,7 @@ class ChapterService
{
// 小说详情
$arrNovel = $this->NovelModel->getNovelByNId($intNId);
// 章节
$ChapterModel = ChapterModel::getInstance();
$arrFilter = ['n_id' => $intNId, 'c_sort_num' => $intCSortNum, 'c_page' => $intCPage];

View File

@@ -416,8 +416,8 @@ class NovelService
}
}
# n_category_sex_zh filter
if (!empty($strNSex)) {
# key filter
if (!empty($strKey)) {
$strKey = mb_substr($strKey, 0, 30);
$arrFilter['$and'][] = [
@@ -468,7 +468,11 @@ class NovelService
$intLifeTime = $intLifeTime;
}
if (empty($arrFilter['$and'])) {
$arrFilter = [];
}
$arrNovel = $this->NovelModel->findPaginatedWithCache(
$arrFilter,
$intPage,
@@ -478,11 +482,12 @@ class NovelService
$intLifeTime,
);
$arrPager = call_user_func([$this, $Func], $arrParams, $arrSort, $arrNovel);
$arrPager = $arrNovel;
unset($arrPager['data']);
$arrPager['pager'] = call_user_func([$this, $Func], $arrParams, $arrSort, $arrNovel);
$arrResult = [
'data' => $arrNovel['data'] ?? [],
'pages' => $arrNovel['pages'] ?? 0,
'data' => $arrNovel['data'],
'p_data' => $arrPager,
];

View File

@@ -8,7 +8,8 @@ class Chapter extends TagLib
{
protected $tags = [
'list' => ['attr' => 'limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val'],
'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val'],
'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,export_name'],
'pagerexp' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 0],
'info' => ['attr' => 'n_id,n_key', 'close' => 0],
];
@@ -22,6 +23,19 @@ class Chapter extends TagLib
}
/**
* pagerexp tag code
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagPagerExp($tag, $content)
{
return $this->tagPager($tag, $content);
}
/**
* chapter pager
*
@@ -42,6 +56,7 @@ class Chapter extends TagLib
$d_val = $tag['d_val'] ?? 'd_val';
$p_val = $tag['p_val'] ?? 'p_val';
$func = $tag['func'];
$export_name = $tag['export_name'] ?? '';
$n_id = $this->customBuildVar($n_id);
$sort_type = $this->customBuildVar($sort_type);
@@ -53,9 +68,11 @@ class Chapter extends TagLib
$cache_life = $this->customBuildVar($cache_life);
$func = $this->customBuildVar($func);
$arrDataName = randomString(5);
$strParse = <<<EOT
<?php
\$arrChapter = app(\\app\\services\\ChapterService::class)->getNovelPager([
\${$arrDataName} = app(\\app\\services\\ChapterService::class)->getNovelPager([
'page' => {$page},
'limit' => {$limit},
'button_num' => {$button_num},
@@ -65,19 +82,27 @@ class Chapter extends TagLib
'cache_life' => {$cache_life},
'func' => {$func},
]);
EOT;
if (isset(\$arrChapter['data']) && is_array(\$arrChapter['data'])):
\${$p_val} = \$arrChapter['p_data'] ?? [];
if (empty($export_name)) {
$strParse .= <<<EOT
if (isset(\${$arrDataName}['data']) && is_array(\${$arrDataName}['data'])):
\${$p_val} = \${$arrDataName}['p_data'] ?? [];
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\$arrChapter['data'] as \${$d_key} => \${$d_val}): ?>
$strParse .= <<<EOT
<?php foreach (\${$arrDataName}['data'] as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
} else {
$strParse .= <<<EOT
\${$export_name} = \${$arrDataName};
EOT;
}
return $strParse;
}
@@ -97,17 +122,17 @@ EOT;
$cache_life = $tag['cache_life'] ?? '0';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$count = $this->customBuildVar($count);
$n_id = $this->customBuildVar($n_id);
$sort_type = $this->customBuildVar($sort_type);
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$arrDataName = randomString(5);
$strParse = <<<EOT
<?php
\$arrChapter = app(\\app\\services\\ChapterService::class)->getChapterList([
\${$arrDataName} = app(\\app\\services\\ChapterService::class)->getChapterList([
'n_id' => {$n_id},
'count' => {$count},
'sort_type' => {$sort_type},
@@ -115,12 +140,12 @@ EOT;
'cache_life' => {$cache_life},
]);
if (!empty(\$arrChapter) && is_array(\$arrChapter)):
if (!empty(\${$arrDataName}) && is_array(\${$arrDataName})):
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\$arrChapter as \${$d_key} => \${$d_val}): ?>
<?php foreach (\${$arrDataName} as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
@@ -148,7 +173,7 @@ EOT;
$n_id = $this->customBuildVar($n_id);
$c_sort_num = $this->customBuildVar($c_sort_num);
$c_page = $this->customBuildVar($c_page);
$strParse = <<<EOT
<?php
\$arrChapter = app(\\app\\services\\ChapterService::class)->getChapterInfo(

View File

@@ -6,62 +6,75 @@ use think\template\TagLib;
class Novel extends TagLib
{
protected $tags = [
'list' => ['attr' => 'limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val'],
'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val'],
'info' => ['attr' => 'n_id,n_key', 'close' => 0],
'sort' => ['attr' => 'd_key,d_val'],
'status' => ['attr' => 'd_key,d_val'],
'sex' => ['attr' => 'd_key,d_val'],
'category' => ['attr' => 'd_key,d_val'],
];
protected $tags = [
'list' => ['attr' => 'limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val', 'close' => 1],
'pager' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 1],
'pagerexp' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val,func,export_name', 'close' => 0],
'info' => ['attr' => 'n_id,n_key', 'close' => 0],
'sort' => ['attr' => 'd_key,d_val'],
'status' => ['attr' => 'd_key,d_val'],
'sex' => ['attr' => 'd_key,d_val'],
'category' => ['attr' => 'd_key,d_val'],
];
private function customBuildVar($mixedArgs)
{
if (substr($mixedArgs, 0, 1) == '$') {
return $this->autoBuildVar($mixedArgs);
} else {
return is_numeric($mixedArgs) ? $mixedArgs : "'" . $mixedArgs . "'";
private function customBuildVar($mixedArgs)
{
if (substr($mixedArgs, 0, 1) == '$') {
return $this->autoBuildVar($mixedArgs);
} else {
return is_numeric($mixedArgs) ? $mixedArgs : "'" . $mixedArgs . "'";
}
}
}
/**
* novel 自定义标签
*/
public function tagPager($tag, $content)
{
$page = $tag['page'] ?? '0';
$limit = $tag['limit'] ?? '10';
$button_num = $tag['button_num'] ?? '10';
$n_category = $tag['n_category'] ?? "all";
$sort_type = $tag['sort_type'] ?? "";
$n_status = $tag['n_status'] ?? "";
$n_sex = $tag['n_sex'] ?? "";
$key = $tag['key'] ?? "";
$diff_key = $tag['diff_key'] ?? "";
$cache_life = $tag['cache_life'] ?? '0';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$p_val = $tag['p_val'] ?? 'p_val';
$n_num = $tag['n_num'] ?? 'n_num';
$func = $tag['func'];
/**
* novel 自定义标签
*/
public function tagPagerExp($tag, $content)
{
return $this->tagPager($tag, $content);
}
$page = $this->customBuildVar($page);
$limit = $this->customBuildVar($limit);
$button_num = $this->customBuildVar($button_num);
$n_category = $this->customBuildVar($n_category);
$sort_type = $this->customBuildVar($sort_type);
$n_status = $this->customBuildVar($n_status);
$n_sex = $this->customBuildVar($n_sex);
$key = $this->customBuildVar($key);
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$func = $this->customBuildVar($func);
/**
* novel 自定义标签
*/
public function tagPager($tag, $content)
{
$page = $tag['page'] ?? '0';
$limit = $tag['limit'] ?? '10';
$button_num = $tag['button_num'] ?? '10';
$n_category = $tag['n_category'] ?? "all";
$sort_type = $tag['sort_type'] ?? "";
$n_status = $tag['n_status'] ?? "";
$n_sex = $tag['n_sex'] ?? "";
$key = $tag['key'] ?? "";
$diff_key = $tag['diff_key'] ?? "";
$cache_life = $tag['cache_life'] ?? '0';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$p_val = $tag['p_val'] ?? 'p_val';
$strParse = <<<EOT
$export_name = $tag['export_name'] ?? '';
$func = $tag['func'];
$page = $this->customBuildVar($page);
$limit = $this->customBuildVar($limit);
$button_num = $this->customBuildVar($button_num);
$n_category = $this->customBuildVar($n_category);
$sort_type = $this->customBuildVar($sort_type);
$n_status = $this->customBuildVar($n_status);
$n_sex = $this->customBuildVar($n_sex);
$key = $this->customBuildVar($key);
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$func = $this->customBuildVar($func);
$arrDataName = randomString(5);
$strParse = <<<EOT
<?php
\$novelData = app(\\app\\services\\NovelService::class)->getNovelPager([
\${$arrDataName} = app(\\app\\services\\NovelService::class)->getNovelPager([
'page' => {$page},
'limit' => {$limit},
'button_num' => {$button_num},
@@ -74,49 +87,61 @@ class Novel extends TagLib
'cache_life' => {$cache_life},
'func' => {$func},
]);
EOT;
if (isset(\$novelData['data']) && is_array(\$novelData['data'])):
\${$p_val} = \$novelData['p_data'] ?? [];
\${$n_num} = \$novelData['pages'] ?? [];
if (empty($export_name)) {
$strParse .= <<<EOT
if (isset(\${$arrDataName}['data']) && is_array(\${$arrDataName}['data'])):
\${$p_val} = \${$arrDataName}['p_data'] ?? [];
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\$novelData['data'] as \${$d_key} => \${$d_val}): ?>
$strParse .= <<<EOT
<?php foreach (\${$arrDataName}['data'] as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
} else {
$strParse .= <<<EOT
\${$export_name} = \${$arrDataName};
?>
EOT;
}
/**
* novel 自定义标签
*/
public function tagList($tag, $content)
{
$count = $tag['count'] ?? '10';
$n_category = $tag['n_category'] ?? "all";
$sort_type = $tag['sort_type'] ?? "";
$n_status = $tag['n_status'] ?? "all";
$n_sex = $tag['n_sex'] ?? "all";
$diff_key = $tag['diff_key'] ?? "";
$cache_life = $tag['cache_life'] ?? '0';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
return $strParse;
}
/**
* novel 自定义标签
*/
public function tagList($tag, $content)
{
$count = $tag['count'] ?? '10';
$n_category = $tag['n_category'] ?? "all";
$sort_type = $tag['sort_type'] ?? "";
$n_status = $tag['n_status'] ?? "all";
$n_sex = $tag['n_sex'] ?? "all";
$diff_key = $tag['diff_key'] ?? "";
$cache_life = $tag['cache_life'] ?? '0';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$n_category = $this->customBuildVar($n_category);
$sort_type = $this->customBuildVar($sort_type);
$n_status = $this->customBuildVar($n_status);
$n_sex = $this->customBuildVar($n_sex);
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$n_category = $this->customBuildVar($n_category);
$sort_type = $this->customBuildVar($sort_type);
$n_status = $this->customBuildVar($n_status);
$n_sex = $this->customBuildVar($n_sex);
$diff_key = $this->customBuildVar($diff_key);
$cache_life = $this->customBuildVar($cache_life);
$strParse = <<<EOT
$arrDataName = randomString(5);
$strParse = <<<EOT
<?php
\$novelData = app(\\app\\services\\NovelService::class)->getNovelList([
\${$arrDataName} = app(\\app\\services\\NovelService::class)->getNovelList([
'count' => {$count},
'n_category' => {$n_category},
'sort_type' => {$sort_type},
@@ -126,42 +151,42 @@ EOT;
'cache_life' => {$cache_life}
]);
if (!empty(\$novelData) && is_array(\$novelData)):
if (!empty(\${$arrDataName}) && is_array(\${$arrDataName})):
?>
EOT;
$strParse .= <<<EOT
<?php foreach (\$novelData as \${$d_key} => \${$d_val}): ?>
$strParse .= <<<EOT
<?php foreach (\${$arrDataName} as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
return $strParse;
}
/**
* 获取小说详情
*
* @param array $tag
* @param string $content
* @return void
*/
public function tagInfo($tag)
{
$n_id = $tag['n_id'] ?? '0';
$n_forge_id = $tag['n_forge_id'] ?? 0;
/**
* 获取小说详情
*
* @param array $tag
* @param string $content
* @return void
*/
public function tagInfo($tag)
{
$n_id = $tag['n_id'] ?? '0';
$n_forge_id = $tag['n_forge_id'] ?? 0;
$n_key = $tag['n_key'] ?? 'arrNovel';
$n_key = $tag['n_key'] ?? 'arrNovel';
$n_id = $this->customBuildVar($n_id);
$n_id = $this->customBuildVar($n_id);
$strParse = <<<EOT
$strParse = <<<EOT
<?php
\$novelData = app(\\app\\services\\NovelService::class)->getNovelByNId(
{$n_id},
@@ -172,23 +197,23 @@ EOT;
?>
EOT;
return $strParse;
}
return $strParse;
}
/**
* 获取排序筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagSort($tag, $content)
{
/**
* 获取排序筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagSort($tag, $content)
{
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$strParse = <<<EOT
$strParse = <<<EOT
<?php
\$arrSort = app(\\app\\services\\NovelService::class)->arrSortType;
@@ -196,31 +221,31 @@ if (!empty(\$arrSort) && is_array(\$arrSort)):
?>
EOT;
$strParse .= <<<EOT
$strParse .= <<<EOT
<?php foreach (\$arrSort as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
return $strParse;
}
/**
* 获取状态筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagStatus($tag, $content)
{
/**
* 获取状态筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagStatus($tag, $content)
{
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$strParse = <<<EOT
$strParse = <<<EOT
<?php
\$arrStatus = app(\\app\\services\\NovelService::class)->arrStatus;
@@ -228,32 +253,32 @@ if (!empty(\$arrStatus) && is_array(\$arrStatus)):
?>
EOT;
$strParse .= <<<EOT
$strParse .= <<<EOT
<?php foreach (\$arrStatus as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
return $strParse;
}
/**
* 获取状态筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagSex($tag, $content)
{
/**
* 获取状态筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagSex($tag, $content)
{
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$strParse = <<<EOT
$strParse = <<<EOT
<?php
\$arrSex = app(\\app\\services\\NovelService::class)->arrSex;
@@ -261,31 +286,31 @@ if (!empty(\$arrSex) && is_array(\$arrSex)):
?>
EOT;
$strParse .= <<<EOT
$strParse .= <<<EOT
<?php foreach (\$arrSex as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
return $strParse;
}
/**
* 获取状态筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagCategory($tag, $content)
{
/**
* 获取状态筛选参数
*
* @param array $tag
* @param string $content
* @return string
*/
public function tagCategory($tag, $content)
{
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$d_key = $tag['d_key'] ?? 'd_key';
$d_val = $tag['d_val'] ?? 'd_val';
$strParse = <<<EOT
$strParse = <<<EOT
<?php
\$arrCategory = app(\\app\\services\\NovelService::class)->getCategoryFilter();
@@ -293,14 +318,14 @@ if (!empty(\$arrCategory) && is_array(\$arrCategory)):
?>
EOT;
$strParse .= <<<EOT
$strParse .= <<<EOT
<?php foreach (\$arrCategory as \${$d_key} => \${$d_val}): ?>
EOT;
$strParse .= $content;
$strParse .= <<<EOT
$strParse .= $content;
$strParse .= <<<EOT
<?php endforeach; ?>
<?php endif; ?>
EOT;
return $strParse;
}
return $strParse;
}
}