This commit is contained in:
make
2025-03-31 19:43:34 +08:00
10 changed files with 293 additions and 45 deletions

View File

@@ -41,4 +41,7 @@ Route::group("/novel", function () {
Route::group("/site", function () { Route::group("/site", function () {
Route::get("/domain/list", [Domain::class, "getDomainList"])->name("Domain@getDomainList"); Route::get("/domain/list", [Domain::class, "getDomainList"])->name("Domain@getDomainList");
Route::post("/domain/upload", [Domain::class, "uploadDomain"])->name("Domain@uploadDomain"); Route::post("/domain/upload", [Domain::class, "uploadDomain"])->name("Domain@uploadDomain");
Route::get("/tkdarg/list", [Domain::class, "getTKDArgList"])->name("Domain@getDomainList");
})->middleware(AdminAuth::class); })->middleware(AdminAuth::class);

View File

@@ -6,6 +6,7 @@ namespace app\admin\controller;
use app\admin\BaseController; use app\admin\BaseController;
use app\model\AdminUserModel; use app\model\AdminUserModel;
use app\model\ConverterMovel;
use app\model\DomainModel; use app\model\DomainModel;
use app\Request; use app\Request;
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
@@ -14,6 +15,19 @@ use think\Response;
class Domain extends BaseController class Domain extends BaseController
{ {
/**
* upload site domain info file
*
* @param Request $Request
* @param AdminUserModel|null $AdminUserModel
* @return Response
*/
public function getTKDArgList(Request $Request, ?AdminUserModel $AdminUserModel)
{
return $this->success(ConverterMovel::$arrDescription);
}
/** /**
* upload site domain info file * upload site domain info file
* *

View File

@@ -82,8 +82,6 @@ class Novel extends BaseController
$intTotal = $Col->countDocuments($arrFilter); $intTotal = $Col->countDocuments($arrFilter);
$arrResult = [ $arrResult = [
'code' => 200,
'msg' => '查询成功',
'data' => $arrData, 'data' => $arrData,
'total' => $intTotal, 'total' => $intTotal,
'page' => $intPage, 'page' => $intPage,

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace app\home; namespace app\home;
use app\model\ConverterMovel;
use think\App; use think\App;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\facade\View; use think\facade\View;
@@ -54,8 +55,32 @@ abstract class BaseController
// View::assign('') // View::assign('')
} }
// 初始化 /**
protected function initialize() {} * 初始化
*
* @return void
*/
protected function initialize()
{
$this->initSiteTKD();
}
/**
* 初始化网站基本信息到全局替换类里
*
* @return void
*/
private function initSiteTKD()
{
ConverterMovel::setVal([
'strSiteTitle' => $this->request->DomainModel->d_title,
'strSiteKeywords' => $this->request->DomainModel->d_keywords,
'strSiteDescription' => $this->request->DomainModel->d_description,
]);
}
/** /**
* 验证数据 * 验证数据

View File

@@ -40,18 +40,18 @@ Route::get('/pc/nvsheng-xiaoshuo', [Novel::class, 'getNovelChannel'])->append([
*/ */
Route::get('/shuku/all', [Novel::class,'getLibrary'])->append(['boolIsMobile' => true]); Route::get('/shuku/all', [Novel::class,'getLibrary'])->append(['boolIsMobile' => true]);
Route::get('/pc/shuku/all', [Novel::class,'getLibrary'])->append(['boolIsMobile' => false]); Route::get('/pc/shuku/all', [Novel::class,'getLibrary'])->append(['boolIsMobile' => false]);
Route::get('/shuku/:strNovelChannel-:strCategory-:strStatus-:intPage', [Novel::class,'getLibrary']) Route::get('/shuku/:intGender-:strCategory-:strStatus-:intPage', [Novel::class,'getLibrary'])
->pattern([ ->pattern([
'strNovelChannel' => '[\w]*', 'intGender' => '\d{1}',
'strCategory' => '[\w]*', 'strCategory' => '[\w]*',
'strStatus' => '[\w]*', 'strStatus' => '[\w]*',
'intPage' => '\d+' 'intPage' => '\d+'
]) ])
->append(['boolIsMobile' => true]); ->append(['boolIsMobile' => true]);
Route::get('/pc/shuku/:strNovelChannel-:strCategory-:strStatus-:intPage', [Novel::class,'getLibrary']) Route::get('/pc/shuku/:intGender-:strCategory-:strStatus-:intPage', [Novel::class,'getLibrary'])
->pattern([ ->pattern([
'strNovelChannel' => '[\w]*', 'intGender' => '\d{1}',
'strCategory' => '[\w]*', 'strCategory' => '[\w]*',
'strStatus' => '[\w]*', 'strStatus' => '[\w]*',
'intPage' => '\d+' 'intPage' => '\d+'

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace app\home\controller; namespace app\home\controller;
use app\home\BaseController; use app\home\BaseController;
use app\model\ConverterMovel;
use app\model\NovelModel; use app\model\NovelModel;
use storage\StorageCore; use storage\StorageCore;
use think\facade\View; use think\facade\View;
@@ -176,11 +177,18 @@ class Index extends BaseController
'strPageCode' => 'home' 'strPageCode' => 'home'
]); ]);
$strTitle = '最新小说网-{strSiteTitle}-{strSiteKeywords}';
$strTitle = ConverterMovel::convert($strTitle);
echo $strTitle;exit;
if ($boolIsMobile) { if ($boolIsMobile) {
return View::fetch(); return View::fetch();
} else { } else {
return View::fetch('pc/index'); return View::fetch('pc/index');
} }
} }
} }

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace app\home\controller; namespace app\home\controller;
use app\home\BaseController; use app\home\BaseController;
use app\model\ConverterMovel;
use app\model\NovelModel; use app\model\NovelModel;
use storage\StorageCore; use storage\StorageCore;
use think\facade\View; use think\facade\View;
@@ -124,16 +125,34 @@ class Novel extends BaseController
* 书库 * 书库
* *
* @param Request $Request * @param Request $Request
* @param [type] $strNovelChannel 男生/女生 -拼音 * @param string $strNovelChannel 男生/女生 -拼音
* @param [type] $strCategory 分类 -拼音 * @param string $strCategory 分类 -拼音
* @param [type] $strStatus 连载/完结 -拼音 * @param string $strStatus 连载/完结 -拼音
* @param integer $intPage 分页 * @param integer $intPage 分页
* @return void * @return void
*/ */
public function getLibrary(Request $Request, $strNovelChannel = 'all', $strCategory = 'all', $strStatus = 'all',$intPage = 1) public function getLibrary(Request $Request) //, $strNovelChannel = 'all', $strCategory = 'all', $strStatus = 'all', $intPage = 1)
{ {
$boolIsMobile = $Request->param('boolIsMobile'); $boolIsMobile = $Request->param('boolIsMobile');
$intGender = (int)$Request->param('intGender',0);
$strCategory = (string)$Request->param('strCategory');
$strStatus = (string)$Request->param('strStatus');
$intPage = (int)$Request->param('intPage');
$intLimit = 20;
$intLifeTime = 24 * 3600;
$NovelModel = new NovelModel;
$strKey = sprintf("Novel:Library:%s:%s:%s:%s", $intGender, $strCategory, $strStatus, $intPage);
// var_dump($intType);exit;
$arrPage = $NovelModel->getCommonNovelPageOnCache($strKey, $intPage, $intLimit, $intLifeTime, $intGender, $strStatus);
// echo '<pre>';
// print_r($arrPage);
// exit;
// 模拟数据 // 模拟数据
$arrNovel = [ $arrNovel = [
['n_id' => 1, 'name' => '小说1', 'author' => '作者1'], ['n_id' => 1, 'name' => '小说1', 'author' => '作者1'],
@@ -149,7 +168,7 @@ class Novel extends BaseController
View::assign([ View::assign([
'arrNovel' => $arrNovel, 'arrNovel' => $arrNovel,
'strPageCode' => 'library', 'strPageCode' => 'library',
'strNovelChannel' => $strNovelChannel, 'intGender' => $intGender,
'strCategory' => $strCategory, 'strCategory' => $strCategory,
'strStatus' => $strStatus, 'strStatus' => $strStatus,
'intPage' => $intPage, 'intPage' => $intPage,
@@ -314,10 +333,14 @@ class Novel extends BaseController
{ {
$intNId = $Request->param('n_id'); $intNId = $Request->param('n_id');
$boolIsMobile = $Request->param('boolIsMobile'); $boolIsMobile = $Request->param('boolIsMobile');
$strNovel = '斗罗大陆';
ConverterMovel::setVal("strNovelName",$strNovel);
// 模拟数据-随机推荐数据10条 // 模拟数据-随机推荐数据10条
$arrRecommendNovel = [ $arrRecommendNovel = [
['id' => 1, 'name' => '小说1', 'author' => '作者1'], ['id' => 1, 'name' => '小说1', 'author' => '作者1'],
@@ -336,6 +359,14 @@ class Novel extends BaseController
// 最新要点->取新意章节, 随机提取一部分内容 大概150字数 // 最新要点->取新意章节, 随机提取一部分内容 大概150字数
// $strTitle = '小说详情-{strNovelName}-xxxxx';
// $strTitle = ConverterMovel::convert($strTitle);
// echo $strTitle;exit;
View::assign([ View::assign([
'arrRecommendNovel' => $arrRecommendNovel, 'arrRecommendNovel' => $arrRecommendNovel,
'strPageCode' => 'boy' 'strPageCode' => 'boy'

View File

@@ -32,25 +32,25 @@
<div class="optCl" mod="search_channel"> <div class="optCl" mod="search_channel">
<span class="optTit">所属频道</span> <span class="optTit">所属频道</span>
<ul> <ul>
<li><a class="on" href="/pc/shuku/all-{$strCategory}-{$strStatus}-1" btn="search_category">全部</a></li> <li><a class="on" href="/pc/shuku/{$intGender}-{$strCategory}-{$strStatus}-{$intPage}.html" btn="search_category">全部</a></li>
<li><a href="/pc/shuku/nansheng-{$strCategory}-{$strStatus}-1" btn="search_category">男生</a></li> <li><a href="/pc/shuku/{$intGender}-{$strCategory}-{$strStatus}-{$intPage}" btn="search_category">男生</a></li>
<li><a href="/pc/shuku/nvsheng-{$strCategory}-{$strStatus}-1" btn="search_category">女生</a></li> <li><a href="/pc/shuku/{$intGender}-{$strCategory}-{$strStatus}-{$intPage}" btn="search_category">女生</a></li>
</ul> </ul>
</div> </div>
<div class="optCl" mod="search_channel"> <div class="optCl" mod="search_channel">
<span class="optTit">所属分类</span> <span class="optTit">所属分类</span>
<ul> <ul>
<li><a class="on" href="/pc/shuku/{$strNovelChannel}-all-{$strStatus}-1" btn="search_category">全部</a></li> <li><a class="on" href="/pc/shuku/{$intGender}-{$strCategory}-{$strStatus}-{$intPage}" btn="search_category">全部</a></li>
<li><a href="/pc/shuku/{$strNovelChannel}-dushixiuxian-{$strStatus}-1" btn="search_category">都市修仙</a></li> <li><a href="/pc/shuku/{$intGender}-{$strCategory}-{$strStatus}-{$intPage}" btn="search_category">都市修仙</a></li>
<li><a href="/pc/shuku/{$strNovelChannel}-xuanhuanxiuzhen-{$strStatus}-1" btn="search_category">玄幻修真</a></li> <li><a href="/pc/shuku/{$intGender}-{$strCategory}-{$strStatus}-{$intPage}" btn="search_category">玄幻修真</a></li>
</ul> </ul>
</div> </div>
<div class="optCl"> <div class="optCl">
<span class="optTit">是否完结</span> <span class="optTit">是否完结</span>
<ul> <ul>
<li><a class="on" href="/pc/shuku/{$strNovelChannel}-{$strCategory}-all-1" btn="search_category">全部</a></li> <li><a class="on" href="/pc/shuku/{$intGender}-{$strCategory}-{$strStatus}-{$intPage}" btn="search_category">全部</a></li>
<li><a href="/pc/shuku/{$strNovelChannel}-{$strCategory}-lianzai-1" btn="search_category">连载</a></li> <li><a href="/pc/shuku/{$intGender}-{$strCategory}-{$strStatus}-{$intPage}" btn="search_category">连载</a></li>
<li><a href="/pc/shuku/{$strNovelChannel}-{$strCategory}-wanben-1" btn="search_category">完本</a></li> <li><a href="/pc/shuku/{$intGender}-{$strCategory}-{$strStatus}-{$intPage}" btn="search_category">完本</a></li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -69,17 +69,17 @@
<ul class="pagination"> <ul class="pagination">
<li class="disabled"><span>«</span></li> <li class="disabled"><span>«</span></li>
<li class="active"><span>1</span></li> <li class="active"><span>1</span></li>
<li><a href="/pc/{$strNovelChannel}-{$strCategory}-{$strStatus}-2">2</a></li> <li><a href="/pc/{$intGender}-{$strCategory}-{$strStatus}-2">2</a></li>
<li><a href="/pc/{$strNovelChannel}-{$strCategory}-{$strStatus}-3">3</a></li> <li><a href="/pc/{$intGender}-{$strCategory}-{$strStatus}-3">3</a></li>
<li><a href="/pc/{$strNovelChannel}-{$strCategory}-{$strStatus}-4">4</a></li> <li><a href="/pc/{$intGender}-{$strCategory}-{$strStatus}-4">4</a></li>
<li><a href="/pc/{$strNovelChannel}-{$strCategory}-{$strStatus}-5">5</a></li> <li><a href="/pc/{$intGender}-{$strCategory}-{$strStatus}-5">5</a></li>
<li><a href="/pc/{$strNovelChannel}-{$strCategory}-{$strStatus}-6">6</a></li> <li><a href="/pc/{$intGender}-{$strCategory}-{$strStatus}-6">6</a></li>
<li><a href="/pc/{$strNovelChannel}-{$strCategory}-{$strStatus}-7">7</a></li> <li><a href="/pc/{$intGender}-{$strCategory}-{$strStatus}-7">7</a></li>
<li><a href="/pc/{$strNovelChannel}-{$strCategory}-{$strStatus}-8">8</a></li> <li><a href="/pc/{$intGender}-{$strCategory}-{$strStatus}-8">8</a></li>
<li class="disabled"><span>...</span></li> <li class="disabled"><span>...</span></li>
<li><a href="/pc/{$strNovelChannel}-{$strCategory}-{$strStatus}-33">33</a></li> <li><a href="/pc/{$intGender}-{$strCategory}-{$strStatus}-33">33</a></li>
<li><a href="/pc/{$strNovelChannel}-{$strCategory}-{$strStatus}-34">34</a></li> <li><a href="/pc/{$intGender}-{$strCategory}-{$strStatus}-34">34</a></li>
<li><a href="/pc/{$strNovelChannel}-{$strCategory}-{$strStatus}-2">»</a></li> <li><a href="/pc/{$intGender}-{$strCategory}-{$strStatus}-2">»</a></li>
</ul> </ul>
</div> </div>
<!--页码切换 结束--> <!--页码切换 结束-->

View File

@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace app\model;
use DateTime;
use think\facade\Cache;
use think\Model;
/**
* @mixin think\Model
*/
class ConverterMovel
{
static private $arrMap = [
'{strSiteTitle}' => '',
'{strSiteKeywords}' => '',
'{strSiteDescription}' => '',
'{strNovelName}' => '',
'{strNovelChapterName}' => '',
'{strNovelCategoryName}' => '',
];
static public $arrDescription = [
'{strSiteTitle}' => '这个是网站标题',
'{strSiteKeywords}' => '这个是网站关键字',
'{strSiteDescription}' => '这个是网站描述',
'{strNovelName}' => '当前页面小说标题',
'{strNovelChapterName}' => '当前页面小说章节名字',
'{strNovelCategoryName}' => '当前页面小说分类名字',
];
static private function getKey($strKey): string
{
return '{' . $strKey . '}';
}
/**
* Undocumented function
*
* @param string|array $mixedKey 全局动态变量键或者数组
* @param string $strVal 全局动态变量值
* @return void
*/
static public function setVal(string | array $mixedKey, $strVal = NULL)
{
if (is_string($mixedKey)) {
self::$arrMap[self::getKey($mixedKey)] = $strVal;
} else if (is_array($mixedKey)) {
foreach ($mixedKey as $strKey => $strVal) {
if (key_exists(self::getKey($strKey), self::$arrMap)) {
self::$arrMap[self::getKey($strKey)] = $strVal;
}
}
}
}
/**
* Undocumented function
*
* @param string $strKey
* @return void
*/
static public function getVal(string $strKey)
{
return self::$arrMap[self::getKey($strKey)];
}
/**
* Undocumented function
*
* @param string $strSubject
* @return string
*/
static public function convert(string $strSubject): string
{
return str_replace(array_keys(self::$arrMap), array_values(self::$arrMap), $strSubject);
}
}

View File

@@ -53,6 +53,94 @@ class NovelModel extends MongoModel
return true; return true;
} }
/**
* Undocumented function
*
* @param string $strKey
* @param int $intLifeTime
* @param integer $intCount
* @param integer $intType
* @param string $strStatus
* @param array $arrSort
* @return array
*/
public function getCommonNovelPageOnCache(
string $strKey,
int $intPage = 1,
int $intLimit = 20,
int $intLifeTime = 24 * 3600,
int $intType = 0,
$strStatus = NULL,
array $arrSort = ['n_level' => -1]
): array {
try {
$arrResult = Cache::get($strKey);
// if (empty($arrResult)) {
if (true) {
$arrFilter = [];
switch ($intType) {
case 1:
$arrCategory = array_values(CategoryModel::getManCategory());
$arrFilter['og_novel_category'] = ['$in' => $arrCategory];
break;
case 2:
$arrCategory = array_values(CategoryModel::getWomenCategory());
$arrFilter['og_novel_category'] = ['$in' => $arrCategory];
break;
}
if ($strStatus !== NULL) {
$arrFilter['og_novel_status'] = $strStatus;
}
$arrOptions = [
'sort' => $arrSort,
// 'limit' => $intCount * 3,
'skip' => ($intPage - 1) * $intLimit,
'limit' => $intLimit,
'projection' => [
'n_id' => 1,
'og_novel_book_name' => 1,
'og_novel_pin_yin' => 1,
'n_cover_path' => 1,
'og_novel_author' => 1,
'og_novel_category' => 1,
'og_description' => 1,
'og_novel_latest_chapter_name' => 1,
'og_novel_update_time' => 1,
],
];
$Cursor = $this->getCol()->find($arrFilter, $arrOptions);
$intTotal = $this->getCol()->countDocuments($arrFilter);
$arrResult = iterator_to_array($Cursor);
shuffle($arrResult);
$arrResult = [
'data' => $arrResult,
'total' => $intTotal,
'page' => $intPage,
'limit' => $intLimit,
'pages' => ceil($intTotal / $intLimit)
];
if (!empty($arrResult)) {
Cache::set($strKey, $arrResult, $intLifeTime);
}
}
return $arrResult;
} catch (\Exception $e) {
return [];
}
}
/** /**
* Undocumented function * Undocumented function
* *