Merge branch 'dev' of ssh://git.bgbg.live:18150/root/SEONexus into dev
This commit is contained in:
@@ -8,10 +8,13 @@ use app\home\controller\User;
|
||||
use think\facade\Route;
|
||||
|
||||
|
||||
Route::get('article/fenlei/:category', function (\think\Request $Request) {
|
||||
Route::get('/article/fenlei/:category', function (\think\Request $Request) {
|
||||
return view('test/test01/index.html');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 路由配置文件
|
||||
*/
|
||||
|
||||
@@ -334,7 +334,7 @@ class Novel extends BaseController
|
||||
|
||||
$intNId = $Request->param('n_id');
|
||||
|
||||
$intForgeId = $Request->param('n_forge_id');
|
||||
$intNForgeId = $Request->param('n_forge_id');
|
||||
|
||||
$boolIsMobile = $Request->param('boolIsMobile');
|
||||
|
||||
@@ -344,7 +344,7 @@ class Novel extends BaseController
|
||||
$arrNovel = $NovelModel->getNovelByNId($intNId);
|
||||
|
||||
foreach ($arrNovel['n_forge_novel'] as $arrForgeNovel) {
|
||||
if ($arrForgeNovel['n_forge_id'] == $intForgeId) {
|
||||
if ($arrForgeNovel['n_forge_id'] == $intNForgeId) {
|
||||
$arrNovel['n_name'] = $arrForgeNovel['n_forge_title'];
|
||||
break;
|
||||
}
|
||||
@@ -421,9 +421,9 @@ class Novel extends BaseController
|
||||
'strNovelDescription' => $arrNovel['n_description'],
|
||||
]);
|
||||
|
||||
$strTitleTemplate = $Request->DomainModel->getFomartSubject('NOVEL@GETNOVELINFO@TITLE', $intForgeId);
|
||||
$strKeywordsTemplate = $Request->DomainModel->getFomartSubject('NOVEL@GETNOVELINFO@KEYWORDS', $intForgeId);
|
||||
$strDescriptionTemplate = $Request->DomainModel->getFomartSubject('NOVEL@GETNOVELINFO@DESCRIPTION', $intForgeId);
|
||||
$strTitleTemplate = $Request->DomainModel->getFomartSubject('NOVEL@GETNOVELINFO@TITLE', $intNForgeId);
|
||||
$strKeywordsTemplate = $Request->DomainModel->getFomartSubject('NOVEL@GETNOVELINFO@KEYWORDS', $intNForgeId);
|
||||
$strDescriptionTemplate = $Request->DomainModel->getFomartSubject('NOVEL@GETNOVELINFO@DESCRIPTION', $intNForgeId);
|
||||
|
||||
$strTitle = ConverterMovel::convert($strTitleTemplate);
|
||||
$strKeywords = ConverterMovel::convert($strKeywordsTemplate);
|
||||
@@ -450,7 +450,7 @@ class Novel extends BaseController
|
||||
]);
|
||||
|
||||
$strView = $boolIsMobile ? 'getNovelInfo' : 'pc/getNovelInfo';
|
||||
$this->generateGrm(2, $intNId . '-' . $intForgeId, 50);
|
||||
$this->generateGrm(2, $intNId . '-' . $intNForgeId, 50);
|
||||
return $this->rending($strView);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
// 这是系统自动生成的middleware定义文件
|
||||
|
||||
use app\services\SiteContext;
|
||||
|
||||
return [
|
||||
function ($request, \Closure $next) {
|
||||
app(SiteContext::class)->initCfg();
|
||||
return $next($request);
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
33
code/app/home/view/default/test/test01/index.html
Normal file
33
code/app/home/view/default/test/test01/index.html
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
{novel:info n_id="33" n_key="arrNovel01" n_forge_id="1125940" /}
|
||||
{$arrNovel01.n_name}
|
||||
|
||||
|
||||
<!-- {$DomainModel->d_domain} -->
|
||||
|
||||
<!-- {site:replace code="INDEX@INDEX@TITLE"}
|
||||
-->
|
||||
|
||||
<!-- {novel:list count="10" n_category="$Request.route.category" d_key="d_key" d_val="novel" p_val="page_data" cache_life="1000"}
|
||||
<li>
|
||||
Index: {$d_key}
|
||||
Title: {$novel.n_name}
|
||||
Author: {$novel.n_category}
|
||||
</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}
|
||||
|
||||
-->
|
||||
@@ -16,6 +16,21 @@ class CategoryModel extends MongoModel
|
||||
|
||||
protected $strCollection = 'category';
|
||||
|
||||
/**
|
||||
* Undocumented variable
|
||||
*
|
||||
* @var CategoryModel
|
||||
*/
|
||||
static public $CategoryModel;
|
||||
|
||||
static public function getInstance(): self
|
||||
{
|
||||
if (self::$CategoryModel == NULL) {
|
||||
self::$CategoryModel = new self;
|
||||
}
|
||||
return self::$CategoryModel;
|
||||
}
|
||||
|
||||
static $arrCategory = [
|
||||
1 => '玄幻修真',
|
||||
2 => '军史小说',
|
||||
@@ -145,6 +160,23 @@ class CategoryModel extends MongoModel
|
||||
return self::$arrCategoryPinYin[$intKey];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get chinese characters based on pinyin
|
||||
*
|
||||
* @param string $strPinYin
|
||||
* @return string|null
|
||||
*/
|
||||
static public function getZhByPinYin(string $strPinYin): string|null
|
||||
{
|
||||
$strZh = NULL;
|
||||
$intKey = array_search($strPinYin, self::$arrCategoryPinYin);
|
||||
if (is_numeric($intKey)) {
|
||||
$strZh = self::$arrCategory[$intKey];
|
||||
}
|
||||
return $strZh;
|
||||
}
|
||||
|
||||
/**
|
||||
* determine the gender of the novel category
|
||||
*
|
||||
|
||||
@@ -16,16 +16,16 @@ class NovelClicksModel extends MongoModel
|
||||
/**
|
||||
* Undocumented variable
|
||||
*
|
||||
* @var self
|
||||
* @var NovelClicksModel
|
||||
*/
|
||||
static public $obj;
|
||||
static public $NovelClicksModel;
|
||||
|
||||
static public function getInstance(): self
|
||||
{
|
||||
if (self::$obj == NULL) {
|
||||
self::$obj = new self;
|
||||
if (self::$NovelClicksModel == NULL) {
|
||||
self::$NovelClicksModel = new self;
|
||||
}
|
||||
return self::$obj;
|
||||
return self::$NovelClicksModel;
|
||||
}
|
||||
|
||||
protected $strCollection = 'novel_clicks';
|
||||
|
||||
28
code/app/services/CategoryService.php
Normal file
28
code/app/services/CategoryService.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ class ChapterService
|
||||
|
||||
public function __construct(SiteContext $SiteContext)
|
||||
{
|
||||
$this->SiteContext = $SiteContext;
|
||||
$this->ChapterModel = ChapterModel::getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,13 @@
|
||||
|
||||
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
|
||||
{
|
||||
@@ -21,10 +26,26 @@ class NovelService
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,73 +211,371 @@ class NovelService
|
||||
|
||||
|
||||
protected $arrSortType = [
|
||||
'day_desc' => 'daily',
|
||||
'week_desc' => 'weekly',
|
||||
'month_desc' => 'monthly',
|
||||
'total_desc' => 'total',
|
||||
'tuijian_desc' => 'total',
|
||||
'all' => '全部排序',
|
||||
'news' => '最新入库',
|
||||
'tuijian' => '推荐',
|
||||
'update' => '最新更新',
|
||||
];
|
||||
|
||||
protected $arrStatus = [
|
||||
'all' => NULL,
|
||||
'all' => '所有',
|
||||
'lianzai' => '连载中',
|
||||
'wanjie' => '已完结',
|
||||
];
|
||||
|
||||
protected $arrSex = [
|
||||
'all' => '所有',
|
||||
'man' => '男生',
|
||||
'women' => '女生',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 获取小说数据
|
||||
*
|
||||
* @param array $arrParams
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function getNovelData(array $arrParams): array
|
||||
public function getNovelList(array $arrParams): array
|
||||
{
|
||||
// 提取参数
|
||||
$intPage = (int)$arrParams['page'] ?? 0;
|
||||
$intLimit = (int)$arrParams['limit'] ?? 10;
|
||||
$intCount = (int)$arrParams['count'] ?? 10;
|
||||
$strNCategory = $arrParams['n_category'] ?? '';
|
||||
$strSortType = (string)$arrParams['sort_type'] ?? '';
|
||||
$strNStatus = (string) $arrParams['n_status'] ?? '';
|
||||
$strNSex = (string) $arrParams['n_sex'] ?? '';
|
||||
$strKey = (string) $arrParams['key'] ?? '';
|
||||
$strDiffKey = (string) $arrParams['diff_key'] ?? '';
|
||||
$intCacheKey = (int)$arrParams['cache_life'] ?? 0;
|
||||
echo $intPage;
|
||||
print_r($arrParams);
|
||||
exit;
|
||||
$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(
|
||||
'Service: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;
|
||||
}
|
||||
|
||||
|
||||
if ($intPage == 0) {
|
||||
/**
|
||||
* 获取小说分页数据
|
||||
*
|
||||
* @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_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;
|
||||
}
|
||||
}
|
||||
|
||||
// 模拟数据处理(可以根据实际需求从数据库获取数据)
|
||||
$data = [];
|
||||
for ($i = 1; $i <= $arrParams['limit']; $i++) {
|
||||
$data[] = [
|
||||
'id' => $i,
|
||||
'name' => "小说名称 {$i}",
|
||||
'category' => $arrParams['n_category'] ?? '默认分类',
|
||||
'status' => $arrParams['n_status'] ?? '连载中',
|
||||
'order' => $arrParams['sort_type'] ?? '默认排序',
|
||||
# n_category_sex_zh filter
|
||||
if (!empty($strNSex)) {
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
// 分页数据
|
||||
$p_data = [
|
||||
'current_page' => $arrParams['page'],
|
||||
'total_page' => 5,
|
||||
'total_count' => 50,
|
||||
$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(
|
||||
'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->NovelModel->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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索定制分页
|
||||
*
|
||||
* @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 = 10;
|
||||
$strBaseUrl = app(NovelService::class)->getNovelSearchUrl($strKey, '{page}');
|
||||
$arrPaginator = CusteomPage02::generate($intPage, $arrNovel['total'], $intLimit, $strBaseUrl, $intButtomNum);
|
||||
|
||||
return $arrPaginator;
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'data' => $data,
|
||||
'p_data' => $p_data,
|
||||
];
|
||||
/**
|
||||
* 根据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);
|
||||
}
|
||||
}
|
||||
|
||||
// 最近五个章节
|
||||
$arrChapter = $this->ChapterModel->findMany([
|
||||
'n_id' => $intNId,
|
||||
'c_page' => 0,
|
||||
], 10, ['c_sort_num' => -1]);
|
||||
|
||||
// 点击数
|
||||
|
||||
$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'],
|
||||
]);
|
||||
|
||||
|
||||
return $arrNovel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace app\services;
|
||||
|
||||
use app\model\ConverterMovel;
|
||||
use app\model\DomainModel;
|
||||
use app\model\TemplatesModel;
|
||||
use think\facade\Request;
|
||||
use think\facade\Config;
|
||||
use think\exception\HttpException;
|
||||
use think\facade\View;
|
||||
|
||||
class SiteContext
|
||||
{
|
||||
@@ -69,4 +71,42 @@ class SiteContext
|
||||
'view_path' => root_path(ltrim($this->TemplatesModel->t_path, '/')),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化网站基本信息到全局替换类里
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initCfg()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ use think\template\TagLib;
|
||||
class Novel extends TagLib
|
||||
{
|
||||
protected $tags = [
|
||||
'list' => ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val'],
|
||||
'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],
|
||||
];
|
||||
|
||||
private function customBuildVar($mixedArgs)
|
||||
@@ -19,10 +21,11 @@ class Novel extends TagLib
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* novel 自定义标签
|
||||
*/
|
||||
public function tagList($tag, $content)
|
||||
public function tagPager($tag, $content)
|
||||
{
|
||||
$page = $tag['page'] ?? '0';
|
||||
$limit = $tag['limit'] ?? '10';
|
||||
@@ -36,6 +39,7 @@ class Novel extends TagLib
|
||||
$d_key = $tag['d_key'] ?? 'd_key';
|
||||
$d_val = $tag['d_val'] ?? 'd_val';
|
||||
$p_val = $tag['p_val'] ?? 'p_val';
|
||||
$func = $tag['func'];
|
||||
|
||||
$page = $this->customBuildVar($page);
|
||||
$limit = $this->customBuildVar($limit);
|
||||
@@ -46,10 +50,11 @@ class Novel extends TagLib
|
||||
$key = $this->customBuildVar($key);
|
||||
$diff_key = $this->customBuildVar($diff_key);
|
||||
$cache_life = $this->customBuildVar($cache_life);
|
||||
$func = $this->customBuildVar($func);
|
||||
|
||||
$parse = <<<EOT
|
||||
$strParse = <<<EOT
|
||||
<?php
|
||||
\$novelData = app(\\app\\services\\NovelService::class)->getNovelData([
|
||||
\$novelData = app(\\app\\services\\NovelService::class)->getNovelPager([
|
||||
'page' => {$page},
|
||||
'limit' => {$limit},
|
||||
'n_category' => {$n_category},
|
||||
@@ -58,21 +63,106 @@ class Novel extends TagLib
|
||||
'n_sex' => {$n_sex},
|
||||
'key' => {$key},
|
||||
'diff_key' => {$diff_key},
|
||||
'cache_life' => {$cache_life}
|
||||
'cache_life' => {$cache_life},
|
||||
'func' => {$func},
|
||||
]);
|
||||
|
||||
if (isset(\$novelData['data']) && is_array(\$novelData['data'])):
|
||||
\${$p_val} = \$novelData['p_data'] ?? [];
|
||||
?>
|
||||
EOT;
|
||||
$parse .= <<<EOT
|
||||
$strParse .= <<<EOT
|
||||
<?php foreach (\$novelData['data'] as \${$d_key} => \${$d_val}): ?>
|
||||
EOT;
|
||||
$parse .= $content;
|
||||
$parse .= <<<EOT
|
||||
$strParse .= $content;
|
||||
$strParse .= <<<EOT
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
EOT;
|
||||
return $parse;
|
||||
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);
|
||||
|
||||
$strParse = <<<EOT
|
||||
<?php
|
||||
\$novelData = app(\\app\\services\\NovelService::class)->getNovelList([
|
||||
'count' => {$count},
|
||||
'n_category' => {$n_category},
|
||||
'sort_type' => {$sort_type},
|
||||
'n_status' => {$n_status},
|
||||
'n_sex' => {$n_sex},
|
||||
'diff_key' => {$diff_key},
|
||||
'cache_life' => {$cache_life}
|
||||
]);
|
||||
|
||||
if (!empty(\$novelData) && is_array(\$novelData)):
|
||||
|
||||
?>
|
||||
EOT;
|
||||
$strParse .= <<<EOT
|
||||
<?php foreach (\$novelData as \${$d_key} => \${$d_val}): ?>
|
||||
EOT;
|
||||
$strParse .= $content;
|
||||
$strParse .= <<<EOT
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
EOT;
|
||||
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;
|
||||
|
||||
$n_key = $tag['n_key'] ?? 'arrNovel';
|
||||
|
||||
$n_id = $this->customBuildVar($n_id);
|
||||
|
||||
$strParse = <<<EOT
|
||||
<?php
|
||||
\$novelData = app(\\app\\services\\NovelService::class)->getNovelByNId(
|
||||
{$n_id},
|
||||
{$n_forge_id}
|
||||
);
|
||||
|
||||
\${$n_key} = \$novelData ?? [];
|
||||
?>
|
||||
EOT;
|
||||
|
||||
return $strParse;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class Site extends TagLib
|
||||
'nclurl' => ['attr' => 'n_id,n_py,order,page', 'close' => 0],
|
||||
'nflurl' => ['attr' => 'gender,category,status,order,page', 'close' => 0],
|
||||
'grm' => ['attr' => 'domain,code,line,diff,start,end,index,type', 'close' => 0],
|
||||
'replace' => ['attr' => 'code', 'close' => 0],
|
||||
];
|
||||
|
||||
|
||||
@@ -217,7 +218,7 @@ EOD;
|
||||
/**
|
||||
* 干扰码
|
||||
*
|
||||
* @param array $n_id
|
||||
* @param array
|
||||
* @return string
|
||||
*/
|
||||
public function tagGrm($tag)
|
||||
@@ -236,6 +237,27 @@ EOD;
|
||||
\$strUrl = \\app\\model\\GanRaoMaModel::getGrmCode("{$strDomain}","{$strPageCode}","{$intLine}","{$strDifference}",{$intStartNumber},{$intEndNumber},{$intIndex},{$intType});
|
||||
echo \$strUrl;
|
||||
?>
|
||||
EOD;
|
||||
return $strParse;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 内容替换
|
||||
*
|
||||
* @param array
|
||||
* @return string
|
||||
*/
|
||||
public function tagReplace($tag)
|
||||
{
|
||||
$strCode = isset($tag['code']) ? $tag['code'] : '';
|
||||
|
||||
$strParse = <<<EOD
|
||||
<?php
|
||||
\$strUrl = app(\\app\\services\\SiteContext::class)->converterTemplate("{$strCode}");
|
||||
echo \$strUrl;
|
||||
?>
|
||||
EOD;
|
||||
return $strParse;
|
||||
}
|
||||
|
||||
@@ -74,3 +74,74 @@
|
||||
<a href="{if condition='$intPage < $intTotalPages'}/{$strFirstPath}/{$intNovelId}-{$intPage + 1}.html{else}/{$strFirstPath}/{$intNovelId}-{$intTotalPages}.html{/if}"
|
||||
class="y">下一页</a>
|
||||
</div> -->
|
||||
|
||||
|
||||
|
||||
```php
|
||||
# 01、 获取多个小说数据并且遍历
|
||||
# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号):
|
||||
$count ?? '10'; # 查询条数
|
||||
$n_category ?? "all"; # 查询分类
|
||||
$sort_type ?? "all"; # 排序方式
|
||||
$n_status ?? "all"; # 查询状态
|
||||
$n_sex ?? "all"; # 查询性别
|
||||
$diff_key ?? ""; # 缓存键值差异
|
||||
$cache_life ?? '0'; # 缓存时间,如果需要开启缓存,这个字段必须传,而且必须大于0
|
||||
$d_key ?? 'd_key'; # 查询出来的数据遍历的时候, 下标键变量的名称
|
||||
$d_val ?? 'd_val'; # 查询出来的数据遍历的时候, 值的名称
|
||||
# 样例
|
||||
{novel:list count="10" n_category="$Request.route.category" d_key="d_key" d_val="novel" p_val="page_data" cache_life="1000"}
|
||||
<li>
|
||||
Index: {$d_key}
|
||||
Title: {$novel.n_name}
|
||||
Author: {$novel.n_category}
|
||||
</li>
|
||||
{/novel:list}
|
||||
|
||||
|
||||
|
||||
# 02、 获取分页小说数据并且遍历
|
||||
# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号):
|
||||
$page ?? '1'; # 页码
|
||||
$limit ?? '10'; # 查询条数
|
||||
$n_category ?? "all"; # 查询分类
|
||||
$sort_type ?? "all"; # 排序方式
|
||||
$n_status ?? "all"; # 查询状态
|
||||
$n_sex ?? "all"; # 查询性别
|
||||
$diff_key ?? ""; # 缓存键值差异
|
||||
$cache_life ?? '0'; # 缓存时间,如果需要开启缓存,这个字段必须传,而且必须大于0
|
||||
$d_key ?? 'd_key'; # 查询出来的数据遍历的时候, 下标键变量的名称
|
||||
$d_val ?? 'd_val'; # 查询出来的数据遍历的时候, 值的名称
|
||||
$p_val ?? 'p_val'; # 分页页码数据,这是一个数组。和之前控制器渲染的那个数组一致的。
|
||||
$func ; # 这个参数是一个回调方法名,用来渲染分页页码数据的,该方法需要在 NovelService 类里面实现,func(array $arrParams, array $arrSort, array $arrNovel)
|
||||
# 样例
|
||||
{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}
|
||||
|
||||
|
||||
# 03、获取替换模板替换后的数据
|
||||
# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号):
|
||||
$code ; # 替换模板编码
|
||||
# 样例
|
||||
{site:replace code="INDEX@INDEX@TITLE"}
|
||||
|
||||
|
||||
# 04、获取小说详情数据
|
||||
# 传参与默认值(传参用下面的变量名,名称不需要$符号, 值的话如果用第三方变量作为值,需要带$符号):
|
||||
$n_id ; # 传入的小说ID
|
||||
$n_forge_id ; # 传入的伪造小说ID,默认值0,不伪造
|
||||
$n_key ; # 查询出来的数据待使用的变量名称
|
||||
# 样例
|
||||
{novel:info n_id="33" n_key="arrNovel01" n_forge_id="1125940" /}
|
||||
{$arrNovel01.n_name}
|
||||
|
||||
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user