diff --git a/code/app/admin/config/router.php b/code/app/admin/config/router.php index cd3ffeb..b024377 100644 --- a/code/app/admin/config/router.php +++ b/code/app/admin/config/router.php @@ -41,4 +41,7 @@ Route::group("/novel", function () { Route::group("/site", function () { Route::get("/domain/list", [Domain::class, "getDomainList"])->name("Domain@getDomainList"); Route::post("/domain/upload", [Domain::class, "uploadDomain"])->name("Domain@uploadDomain"); + + + Route::get("/tkdarg/list", [Domain::class, "getTKDArgList"])->name("Domain@getDomainList"); })->middleware(AdminAuth::class); diff --git a/code/app/admin/controller/Domain.php b/code/app/admin/controller/Domain.php index 7090534..1434c27 100644 --- a/code/app/admin/controller/Domain.php +++ b/code/app/admin/controller/Domain.php @@ -6,6 +6,7 @@ namespace app\admin\controller; use app\admin\BaseController; use app\model\AdminUserModel; +use app\model\ConverterMovel; use app\model\DomainModel; use app\Request; use PhpOffice\PhpSpreadsheet\IOFactory; @@ -14,6 +15,19 @@ use think\Response; 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 * diff --git a/code/app/admin/controller/Novel.php b/code/app/admin/controller/Novel.php index b8fa98e..925fe8f 100644 --- a/code/app/admin/controller/Novel.php +++ b/code/app/admin/controller/Novel.php @@ -82,8 +82,6 @@ class Novel extends BaseController $intTotal = $Col->countDocuments($arrFilter); $arrResult = [ - 'code' => 200, - 'msg' => '查询成功', 'data' => $arrData, 'total' => $intTotal, 'page' => $intPage, diff --git a/code/app/home/BaseController.php b/code/app/home/BaseController.php index 8fdb0d3..f6122cd 100644 --- a/code/app/home/BaseController.php +++ b/code/app/home/BaseController.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace app\home; +use app\model\ConverterMovel; use think\App; use think\exception\ValidateException; use think\facade\View; @@ -54,8 +55,32 @@ abstract class BaseController // 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, + ]); + } + /** * 验证数据 diff --git a/code/app/home/config/router.php b/code/app/home/config/router.php index 3364fb8..08d3f6d 100644 --- a/code/app/home/config/router.php +++ b/code/app/home/config/router.php @@ -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('/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([ - 'strNovelChannel' => '[\w]*', + 'intGender' => '\d{1}', 'strCategory' => '[\w]*', 'strStatus' => '[\w]*', 'intPage' => '\d+' ]) ->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([ - 'strNovelChannel' => '[\w]*', + 'intGender' => '\d{1}', 'strCategory' => '[\w]*', 'strStatus' => '[\w]*', 'intPage' => '\d+' diff --git a/code/app/home/controller/Index.php b/code/app/home/controller/Index.php index 58a80d8..4d5d56e 100644 --- a/code/app/home/controller/Index.php +++ b/code/app/home/controller/Index.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace app\home\controller; use app\home\BaseController; +use app\model\ConverterMovel; use app\model\NovelModel; use storage\StorageCore; use think\facade\View; @@ -132,28 +133,28 @@ class Index extends BaseController // 推荐等级为9的完结的 随机12个小说 $arrRecommendEndNovel = $NovelModel->getFinishedNovelOnCache($Request->DomainModel->d_domain, 12); - + // 男生频道,最新的 随机5个小说 $arrBoyNewsNovel = $NovelModel->getSexNovelOnCache($Request->DomainModel->d_domain, 5, 1); - + // 男生频道,周排行榜 随机10个小说 $arrBoyWeekRankNovel = $NovelModel->getRankNovelOnCache($Request->DomainModel->d_domain, 5, 1, 'weekly'); // 男生频道,月排行榜 随机10个小说 $arrBoyMoonRankNovel = $NovelModel->getRankNovelOnCache($Request->DomainModel->d_domain, 5, 1, 'monthly'); - + // 男生频道,总排行榜 随机10个小说 $arrBoyTotalRankNovel = $NovelModel->getRankNovelOnCache($Request->DomainModel->d_domain, 5, 1, 'total'); // 女生频道,最新的 随机5个小说 $arrGirlNewsNovel = $NovelModel->getSexNovelOnCache($Request->DomainModel->d_domain, 5, 2); - + // 女生频道,周排行榜 随机10个小说 $arrGirlWeekRankNovel = $NovelModel->getRankNovelOnCache($Request->DomainModel->d_domain, 5, 2, 'weekly'); // 女生频道,月排行榜 随机10个小说 $arrGirlMoonRankNovel = $NovelModel->getRankNovelOnCache($Request->DomainModel->d_domain, 5, 2, 'monthly'); - + // 女生频道,总排行榜 随机10个小说 $arrBGirlTotalRankNovel = $NovelModel->getRankNovelOnCache($Request->DomainModel->d_domain, 5, 2, 'total'); @@ -176,11 +177,18 @@ class Index extends BaseController 'strPageCode' => 'home' ]); + + $strTitle = '最新小说网-{strSiteTitle}-{strSiteKeywords}'; + + $strTitle = ConverterMovel::convert($strTitle); + + echo $strTitle;exit; + + if ($boolIsMobile) { return View::fetch(); } else { return View::fetch('pc/index'); } } - } diff --git a/code/app/home/controller/Novel.php b/code/app/home/controller/Novel.php index 7367d84..6d5cf4a 100644 --- a/code/app/home/controller/Novel.php +++ b/code/app/home/controller/Novel.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace app\home\controller; use app\home\BaseController; +use app\model\ConverterMovel; use app\model\NovelModel; use storage\StorageCore; use think\facade\View; @@ -124,16 +125,34 @@ class Novel extends BaseController * 书库 * * @param Request $Request - * @param [type] $strNovelChannel 男生/女生 -拼音 - * @param [type] $strCategory 分类 -拼音 - * @param [type] $strStatus 连载/完结 -拼音 + * @param string $strNovelChannel 男生/女生 -拼音 + * @param string $strCategory 分类 -拼音 + * @param string $strStatus 连载/完结 -拼音 * @param integer $intPage 分页 * @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'); + $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 '
';
+        // print_r($arrPage);
+        // exit;
+
         // 模拟数据
         $arrNovel = [
             ['n_id' => 1, 'name' => '小说1', 'author' => '作者1'],
@@ -149,7 +168,7 @@ class Novel extends BaseController
         View::assign([
             'arrNovel' => $arrNovel,
             'strPageCode' => 'library',
-            'strNovelChannel' => $strNovelChannel,
+            'intGender' => $intGender,
             'strCategory' => $strCategory,
             'strStatus' => $strStatus,
             'intPage' => $intPage,
@@ -210,7 +229,7 @@ class Novel extends BaseController
         $strStuatus = '连载中';
 
         $arrRecommendSerializationNovel = $NovelModel->getCommonNovelOnCache($strKey, $intLifeTime, $intCount, $intType, $strStuatus);
-       
+
         // 推荐等级为9的,完结的,男生频道/女生频道, 随机8个小说
         $strKey = sprintf('%s:PC:Novel:Channel:Hot:%s:%s', $Request->DomainModel->d_domain,  $intType, 'Finish');
         $intCount = 8;
@@ -222,7 +241,7 @@ class Novel extends BaseController
         $strKey = sprintf('%s:PC:Novel:Channel:Latest:%s', $Request->DomainModel->d_domain,  $intType);
         $intCount = 20;
         $arrNewsUpdateNovel = $NovelModel->getCommonNovelOnCache($strKey, $intLifeTime, $intCount, $intType, NULL, ['og_novel_update_time' => -1]);
-        
+
         View::assign([
             'arrRecommendSerializationNovel' => $arrRecommendSerializationNovel,
             'arrRecommendEndNovel' => $arrRecommendEndNovel,
@@ -314,10 +333,14 @@ class Novel extends BaseController
     {
         $intNId = $Request->param('n_id');
 
-
-
         $boolIsMobile = $Request->param('boolIsMobile');
 
+
+        $strNovel = '斗罗大陆';
+
+        ConverterMovel::setVal("strNovelName",$strNovel);
+
+
         // 模拟数据-随机推荐数据10条
         $arrRecommendNovel = [
             ['id' => 1, 'name' => '小说1', 'author' => '作者1'],
@@ -336,6 +359,14 @@ class Novel extends BaseController
         // 最新要点->取新意章节, 随机提取一部分内容 大概150字数
 
 
+
+        
+        // $strTitle = '小说详情-{strNovelName}-xxxxx';
+
+        // $strTitle = ConverterMovel::convert($strTitle);
+
+        // echo $strTitle;exit;
+
         View::assign([
             'arrRecommendNovel' => $arrRecommendNovel,
             'strPageCode' => 'boy'
@@ -351,7 +382,7 @@ class Novel extends BaseController
     public function getNovelNewsChapter(Request $Request)
     {
 
-       
+
         $intNId = $Request->param('n_id');
 
 
@@ -385,7 +416,7 @@ class Novel extends BaseController
             return View::fetch('pc/getNovelChapter');
         }
     }
-    
+
 
     /**
      * 小说章节
diff --git a/code/app/home/view/kuangyu/Pc/getLibrary.html b/code/app/home/view/kuangyu/Pc/getLibrary.html
index 75013dd..037a0c9 100644
--- a/code/app/home/view/kuangyu/Pc/getLibrary.html
+++ b/code/app/home/view/kuangyu/Pc/getLibrary.html
@@ -29,28 +29,28 @@
      
     
-
+
所属频道
是否完结
@@ -69,17 +69,17 @@
diff --git a/code/app/model/ConverterMovel.php b/code/app/model/ConverterMovel.php new file mode 100644 index 0000000..33f7902 --- /dev/null +++ b/code/app/model/ConverterMovel.php @@ -0,0 +1,81 @@ + '', + '{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); + } +} diff --git a/code/app/model/NovelModel.php b/code/app/model/NovelModel.php index 3c4d270..2c4ec7e 100644 --- a/code/app/model/NovelModel.php +++ b/code/app/model/NovelModel.php @@ -53,6 +53,94 @@ class NovelModel extends MongoModel 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 *