From eb9035a7aed0cda174de8615f88265013264c4ff Mon Sep 17 00:00:00 2001 From: Default Date: Sat, 15 Mar 2025 20:12:21 +0800 Subject: [PATCH] debug --- code/.example.env | 10 + code/LICENSE.txt | 32 - code/README.md | 77 -- code/app/admin/AdminServiceProvider.php | 36 + code/app/admin/BaseController.php | 107 +++ code/app/admin/config/error.php | 38 + code/app/admin/config/router.php | 60 ++ code/app/admin/controller/AdminUser.php | 153 ++++ code/app/admin/controller/GuangGao.php | 359 ++++++++ code/app/admin/controller/Guest.php | 70 ++ code/app/admin/controller/SeoKeywords.php | 154 ++++ code/app/admin/controller/SystemConfig.php | 367 ++++++++ code/app/admin/controller/XiaoShuo.php | 179 ++++ code/app/admin/middleware.php | 6 +- code/app/admin/middleware/AdminAuth.php | 34 + code/app/admin/middleware/AdminCors.php | 22 + code/app/admin/middleware/AdminException.php | 17 + code/app/admin/middleware/AdminResponse.php | 57 ++ code/app/admin/model/AdminNodeModel.php | 15 + code/app/admin/model/AdminRoleModel.php | 47 + code/app/admin/model/AdminRoleNodeModel.php | 15 + code/app/admin/model/AdminUserModel.php | 92 ++ code/app/admin/model/BaseModel.php | 21 + code/app/admin/model/CaiJiPeiZhiModel.php | 39 + code/app/admin/model/ContentStatsModel.php | 70 ++ code/app/admin/model/FenLeiModel.php | 133 +++ code/app/admin/model/GanRaoMaModel.php | 76 ++ code/app/admin/model/GuangGaoFenZuModel.php | 17 + code/app/admin/model/GuangGaoModel.php | 59 ++ code/app/admin/model/GuangGaoPeiZhiModel.php | 40 + code/app/admin/model/NovelInfoSeoModel.php | 41 + code/app/admin/model/PlanTaskModel.php | 17 + code/app/admin/model/ReSouFenZuModel.php | 42 + code/app/admin/model/ReSouModel.php | 101 +++ code/app/admin/model/SeoHtmlModel.php | 63 ++ code/app/admin/model/SeoKeywordsModel.php | 63 ++ code/app/admin/model/SeoTdkConfigModel.php | 63 ++ code/app/admin/model/SiteModel.php | 82 ++ code/app/admin/model/SystemConfigModel.php | 39 + code/app/admin/model/VideoClassModel.php | 112 +++ code/app/admin/model/VideoDiquModel.php | 90 ++ code/app/admin/model/VideoInfoModel.php | 119 +++ code/app/admin/model/VideoInfoSeoModel.php | 41 + code/app/admin/model/VideoJuqingModel.php | 90 ++ code/app/admin/model/VideoLeixinModel.php | 90 ++ code/app/admin/model/VideoPlayurlModel.php | 96 ++ code/app/admin/model/VideoYearsModel.php | 90 ++ code/app/admin/model/VideoYuyanModel.php | 90 ++ code/app/admin/model/VisitLogsModel.php | 63 ++ code/app/admin/model/XiaoShuoFenLeiModel.php | 92 ++ .../admin/model/XiaoShuoXiangQingModel.php | 86 ++ .../app/admin/model/XiaoShuoZhangJieModel.php | 49 + code/app/admin/model/ZiYuanDuanDianModel.php | 40 + code/app/admin/provider.php | 12 + code/app/common.php | 763 ++++++++++++++++ code/app/home/controller/Index.php | 5 + code/app/service.php | 2 + code/app/task/collection/PullDataColBase.php | 124 +++ .../collection/biquxs/BiquxsXiaoShuoCol.php | 427 +++++++++ .../task/collection/ccc5/XiaoShuo5cccCol.php | 545 +++++++++++ .../task/collection/dadi/DaDiDianyingCol.php | 498 ++++++++++ .../collection/heimuer/HeiMuErYingShiCol.php | 560 ++++++++++++ .../collection/novel/Zw630XiaoShuoCol.php | 850 ++++++++++++++++++ .../novelone/NovelJiuYuFanXianCol.php | 426 +++++++++ .../novelone/NovelWenXueGuanCol.php | 441 +++++++++ .../collection/seo/GenerateSiteMapCol.php | 137 +++ .../collection/seo/GenerateSiteMapNovel.php | 188 ++++ .../collection/seo/GenerateSiteMapNovelSk.php | 242 +++++ .../collection/seo/GenerateSiteMapNovelZw.php | 242 +++++ .../collection/tianlai/TianLaiXiaoShuoCol.php | 538 +++++++++++ .../collection/visitlogs/ContentStatsCol.php | 90 ++ .../collection/visitlogs/VisitLogsCol.php | 47 + .../task/collection/yzzy/YouZhiYingShiCol.php | 375 ++++++++ code/app/task/command/DatabaseCommand.php | 115 +++ .../task/command/InsertSeoWordsCommand.php | 50 ++ code/app/task/command/Task.php | 89 ++ code/app/task/core/Core.php | 129 +++ code/app/task/core/Listen.php | 90 ++ code/app/task/core/Rout.php | 31 + code/app/task/core/ScheduledTasks.php | 24 + code/app/task/core/Service.php | 87 ++ code/app/task/core/TaskCore.php | 35 + code/app/task/logic/AdTask.php | 70 ++ code/app/task/logic/SystemLogic.php | 30 + code/app/task/module/PlanTask.php | 358 ++++++++ code/composer.json | 13 +- code/config/app.php | 3 +- code/config/cache.php | 23 +- code/config/console.php | 2 + code/config/database.php | 4 +- code/config/task.php | 68 ++ ...add_gg_pai_xu_colum_on_guang_gao_table.php | 20 + .../20240809204922_seo_keywords_table.php | 46 + .../20240924114816_guanggao_add_status.php | 20 + .../migrations/20250104155836_video_class.php | 65 ++ .../20250104160751_video_leixin.php | 65 ++ .../20250104161057_video_juqing.php | 58 ++ .../migrations/20250104161633_video_diqu.php | 59 ++ .../migrations/20250104161642_video_years.php | 58 ++ .../20250104161650_video_language.php | 59 ++ .../migrations/20250104162037_video_info.php | 91 ++ .../20250104162430_video_playurl.php | 68 ++ .../migrations/20250105042300_gan_rao_ma.php | 62 ++ .../20250108092206_seo_tdk_config.php | 48 + .../20250110025821_create_visit_logs.php | 56 ++ .../20250110065748_create_content_stats.php | 87 ++ ...212095020_add_new_column_to_video_info.php | 41 + .../migrations/20250215153113_seo_html.php | 48 + ...155929_create_xiao_shuo_xiang_qing_seo.php | 54 ++ ..._add_new_column_to_xiao_shuo_zhang_jie.php | 56 ++ .../20250223165039_create_video_info_seo.php | 54 ++ .../migrations/20250223165052_create_site.php | 56 ++ ...65158_add_clouma_to_all_table_add_site.php | 57 ++ ...031014_add_cloumn_to_xiao_shuo_fen_lei.php | 34 + code/database/schema/mysql-schema.dump | 297 ++++++ code/database/seeders/AdminUserSeeder.php | 20 + code/database/seeders/GuangGaoSeeder.php | 104 +++ code/database/seeders/NovelClassSeeder.php | 82 ++ code/database/seeders/PlanTaskSeeder.php | 127 +++ code/database/seeders/SeedManager.php | 19 + code/database/seeders/SeoTdkConfigSeeder.php | 189 ++++ code/database/seeders/SiteSeeder.php | 467 ++++++++++ code/database/seeders/SystemConfigSeeder.php | 163 ++++ code/database/seeders/VideoInfoSeeder.php | 318 +++++++ code/database/seeders/VideoSeoSeeder.php | 35 + .../database/seeders/ZiYuanDuanDianSeeder.php | 76 ++ code/extend/.gitignore | 2 - code/extend/SeoTdkHelper.php | 37 + code/extend/processor/ImageProcessor.php | 133 +++ code/extend/template/page/CusteomPage.php | 215 +++++ code/extend/template/taglib/Ad.php | 36 + code/extend/template/taglib/Rs.php | 35 + code/extend/template/taglib/Site.php | 140 +++ code/extend/template/ziku/WordsEntities.php | 18 + 134 files changed, 15450 insertions(+), 119 deletions(-) delete mode 100644 code/LICENSE.txt delete mode 100644 code/README.md create mode 100644 code/app/admin/AdminServiceProvider.php create mode 100644 code/app/admin/BaseController.php create mode 100644 code/app/admin/config/error.php create mode 100644 code/app/admin/config/router.php create mode 100644 code/app/admin/controller/AdminUser.php create mode 100644 code/app/admin/controller/GuangGao.php create mode 100644 code/app/admin/controller/Guest.php create mode 100644 code/app/admin/controller/SeoKeywords.php create mode 100644 code/app/admin/controller/SystemConfig.php create mode 100644 code/app/admin/controller/XiaoShuo.php create mode 100644 code/app/admin/middleware/AdminAuth.php create mode 100644 code/app/admin/middleware/AdminCors.php create mode 100644 code/app/admin/middleware/AdminException.php create mode 100644 code/app/admin/middleware/AdminResponse.php create mode 100644 code/app/admin/model/AdminNodeModel.php create mode 100644 code/app/admin/model/AdminRoleModel.php create mode 100644 code/app/admin/model/AdminRoleNodeModel.php create mode 100644 code/app/admin/model/AdminUserModel.php create mode 100644 code/app/admin/model/BaseModel.php create mode 100644 code/app/admin/model/CaiJiPeiZhiModel.php create mode 100644 code/app/admin/model/ContentStatsModel.php create mode 100644 code/app/admin/model/FenLeiModel.php create mode 100644 code/app/admin/model/GanRaoMaModel.php create mode 100644 code/app/admin/model/GuangGaoFenZuModel.php create mode 100644 code/app/admin/model/GuangGaoModel.php create mode 100644 code/app/admin/model/GuangGaoPeiZhiModel.php create mode 100644 code/app/admin/model/NovelInfoSeoModel.php create mode 100644 code/app/admin/model/PlanTaskModel.php create mode 100644 code/app/admin/model/ReSouFenZuModel.php create mode 100644 code/app/admin/model/ReSouModel.php create mode 100644 code/app/admin/model/SeoHtmlModel.php create mode 100644 code/app/admin/model/SeoKeywordsModel.php create mode 100644 code/app/admin/model/SeoTdkConfigModel.php create mode 100644 code/app/admin/model/SiteModel.php create mode 100644 code/app/admin/model/SystemConfigModel.php create mode 100644 code/app/admin/model/VideoClassModel.php create mode 100644 code/app/admin/model/VideoDiquModel.php create mode 100644 code/app/admin/model/VideoInfoModel.php create mode 100644 code/app/admin/model/VideoInfoSeoModel.php create mode 100644 code/app/admin/model/VideoJuqingModel.php create mode 100644 code/app/admin/model/VideoLeixinModel.php create mode 100644 code/app/admin/model/VideoPlayurlModel.php create mode 100644 code/app/admin/model/VideoYearsModel.php create mode 100644 code/app/admin/model/VideoYuyanModel.php create mode 100644 code/app/admin/model/VisitLogsModel.php create mode 100644 code/app/admin/model/XiaoShuoFenLeiModel.php create mode 100644 code/app/admin/model/XiaoShuoXiangQingModel.php create mode 100644 code/app/admin/model/XiaoShuoZhangJieModel.php create mode 100644 code/app/admin/model/ZiYuanDuanDianModel.php create mode 100644 code/app/admin/provider.php create mode 100644 code/app/task/collection/PullDataColBase.php create mode 100644 code/app/task/collection/biquxs/BiquxsXiaoShuoCol.php create mode 100644 code/app/task/collection/ccc5/XiaoShuo5cccCol.php create mode 100644 code/app/task/collection/dadi/DaDiDianyingCol.php create mode 100644 code/app/task/collection/heimuer/HeiMuErYingShiCol.php create mode 100644 code/app/task/collection/novel/Zw630XiaoShuoCol.php create mode 100644 code/app/task/collection/novelone/NovelJiuYuFanXianCol.php create mode 100644 code/app/task/collection/novelone/NovelWenXueGuanCol.php create mode 100644 code/app/task/collection/seo/GenerateSiteMapCol.php create mode 100644 code/app/task/collection/seo/GenerateSiteMapNovel.php create mode 100644 code/app/task/collection/seo/GenerateSiteMapNovelSk.php create mode 100644 code/app/task/collection/seo/GenerateSiteMapNovelZw.php create mode 100644 code/app/task/collection/tianlai/TianLaiXiaoShuoCol.php create mode 100644 code/app/task/collection/visitlogs/ContentStatsCol.php create mode 100644 code/app/task/collection/visitlogs/VisitLogsCol.php create mode 100644 code/app/task/collection/yzzy/YouZhiYingShiCol.php create mode 100644 code/app/task/command/DatabaseCommand.php create mode 100644 code/app/task/command/InsertSeoWordsCommand.php create mode 100644 code/app/task/command/Task.php create mode 100644 code/app/task/core/Core.php create mode 100644 code/app/task/core/Listen.php create mode 100644 code/app/task/core/Rout.php create mode 100644 code/app/task/core/ScheduledTasks.php create mode 100644 code/app/task/core/Service.php create mode 100644 code/app/task/core/TaskCore.php create mode 100644 code/app/task/logic/AdTask.php create mode 100644 code/app/task/logic/SystemLogic.php create mode 100644 code/app/task/module/PlanTask.php create mode 100644 code/config/task.php create mode 100644 code/database/migrations/20240717191901_add_gg_pai_xu_colum_on_guang_gao_table.php create mode 100644 code/database/migrations/20240809204922_seo_keywords_table.php create mode 100644 code/database/migrations/20240924114816_guanggao_add_status.php create mode 100644 code/database/migrations/20250104155836_video_class.php create mode 100644 code/database/migrations/20250104160751_video_leixin.php create mode 100644 code/database/migrations/20250104161057_video_juqing.php create mode 100644 code/database/migrations/20250104161633_video_diqu.php create mode 100644 code/database/migrations/20250104161642_video_years.php create mode 100644 code/database/migrations/20250104161650_video_language.php create mode 100644 code/database/migrations/20250104162037_video_info.php create mode 100644 code/database/migrations/20250104162430_video_playurl.php create mode 100644 code/database/migrations/20250105042300_gan_rao_ma.php create mode 100644 code/database/migrations/20250108092206_seo_tdk_config.php create mode 100644 code/database/migrations/20250110025821_create_visit_logs.php create mode 100644 code/database/migrations/20250110065748_create_content_stats.php create mode 100644 code/database/migrations/20250212095020_add_new_column_to_video_info.php create mode 100644 code/database/migrations/20250215153113_seo_html.php create mode 100644 code/database/migrations/20250219155929_create_xiao_shuo_xiang_qing_seo.php create mode 100644 code/database/migrations/20250221094510_add_new_column_to_xiao_shuo_zhang_jie.php create mode 100644 code/database/migrations/20250223165039_create_video_info_seo.php create mode 100644 code/database/migrations/20250223165052_create_site.php create mode 100644 code/database/migrations/20250223165158_add_clouma_to_all_table_add_site.php create mode 100644 code/database/migrations/20250224031014_add_cloumn_to_xiao_shuo_fen_lei.php create mode 100644 code/database/schema/mysql-schema.dump create mode 100644 code/database/seeders/AdminUserSeeder.php create mode 100644 code/database/seeders/GuangGaoSeeder.php create mode 100644 code/database/seeders/NovelClassSeeder.php create mode 100644 code/database/seeders/PlanTaskSeeder.php create mode 100644 code/database/seeders/SeedManager.php create mode 100644 code/database/seeders/SeoTdkConfigSeeder.php create mode 100644 code/database/seeders/SiteSeeder.php create mode 100644 code/database/seeders/SystemConfigSeeder.php create mode 100644 code/database/seeders/VideoInfoSeeder.php create mode 100644 code/database/seeders/VideoSeoSeeder.php create mode 100644 code/database/seeders/ZiYuanDuanDianSeeder.php delete mode 100644 code/extend/.gitignore create mode 100644 code/extend/SeoTdkHelper.php create mode 100644 code/extend/processor/ImageProcessor.php create mode 100644 code/extend/template/page/CusteomPage.php create mode 100644 code/extend/template/taglib/Ad.php create mode 100644 code/extend/template/taglib/Rs.php create mode 100644 code/extend/template/taglib/Site.php create mode 100644 code/extend/template/ziku/WordsEntities.php diff --git a/code/.example.env b/code/.example.env index 5abd8bb..3a7919e 100644 --- a/code/.example.env +++ b/code/.example.env @@ -1,5 +1,8 @@ +[APP] APP_DEBUG = true +SHOW_ERROR_MSG = true +[DB] DB_TYPE = mysql DB_HOST = 127.0.0.1 DB_NAME = test @@ -7,5 +10,12 @@ DB_USER = username DB_PASS = password DB_PORT = 3306 DB_CHARSET = utf8mb4 +DB_SQL_DEBUG = true +DB_FIELD_CACHE = false +[CACHE] + +[TASK] + +[LANG] DEFAULT_LANG = zh-cn diff --git a/code/LICENSE.txt b/code/LICENSE.txt deleted file mode 100644 index 8d94897..0000000 --- a/code/LICENSE.txt +++ /dev/null @@ -1,32 +0,0 @@ - -ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 -版权所有Copyright © 2006-2025 by ThinkPHP (http://thinkphp.cn) -All rights reserved。 -ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 - -Apache Licence是著名的非盈利开源组织Apache采用的协议。 -该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, -允许代码修改,再作为开源或商业软件发布。需要满足 -的条件: -1. 需要给代码的用户一份Apache Licence ; -2. 如果你修改了代码,需要在被修改的文件中说明; -3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 -带有原来代码中的协议,商标,专利声明和其他原来作者规 -定需要包含的说明; -4. 如果再发布的产品中包含一个Notice文件,则在Notice文 -件中需要带有本协议内容。你可以在Notice中增加自己的 -许可,但不可以表现为对Apache Licence构成更改。 -具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. diff --git a/code/README.md b/code/README.md deleted file mode 100644 index 05c7b83..0000000 --- a/code/README.md +++ /dev/null @@ -1,77 +0,0 @@ -![](https://www.thinkphp.cn/uploads/images/20230630/300c856765af4d8ae758c503185f8739.png) - -ThinkPHP 8 -=============== - -## 特性 - -* 基于PHP`8.0+`重构 -* 升级`PSR`依赖 -* 依赖`think-orm`3.0+版本 -* 全新的`think-dumper`服务,支持远程调试 -* 支持`6.0`/`6.1`无缝升级 - -> ThinkPHP8的运行环境要求PHP8.0+ - -现在开始,你可以使用官方提供的[ThinkChat](https://chat.topthink.com/),让你在学习ThinkPHP的旅途中享受私人AI助理服务! - -![](https://www.topthink.com/uploads/assistant/20230630/4d1a3f0ad2958b49bb8189b7ef824cb0.png) - -ThinkPHP生态服务由[顶想云](https://www.topthink.com)(TOPThink Cloud)提供,为生态提供专业的开发者服务和价值之选。 - -## 文档 - -[完全开发手册](https://doc.thinkphp.cn) - - -## 赞助 - -全新的[赞助计划](https://www.thinkphp.cn/sponsor)可以让你通过我们的网站、手册、欢迎页及GIT仓库获得巨大曝光,同时提升企业的品牌声誉,也更好保障ThinkPHP的可持续发展。 - -[![](https://www.thinkphp.cn/sponsor/special.svg)](https://www.thinkphp.cn/sponsor/special) - -[![](https://www.thinkphp.cn/sponsor.svg)](https://www.thinkphp.cn/sponsor) - -## 安装 - -~~~ -composer create-project topthink/think tp -~~~ - -启动服务 - -~~~ -cd tp -php think run -~~~ - -然后就可以在浏览器中访问 - -~~~ -http://localhost:8000 -~~~ - -如果需要更新框架使用 -~~~ -composer update topthink/framework -~~~ - -## 命名规范 - -`ThinkPHP`遵循PSR-2命名规范和PSR-4自动加载规范。 - -## 参与开发 - -直接提交PR或者Issue即可 - -## 版权信息 - -ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 - -本项目包含的第三方源码和二进制文件之版权信息另行标注。 - -版权所有Copyright © 2006-2024 by ThinkPHP (http://thinkphp.cn) All rights reserved。 - -ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 - -更多细节参阅 [LICENSE.txt](LICENSE.txt) diff --git a/code/app/admin/AdminServiceProvider.php b/code/app/admin/AdminServiceProvider.php new file mode 100644 index 0000000..85e6a95 --- /dev/null +++ b/code/app/admin/AdminServiceProvider.php @@ -0,0 +1,36 @@ +bind(AdminUserModel::class, function (Request $Request) { + return AdminUserModel::getUserByToken($Request->header("admin-token")); + }); + } + + /** + * 执行服务 + * + * @return mixed + */ + public function boot() + { + // + } +} diff --git a/code/app/admin/BaseController.php b/code/app/admin/BaseController.php new file mode 100644 index 0000000..47ab2c6 --- /dev/null +++ b/code/app/admin/BaseController.php @@ -0,0 +1,107 @@ +app = $app; + $this->request = $this->app->request; + + // 控制器初始化 + $this->initialize(); + } + + // 初始化 + protected function initialize() + { + } + + /** + * 验证数据 + * @access protected + * @param array $data 数据 + * @param string|array $validate 验证器名或者验证规则数组 + * @param array $message 提示信息 + * @param bool $batch 是否批量验证 + * @return array|string|true + * @throws ValidateException + */ + protected function validate(array $data, $validate, array $message = [], bool $batch = false) + { + if (is_array($validate)) { + $v = new Validate(); + $v->rule($validate); + } else { + if (strpos($validate, '.')) { + // 支持场景 + [$validate, $scene] = explode('.', $validate); + } + $class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate); + $v = new $class(); + if (!empty($scene)) { + $v->scene($scene); + } + } + + $v->message($message); + + // 是否批量验证 + if ($batch || $this->batchValidate) { + $v->batch(true); + } + + return $v->failException(true)->check($data); + } + + + public function success($arrData = [], $strMsg = "", $strCode = "1000") + { + return AdminResponse::create($strCode, $strMsg, $arrData); + } + + public function error($strCode = "9999", $strMsg = "", $arrData = []) + { + return AdminResponse::create($strCode, $strMsg, $arrData); + } +} diff --git a/code/app/admin/config/error.php b/code/app/admin/config/error.php new file mode 100644 index 0000000..49ef0f8 --- /dev/null +++ b/code/app/admin/config/error.php @@ -0,0 +1,38 @@ + '成功', + + '1001' => '用户不存在!', + '1002' => '密码错误!', + '1003' => '用户名不能为空!', + '1004' => '密码不能为空!', + + #权限节点组 + '1011' => '权限节点路径不能为空!', + '1012' => '权限节点名不能为空!', + '1013' => '权限节点是否显示不能为空!', + '1014' => '权限节点ID不能为空!', + '1015' => '权限节点集合不能为空!', + '1016' => '该部门下存在成员无法删除!', + '1017' => '角色名不能为空!', + '1018' => '角色ID不能为空!', + + + + #其他组 + '9900' => '参数错误!', + '9901' => '获取PHP程序位置失败!', + '9991' => '你没有这个权限!', + '9992' => '远程密钥错误!', + '9993' => '未查询到相关数据!', + '9994' => '信息输入有误!', + '9995' => '请先登录!', + '9996' => '无效令牌!', + '9997' => '地址错误!', + '9998' => '请求对象未定义!', + '9999' => '系统异常!', +]; diff --git a/code/app/admin/config/router.php b/code/app/admin/config/router.php new file mode 100644 index 0000000..ef340bb --- /dev/null +++ b/code/app/admin/config/router.php @@ -0,0 +1,60 @@ +name("Guest@Login"); + Route::post("/logout", "Guest/Logout")->name("Guest@Logout"); +}); + + +# 系统配置 +Route::group("/system", function () { + Route::get("/user/info", "AdminUser/Info")->name("AdminUser@Info"); + Route::get("/user/list", "AdminUser/getAdminUserList")->name("AdminUser@getAdminUserList"); + Route::post("/user/save", "AdminUser/saveAdminUser")->name("AdminUser@saveAdminUser"); + Route::post("/user/del", "AdminUser/delAdminUser")->name("AdminUser@delAdminUser"); + + Route::get("/config/list", "SystemConfig/getSystemConfigList")->name("SystemConfig@getSystemConfigList"); + Route::post("/config/save", "SystemConfig/saveSystemConfig")->name("SystemConfig@saveSystemConfig"); + + Route::get("/cjpz/list", "SystemConfig/getCaiJiPeiZhiList")->name("SystemConfig@getCaiJiPeiZhiList"); + Route::post("/cjpz/save", "SystemConfig/saveCaiJiPeiZhi")->name("SystemConfig@saveCaiJiPeiZhi"); + + Route::get("/zydd/list", "SystemConfig/getZiYuanDuanDianList")->name("SystemConfig@getZiYuanDuanDianList"); + Route::post("/zydd/save", "SystemConfig/saveZiYuanDuanDian")->name("SystemConfig@saveZiYuanDuanDian"); + + Route::get("/plan/list", "SystemConfig/getPlanTaskList")->name("SystemConfig@getPlanTaskList"); + Route::post("/plan/save", "SystemConfig/savePlanTask")->name("SystemConfig@savePlanTask"); + + Route::get("/keyword/list", "SeoKeywords/getSeoKeywordList")->name("SeoKeywords@getSeoKeywordList"); + Route::post("/keyword/save", "SeoKeywords/saveSeoKeyword")->name("SeoKeywords@saveSeoKeyword"); + Route::post("/keyword/del", "SeoKeywords/delSeoKeyword")->name("SeoKeywords@delSeoKeyword"); +})->middleware(AdminAuth::class); + +# 广告 +Route::group("/guanggao", function () { + # 主 + Route::get("/main/group/list", "GuangGao/getGuangGaoFenZuList")->name("GuangGao@getGuangGaoFenZuList"); + Route::post("/main/group/save", "GuangGao/saveGuangGaoFenZu")->name("GuangGao@saveGuangGaoFenZu"); + Route::post("/main/group/del", "GuangGao/delGuangGaoFenZu")->name("GuangGao@delGuangGaoFenZu"); + Route::get("/main/list", "GuangGao/getGuangGaoList")->name("GuangGao@getGuangGaoList"); + Route::post("/main/save", "GuangGao/saveGuangGao")->name("GuangGao@saveGuangGao"); + Route::post("/main/del", "GuangGao/delGuangGao")->name("GuangGao@delGuangGao"); + + # 广告配置 + Route::get("/ggpz/list", "GuangGao/getGuangGaoPeiZhiList")->name("GuangGao@getGuangGaoPeiZhiList"); + Route::post("/ggpz/save", "GuangGao/saveGuangGaoPeiZhi")->name("GuangGao@saveGuangGaoPeiZhi"); + +})->middleware(AdminAuth::class); + +# 小说 +Route::group("/xiaoshuo", function () { + Route::get("/main/list", "XiaoShuo/getXiaoShuoList")->name("XiaoShuo@getXiaoShuoList"); + Route::get("/zhangjie/list", "XiaoShuo/getXiaoShuoZhangJieList")->name("XiaoShuo@getXiaoShuoZhangJieList"); + Route::get("/fenlei/list", "XiaoShuo/getXiaoShuoFenLeiList")->name("XiaoShuo@getXiaoShuoFenLeiList"); +})->middleware(AdminAuth::class); + diff --git a/code/app/admin/controller/AdminUser.php b/code/app/admin/controller/AdminUser.php new file mode 100644 index 0000000..ac833f6 --- /dev/null +++ b/code/app/admin/controller/AdminUser.php @@ -0,0 +1,153 @@ + $AdminUserModel, + ]; + + return $this->success($arrResult); + } + + /** + * 列表 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function getAdminUserList(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "page" => $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $AdminUserModel = AdminUserModel::alias('au'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $AdminUserModel->where(function ($AdminUserModel) use ($strKey) { + $AdminUserModel->whereOr([ + ['au.au_name', 'like', "%" . $strKey . "%"], + ['au.au_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $AdminUserModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + /** + * 设置管理员 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function saveAdminUser(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "au_id" => $Request->post('au_id'), + "au_status" => $Request->post('au_status'), + "au_name" => $Request->post('au_name'), + "au_pwd" => $Request->post('au_pwd'), + ]; + + $arrRule = [ + // 'au_id' => 'require', + 'au_status' => 'require', + 'au_name' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + if ($arrData['au_id'] == NULL) { + $AdminUserModel = new AdminUserModel; + } else { + $AdminUserModel = AdminUserModel::where('au_id', $arrData['au_id'])->find(); + + if (empty($AdminUserModel)) { + return $this->error('9993'); + } + } + + if (isset($arrData['au_pwd']) && !empty($arrData['au_pwd'])) { + $arrData['au_pwd'] = md5($arrData['au_pwd']); + } else { + unset($arrData['au_pwd']); + } + + $AdminUserModel->fill($arrData); + + $AdminUserModel->save(); + return $this->success(); + } + + /** + * 删除管理员 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function delAdminUser(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "au_id" => $Request->post('au_id'), + ]; + + $arrRule = [ + 'au_id' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + $arrData['au_id'] = explode(',', $arrData['au_id']); + + AdminUserModel::whereIn('au_id', $arrData['au_id'])->delete(); + + + return $this->success(); + } +} diff --git a/code/app/admin/controller/GuangGao.php b/code/app/admin/controller/GuangGao.php new file mode 100644 index 0000000..587c6a7 --- /dev/null +++ b/code/app/admin/controller/GuangGao.php @@ -0,0 +1,359 @@ + $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $GuangGaoFenZuModel = GuangGaoFenZuModel::alias('ggfz'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $GuangGaoFenZuModel->where(function ($GuangGaoFenZuModel) use ($strKey) { + $GuangGaoFenZuModel->whereOr([ + ['ggfz.ggfz_name', 'like', "%" . $strKey . "%"], + ['ggfz.ggfz_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $GuangGaoFenZuModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + /** + * 设置广告分组 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function saveGuangGaoFenZu(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "ggfz_id" => $Request->post('ggfz_id'), + "ggfz_code" => $Request->post('ggfz_code'), + "ggfz_name" => $Request->post('ggfz_name'), + ]; + + $arrRule = [ + // 'ggfz_id' => 'require', + 'ggfz_code' => 'require', + 'ggfz_name' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + if ($arrData['ggfz_id'] == NULL) { + $GuangGaoFenZuModel = new GuangGaoFenZuModel; + } else { + $GuangGaoFenZuModel = GuangGaoFenZuModel::where('ggfz_id', $arrData['ggfz_id'])->find(); + + if (empty($GuangGaoFenZuModel)) { + return $this->error('9993'); + } + } + + $GuangGaoFenZuModel->fill($arrData); + + $GuangGaoFenZuModel->save(); + GuangGaoModel::flushCache(); + return $this->success(); + } + + /** + * 删除广告分组 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function delGuangGaoFenZu(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "ggfz_id" => $Request->post('ggfz_id'), + ]; + + $arrRule = [ + 'ggfz_id' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + $arrData['ggfz_id'] = explode(',', $arrData['ggfz_id']); + + GuangGaoFenZuModel::whereIn('ggfz_id', $arrData['ggfz_id'])->delete(); + + GuangGaoModel::whereIn('ggfz_id', $arrData['ggfz_id'])->delete(); + GuangGaoModel::flushCache(); + return $this->success(); + } + + + /** + * 列表 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function getGuangGaoList(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "page" => $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + "ggfz_id" => $Request->get('ggfz_id'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $GuangGaoModel = GuangGaoModel::alias('gg') + ->leftJoin('guang_gao_fen_zu ggfz', 'ggfz.ggfz_id = gg.ggfz_id') + ->field(['gg.*', 'ggfz.ggfz_name']) + ->order('ggfz.ggfz_id','desc') + ->order('gg.gg_sort','desc'); + + if ($arrData['ggfz_id'] !== NULL) { + $GuangGaoModel = $GuangGaoModel->where('gg.ggfz_id', $arrData['ggfz_id']); + } + + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $GuangGaoModel->where(function ($GuangGaoModel) use ($strKey) { + $GuangGaoModel = $GuangGaoModel->whereOr([ + ['gg.gg_wen_zi', 'like', "%" . $strKey . "%"], + ['gg.gg_id', 'like', "%" . $strKey . "%"], + ['ggfz.ggfz_name', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $GuangGaoModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + + /** + * 设置广告 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function saveGuangGao(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "gg_id" => $Request->post('gg_id'), + "ggfz_id" => $Request->post('ggfz_id'), + "gg_lei_xing" => $Request->post('gg_lei_xing'), + "gg_tu_pian" => $Request->post('gg_tu_pian'), + "gg_wen_zi" => $Request->post('gg_wen_zi'), + "gg_tiao_zhuan_di_zhi" => $Request->post('gg_tiao_zhuan_di_zhi'), + "gg_sort" => $Request->post('gg_sort'), + "gg_status" => $Request->post('gg_status'), + ]; + + $arrRule = [ + // 'gg_id' => 'require', + 'ggfz_id' => 'require', + 'gg_lei_xing' => 'require', + 'gg_status' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + if ($arrData['gg_id'] == NULL) { + $GuangGaoModel = new GuangGaoModel; + } else { + $GuangGaoModel = GuangGaoModel::where('gg_id', $arrData['gg_id'])->find(); + + if (empty($GuangGaoModel)) { + return $this->error('9993'); + } + } + + $GuangGaoModel->fill($arrData); + + $GuangGaoModel->save(); + GuangGaoModel::flushCache(); + return $this->success(); + } + + /** + * 删除广告 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function delGuangGao(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "gg_id" => $Request->post('gg_id'), + ]; + + $arrRule = [ + 'gg_id' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + $arrData['gg_id'] = explode(',', $arrData['gg_id']); + + GuangGaoModel::whereIn('gg_id', $arrData['gg_id'])->delete(); + + GuangGaoModel::flushCache(); + return $this->success(); + } + + + + /** + * 广告配置列表 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function getGuangGaoPeiZhiList(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "page" => $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $GuangGaoPeiZhiModel = GuangGaoPeiZhiModel::alias('ggpz'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $GuangGaoPeiZhiModel->where(function ($GuangGaoPeiZhiModel) use ($strKey) { + $GuangGaoPeiZhiModel->whereOr([ + ['ggpz.ggpz_code', 'like', "%" . $strKey . "%"], + ['ggpz.ggpz_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $GuangGaoPeiZhiModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + /** + * 设置广告配置 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function saveGuangGaoPeiZhi(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "ggpz_id" => $Request->post('ggpz_id'), + "ggpz_val" => $Request->post('ggpz_val'), + ]; + + $arrRule = [ + 'ggpz_id' => 'require', + 'ggpz_val' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + $GuangGaoPeiZhiModel = GuangGaoPeiZhiModel::where('ggpz_id', $arrData['ggpz_id'])->find(); + + if (empty($GuangGaoPeiZhiModel)) { + return $this->error('9993'); + } + + $GuangGaoPeiZhiModel->fill($arrData); + + $GuangGaoPeiZhiModel->save(); + + GuangGaoPeiZhiModel::flushCache(); + + return $this->success(); + } +} diff --git a/code/app/admin/controller/Guest.php b/code/app/admin/controller/Guest.php new file mode 100644 index 0000000..5607bdf --- /dev/null +++ b/code/app/admin/controller/Guest.php @@ -0,0 +1,70 @@ + $Request->post('au_name'), + "au_pwd" => $Request->post('au_pwd'), + ]; + + $arrRule = [ + 'au_name' => 'require|max:25', + 'au_pwd' => 'require|min:6', + ]; + + $this->validate($arrData, $arrRule); + + $arrData['au_pwd'] = md5(trim($arrData['au_pwd'])); + + $AdminUserModel = AdminUserModel::where('au_name', $arrData['au_name']) + ->where('au_pwd', $arrData['au_pwd']) + ->where('au_status', 0) + ->find(); + + if (empty($AdminUserModel)) { + return $this->error("1002"); + } + + $arrResult = [ + 'admin-token' => $AdminUserModel->createToken(), + ]; + + return $this->success($arrResult); + } + + /** + * 退出 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function Logout(Request $Request, ?AdminUserModel $AdminUserModel) + { + $strToken = $Request->header("admin-token"); + + if ($strToken) { + Cache::delete($strToken); + } + } +} diff --git a/code/app/admin/controller/SeoKeywords.php b/code/app/admin/controller/SeoKeywords.php new file mode 100644 index 0000000..6843385 --- /dev/null +++ b/code/app/admin/controller/SeoKeywords.php @@ -0,0 +1,154 @@ + $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $SeoKeywordsModel = SeoKeywordsModel::alias('sw'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $SeoKeywordsModel->where(function ($SeoKeywordsModel) use ($strKey) { + $SeoKeywordsModel->whereOr([ + ['sw.sw_title', 'like', "%" . $strKey . "%"], + ['sw.sw_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $SeoKeywordsModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + /** + * 设置系统配置 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function saveSeoKeyword(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "sw_id" => $Request->post('sw_id'), + "sw_title" => $Request->post('sw_title'), + "sw_status" => $Request->post('sw_status'), + "sw_html_path" => $Request->post('sw_html_path') ?? '', + ]; + + $arrRule = [ + // 'sw_id' => 'require', + 'sw_title' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + if ($arrData['sw_id'] == NULL) { + $SeoKeywordsModel = new SeoKeywordsModel; + } else { + $SeoKeywordsModel = SeoKeywordsModel::where('sw_id', $arrData['sw_id'])->find(); + + if (empty($SeoKeywordsModel)) { + return $this->error('9993'); + } + } + + if (isset($arrData['sw_status']) && empty($arrData['sw_status']) && $arrData['sw_status'] != 0) { + unset($arrData['sw_status']); + } + if (isset($arrData['sw_html_path']) && empty($arrData['sw_html_path'])) { + unset($arrData['sw_html_path']); + } + + $SeoKeywordsModel->fill($arrData); + + $SeoKeywordsModel->save(); + $strHtmlPath = $SeoKeywordsModel->sw_html_path; + + if(!empty($strHtmlPath)){ + SeoKeywordsModel::flushCache($strHtmlPath); + } + + + return $this->success(); + } + + /** + * 删除 + * + * @param Request $Request + * @param SeoKeywordsModel|null $SeoKeywordsModel + * @return Response + */ + public function delSeoKeyword(Request $Request, ?SeoKeywordsModel $SeoKeywordsModel) + { + $arrData = [ + "sw_id" => $Request->post('sw_id'), + ]; + + $arrRule = [ + 'sw_id' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + $arrData['sw_id'] = explode(',', $arrData['sw_id']); + + SeoKeywordsModel::whereIn('sw_id', $arrData['sw_id'])->delete(); + + return $this->success(); + } + + +} diff --git a/code/app/admin/controller/SystemConfig.php b/code/app/admin/controller/SystemConfig.php new file mode 100644 index 0000000..46be312 --- /dev/null +++ b/code/app/admin/controller/SystemConfig.php @@ -0,0 +1,367 @@ + $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $CaiJiPeiZhiModel = CaiJiPeiZhiModel::alias('cjpz'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $CaiJiPeiZhiModel->where(function ($CaiJiPeiZhiModel) use ($strKey) { + $CaiJiPeiZhiModel->whereOr([ + ['cjpz.cjpz_code', 'like', "%" . $strKey . "%"], + ['cjpz.cjpz_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $CaiJiPeiZhiModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + /** + * 设置采集配置 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function saveCaiJiPeiZhi(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "cjpz_id" => $Request->post('cjpz_id'), + "cjpz_val" => $Request->post('cjpz_val'), + ]; + + $arrRule = [ + 'cjpz_id' => 'require', + 'cjpz_val' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + $CaiJiPeiZhiModel = CaiJiPeiZhiModel::where('cjpz_id', $arrData['cjpz_id'])->find(); + + if (empty($CaiJiPeiZhiModel)) { + return $this->error('9993'); + } + + $CaiJiPeiZhiModel->fill($arrData); + + $CaiJiPeiZhiModel->save(); + + CaiJiPeiZhiModel::flushCache(); + + return $this->success(); + } + + + + /** + * 系统配置列表 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function getSystemConfigList(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "page" => $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $SystemConfigModel = SystemConfigModel::alias('sc'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $SystemConfigModel->where(function ($SystemConfigModel) use ($strKey) { + $SystemConfigModel->whereOr([ + ['sc.sc_code', 'like', "%" . $strKey . "%"], + ['sc.sc_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $SystemConfigModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + /** + * 设置系统配置 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function saveSystemConfig(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "sc_id" => $Request->post('sc_id'), + "sc_val" => $Request->post('sc_val'), + ]; + + $arrRule = [ + 'sc_id' => 'require', + 'sc_val' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + $SystemConfigModel = SystemConfigModel::where('sc_id', $arrData['sc_id'])->find(); + + if (empty($SystemConfigModel)) { + return $this->error('9993'); + } + + $SystemConfigModel->fill($arrData); + + $SystemConfigModel->save(); + + SystemConfigModel::flushCache(); + + return $this->success(); + } + + + /** + * 资源端点列表 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function getZiYuanDuanDianList(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "page" => $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $ZiYuanDuanDianModel = ZiYuanDuanDianModel::alias('zydd'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $ZiYuanDuanDianModel->where(function ($ZiYuanDuanDianModel) use ($strKey) { + $ZiYuanDuanDianModel->whereOr([ + ['zydd.zydd_ming_zi', 'like', "%" . $strKey . "%"], + ['zydd.zydd_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $ZiYuanDuanDianModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + /** + * 设置资源端点 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function saveZiYuanDuanDian(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "zydd_id" => $Request->post('zydd_id'), + "zydd_domain" => $Request->post('zydd_domain'), + ]; + + $arrRule = [ + 'zydd_id' => 'require', + 'zydd_domain' => 'require', + ]; + + $this->validate($arrData, $arrRule); + + $ZiYuanDuanDianModel = ZiYuanDuanDianModel::where('zydd_id', $arrData['zydd_id'])->find(); + + if (empty($ZiYuanDuanDianModel)) { + return $this->error('9993'); + } + + $ZiYuanDuanDianModel->fill($arrData); + + $ZiYuanDuanDianModel->save(); + + ZiYuanDuanDianModel::flushCache(); + + return $this->success(); + } + + + /** + * 计划任务列表 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function getPlanTaskList(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "page" => $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $PlanTaskModel = PlanTaskModel::alias('pt'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $PlanTaskModel->where(function ($PlanTaskModel) use ($strKey) { + $PlanTaskModel->whereOr([ + ['pt.pt_name', 'like', "%" . $strKey . "%"], + ['pt.pt_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $PlanTaskModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + /** + * 设置计划任务 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function savePlanTask(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "pt_id" => $Request->post('pt_id'), + "pt_enable" => $Request->post('pt_enable'), + "pt_limit" => $Request->post('pt_limit'), + ]; + + $arrRule = [ + 'pt_id' => 'require|number', + 'pt_enable' => 'require|number', + 'pt_limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $PlanTaskModel = PlanTaskModel::where('pt_id', $arrData['pt_id'])->find(); + + if (empty($PlanTaskModel)) { + return $this->error('9993'); + } + + $PlanTaskModel->fill($arrData); + + $PlanTaskModel->save(); + + return $this->success(); + } +} diff --git a/code/app/admin/controller/XiaoShuo.php b/code/app/admin/controller/XiaoShuo.php new file mode 100644 index 0000000..c04ce03 --- /dev/null +++ b/code/app/admin/controller/XiaoShuo.php @@ -0,0 +1,179 @@ + $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $XiaoShuoXiangQingModel = XiaoShuoXiangQingModel::alias('xsxq'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $XiaoShuoXiangQingModel->where(function ($XiaoShuoXiangQingModel) use ($strKey) { + $XiaoShuoXiangQingModel->whereOr([ + ['xsxq.xsxq_ming_zi', 'like', "%" . $strKey . "%"], + ['xsxq.xsxq_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $XiaoShuoXiangQingModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + + /** + * 列表 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function getXiaoShuoZhangJieList(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "page" => $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + "xsxq_id" => $Request->get('xsxq_id'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $XiaoShuoZhangJieModel = XiaoShuoZhangJieModel::alias('xszj'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $XiaoShuoZhangJieModel->where(function ($XiaoShuoZhangJieModel) use ($strKey) { + $XiaoShuoZhangJieModel->whereOr([ + ['xszj.xszj_ming_zi', 'like', "%" . $strKey . "%"], + ['xszj.xszj_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + if (!empty($arrData['xsxq_id'])) { + $XiaoShuoZhangJieModel->where('xszj.xsxq_id', $arrData['xsxq_id']); + $XiaoShuoZhangJieModel->order('xszj.xszj_pai_xu', 'desc'); + } + + $Paginate = $XiaoShuoZhangJieModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } + + + /** + * 列表 + * + * @param Request $Request + * @param AdminUserModel|null $AdminUserModel + * @return Response + */ + public function getXiaoShuoFenLeiList(Request $Request, ?AdminUserModel $AdminUserModel) + { + $arrData = [ + "page" => $Request->get('page', 1), + "limit" => $Request->get('limit', 10), + "key" => $Request->get('key'), + ]; + + $arrRule = [ + 'page' => 'require|number', + 'limit' => 'require|number', + ]; + + $this->validate($arrData, $arrRule); + + $XiaoShuoFenLeiModel = XiaoShuoFenLeiModel::alias('xsfl'); + + if (!empty($arrData['key'])) { + $strKey = $arrData['key']; + $XiaoShuoFenLeiModel->where(function ($XiaoShuoFenLeiModel) use ($strKey) { + $XiaoShuoFenLeiModel->whereOr([ + ['xsfl.xsfl_name', 'like', "%" . $strKey . "%"], + ['xsfl.xsfl_id', 'like', "%" . $strKey . "%"], + ]); + }); + } + + $Paginate = $XiaoShuoFenLeiModel->paginate([ + 'list_rows' => $arrData['limit'], + 'page' => $arrData['page'], + ]); + + $arrResult = [ + 'items' => $Paginate->items(), + 'total' => $Paginate->total(), + 'current_page' => $Paginate->currentPage(), + 'total_pages' => $Paginate->lastPage(), + ]; + + return $this->success($arrResult); + } +} diff --git a/code/app/admin/middleware.php b/code/app/admin/middleware.php index ec9473e..dc03bee 100644 --- a/code/app/admin/middleware.php +++ b/code/app/admin/middleware.php @@ -1,5 +1,9 @@ checkRole() == false) { + return AdminResponse::create("9991"); + } + + return $Next($Request); + } catch (\Throwable $T) { + return AdminResponse::createByErr($T); + } + } +} diff --git a/code/app/admin/middleware/AdminCors.php b/code/app/admin/middleware/AdminCors.php new file mode 100644 index 0000000..98503c5 --- /dev/null +++ b/code/app/admin/middleware/AdminCors.php @@ -0,0 +1,22 @@ + 'true', + 'Access-Control-Max-Age' => 3600, + 'Access-Control-Allow-Methods' => '*', + 'Access-Control-Allow-Headers' => '*', + ]; +} diff --git a/code/app/admin/middleware/AdminException.php b/code/app/admin/middleware/AdminException.php new file mode 100644 index 0000000..ecde2c5 --- /dev/null +++ b/code/app/admin/middleware/AdminException.php @@ -0,0 +1,17 @@ + $strCode, + 'msg' => $strMsg, + 'data' => $arrData, + ]; + + return json($arrData, 200, [], [JSON_UNESCAPED_UNICODE]); + } + + static $arrExceptionMap = [ + ValidateException::class => "9900", + ]; + + static public function createByErr(\Throwable $T) + { + $strCode = $T->getCode(); + + if ($T instanceof ValidateException) { + $strCode = "9900"; + } + + foreach (self::$arrExceptionMap as $ExceptionClass => $strExceptonCode) { + if ($T instanceof $ExceptionClass) { + $strCode = $strExceptonCode; + break; + } + } + + return self::create($strCode, $T->getMessage()); + } +} diff --git a/code/app/admin/model/AdminNodeModel.php b/code/app/admin/model/AdminNodeModel.php new file mode 100644 index 0000000..8c315fe --- /dev/null +++ b/code/app/admin/model/AdminNodeModel.php @@ -0,0 +1,15 @@ +alias('arn') + ->field('an.an_url') + ->leftjoin('admin_node an','an.an_id=arn.an_id'); + + if($intArId>0) + { + $AdminRoleNodeModel = $AdminRoleNodeModel->where('arn.ar_id',$intArId); + } + + $arrRoleNode = $AdminRoleNodeModel + ->select() + ->toArray(); + + $arrRoleNode = array_column($arrRoleNode, 'an_url'); + + // Cache::set($strCacheKey,$arrRoleNode); + } + + return $arrRoleNode; + } +} diff --git a/code/app/admin/model/AdminRoleNodeModel.php b/code/app/admin/model/AdminRoleNodeModel.php new file mode 100644 index 0000000..3837f55 --- /dev/null +++ b/code/app/admin/model/AdminRoleNodeModel.php @@ -0,0 +1,15 @@ +token = $strToken; + + $AdminUserModel->refreshToken(); + + return $AdminUserModel; + } + + public function checkRole() + { + return true; + } + + + public function createToken() + { + $this->token = Str::random(32); + + $this->refreshToken(); + + return $this->token; + } + + public function refreshToken() + { + Cache::set("AdminToken:" . $this->token, $this->au_id, 3600); + } + + static public function getAdminUserModelByCache($intAuId, $boolForceUpdate = false) + { + $strKey = "AdminUser:Id:" . $intAuId; + + $AdminUserModel = Cache::get($strKey); + + if (empty($AdminUserModel) || $boolForceUpdate == true) { + $AdminUserModel = self::where('au_id', $intAuId)->find(); + + if (empty($AdminUserModel)) { + throw new \Exception("用户不存在", 9999); + } + $AdminUserModel->au_pwd = ""; + + Cache::set($strKey, $AdminUserModel); + } + + return $AdminUserModel; + } +} diff --git a/code/app/admin/model/BaseModel.php b/code/app/admin/model/BaseModel.php new file mode 100644 index 0000000..714d7d4 --- /dev/null +++ b/code/app/admin/model/BaseModel.php @@ -0,0 +1,21 @@ + $strVal) { + $this->$strKey = $strVal; + } + } +} diff --git a/code/app/admin/model/CaiJiPeiZhiModel.php b/code/app/admin/model/CaiJiPeiZhiModel.php new file mode 100644 index 0000000..94c570b --- /dev/null +++ b/code/app/admin/model/CaiJiPeiZhiModel.php @@ -0,0 +1,39 @@ +set('CaiJiPeiZhi', $arrCaiJiPeiZhi); + } +} diff --git a/code/app/admin/model/ContentStatsModel.php b/code/app/admin/model/ContentStatsModel.php new file mode 100644 index 0000000..204c06f --- /dev/null +++ b/code/app/admin/model/ContentStatsModel.php @@ -0,0 +1,70 @@ + $arrData['cs_md5'], + ])->find(); + if ($existingRecord) { + $existingRecord->cs_pv = $arrData['cs_pv']; + $existingRecord->cs_uv = $arrData['cs_uv']; + $existingRecord->updated_at = $arrData['updated_at']; + // 尝试保存数据 + if (!$existingRecord->save()) { + // 数据保存失败,抛出异常 + throw new \RuntimeException('数据保存失败:' . json_encode($data, JSON_UNESCAPED_UNICODE)); + } + + // 返回模型实例 + return $existingRecord; + // return $existingRecord->save(); + // return $existingRecord->save($arrData); + } else { + // 插入新记录 + return self::create($arrData); + } + // if ($existingRecord) { + // // 更新记录 + // $existingRecord->cs_pv = $arrData['cs_pv']; + // $existingRecord->cs_uv = $arrData['cs_uv']; + // $existingRecord->updated_at = $arrData['updated_at']; + // $existingRecord->save(); + + // return $existingRecord; + // } + + // $existingRecord = new self; + // $existingRecord->save($arrData); + // return $existingRecord; + + } catch (\Throwable $T) { + var_dump($T); + if ($T->getCode() == 10501) { + //return self::addVideoLeixin($arrData); + } + throw $T; + } + } + +} diff --git a/code/app/admin/model/FenLeiModel.php b/code/app/admin/model/FenLeiModel.php new file mode 100644 index 0000000..b1145b5 --- /dev/null +++ b/code/app/admin/model/FenLeiModel.php @@ -0,0 +1,133 @@ +where('fl_mingzi',$strFlMingzi)->find(); + + if ($FenLeiModel) { + return $FenLeiModel; + } + + $FenLeiModel = new self; + // $FenLeiModel->fl_id = $intFlId; + $FenLeiModel->fl_leixing = 0; + $FenLeiModel->fl_pid = $intFlPId; + $FenLeiModel->fl_mingzi = $strFlMingzi; + $FenLeiModel->save(); + return $FenLeiModel; + } catch (\Throwable $T) { + } + + if ($T->getCode() == 10501) { + return self::addFenlei($intFlId, $intFlPId, $strFlMingzi); + } + throw $T; + } + + static public function getAllFenLei() + { + if (self::$arrFenLei == []) { + self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI'); + + if (empty(self::$arrFenLei)) { + self::flushCache(); + self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI'); + } + } + + + return self::$arrFenLei; + } + + + static public function getFenLeiByFlId($intFlId) + { + if (self::$arrFenLei == []) { + self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI'); + + if (empty(self::$arrFenLei)) { + self::flushCache(); + self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI'); + } + } + + + return self::$arrFenLei[$intFlId] ?? ""; + } + + static public function getFenLeiMingZiByFlId($intFlId, $intZiFlId) + { + if (empty(self::$arrFenLei)) { + self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI'); + + if (empty(self::$arrFenLei)) { + self::flushCache(); + self::$arrFenLei = Cache::get('SHI_PIN_FEN_LEI'); + } + } + + if ($intZiFlId == 0) { + return self::$arrFenLei[$intFlId]['fl_mingzi'] ?? ''; + } else { + $arrFenLeiChild = self::$arrFenLei[$intFlId]['child'] ?? []; + foreach ($arrFenLeiChild as $item) { + if ($item['fl_id'] == $intZiFlId) { + return $item['fl_mingzi']; + } + } + } + + return ''; + } + + + static public function flushCache() + { + // $arrFenLei = self::select()->toArray(); + $arrFenLei = self::order('fl_sort', 'desc')->select()->toArray(); + + $arrFenLei = static::buildTree($arrFenLei); + + Cache::tag('SHI_PIN_FEN_LEI')->set('SHI_PIN_FEN_LEI', $arrFenLei); + } + + static public function buildTree(array $elements, $parentId = 0) + { + $branch = []; + + foreach ($elements as $element) { + if ($element['fl_pid'] == $parentId) { + $children = static::buildTree($elements, $element['fl_id']); + if ($children) { + $element['child'] = $children; + } + $branch[$element['fl_id']] = $element; + } + } + + return $branch; + } +} diff --git a/code/app/admin/model/GanRaoMaModel.php b/code/app/admin/model/GanRaoMaModel.php new file mode 100644 index 0000000..2a3324b --- /dev/null +++ b/code/app/admin/model/GanRaoMaModel.php @@ -0,0 +1,76 @@ +where('grm_html_path', $strHtmlPath)->value('grm_neirong'); + + if ($strGamRaoMa) { + // 设置缓存 + $cache->set($strHtmlPath, $strGamRaoMa); + } else { + // 如果数据库中没有记录,生成随机内容 + $fallbackKeyword = generateRandomHTML(3, 15); + + if ($fallbackKeyword) { + $arrGanRaoMa = [ + 'grm_html_path' => $strHtmlPath, + 'grm_neirong' => $fallbackKeyword, + 'site_id' => config('app.default_app_id'), + ]; + + // 保存到数据库 + $model = new self(); + $model->save($arrGanRaoMa); + + // 设置缓存 + $cache->set($strHtmlPath, $fallbackKeyword); + } else { + // 记录日志或其他处理逻辑 + // Log::warning("No fallback keyword generated for path: $strHtmlPath"); + } + } + } +} diff --git a/code/app/admin/model/GuangGaoFenZuModel.php b/code/app/admin/model/GuangGaoFenZuModel.php new file mode 100644 index 0000000..6d8d280 --- /dev/null +++ b/code/app/admin/model/GuangGaoFenZuModel.php @@ -0,0 +1,17 @@ +order('ggfz_id', 'desc')->order('gg_sort', 'desc')->where('gg_status',0)->select(); + + foreach ($GuangGaoModelAll as $GuangGaoModel) { + $GuangGaoModel->ggfz_id; + if (!key_exists($GuangGaoModel->ggfz_id, $arrGGFZCode)) { + continue; + } + + if (!key_exists($arrGGFZCode[$GuangGaoModel->ggfz_id], $arrGuangGao)) { + $arrGuangGao[$arrGGFZCode[$GuangGaoModel->ggfz_id]] = []; + } + + $arrGuangGao[$arrGGFZCode[$GuangGaoModel->ggfz_id]][] = $GuangGaoModel->toArray(); + } + + Cache::tag('GuangGao')->set('GuangGao', $arrGuangGao); + } +} diff --git a/code/app/admin/model/GuangGaoPeiZhiModel.php b/code/app/admin/model/GuangGaoPeiZhiModel.php new file mode 100644 index 0000000..9bedffb --- /dev/null +++ b/code/app/admin/model/GuangGaoPeiZhiModel.php @@ -0,0 +1,40 @@ +set('GuangGaoPeiZhi', $arrGuangGaoPeiZhi); + } +} diff --git a/code/app/admin/model/NovelInfoSeoModel.php b/code/app/admin/model/NovelInfoSeoModel.php new file mode 100644 index 0000000..de3e2a6 --- /dev/null +++ b/code/app/admin/model/NovelInfoSeoModel.php @@ -0,0 +1,41 @@ +find(); + + if ($XiaoShuoXiangQingModel) { + + return $XiaoShuoXiangQingModel; + } + + $XiaoShuoXiangQingModel = new self; + + $XiaoShuoXiangQingModel->save($arrData); + return $XiaoShuoXiangQingModel; + } catch (\Throwable $T) { + + throw $T; // 超过重试次数后抛出异常 + + } + } +} diff --git a/code/app/admin/model/PlanTaskModel.php b/code/app/admin/model/PlanTaskModel.php new file mode 100644 index 0000000..8ccf7da --- /dev/null +++ b/code/app/admin/model/PlanTaskModel.php @@ -0,0 +1,17 @@ +find(); + if ($ReSouFenZuModel) { + return $ReSouFenZuModel; + } + + $ReSouFenZuModel = new self; + $ReSouFenZuModel->rsfz_pai_xu = $arrData['rsfz_pai_xu']; + $ReSouFenZuModel->rsfz_ming_zi = $arrData['rsfz_ming_zi']; + $ReSouFenZuModel->save(); + return $ReSouFenZuModel; + } catch (\Throwable $T) { + + if ($T->getCode() == 10501) { + return self::addReSouFenZu($arrData); + } + throw $T; + } + } +} diff --git a/code/app/admin/model/ReSouModel.php b/code/app/admin/model/ReSouModel.php new file mode 100644 index 0000000..a418eb2 --- /dev/null +++ b/code/app/admin/model/ReSouModel.php @@ -0,0 +1,101 @@ +find(); + if ($ReSouModel) { + return $ReSouModel; + } + + $ReSouModel = new self; + $ReSouModel->rs_ming_zi = $arrData['rs_ming_zi']; + $ReSouModel->rsfz_id = $arrData['rsfz_id']; + $ReSouModel->save(); + return $ReSouModel; + } catch (\Throwable $T) { + if ($T->getCode() == 10501) { + return self::addReSou($arrData); + } + throw $T; + } + } + + static public function getRsByCache($intLimit = 2, $strSort = 'asc') + { + if (self::$arrReSouAll == []) { + self::$arrReSouAll = Cache::get('RE_SOU_ALL'); + + if (empty(self::$arrReSouAll)) { + self::flushCache(); + self::$arrReSouAll = Cache::get('RE_SOU_ALL'); + } + } + $arrTemp = self::$arrReSouAll; + + if ($strSort == 'rand') { + shuffle($arrTemp); + } + + return array_slice($arrTemp, 0, $intLimit); + } + + static public function getFomartDataByCache() + { + if (self::$arrReSou == []) { + self::$arrReSou = Cache::get('RE_SOU'); + + if (empty(self::$arrReSou)) { + self::flushCache(); + self::$arrReSou = Cache::get('RE_SOU'); + } + } + + return self::$arrReSou; + } + + static public function flushCache() + { + $FenZu = ReSouFenZuModel::order('rsfz_pai_xu', 'asc')->select(); + $arrFenZu = []; + foreach ($FenZu as $FenZuOne) { + $arrFenZu[$FenZuOne->rsfz_id] = $FenZuOne->toArray(); + $arrFenZu[$FenZuOne->rsfz_id]['child'] = []; + } + + + $ReSou = self::select(); + + foreach ($ReSou as $ReSouOne) { + $arrFenZu[$ReSouOne->rsfz_id]['child'][] = $ReSouOne->toArray(); + } + + $arrFenZu = array_values($arrFenZu); + + Cache::tag('RE_SOU')->set('RE_SOU', $arrFenZu); + Cache::tag('RE_SOU_ALL')->set('RE_SOU_ALL', $ReSou->toArray()); + } +} diff --git a/code/app/admin/model/SeoHtmlModel.php b/code/app/admin/model/SeoHtmlModel.php new file mode 100644 index 0000000..0765df5 --- /dev/null +++ b/code/app/admin/model/SeoHtmlModel.php @@ -0,0 +1,63 @@ +value('sw_title'); + + if ($strSeoKeyword) { + + $cache->set($strHtmlPath, $strSeoKeyword); + + } else { + + $fallbackKeyword = self::where('sw_status', 0)->find(); + + if ($fallbackKeyword) { + + $fallbackKeyword->sw_status = 1; + + $fallbackKeyword->sw_html_path = $strHtmlPath; + + $fallbackKeyword->save(); + + $cache->set($strHtmlPath, $fallbackKeyword->sw_title); + } else { + // 如果连 sw_status = 0 的记录也没有,则可以选择不进行任何操作或进行日志记录 + // Log::warning("No available SEO keyword found for fallback."); + } + } + } + +} diff --git a/code/app/admin/model/SeoKeywordsModel.php b/code/app/admin/model/SeoKeywordsModel.php new file mode 100644 index 0000000..ff1b566 --- /dev/null +++ b/code/app/admin/model/SeoKeywordsModel.php @@ -0,0 +1,63 @@ +value('sw_title'); + + if ($strSeoKeyword) { + + $cache->set($strHtmlPath, $strSeoKeyword); + + } else { + + $fallbackKeyword = self::where('sw_status', 0)->find(); + + if ($fallbackKeyword) { + + $fallbackKeyword->sw_status = 1; + + $fallbackKeyword->sw_html_path = $strHtmlPath; + + $fallbackKeyword->save(); + + $cache->set($strHtmlPath, $fallbackKeyword->sw_title); + } else { + // 如果连 sw_status = 0 的记录也没有,则可以选择不进行任何操作或进行日志记录 + // Log::warning("No available SEO keyword found for fallback."); + } + } + } + +} diff --git a/code/app/admin/model/SeoTdkConfigModel.php b/code/app/admin/model/SeoTdkConfigModel.php new file mode 100644 index 0000000..8ca321b --- /dev/null +++ b/code/app/admin/model/SeoTdkConfigModel.php @@ -0,0 +1,63 @@ +select()->toArray(); + + // 按照 'stc_code' 进行键值映射 + $arrSeoTdkConfig = array_column($arrSeoTdkConfig, null, 'stc_code'); + // var_dump($arrSeoTdkConfig); + // $arrSeoTdkConfig = self::select(); + // $arrSeoTdkConfig = self::column('stc_title', 'stc_code'); + // var_dump($arrSeoTdkConfig); + Cache::tag('seoTdkTonfig')->set('seoTdkTonfig', $arrSeoTdkConfig); + } +} diff --git a/code/app/admin/model/SiteModel.php b/code/app/admin/model/SiteModel.php new file mode 100644 index 0000000..023f030 --- /dev/null +++ b/code/app/admin/model/SiteModel.php @@ -0,0 +1,82 @@ +find(); + + if ($SiteModel) { + + return $SiteModel; + } + + $SiteModel = new self; + + $SiteModel->save($arrData); + return $SiteModel; + } catch (\Throwable $T) { + + throw $T; // 超过重试次数后抛出异常 + + } + } + + static public function getValById($intSiteId) + { + + //self::flushCache(); + if (self::$arrSite == []) { + self::$arrSite = Cache::get('site'); + + if (empty(self::$arrSite)) { + self::flushCache(); + self::$arrSite = Cache::get('site'); + } + } + return self::$arrSite[$intSiteId] ?? NULL; + } + + // 标签使用 + static public function getValBySiteIdByValCode($strValCode) + { + + if (self::$arrSite == []) { + self::$arrSite = Cache::get('site'); + + if (empty(self::$arrSite)) { + self::flushCache(); + self::$arrSite = Cache::get('site'); + } + } + return self::$arrSite[config('app.default_app_id')][$strValCode] ?? NULL; + } + + static public function flushCache() + { + // 查询所有数据 where('site_id',config('app.default_app_id')) + $arrSite = self::select()->toArray(); + + // 按照 'stc_code' 进行键值映射 + $arrSite = array_column($arrSite, null, 'site_id'); + + Cache::tag('site')->set('site', $arrSite); + } +} diff --git a/code/app/admin/model/SystemConfigModel.php b/code/app/admin/model/SystemConfigModel.php new file mode 100644 index 0000000..8c0eac6 --- /dev/null +++ b/code/app/admin/model/SystemConfigModel.php @@ -0,0 +1,39 @@ +set('Config', $arrSystemConfig); + } +} diff --git a/code/app/admin/model/VideoClassModel.php b/code/app/admin/model/VideoClassModel.php new file mode 100644 index 0000000..d425b03 --- /dev/null +++ b/code/app/admin/model/VideoClassModel.php @@ -0,0 +1,112 @@ +find(); + if ($VideoFenLeiModel) { + return $VideoFenLeiModel; + } + + $VideoFenLeiModel = new self; + $VideoFenLeiModel->vc_name = $arrData['vc_name']; + $VideoFenLeiModel->save(); + return $VideoFenLeiModel; + } catch (\Throwable $T) { + + if ($T->getCode() == 10501) { + return self::addVideoFenLei($arrData); + } + throw $T; + } + } + + static public function getIdByName($strName) + { + $intId = 0; + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vc_name'] == $strName) { + $intId = $arrFenLei['vc_id']; + } + } + return $intId; + } + + static public function getNameById($intId) + { + static::getDataByCache(); + $strName = '未知'; + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vc_id'] === $intId) { + $strName = $arrFenLei['vc_name']; + } + } + return $strName; + } + + static public function getInfoById($intId) + { + $arrDefault = ['vc_id' => 1, 'vc_name' => '电影' , 'vc_necheng' => 'dy']; + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vc_id'] == $intId) { + $arrDefault = $arrFenLei; + } + } + return $arrDefault; + } + + static public function getInfoByNeCheng($strNeCheng) + { + $arrDefault = ['vc_id' => 1, 'vc_source_id' => 1,'vc_name' => '电影' , 'vc_necheng' => 'dy']; + + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vc_nicheng'] == $strNeCheng) { + $arrDefault = $arrFenLei; + } + } + return $arrDefault; + } + + + static public function getDataByCache() + { + if (self::$arrVideoShuoFenLei == []) { + self::$arrVideoShuoFenLei = Cache::get('VIDEO_FEN_LEI'); + + if (empty(self::$arrVideoShuoFenLei)) { + self::flushCache(); + self::$arrVideoShuoFenLei = Cache::get('VIDEO_FEN_LEI'); + } + } + + return self::$arrVideoShuoFenLei; + } + + static public function flushCache() + { + $arrVideoShuoFenLei = self::where('vc_status', 1)->where('site_id',config('app.default_app_id'))->order('vc_sort', 'asc')->select()->toArray(); + self::$arrVideoShuoFenLei = $arrVideoShuoFenLei; + Cache::tag('VIDEO_FEN_LEI')->set('VIDEO_FEN_LEI', $arrVideoShuoFenLei); + } +} diff --git a/code/app/admin/model/VideoDiquModel.php b/code/app/admin/model/VideoDiquModel.php new file mode 100644 index 0000000..47a0cb7 --- /dev/null +++ b/code/app/admin/model/VideoDiquModel.php @@ -0,0 +1,90 @@ +where('vc_id', $arrData['vc_id'])->find(); + if ($VideoFenLeiModel) { + return $VideoFenLeiModel; + } + + $VideoFenLeiModel = new self; + $VideoFenLeiModel->save($arrData); + return $VideoFenLeiModel; + } + + + } catch (\Throwable $T) { + + if ($T->getCode() == 10501) { + //return self::add($arrData); + } + throw $T; + } + } + + static public function getIdByName($strName) + { + $intId = 0; + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vd_name'] == $strName) { + $intId = $arrFenLei['vd_id']; + } + } + return $intId; + } + + static public function getNameById($intId) + { + static::getDataByCache(); + $strName = '未知'; + // var_dump(self::$arrXiaoShuoFenLei); + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vd_id'] === $intId) { + $strName = $arrFenLei['vd_name']; + } + } + return $strName; + } + + static public function getDataByCache() + { + if (self::$arrVideoShuoFenLei == []) { + self::$arrVideoShuoFenLei = Cache::get('VIDEO_DI_QU'); + + if (empty(self::$arrVideoShuoFenLei)) { + self::flushCache(); + self::$arrVideoShuoFenLei = Cache::get('VIDEO_DI_QU'); + } + } + + return self::$arrVideoShuoFenLei; + } + + static public function flushCache() + { + $arrVideoShuoFenLei = self::select()->toArray(); + + Cache::tag('VIDEO_DI_QU')->set('VIDEO_DI_QU', $arrVideoShuoFenLei); + } +} diff --git a/code/app/admin/model/VideoInfoModel.php b/code/app/admin/model/VideoInfoModel.php new file mode 100644 index 0000000..88debef --- /dev/null +++ b/code/app/admin/model/VideoInfoModel.php @@ -0,0 +1,119 @@ +find(); + + if ($VideoXiangQingModel) { + + return [ + 'model' => $VideoXiangQingModel, + 'isNew' => false, // 已存在 + ]; + } + $VideoXiangQingModel = new self; + $VideoXiangQingModel->save($arrData); + return [ + 'model' => $VideoXiangQingModel, + 'isNew' => true, // 新增 + ]; + + } catch (\Throwable $T) { + + throw $T; // 超过重试次数后抛出异常 + + } + + + } + +} diff --git a/code/app/admin/model/VideoInfoSeoModel.php b/code/app/admin/model/VideoInfoSeoModel.php new file mode 100644 index 0000000..820333b --- /dev/null +++ b/code/app/admin/model/VideoInfoSeoModel.php @@ -0,0 +1,41 @@ +find(); + + if ($VideoModel) { + + return $VideoModel; + } + + $VideoModel = new self; + + $VideoModel->save($arrData); + return $VideoModel; + } catch (\Throwable $T) { + + throw $T; // 超过重试次数后抛出异常 + + } + } +} diff --git a/code/app/admin/model/VideoJuqingModel.php b/code/app/admin/model/VideoJuqingModel.php new file mode 100644 index 0000000..810c463 --- /dev/null +++ b/code/app/admin/model/VideoJuqingModel.php @@ -0,0 +1,90 @@ +where('vc_id', $arrData['vc_id'])->find(); + if ($VideoFenLeiModel) { + return $VideoFenLeiModel; + } + + $VideoFenLeiModel = new self; + $VideoFenLeiModel->save($arrData); + return $VideoFenLeiModel; + } + + + } catch (\Throwable $T) { + + if ($T->getCode() == 10501) { + //return self::add($arrData); + } + throw $T; + } + } + + static public function getIdByName($strName) + { + $intId = 0; + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vj_name'] == $strName) { + $intId = $arrFenLei['vj_id']; + } + } + return $intId; + } + + static public function getNameById($intId) + { + static::getDataByCache(); + $strName = '未知'; + // var_dump(self::$arrXiaoShuoFenLei); + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vj_id'] === $intId) { + $strName = $arrFenLei['vj_name']; + } + } + return $strName; + } + + static public function getDataByCache() + { + if (self::$arrVideoShuoFenLei == []) { + self::$arrVideoShuoFenLei = Cache::get('VIDEO_JU_QING'); + + if (empty(self::$arrVideoShuoFenLei)) { + self::flushCache(); + self::$arrVideoShuoFenLei = Cache::get('VIDEO_JU_QING'); + } + } + + return self::$arrVideoShuoFenLei; + } + + static public function flushCache() + { + $arrVideoShuoFenLei = self::select()->toArray(); + + Cache::tag('VIDEO_JU_QING')->set('VIDEO_JU_QING', $arrVideoShuoFenLei); + } +} diff --git a/code/app/admin/model/VideoLeixinModel.php b/code/app/admin/model/VideoLeixinModel.php new file mode 100644 index 0000000..4af51aa --- /dev/null +++ b/code/app/admin/model/VideoLeixinModel.php @@ -0,0 +1,90 @@ +where('vc_id', $arrData['vc_id'])->find(); + if ($VideoFenLeiModel) { + return $VideoFenLeiModel; + } + + $VideoFenLeiModel = new self; + $VideoFenLeiModel->save($arrData); + return $VideoFenLeiModel; + } + + + } catch (\Throwable $T) { + + if ($T->getCode() == 10501) { + //return self::addVideoLeixin($arrData); + } + throw $T; + } + } + + static public function getIdByName($strName) + { + $intId = 0; + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vl_name'] == $strName) { + $intId = $arrFenLei['vl_id']; + } + } + return $intId; + } + + static public function getNameById($intId) + { + static::getDataByCache(); + $strName = '未知'; + // var_dump(self::$arrXiaoShuoFenLei); + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vl_id'] === $intId) { + $strName = $arrFenLei['vl_name']; + } + } + return $strName; + } + + static public function getDataByCache() + { + if (self::$arrVideoShuoFenLei == []) { + self::$arrVideoShuoFenLei = Cache::get('VIDEO_LEI_XIN'); + + if (empty(self::$arrVideoShuoFenLei)) { + self::flushCache(); + self::$arrVideoShuoFenLei = Cache::get('VIDEO_LEI_XIN'); + } + } + + return self::$arrVideoShuoFenLei; + } + + static public function flushCache() + { + $arrVideoShuoFenLei = self::select()->toArray(); + + Cache::tag('VIDEO_LEI_XIN')->set('VIDEO_LEI_XIN', $arrVideoShuoFenLei); + } +} diff --git a/code/app/admin/model/VideoPlayurlModel.php b/code/app/admin/model/VideoPlayurlModel.php new file mode 100644 index 0000000..7347d55 --- /dev/null +++ b/code/app/admin/model/VideoPlayurlModel.php @@ -0,0 +1,96 @@ +find(); + + // 如果已存在,返回已有模型 + if ($XiaoShuoZhangJieModel) { + return [ + 'model' => $XiaoShuoZhangJieModel, + 'isNew' => false, // 已存在 + ]; + } + + // 新增数据 + $XiaoShuoZhangJieModel = new self; + $XiaoShuoZhangJieModel->save($arrData); + + return [ + 'model' => $XiaoShuoZhangJieModel, + 'isNew' => true, // 新增 + ]; + } catch (\Throwable $T) { + var_dump($T); + throw $T; + } + + } + + // static public function add($arrData): self + // { + + // try { + // $XiaoShuoZhangJieModel = self::where('vp_md5', $arrData['vp_md5'])->find(); + // if ($XiaoShuoZhangJieModel) { + // return $XiaoShuoZhangJieModel; + // } + + // $XiaoShuoZhangJieModel = new self; + + // $XiaoShuoZhangJieModel->save($arrData); + // return $XiaoShuoZhangJieModel; + + // } catch (\Throwable $T) { + // var_dump($T); + // // if ($T->getCode() == 10501) { + // // return self::add($arrData); + // // } + // throw $T; + // } + // } + + /** + * 判断章节是否存在 + * + * @param bool $strXszjSourceCode + * @return void + */ + static public function checkZhangJieExists($strXszjSourceCode) + { + $XiaoShuoZhangJieModel = self::where('vp_md5', $strXszjSourceCode)->find(); + return !empty($XiaoShuoZhangJieModel); + } +} diff --git a/code/app/admin/model/VideoYearsModel.php b/code/app/admin/model/VideoYearsModel.php new file mode 100644 index 0000000..f5895fc --- /dev/null +++ b/code/app/admin/model/VideoYearsModel.php @@ -0,0 +1,90 @@ +where('vc_id', $arrData['vc_id'])->find(); + if ($VideoFenLeiModel) { + return $VideoFenLeiModel; + } + + $VideoFenLeiModel = new self; + $VideoFenLeiModel->save($arrData); + return $VideoFenLeiModel; + } + + + } catch (\Throwable $T) { + + if ($T->getCode() == 10501) { + //return self::add($arrData); + } + throw $T; + } + } + + static public function getIdByName($strName) + { + $intId = 0; + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vy_name'] == $strName) { + $intId = $arrFenLei['vy_id']; + } + } + return $intId; + } + + static public function getNameById($intId) + { + static::getDataByCache(); + $strName = '未知'; + // var_dump(self::$arrXiaoShuoFenLei); + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vy_id'] === $intId) { + $strName = $arrFenLei['vy_name']; + } + } + return $strName; + } + + static public function getDataByCache() + { + if (self::$arrVideoShuoFenLei == []) { + self::$arrVideoShuoFenLei = Cache::get('VIDEO_YEARS'); + + if (empty(self::$arrVideoShuoFenLei)) { + self::flushCache(); + self::$arrVideoShuoFenLei = Cache::get('VIDEO_YEARS'); + } + } + + return self::$arrVideoShuoFenLei; + } + + static public function flushCache() + { + $arrVideoShuoFenLei = self::select()->toArray(); + + Cache::tag('VIDEO_YEARS')->set('VIDEO_YEARS', $arrVideoShuoFenLei); + } +} diff --git a/code/app/admin/model/VideoYuyanModel.php b/code/app/admin/model/VideoYuyanModel.php new file mode 100644 index 0000000..3ed2949 --- /dev/null +++ b/code/app/admin/model/VideoYuyanModel.php @@ -0,0 +1,90 @@ +where('vc_id', $arrData['vc_id'])->find(); + if ($VideoFenLeiModel) { + return $VideoFenLeiModel; + } + + $VideoFenLeiModel = new self; + $VideoFenLeiModel->save($arrData); + return $VideoFenLeiModel; + } + + + } catch (\Throwable $T) { + + if ($T->getCode() == 10501) { + //return self::add($arrData); + } + throw $T; + } + } + + static public function getIdByName($strName) + { + $intId = 0; + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vla_name'] == $strName) { + $intId = $arrFenLei['vla_id']; + } + } + return $intId; + } + + static public function getNameById($intId) + { + static::getDataByCache(); + $strName = '未知'; + // var_dump(self::$arrXiaoShuoFenLei); + foreach (self::$arrVideoShuoFenLei as $arrFenLei) { + if ($arrFenLei['vla_id'] === $intId) { + $strName = $arrFenLei['vla_name']; + } + } + return $strName; + } + + static public function getDataByCache() + { + if (self::$arrVideoShuoFenLei == []) { + self::$arrVideoShuoFenLei = Cache::get('VIDEO_YUYAN'); + + if (empty(self::$arrVideoShuoFenLei)) { + self::flushCache(); + self::$arrVideoShuoFenLei = Cache::get('VIDEO_YUYAN'); + } + } + + return self::$arrVideoShuoFenLei; + } + + static public function flushCache() + { + $arrVideoShuoFenLei = self::select()->toArray(); + + Cache::tag('VIDEO_YUYAN')->set('VIDEO_YUYAN', $arrVideoShuoFenLei); + } +} diff --git a/code/app/admin/model/VisitLogsModel.php b/code/app/admin/model/VisitLogsModel.php new file mode 100644 index 0000000..42771b8 --- /dev/null +++ b/code/app/admin/model/VisitLogsModel.php @@ -0,0 +1,63 @@ + $arrData['vil_ip'] ?? '', + 'vil_user_agent' => $arrData['vil_user_agent'] ?? '', + 'vil_url' => $arrData['vil_url'] ?? '', + 'vil_method' => $arrData['vil_method'] ?? '', + 'vil_headers' => $arrData['vil_headers'] ?? '', + 'vil_timestamp' => date('Y-m-d H:i:s'), + 'vil_content_type' => $arrData['vil_content_type'] ?? '', + 'vil_content_id' => $arrData['vil_content_id'] ?? '', + 'vil_is_spider' => $arrData['vil_is_spider'] ?? '', + 'vil_location' => $arrData['vil_location'] ?? '', + ]; + + try { + // 必填字段校验 + $requiredFields = ['vil_ip', 'vil_url', 'vil_content_id', 'vil_content_type', 'vil_method']; + foreach ($requiredFields as $field) { + if (empty($arrData[$field])) { + var_dump('字段缺失: {}'.$field); + // throw new \InvalidArgumentException("字段缺失: {$field}"); + } + } + + // 创建模型实例 + $visitLogModel = new self; + + // 保存数据 + if (!$visitLogModel::create($arrData)) { + var_dump('保存失败: '); + // throw new \RuntimeException('访问日志保存失败: ' . json_encode($arrData, JSON_UNESCAPED_UNICODE)); + } + + return $visitLogModel; + } catch (\Throwable $T) { + // 如果错误码是 10501,可以在这里做特殊处理 + if ($T->getCode() == 10501) { + // 记录日志或进行备用操作 + // logError($T->getMessage()); + } + + throw $T; // 继续抛出异常 + } + } +} diff --git a/code/app/admin/model/XiaoShuoFenLeiModel.php b/code/app/admin/model/XiaoShuoFenLeiModel.php new file mode 100644 index 0000000..6d14688 --- /dev/null +++ b/code/app/admin/model/XiaoShuoFenLeiModel.php @@ -0,0 +1,92 @@ +find(); + if ($XiaoShuoFenLeiModel) { + return $XiaoShuoFenLeiModel; + } + + $XiaoShuoFenLeiModel = new self; + $XiaoShuoFenLeiModel->xsfl_source_id = $arrData['xsfl_source_id']; + $XiaoShuoFenLeiModel->xsfl_source_code = $arrData['xsfl_source_code']; + $XiaoShuoFenLeiModel->xsfl_name = $arrData['xsfl_name']; + $XiaoShuoFenLeiModel->save(); + return $XiaoShuoFenLeiModel; + } catch (\Throwable $T) { + + if ($T->getCode() == 10501) { + return self::addXiaoShuoFenLei($arrData); + } + throw $T; + } + } + + static public function getIdByName($strName) + { + $intId = 0; + foreach (self::$arrXiaoShuoFenLei as $arrFenLei) { + if ($arrFenLei['xsfl_name'] == $strName && $arrFenLei['site_id'] == config('app.default_app_id')) { + $intId = $arrFenLei['xsfl_id']; + } + } + return $intId; + } + + static public function getNameById($intId) + { + static::getDataByCache(); + $strName = '全部'; + foreach (self::$arrXiaoShuoFenLei as $arrFenLei) { + if ($arrFenLei['xsfl_source_id'] == $intId && $arrFenLei['site_id'] == config('app.default_app_id')) { + $strName = $arrFenLei['xsfl_name']; + } + } + return $strName; + } + + static public function getDataByCache() + { + $strCacheKey = 'XIAO_SHUO_FEN_LEI'; + if (self::$arrXiaoShuoFenLei == []) { + self::$arrXiaoShuoFenLei = Cache::get( $strCacheKey); + + if (empty(self::$arrXiaoShuoFenLei)) { + self::flushCache(); + self::$arrXiaoShuoFenLei = Cache::get( $strCacheKey); + } + } + + return self::$arrXiaoShuoFenLei; + } + + static public function flushCache() + { + $strCacheKey = 'XIAO_SHUO_FEN_LEI'; + $arrXiaoShuoFenLei = self::where('site_id',config('app.default_app_id'))->select()->toArray(); + + Cache::tag( $strCacheKey)->set( $strCacheKey, $arrXiaoShuoFenLei); + } +} diff --git a/code/app/admin/model/XiaoShuoXiangQingModel.php b/code/app/admin/model/XiaoShuoXiangQingModel.php new file mode 100644 index 0000000..c57259c --- /dev/null +++ b/code/app/admin/model/XiaoShuoXiangQingModel.php @@ -0,0 +1,86 @@ +find(); + + if ($XiaoShuoXiangQingModel) { + + if ($XiaoShuoXiangQingModel->xsxq_geng_xin_shi_jian != $arrData['xsxq_geng_xin_shi_jian']) { + $XiaoShuoXiangQingModel->xsxq_geng_xin_shi_jian = $arrData['xsxq_geng_xin_shi_jian']; + $XiaoShuoXiangQingModel->xsxq_zuozhe = $arrData['xsxq_zuozhe']; + $XiaoShuoXiangQingModel->save(); + } + + return $XiaoShuoXiangQingModel; + } + + $XiaoShuoXiangQingModel = new self; + + $XiaoShuoXiangQingModel->save($arrData); + return $XiaoShuoXiangQingModel; + } catch (\Throwable $T) { + // if ($T->getCode() == 10501 && $retryCount < 3) { // 限制重试次数 + // $retryCount++; + // return self::addXiaoShuoXiangQing($arrData, $retryCount); + // } + throw $T; // 超过重试次数后抛出异常 + // if ($T->getCode() == 10501) { + // return self::addXiaoShuoXiangQing($arrData); + // } + // throw $T; + } + } +} diff --git a/code/app/admin/model/XiaoShuoZhangJieModel.php b/code/app/admin/model/XiaoShuoZhangJieModel.php new file mode 100644 index 0000000..01728cb --- /dev/null +++ b/code/app/admin/model/XiaoShuoZhangJieModel.php @@ -0,0 +1,49 @@ +find(); + if ($XiaoShuoZhangJieModel) { + return $XiaoShuoZhangJieModel; + } + + $XiaoShuoZhangJieModel = new self; + + $XiaoShuoZhangJieModel->save($arrData); + return $XiaoShuoZhangJieModel; + } catch (\Throwable $T) { + if ($T->getCode() == 10501) { + return self::addXiaoShuoZhangJie($arrData); + } + throw $T; + } + } + + /** + * 判断章节是否存在 + * + * @param bool $strXszjSourceCode + * @return void + */ + static public function checkZhangJieExists($strXszjSourceCode) + { + $XiaoShuoZhangJieModel = self::where('xszj_source_code', $strXszjSourceCode)->find(); + return !empty($XiaoShuoZhangJieModel); + } +} diff --git a/code/app/admin/model/ZiYuanDuanDianModel.php b/code/app/admin/model/ZiYuanDuanDianModel.php new file mode 100644 index 0000000..025737a --- /dev/null +++ b/code/app/admin/model/ZiYuanDuanDianModel.php @@ -0,0 +1,40 @@ +set('Zydd', $arrZiYuanDuanDian); + } +} diff --git a/code/app/admin/provider.php b/code/app/admin/provider.php new file mode 100644 index 0000000..916884b --- /dev/null +++ b/code/app/admin/provider.php @@ -0,0 +1,12 @@ + Request::class, + 'think\exception\Handle' => AdminException::class, +]; diff --git a/code/app/common.php b/code/app/common.php index 57cb6d8..961b81c 100644 --- a/code/app/common.php +++ b/code/app/common.php @@ -1,2 +1,765 @@ 标签 + return preg_replace($rpText, '', $newText); + } + + function extractFilename($url) + { + // 检查 URL 是否以 .html 结尾 + if (substr($url, -5) !== '.html') { + throw new InvalidArgumentException('URL must end with .html'); + } + + // 解析 URL 获取路径部分 + $path = parse_url($url, PHP_URL_PATH); + + // 获取文件名部分 + $filename = basename($path, '.html'); + + return $filename; + } + + function extractIdFromUrl($url) + { + if (preg_match('/-id-(\d+)\.html/', $url, $matches)) { + return $matches[1]; + } + return null; + } + + function extractNumbersFromUrl($url) + { + // 使用正则表达式匹配路径中的数字部分 + if (preg_match('#/(\d+)/(\d+)/#', $url, $matches)) { + return [ + 'first' => $matches[1], // 提取到的第一个数字 + 'second' => $matches[2], // 提取到的第二个数字 + ]; + } + return null; // 如果未匹配,返回 null + } + + function extractNumberFromUrl($url) + { + // 使用正则表达式匹配 /class/{数字}_ 的格式 + if (preg_match('/\/class\/(\d+)_/', $url, $matches)) { + return $matches[1]; // 返回匹配的数字部分 + } + return null; // 如果未匹配,返回 null + } + + + function encImgBy17C($strInputImgPath, $strOutImgPath, $strKey = 0x88) + { + // 读取图像内容 + $strImgData = file_get_contents($strInputImgPath); + if ($strImgData === false) { + throw new Exception("无法读取图片文件: $strInputImgPath"); + } + + // 将图像内容转换为字节数组 + $bytes = array_values(unpack('C*', $strImgData)); + $len = count($bytes); + + // 对每个字节进行异或操作加密 + for ($i = 0; $i < $len; $i++) { + $bytes[$i] ^= $strKey; + } + + // 将字节数组转换回二进制数据 + $strEncryptedData = pack('C*', ...$bytes); + + // 将加密后的数据写入文件 + if (file_put_contents($strOutImgPath, $strEncryptedData) === false) { + throw new Exception("无法写入加密文件: $strOutImgPath"); + } + } + function customEntities($text) + { + $result = ''; + $length = mb_strlen($text, 'UTF-8'); + + for ($i = 0; $i < $length; $i++) { + $char = mb_substr($text, $i, 1, 'UTF-8'); + $code = ord($char); + + if ($code < 128) { + // 对于 ASCII 字符,直接使用 ord + $result .= '&#' . $code . ';'; + } else { + // 对于非 ASCII 字符,使用 mb_ord 获取 Unicode 码 + $code = mb_ord($char, 'UTF-8'); + $result .= '&#' . $code . ';'; + } + } + + return $result; + } + + function isValidDateTime($dateTimeStr, $format = 'Y-m-d H:i:s') + { + $date = DateTime::createFromFormat($format, $dateTimeStr); + return $date && $date->format($format) === $dateTimeStr; + } + + // 创建保存文件 + function saveContentToFile($filePath, $content) + { + // 确保目标路径的目录存在 + $directory = dirname($filePath); + if (!is_dir($directory)) { + // 尝试创建目录 + if (!mkdir($directory, 0777, true)) { + return [ + 'status' => false, + 'message' => "Failed to create directory: $directory" + ]; + } + } + + // 写入内容到文件 + if (file_put_contents($filePath, $content) !== false) { + return [ + 'status' => true, + 'message' => "Content successfully written to $filePath" + ]; + } else { + return [ + 'status' => false, + 'message' => "Failed to write content to $filePath" + ]; + } + } + + function saveCompressAndDeleteTxt($filePath, $content) + { + // 确保目标路径的目录存在 + $directory = dirname($filePath); + if (!is_dir($directory)) { + if (!mkdir($directory, 0777, true)) { + return [ + 'status' => false, + 'message' => "Failed to create directory: $directory" + ]; + } + } + + // 写入内容到文件 + $fp = fopen($filePath, "c+"); // 使用 c+ 模式,支持加锁 + if (!$fp) { + return [ + 'status' => false, + 'message' => "Failed to open file for writing: $filePath" + ]; + } + + // 加锁防止其他进程同时操作 + if (!flock($fp, LOCK_EX)) { // 加排他锁 + fclose($fp); + return [ + 'status' => false, + 'message' => "Failed to acquire lock for file: $filePath" + ]; + } + + // 写入内容 + if (fwrite($fp, $content) === false) { + flock($fp, LOCK_UN); // 释放锁 + fclose($fp); + return [ + 'status' => false, + 'message' => "Failed to write content to $filePath" + ]; + } + + // 解锁并关闭文件 + flock($fp, LOCK_UN); + fclose($fp); + + // 压缩文件为 ZIP + $zipPath = $filePath . ".zip"; // 压缩后的 ZIP 文件路径 + $zip = new ZipArchive(); + + $zipOpenResult = $zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE); + if ($zipOpenResult !== true) { + return [ + 'status' => false, + 'message' => "Failed to open zip archive: $zipPath" + ]; + } + + // 添加文件到 ZIP 中 + if (!$zip->addFile($filePath, basename($filePath))) { + $zip->close(); + return [ + 'status' => false, + 'message' => "Failed to add file to zip archive: $filePath" + ]; + } + + if (!$zip->close()) { + return [ + 'status' => false, + 'message' => "Failed to close zip archive: $zipPath" + ]; + } + + // 删除原始文件 + $fp = fopen($filePath, "c+"); // 重新打开文件以加锁 + if ($fp && flock($fp, LOCK_EX)) { + if (!file_exists($filePath)) { + unlink($filePath); // 删除文件 + } + + flock($fp, LOCK_UN); + fclose($fp); + } + + return [ + 'status' => true, + 'message' => "File success save to $zipPath and del", + 'zip_path' => $zipPath + ]; + } + + /** + * 提取 ZIP 文件中的所有 .txt 文件内容 + * + * @param string $zipPath ZIP 文件的完整路径 + * @return array 返回一个数组,键是文件名,值是对应的文件内容 + * @throws Exception 如果文件不存在或解压失败则抛出异常 + */ + function extractTxtFromZip($zipPath) + { + if (!file_exists($zipPath)) { + throw new Exception("ZIP 文件路径无效: " . $zipPath); + } + + $zip = new ZipArchive(); + + if ($zip->open($zipPath) === true) { + $txtContents = ""; + + // 遍历所有文件 + for ($i = 0; $i < $zip->numFiles; $i++) { + $fileName = $zip->getNameIndex($i); + + // 检查文件是否是 .txt 结尾 + if (pathinfo($fileName, PATHINFO_EXTENSION) === 'txt') { + // 读取文件内容 + $content = $zip->getFromName($fileName); + $txtContents = $content; + } + } + + $zip->close(); + return $txtContents; + } else { + throw new Exception("无法打开 ZIP 文件。"); + } + } + + + function readExtractAndDeleteTxt($zipPath, $extractTo = null) + { + // 检查 ZIP 文件是否存在 + if (!file_exists($zipPath)) { + return [ + 'status' => false, + 'message' => "ZIP file does not exist: $zipPath" + ]; + } + + // 打开 ZIP 文件 + $zip = new ZipArchive(); + if ($zip->open($zipPath) !== true) { + return [ + 'status' => false, + 'message' => "Failed to open ZIP file: $zipPath" + ]; + } + + // 获取 ZIP 文件内容列表 + $fileList = []; + for ($i = 0; $i < $zip->numFiles; $i++) { + $fileList[] = $zip->getNameIndex($i); + } + + // 如果需要提取文件 + if ($extractTo) { + // 确保目标目录存在 + if (!is_dir($extractTo)) { + if (!mkdir($extractTo, 0777, true)) { + return [ + 'status' => false, + 'message' => "Failed to create extraction directory: $extractTo" + ]; + } + } + + // 提取文件到指定目录 + if (!$zip->extractTo($extractTo)) { + $zip->close(); + return [ + 'status' => false, + 'message' => "Failed to extract ZIP file to $extractTo" + ]; + } + } + + // 关闭 ZIP 文件 + $zip->close(); + + // 删除提取的 .txt 文件 + $deletedFiles = []; + foreach ($fileList as $file) { + if (pathinfo($file, PATHINFO_EXTENSION) === 'txt') { // 检查是否是 .txt 文件 + $filePath = rtrim($extractTo, '/') . '/' . $file; + if (file_exists($filePath) && unlink($filePath)) { + $deletedFiles[] = $file; + } + } + } + + // 返回提取和删除状态 + return [ + 'status' => true, + 'message' => "ZIP file successfully extracted to $extractTo and .txt files deleted.", + 'files_extracted' => $fileList, + 'files_deleted' => $deletedFiles + ]; + } + + function getRandomUserAgent() + { + $userAgents = [ + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36', + // 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', + // 'Mozilla/5.0 (Linux; Android 9; ASUS_X00TD) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/359.0.0.288 Mobile Safari/537.36', + // 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1', + // 'Mozilla/5.0 (Linux; Android 9; ASUS_X00TD; Flow) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/359.0.0.288 Mobile Safari/537.36' + ]; + return $userAgents[array_rand($userAgents)]; + } + + function getRandomProxies() + { + $proxies = [ + 'http://114.115.130.225:3128', + // 'http://36.6.145.131:8089', + // 'http://202.101.213.205:19926', + // 'http://218.87.205.35:21874', + // 'http://203.19.38.114:1080', + // 'http://121.89.222.174:8090', + // 'http://223.113.80.158:9091', + // 'http://120.232.194.134:8998', + // 'http://120.46.197.14:8083', + // 'http://139.9.5.196:7890', + + // 'http://203.89.8.107:80', + // 'http://117.186.143.130:8118', + // 'http://117.186.232.73:8080', + // 'http://203.12.200.179:8085', + // 'http://120.46.215.52:15280', + // 'http://111.230.243.170:80', + // 'http://223.113.101.150:8060', + // 'http://117.50.113.39:1337', + ]; + return $proxies[array_rand($proxies)]; + } + + function fetchContentWithCurl($url, $headers = [], $timeout = 10, $proxy = null, $proxyAuth = null) + { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + + // 设置头部 + if (!empty($headers)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } + + // 模拟浏览器 + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 9; ASUS_X00TD; Flow) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/359.0.0.288 Mobile Safari/537.36'); + + // 如果需要代理 + if ($proxy) { + curl_setopt($ch, CURLOPT_PROXY, $proxy); + if ($proxyAuth) { + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth); // 代理用户名和密码 + } + } + + // 执行请求 + $response = curl_exec($ch); + + // 检查错误 + if (curl_errno($ch)) { + $error = 'cURL Error: ' . curl_error($ch); + curl_close($ch); + return ['success' => false, 'error' => $error]; + } + + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + // 返回结果 + if ($httpCode >= 200 && $httpCode < 300) { + return ['success' => true, 'data' => $response]; + } else { + return ['success' => false, 'error' => "HTTP Error: $httpCode"]; + } + } + + /** + * // 调用函数生成随机 HTML + * generateRandomHTML(10, 30); // 随机生成 10~30 个标签 + * + * @param integer $minTags + * @param integer $maxTags + * @return void + */ + function generateRandomHTML($minTags = 5, $maxTags = 20) + { + // 可随机生成的标签字符集 + $tagCharset = 'abcdefghijklmnopqrstuvwxyz'; + + // 属性的随机字符集 + $attrCharset = 'abcdefghijklmnopqrstuvwxyz'; + + // 可生成的属性名称 + $possibleAttributes = ['draggable', 'date-time', 'lang', 'id', 'dir', 'class']; + + // 标签的最大长度和属性值的最大长度 + $tagMaxLength = 8; // 标签名的最大长度 + $attrValueMaxLength = 10; // 属性值的最大长度 + + // 随机生成的标签数量 + $numTags = rand($minTags, $maxTags); + + $htmlResult = ''; + + for ($i = 0; $i < $numTags; $i++) { + // 随机生成标签名称 + $tagName = randomString(rand(3, $tagMaxLength), $tagCharset); + + // 随机生成属性数量 + $numAttributes = rand(1, 3); // 每个标签随机生成 1~3 个属性 + $attributes = ''; + + for ($j = 0; $j < $numAttributes; $j++) { + // 随机选择属性名称 + $attrName = $possibleAttributes[array_rand($possibleAttributes)]; + // 随机生成属性值 + $attrValue = randomString(rand(3, $attrValueMaxLength), $attrCharset); + $attributes .= " {$attrName}=\"{$attrValue}\""; + } + + // 拼接随机标签 + $htmlResult .= "<{$tagName}{$attributes}>\n"; + } + + return $htmlResult; + } + // 辅助函数:生成随机字符串 + function randomString($length = 8, $charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') + { + $charsetLength = strlen($charset); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $charset[rand(0, $charsetLength - 1)]; + } + return $randomString; + } + + // 随机颜色生成函数 + function getRandomColor() + { + return 'color:rgb(' . mt_rand(0, 255) . ', ' . mt_rand(0, 255) . ', ' . mt_rand(0, 255) . ');'; + } + + /** + * 生成分页 HTML 的通用函数 + * + * @param int $currentPage 当前页码 + * @param int $lastPage 总页数 + * @param string $baseUrl 基础 URL + * @param string $queryParams 查询参数(包含占位符 :page) + * @param int $maxPagesToShow 最大显示页码数 + * @return string 分页 HTML + * 示例调用 + * $paginationHtml = generatePaginationHtml( + * 3, // 当前页 + * 10, // 总页数 + * '/vodshow/dy-cn-hot-action-en-', // 基础 URL + * ':page---2024.html', // 查询参数,包含占位符 :page + * 5 // 最多显示 5 个页码 + * ); + * // 输出分页 HTML + * echo $paginationHtml; + * + */ + function generatePaginationHtml($currentPage, $lastPage, $baseUrl, $queryParams, $maxPagesToShow = 5) + { + + $paginationHtml = ''; + + return $paginationHtml; + } + + + /** + * 生成分页 HTML 的通用函数 + * + * @param int $currentPage 当前页码 + * @param int $lastPage 总页数 + * @param string $baseUrl 基础 URL + * @param string $queryParams 查询参数(包含占位符 :page) + * @param int $maxPagesToShow 最大显示页码数 + * @return string 分页 HTML + * 示例调用 + * $paginationHtml = generatePaginationHtml( + * 3, // 当前页 + * 10, // 总页数 + * '/vodshow/dy-cn-hot-action-en-', // 基础 URL + * ':page---2024.html', // 查询参数,包含占位符 :page + * 5 // 最多显示 5 个页码 + * ); + * // 输出分页 HTML + * echo $paginationHtml; + * + */ + function generateNovelPaginationHtml($currentPage, $lastPage, $baseUrl, $queryParams, $maxPagesToShow = 10) + { + $paginationHtml = '
'; + + // 首页按钮 + $paginationHtml .= '首 页'; + + // 计算分页起始和结束 + $start = max(1, $currentPage - floor($maxPagesToShow / 2)); + $end = min($lastPage, $start + $maxPagesToShow - 1); + if ($end - $start + 1 < $maxPagesToShow) { + $start = max(1, $end - $maxPagesToShow + 1); + } + + // 页码按钮 + for ($i = $start; $i <= $end; $i++) { + if ($i == $currentPage) { + $paginationHtml .= ' ' . $i . ' '; + } else { + $paginationHtml .= ' ' . $i . ' '; + } + } + + // 下一页按钮 + if ($currentPage < $lastPage) { + $paginationHtml .= '下一页'; + } + + $paginationHtml .= '
'; + + return $paginationHtml; + } + + // 分页模板-时空小说模板 + function generateNovelSkPaginationHtml($currentPage, $lastPage, $baseUrl, $queryParams, $maxPagesToShow = 10) + { + $paginationHtml = ''; + + return $paginationHtml; + } + + + + // 更据IP 获取地区 + function getLocationByIp($ip) + { + try { + $response = file_get_contents("http://ip-api.com/json/{$ip}"); + $locationData = json_decode($response, true); + + if ($locationData['status'] === 'success') { + return [ + 'country' => $locationData['country'], + 'region' => $locationData['regionName'], + 'city' => $locationData['city'], + 'lat' => $locationData['lat'], + 'lon' => $locationData['lon'] + ]; + } + } catch (\Exception $e) { + // 记录异常或忽略 + } + + return null; // 无法获取地理信息时返回 null + } + + // 检查解密内容是否包含潜在的漏洞代码 + function checkForVulnerabilities($content) + { + // 检查是否包含 'eval' 函数 + if (stripos($content, 'eval') !== false) { + return true; + } + + // 检查是否包含恶意的 http 或域名 + $vulnerablePatterns = [ + '/http(s)?:\/\/[^ ]+/', // 匹配 URL + '/.*<\/script>/i' // 匹配 script 标签 + ]; + + foreach ($vulnerablePatterns as $pattern) { + if (preg_match($pattern, $content)) { + return true; + } + } + + return false; + } +} diff --git a/code/app/home/controller/Index.php b/code/app/home/controller/Index.php index c4062fa..e36e953 100644 --- a/code/app/home/controller/Index.php +++ b/code/app/home/controller/Index.php @@ -7,6 +7,11 @@ class Index { public function index() { + $arrConfig = config(); + echo '
';
+        print_r($arrConfig);
+        echo '
'; + // exit; return '您好!这是一个[home]示例应用'; } } diff --git a/code/app/service.php b/code/app/service.php index db1ee6a..d820878 100644 --- a/code/app/service.php +++ b/code/app/service.php @@ -1,9 +1,11 @@ Client = new Client(); + + $this->TaskCore = new TaskCore(); + } + + + + public function getAilisiDomain() + { + if (!key_exists('AILISI_DOMAIN', $this->arrCaiJiPeiZhi)) { + $this->arrCaiJiPeiZhi['AILISI_DOMAIN'] = CaiJiPeiZhiModel::getValByCode('AILISI_DOMAIN'); + } + + return $this->arrCaiJiPeiZhi['AILISI_DOMAIN']; + } + + public function getAilisiCookie() + { + if (!key_exists('AILISI_COOKIE', $this->arrCaiJiPeiZhi)) { + $strCookie = CaiJiPeiZhiModel::getValByCode('AILISI_COOKIE'); + $this->arrCaiJiPeiZhi['AILISI_COOKIE'] = parseCookies($strCookie); + } + + return $this->arrCaiJiPeiZhi['AILISI_COOKIE']; + } + + public function getTianLaiDomain() + { + if (!key_exists('TIANLAI_DOMAIN', $this->arrCaiJiPeiZhi)) { + $this->arrCaiJiPeiZhi['TIANLAI_DOMAIN'] = CaiJiPeiZhiModel::getValByCode('TIANLAI_DOMAIN'); + } + + return $this->arrCaiJiPeiZhi['TIANLAI_DOMAIN']; + } + + public function getBiquxsDomain() + { + if (!key_exists('BIQUXS_DOMAIN', $this->arrCaiJiPeiZhi)) { + $this->arrCaiJiPeiZhi['BIQUXS_DOMAIN'] = CaiJiPeiZhiModel::getValByCode('BIQUXS_DOMAIN'); + } + + return $this->arrCaiJiPeiZhi['BIQUXS_DOMAIN']; + } + + public function get5cccDomain() + { + if (!key_exists('5CCC_DOMAIN', $this->arrCaiJiPeiZhi)) { + $this->arrCaiJiPeiZhi['5CCC_DOMAIN'] = CaiJiPeiZhiModel::getValByCode('5CCC_DOMAIN'); + } + + return $this->arrCaiJiPeiZhi['5CCC_DOMAIN']; + } + + public function get630zwDomain() + { + if (!key_exists('630zw_DOMAIN', $this->arrCaiJiPeiZhi)) { + $this->arrCaiJiPeiZhi['630zw_DOMAIN'] = CaiJiPeiZhiModel::getValByCode('630zw_DOMAIN'); + } + + return $this->arrCaiJiPeiZhi['630zw_DOMAIN']; + } + + + public function getDadiDomain() + { + if (!key_exists('DADI_DOMAIN', $this->arrCaiJiPeiZhi)) { + $this->arrCaiJiPeiZhi['DADI_DOMAIN'] = CaiJiPeiZhiModel::getValByCode('DADI_DOMAIN'); + } + + return $this->arrCaiJiPeiZhi['DADI_DOMAIN']; + } + public function getHeiMuErDomain() + { + if (!key_exists('HEIMUER_DOMAIN', $this->arrCaiJiPeiZhi)) { + $this->arrCaiJiPeiZhi['HEIMUER_DOMAIN'] = CaiJiPeiZhiModel::getValByCode('HEIMUER_DOMAIN'); + } + + return $this->arrCaiJiPeiZhi['HEIMUER_DOMAIN']; + } + public function YouZhiZiYuanDomain() + { + if (!key_exists('YZZY_DOMAIN', $this->arrCaiJiPeiZhi)) { + $this->arrCaiJiPeiZhi['YZZY_DOMAIN'] = CaiJiPeiZhiModel::getValByCode('YZZY_DOMAIN'); + } + + return $this->arrCaiJiPeiZhi['YZZY_DOMAIN']; + } + + +} diff --git a/code/app/task/collection/biquxs/BiquxsXiaoShuoCol.php b/code/app/task/collection/biquxs/BiquxsXiaoShuoCol.php new file mode 100644 index 0000000..8bbf374 --- /dev/null +++ b/code/app/task/collection/biquxs/BiquxsXiaoShuoCol.php @@ -0,0 +1,427 @@ +TaskCore; + // 20054 + for ($i = 1; $i <= 20054; $i++) { + echo "当前值: $i\n"; + $arrTask = [ + 'callback' => [self::class, 'getNovelInfo'], + 'data' => [ + 'xs_source_id' => $i, + 'xs_source_seo_id' => 1, + ] + ]; + $TaskCore->set($arrTask); + var_dump($arrTask); + } + + } + + public function getNovelInfo($arrData) + { + $TaskCore = $this->TaskCore; + $Client = $this->Client; + $strSiteUrl = $this->getBiquxsDomain(); + + $strUrl = 'http://www.biquxs.com/book/' . $arrData['xs_source_id'] ; //'http://www.biquxs.com/book/20053'; + $intXiaoShuoSourceId = $arrData['xs_source_id']; //20053; + $intXiaoShuoSourceSeoId = $arrData['xs_source_seo_id']; //1 ; + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($strUrl); + + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + $Response = $Client->request('GET', $strUrl, [ + 'headers' => [ + 'User-Agent' => $userAgent, + 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language' => 'en-US,en;q=0.5', + ], + 'cookies' => $CookieJar, + // 'proxy' => $proxy, + 'timeout' => 30, + ]); + + $strResult = (string)$Response->getBody(); + + $QueryList = QueryList::html($strResult); + // var_dump($QueryList); + // 提取所有 标签的属性 + $result = $QueryList->find('meta[property^="og:"]')->map(function ($item) { + return [ + 'property' => $item->attr('property'), + 'content' => $item->attr('content'), + ]; + }); + + // 打印结果 + // print_r($result->all()); + $strZuoZhe = ''; + $strMingZi = ''; + $strLastDate = ''; + $strJieShao = ''; + $strCover = ''; + $strFenlei = ''; + $strZiShu = 0; + $strZhuangTai = $QueryList->find('#info p')->eq(1)->text(); + $strZhuangTai = getStringAfterWord($strZhuangTai, '状态:'); + + foreach ($result as $item) { + switch ($item['property']) { + case 'og:title': + $strMingZi = $item['content']; + break; + case 'og:description': + $strJieShao = $item['content']; + break; + case 'og:image': + $strCover = $item['content']; + break; + case 'og:book:category': + $strFenlei = $item['content']; + break; + case 'og:book:author': + $strZuoZhe = $item['content']; + break; + case 'og:book:update_time': + $strLastDate = $item['content']; + break; + } + } + + + $strLastDate = trim((string)$strLastDate); + if (!isValidDateTime($strLastDate)) { + $strLastDate = date('Y-m-d H:i:s'); + } + + $arrTag = []; + + if (strpos($strCover, 'http') === false) { + $strCover = $strSiteUrl . $strCover; + } + $strCoverUri = $strCover; + + try { + $strCoverUri = ""; + $strCoverUri = ImageProcessor::getInstance()->downloadImage( $intXiaoShuoSourceId,$strCover, 'xs'); + } catch (\Throwable $t) { + $strErr = sprintf("采集[%s]小说图片错误,异常:%s", $strCover, $t->getMessage()); + echo $strErr; + } + + $arrCover = [ + 'code' => 'BI_QU_XS_COVER', + // 'uri' => getUriByUrl($strCover), + 'uri' => $strCoverUri, + + ]; + + $strFenleiIId = 1 ; + switch ($strFenlei) { + case '玄幻小说': + $strName = "玄幻"; + $strFenleiIId = 1; + break; + case '修真小说': + $strName = "修真"; + $strFenleiIId = 2; + break; + case '都市小说': + $strName = "都市"; + $strFenleiIId = 3; + break; + case '历史小说': + $strName = "历史"; + $strFenleiIId = 4; + break; + case '网游小说': + $strName = "网游"; + $strFenleiIId = 5; + break; + case '科幻小说': + $strName = "科幻"; + $strFenleiIId = 6; + break; + case '女频小说': + $strName = "女频"; + $strFenleiIId = 7; + break; + case '其它小说': + $strName = "其它"; + $strFenleiIId = 8; + break; + default: + $strName = "其它"; + $strFenleiIId = 8; + break; + } + + $arrXiaoShuoInfo = [ + 'xsxq_ming_zi' => $strMingZi, + 'xsxq_zuozhe' => $strZuoZhe , //$arrData['xiaoshuo_zuozhe'], + 'xsfl_id' => $strFenleiIId, + 'xsxq_zhuang_tai' => $strZhuangTai, + 'xsxq_zi_shu' => $strZiShu, + 'xsxq_jie_shao' => $strJieShao, + 'xsxq_feng_mian' => json_encode($arrCover), + 'xsxq_geng_xin_shi_jian' => $strLastDate, + 'xsxq_tag' => json_encode($arrTag, JSON_UNESCAPED_UNICODE), + 'xsxq_source_id' => $intXiaoShuoSourceId, + 'xsxq_source_seo_id' => $intXiaoShuoSourceId.'1', + 'xsxq_source_code' => 'BIQU_XIAOSHUO_' . $intXiaoShuoSourceId . '_' . $intXiaoShuoSourceSeoId, + ]; + // print_r($arrXiaoShuoInfo); + var_dump($arrXiaoShuoInfo['xsxq_source_code']); + + $XiaoShuoXiangQingModel = XiaoShuoXiangQingModel::addXiaoShuoXiangQing($arrXiaoShuoInfo); + + $arrZhangjie = []; + $intChapterIndex = 0; // 定义一个计数器变量 + + // 检查是否找到元素 + if ($QueryList->find('.listmain a')->count() > 0) { + $QueryList->find('.listmain a')->map(function ($ZhangJie) use (&$arrZhangjie, &$intChapterIndex) { + echo "Processing index $intChapterIndex: " . $ZhangJie->text() . PHP_EOL; + + // 从索引6开始 + if ($intChapterIndex >= 5) { + $arrZhangjie[] = [ + 'mingzi' => $ZhangJie->text(), + 'url' => $ZhangJie->attr('href'), + ]; + } + $intChapterIndex++; + }); + + // 输出最终结果 + var_dump($arrZhangjie); + } else { + echo "No elements found for .listmain a" . PHP_EOL; + } + + //unset($QueryList); + + // 获取最大章节索引 + $intMaxXiaoShuoZhangJiePaixu = XiaoShuoZhangJieModel::where('xsxq_id', $intXiaoShuoSourceId) + ->max('xszj_pai_xu'); // 获取最大值 + var_dump('获取小说章节最大值-'.$intMaxXiaoShuoZhangJiePaixu); + + // 如果没有结果,max 返回 null,可以设置默认值 + $intMaxXiaoShuoZhangJiePaixu = $intMaxXiaoShuoZhangJiePaixu ?? 0; + + foreach ($arrZhangjie as $intZhangJieNum => $arrZhangjieOne) { + var_dump($intZhangJieNum); + + // 如果数据库里的章节最大索引大于当前索引,说明已经入库,不需要入队列了 + if($intMaxXiaoShuoZhangJiePaixu > $intZhangJieNum){ + var_dump("小说章节已经入库,不再推送任务"); + continue;// 如果任务已存在,直接跳过 break + } + + $strZhangJieUrl = $strSiteUrl . $arrZhangjieOne['url']; + + $strZhangJieId = extractFilename($strZhangJieUrl); + + # 'AILISI_XIAOSHUO_ZHANGJIE_小说源id_小说源章节id' + $strXszjSourceCode = 'AILISI_XIAOSHUO_ZHANGJIE_'. $XiaoShuoXiangQingModel->xsxq_source_id . '_' . $strZhangJieId; + + $arrTask = [ + 'callback' => [self::class, 'getNovelReader'], + 'data' => [ + 'xszj_source_id' => $strZhangJieId, + 'xszj_paixu' => $intZhangJieNum, + 'xszj_name' => $arrZhangjieOne['mingzi'], + 'xszj_url' => $strZhangJieUrl, + 'xszj_source_code' => $strXszjSourceCode, + 'xsxq_source_id' => $XiaoShuoXiangQingModel->xsxq_source_id, + 'xsfl_id' => $strFenleiIId, + ] + ]; + $TaskCore->set($arrTask); + + } + var_dump("章节任务投递成功"); + + } catch (\Throwable $T) { + throw $T; + } + } + + public function getNovelFengMian($arrData) + { + //var_dump('getNovelFengMian'); + //var_dump($arrData); + $Client = $this->Client; + $TaskCore = $this->TaskCore; + + // 获取 Redis 实例 + $redis = Cache::store('redis')->handler(); + $intXiaoShuoSourceId = $arrData['xiaoshuo_id']; + $intXiaoShuoSourceSeoId = $arrData['xiaoshuo_seo_id']; + $redisKey = "task:novel_source_id:" . $intXiaoShuoSourceId; + + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($arrData['xiaoshuo_url']); + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $strSiteUrl = $this->getAilisiDomain(); + + + $strCover = $QueryList->find('#fmimg img')->eq(0)->attr("src"); + + if (strpos($strCover, 'http') === false) { + $strCover = $strSiteUrl . $strCover; + } + $strCoverUri = $strCover; + + try { + $strCoverUri = ""; + $strCoverUri = ImageProcessor::getInstance()->downloadAndEncryptImage($strCover, 'xs'); + $arrCover = [ + 'code' => 'AI_LI_SI_COVER', + // 'uri' => getUriByUrl($strCover), + 'uri' => $strCoverUri, + + ]; + + $arrXiaoShuoInfo = [ + 'xsxq_feng_mian' => json_encode($arrCover), + + ]; + $XiaoShuoXiangQingModel = XiaoShuoXiangQingModel::addXiaoShuoXiangQing($arrXiaoShuoInfo); + } catch (\Throwable $t) { + $strErr = sprintf("采集[%s]小说图片错误,异常:%s", $strCover, $t->getMessage()); + echo $strErr; + } + + + + } catch (\Throwable $T) { + throw $T; + } + } + + public function getNovelReader($arrData) + { + var_dump('getNovelReader'); + var_dump($arrData['xszj_url']); + $Client = $this->Client; + $strXszjSourceCode = $arrData['xszj_source_code']; + $strZhangJieUrl = $arrData['xszj_url']; + $intZhangJiePaiXu = $arrData['xszj_paixu']; + $intFenleiId = $arrData['xsfl_id']; + $intXiaoShuoSourceID = $arrData['xsxq_source_id']; + $strZhangJieSourceId = $arrData['xszj_source_id']; + $strZhangJieName = $arrData['xszj_name']; + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($strZhangJieUrl); + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + if (XiaoShuoZhangJieModel::checkZhangJieExists($strXszjSourceCode)) { + return true; + } + + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + $Response = $Client->request('GET', $strZhangJieUrl, [ + 'headers' => [ + 'User-Agent' => $userAgent, + 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language' => 'en-US,en;q=0.5', + ], + 'cookies' => $CookieJar, + // 'proxy' => $proxy, + 'timeout' => 30, + ]); + + $strResult = (string)$Response->getBody(); + unset($Response); + $ZhangJieQueryList = QueryList::html($strResult); + + + // 获取原始 HTML + $strNeiRong = $ZhangJieQueryList->find('#content')->eq(0)->html(); + + // 解码 HTML 实体 + $strNeiRong = html_entity_decode($strNeiRong, ENT_QUOTES, 'UTF-8'); + + // 去掉

标签中的 class="content_detail" 属性 + $strNeiRong = preg_replace('/'); + + // 替换不间断空格 (\xc2\xa0) 和   为普通空格 + $strNeiRong = preg_replace('/\xc2\xa0/', ' ', $strNeiRong); // 替换 UTF-8 不间断空格 + $strNeiRong = preg_replace('/ /', ' ', $strNeiRong); // 替换   + + // 清理多余空格和换行符 + $strNeiRong = preg_replace('/\s+/', ' ', $strNeiRong); + $strNeiRong = preg_replace('/

\s+/', '

', $strNeiRong); // 清理

标签内部多余空格 + $strNeiRong = preg_replace('/\s+<\/p>/', '

', $strNeiRong); // 清理

标签结尾多余空格 + + // 输出结果 + // var_dump($strNeiRong); + + + # '/novel/123yqw/分类id/小说源id/小说源章节id.txt' + $strNeiRongTxtPath = config("filesystem.novel").'/novel/biquxs/'.$intFenleiId.'/'.$intXiaoShuoSourceID.'/'.$strZhangJieSourceId.'.txt'; + //$strNeiRongTxtPath = "/www/novel/123yqw/1/11/111.txt"; + // 调用函数 + $result = saveCompressAndDeleteTxt($strNeiRongTxtPath, $strNeiRong); + + // 输出状态 + if ($result['status']) { + var_dump("Success: " . $result['message']) ; + } else { + var_dump("Error: " . $result['message']) ; + } + + $arrXiaoShuoZhangJie = [ + 'xsxq_id' => $intXiaoShuoSourceID, + 'xszj_pai_xu' => $intZhangJiePaiXu, + 'xszj_ming_zi' => $strZhangJieName, + 'xszj_nei_rong' => $strNeiRongTxtPath, + 'xszj_source_id' => $strZhangJieSourceId, + 'xszj_source_code' => $strXszjSourceCode, + ]; + + XiaoShuoZhangJieModel::addXiaoShuoZhangJie($arrXiaoShuoZhangJie); + unset($ZhangJieQueryList); + // 延时 3 秒 + //sleep(3); + + } catch (\Throwable $T) { + throw $T; + } + } +} diff --git a/code/app/task/collection/ccc5/XiaoShuo5cccCol.php b/code/app/task/collection/ccc5/XiaoShuo5cccCol.php new file mode 100644 index 0000000..b65b96d --- /dev/null +++ b/code/app/task/collection/ccc5/XiaoShuo5cccCol.php @@ -0,0 +1,545 @@ +TaskCore; + // 20054 + for ($i = 3; $i <= 3; $i++) { + echo "当前值: $i\n"; + $arrTask = [ + 'callback' => [self::class, 'getNovelInfo'], + 'data' => [ + 'xs_source_id' => $i, + 'xs_source_seo_id' => 1, + ] + ]; + $TaskCore->set($arrTask); + var_dump($arrTask); + } + + } + + public function getNovelInfo($arrData) + { + $TaskCore = $this->TaskCore; + $Client = $this->Client; + $strSiteUrl = $this->get5cccDomain(); + + $strUrl = 'https://www.5ccc.org/chapter/' . $arrData['xs_source_id'].'.html' ; //'http://www.biquxs.com/book/20053'; + $intXiaoShuoSourceId = $arrData['xs_source_id']; //20053; + $intXiaoShuoSourceSeoId = $arrData['xs_source_seo_id']; //1 ; + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($strUrl); + + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + $Response = $Client->request('GET', $strUrl, [ + 'headers' => [ + 'User-Agent' => $userAgent, + 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language' => 'en-US,en;q=0.5', + ], + 'cookies' => $CookieJar, + // 'proxy' => $proxy, + 'timeout' => 30, + ]); + + $strResult = (string)$Response->getBody(); + + $QueryList = QueryList::html($strResult); + // var_dump($QueryList); + // 提取所有 标签的属性 + $result = $QueryList->find('meta[property^="og:"]')->map(function ($item) { + return [ + 'property' => $item->attr('property'), + 'content' => $item->attr('content'), + ]; + }); + + // 打印结果 + print_r($result->all()); + $strZuoZhe = ''; + $strMingZi = ''; + $strLastDate = ''; + $strJieShao = ''; + $strCover = ''; + $strFenlei = ''; + $strZiShu = 0; + $strZhuangTai = ""; + + foreach ($result as $item) { + switch ($item['property']) { + case 'og:title': + $strMingZi = $item['content']; + break; + case 'og:description': + $strJieShao = $item['content']; + break; + case 'og:image': + $strCover = $item['content']; + break; + case 'og:novel:category': + $strFenlei = $item['content']; + break; + case 'og:novel:author': + $strZuoZhe = $item['content']; + break; + case 'og:novel:update_time': + $strLastDate = $item['content']; + break; + case 'og:novel:status': + $strZhuangTai = $item['content']; + break; + } + } + + + $strLastDate = trim((string)$strLastDate); + if (!isValidDateTime($strLastDate)) { + $strLastDate = date('Y-m-d H:i:s'); + } + + $arrTag = []; + + $strCover = $QueryList->find('.imgbox img')->eq(0)->attr("src"); + if (strpos($strCover, 'http') === false) { + $strCover = $strSiteUrl . $strCover; + } + $strCoverUri = $strCover; + + try { + $strCoverUri = ""; + $strCoverUri = ImageProcessor::getInstance()->downloadImage( $intXiaoShuoSourceId,$strCover, 'xs'); + } catch (\Throwable $t) { + $strErr = sprintf("采集[%s]小说图片错误,异常:%s", $strCover, $t->getMessage()); + echo $strErr; + } + + $arrCover = [ + 'code' => '5CCC_XS_COVER', + // 'uri' => getUriByUrl($strCover), + 'uri' => $strCoverUri, + + ]; + + $strFenleiIId = 1 ; + switch ($strFenlei) { + case '玄幻修真': + $strName = "玄幻修真"; + $strFenleiIId = 1; + break; + case '重生穿越': + $strName = "重生穿越"; + $strFenleiIId = 2; + break; + case '都市小说': + $strName = "都市小说"; + $strFenleiIId = 3; + break; + case '军史小说': + $strName = "军史小说"; + $strFenleiIId = 4; + break; + case '网游小说': + $strName = "网游小说"; + $strFenleiIId = 5; + break; + case '科幻小说': + $strName = "科幻小说"; + $strFenleiIId = 6; + break; + case '灵异小说': + $strName = "灵异小说"; + $strFenleiIId = 7; + break; + case '言情小说': + $strName = "言情小说"; + $strFenleiIId = 8; + break; + case '其他小说': + $strName = "其他小说"; + $strFenleiIId = 9; + break; + } + + $arrXiaoShuoInfo = [ + 'xsxq_ming_zi' => $strMingZi, + 'xsxq_zuozhe' => $strZuoZhe , //$arrData['xiaoshuo_zuozhe'], + 'xsfl_id' => $strFenleiIId, + 'xsxq_zhuang_tai' => $strZhuangTai, + 'xsxq_zi_shu' => $strZiShu, + 'xsxq_jie_shao' => $strJieShao, + 'xsxq_feng_mian' => json_encode($arrCover), + 'xsxq_geng_xin_shi_jian' => $strLastDate, + 'xsxq_tag' => json_encode($arrTag, JSON_UNESCAPED_UNICODE), + 'xsxq_source_id' => $intXiaoShuoSourceId, + 'xsxq_source_seo_id' => $intXiaoShuoSourceId.'1', + 'xsxq_source_code' => 'BIQU_XIAOSHUO_' . $intXiaoShuoSourceId . '_' . $intXiaoShuoSourceSeoId, + ]; + // print_r($arrXiaoShuoInfo); + var_dump($arrXiaoShuoInfo['xsxq_source_code']); + + $XiaoShuoXiangQingModel = XiaoShuoXiangQingModel::addXiaoShuoXiangQing($arrXiaoShuoInfo); + + $strMuluHref = $QueryList->find('.btn-mulu')->eq(0)->attr("href"); + + $arrTask = [ + 'callback' => [self::class, 'getNovelReaderAll'], + 'data' => [ + 'xszj_href' => $strMuluHref, + ] + ]; + $TaskCore->set($arrTask); +/* + + $arrZhangjie = []; + $intChapterIndex = 0; // 定义一个计数器变量 + + // 检查是否找到元素 + if ($QueryList->find('.section-list a')->count() > 0) { + $QueryList->find('.section-list a')->map(function ($ZhangJie) use (&$arrZhangjie, &$intChapterIndex) { + echo "Processing index $intChapterIndex: " . $ZhangJie->text() . PHP_EOL; + + // 从索引6开始 + //if ($intChapterIndex >= 5) { + $arrZhangjie[] = [ + 'mingzi' => $ZhangJie->text(), + 'url' => $ZhangJie->attr('href'), + ]; + //} + $intChapterIndex++; + }); + + // 输出最终结果 + var_dump($arrZhangjie); + } else { + echo "No elements found for .section-list a" . PHP_EOL; + } + + //unset($QueryList); + var_dump($arrZhangjie); + + + // 获取最大章节索引 + $intMaxXiaoShuoZhangJiePaixu = XiaoShuoZhangJieModel::where('xsxq_id', $intXiaoShuoSourceId) + ->max('xszj_pai_xu'); // 获取最大值 + var_dump($intMaxXiaoShuoZhangJiePaixu); + + // 如果没有结果,max 返回 null,可以设置默认值 + $intMaxXiaoShuoZhangJiePaixu = $intMaxXiaoShuoZhangJiePaixu ?? 0; + + foreach ($arrZhangjie as $intZhangJieNum => $arrZhangjieOne) { + var_dump($intZhangJieNum); + + // 如果数据库里的章节最大索引大于当前索引,说明已经入库,不需要入队列了 + if($intMaxXiaoShuoZhangJiePaixu > $intZhangJieNum){ + var_dump("小说章节已经入库,不再推送任务"); + continue;// 如果任务已存在,直接跳过 break + } + + $strZhangJieUrl = $strSiteUrl . $arrZhangjieOne['url']; + + $strZhangJieId = extractFilename($strZhangJieUrl); + + # 'AILISI_XIAOSHUO_ZHANGJIE_小说源id_小说源章节id' + $strXszjSourceCode = '5CCC_XIAOSHUO_ZHANGJIE_'. $XiaoShuoXiangQingModel->xsxq_source_id . '_' . $strZhangJieId; + + $arrTask = [ + 'callback' => [self::class, 'getNovelReader'], + 'data' => [ + 'xszj_source_id' => $strZhangJieId, + 'xszj_paixu' => $intZhangJieNum, + 'xszj_name' => $arrZhangjieOne['mingzi'], + 'xszj_url' => $strZhangJieUrl, + 'xszj_source_code' => $strXszjSourceCode, + 'xsxq_source_id' => $XiaoShuoXiangQingModel->xsxq_source_id, + 'xsfl_id' => $strFenleiIId, + ] + ]; + $TaskCore->set($arrTask); + var_dump("章节任务投递成功".$strXszjSourceCode); + } + */ + + } catch (\Throwable $T) { + throw $T; + } + } + + public function getNovelFengMian($arrData) + { + //var_dump('getNovelFengMian'); + //var_dump($arrData); + $Client = $this->Client; + $TaskCore = $this->TaskCore; + + // 获取 Redis 实例 + $redis = Cache::store('redis')->handler(); + $intXiaoShuoSourceId = $arrData['xiaoshuo_id']; + $intXiaoShuoSourceSeoId = $arrData['xiaoshuo_seo_id']; + $redisKey = "task:novel_source_id:" . $intXiaoShuoSourceId; + + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($arrData['xiaoshuo_url']); + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $strSiteUrl = $this->getAilisiDomain(); + + + $strCover = $QueryList->find('#fmimg img')->eq(0)->attr("src"); + + if (strpos($strCover, 'http') === false) { + $strCover = $strSiteUrl . $strCover; + } + $strCoverUri = $strCover; + + try { + $strCoverUri = ""; + $strCoverUri = ImageProcessor::getInstance()->downloadAndEncryptImage($strCover, 'xs'); + $arrCover = [ + 'code' => 'AI_LI_SI_COVER', + // 'uri' => getUriByUrl($strCover), + 'uri' => $strCoverUri, + + ]; + + $arrXiaoShuoInfo = [ + 'xsxq_feng_mian' => json_encode($arrCover), + + ]; + $XiaoShuoXiangQingModel = XiaoShuoXiangQingModel::addXiaoShuoXiangQing($arrXiaoShuoInfo); + } catch (\Throwable $t) { + $strErr = sprintf("采集[%s]小说图片错误,异常:%s", $strCover, $t->getMessage()); + echo $strErr; + } + + + + } catch (\Throwable $T) { + throw $T; + } + } + + public function getNovelReaderAll($arrData) + { + var_dump('getNovelReaderAll'); + $strMuluHref = $arrData['xszj_href']; + var_dump($strMuluHref); + $Client = $this->Client; + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($strMuluHref); + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + $Response = $Client->request('GET', $strMuluHref, [ + 'headers' => [ + 'User-Agent' => $userAgent, + 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language' => 'en-US,en;q=0.5', + ], + 'cookies' => $CookieJar, + // 'proxy' => $proxy, + 'timeout' => 30, + ]); + + $strResult = (string)$Response->getBody(); + unset($Response); + $QueryList = QueryList::html($strResult); + + + $intChapterIndex = 0; // 定义一个计数器变量 + var_dump($QueryList->find('.section-list a')->count()); + // 检查是否找到元素 + if ($QueryList->find('.section-list a')->count() > 0) { + $QueryList->find('.section-list a')->map(function ($ZhangJie) use (&$arrZhangjie, &$intChapterIndex) { + echo "Processing index $intChapterIndex: " . $ZhangJie->text() . PHP_EOL; + + // 从索引6开始 + //if ($intChapterIndex >= 5) { + $arrZhangjie[] = [ + 'mingzi' => $ZhangJie->text(), + 'url' => $ZhangJie->attr('href'), + ]; + //} + $intChapterIndex++; + }); + + // 输出最终结果 + var_dump($arrZhangjie); + } else { + echo "No elements found for .section-list a" . PHP_EOL; + } + + //unset($QueryList); + var_dump($arrZhangjie); +/* + + // 获取最大章节索引 + $intMaxXiaoShuoZhangJiePaixu = XiaoShuoZhangJieModel::where('xsxq_id', $intXiaoShuoSourceId) + ->max('xszj_pai_xu'); // 获取最大值 + var_dump($intMaxXiaoShuoZhangJiePaixu); + + // 如果没有结果,max 返回 null,可以设置默认值 + $intMaxXiaoShuoZhangJiePaixu = $intMaxXiaoShuoZhangJiePaixu ?? 0; + + foreach ($arrZhangjie as $intZhangJieNum => $arrZhangjieOne) { + var_dump($intZhangJieNum); + + // 如果数据库里的章节最大索引大于当前索引,说明已经入库,不需要入队列了 + if($intMaxXiaoShuoZhangJiePaixu > $intZhangJieNum){ + var_dump("小说章节已经入库,不再推送任务"); + continue;// 如果任务已存在,直接跳过 break + } + + $strZhangJieUrl = $strSiteUrl . $arrZhangjieOne['url']; + + $strZhangJieId = extractFilename($strZhangJieUrl); + + # 'AILISI_XIAOSHUO_ZHANGJIE_小说源id_小说源章节id' + $strXszjSourceCode = '5CCC_XIAOSHUO_ZHANGJIE_'. $XiaoShuoXiangQingModel->xsxq_source_id . '_' . $strZhangJieId; + + $arrTask = [ + 'callback' => [self::class, 'getNovelReader'], + 'data' => [ + 'xszj_source_id' => $strZhangJieId, + 'xszj_paixu' => $intZhangJieNum, + 'xszj_name' => $arrZhangjieOne['mingzi'], + 'xszj_url' => $strZhangJieUrl, + 'xszj_source_code' => $strXszjSourceCode, + 'xsxq_source_id' => $XiaoShuoXiangQingModel->xsxq_source_id, + 'xsfl_id' => $strFenleiIId, + ] + ]; + $TaskCore->set($arrTask); + var_dump("章节任务投递成功".$strXszjSourceCode); + } + */ + + } catch (\Throwable $T) { + throw $T; + } + } + + public function getNovelReader($arrData) + { + var_dump('getNovelReader'); + var_dump($arrData['xszj_url']); + $Client = $this->Client; + $strXszjSourceCode = $arrData['xszj_source_code']; + $strZhangJieUrl = $arrData['xszj_url']; + $intZhangJiePaiXu = $arrData['xszj_paixu']; + $intFenleiId = $arrData['xsfl_id']; + $intXiaoShuoSourceID = $arrData['xsxq_source_id']; + $strZhangJieSourceId = $arrData['xszj_source_id']; + $strZhangJieName = $arrData['xszj_name']; + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($strZhangJieUrl); + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + if (XiaoShuoZhangJieModel::checkZhangJieExists($strXszjSourceCode)) { + return true; + } + + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + $Response = $Client->request('GET', $strZhangJieUrl, [ + 'headers' => [ + 'User-Agent' => $userAgent, + 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language' => 'en-US,en;q=0.5', + ], + 'cookies' => $CookieJar, + // 'proxy' => $proxy, + 'timeout' => 30, + ]); + + $strResult = (string)$Response->getBody(); + unset($Response); + $ZhangJieQueryList = QueryList::html($strResult); + + + // 获取原始 HTML + $strNeiRong = $ZhangJieQueryList->find('#content')->eq(0)->html(); + + // 解码 HTML 实体 + $strNeiRong = html_entity_decode($strNeiRong, ENT_QUOTES, 'UTF-8'); + + // 去掉

标签中的 class="content_detail" 属性 + $strNeiRong = preg_replace('/'); + + // 替换不间断空格 (\xc2\xa0) 和   为普通空格 + $strNeiRong = preg_replace('/\xc2\xa0/', ' ', $strNeiRong); // 替换 UTF-8 不间断空格 + $strNeiRong = preg_replace('/ /', ' ', $strNeiRong); // 替换   + + // 清理多余空格和换行符 + $strNeiRong = preg_replace('/\s+/', ' ', $strNeiRong); + $strNeiRong = preg_replace('/

\s+/', '

', $strNeiRong); // 清理

标签内部多余空格 + $strNeiRong = preg_replace('/\s+<\/p>/', '

', $strNeiRong); // 清理

标签结尾多余空格 + + // 输出结果 + // var_dump($strNeiRong); + + + # '/novel/123yqw/分类id/小说源id/小说源章节id.txt' + $strNeiRongTxtPath = config("filesystem.novel").'/novel/biquxs/'.$intFenleiId.'/'.$intXiaoShuoSourceID.'/'.$strZhangJieSourceId.'.txt'; + //$strNeiRongTxtPath = "/www/novel/123yqw/1/11/111.txt"; + // 调用函数 + $result = saveCompressAndDeleteTxt($strNeiRongTxtPath, $strNeiRong); + + // 输出状态 + if ($result['status']) { + var_dump("Success: " . $result['message']) ; + } else { + var_dump("Error: " . $result['message']) ; + } + + $arrXiaoShuoZhangJie = [ + 'xsxq_id' => $intXiaoShuoSourceID, + 'xszj_pai_xu' => $intZhangJiePaiXu, + 'xszj_ming_zi' => $strZhangJieName, + 'xszj_nei_rong' => $strNeiRongTxtPath, + 'xszj_source_id' => $strZhangJieSourceId, + 'xszj_source_code' => $strXszjSourceCode, + ]; + + XiaoShuoZhangJieModel::addXiaoShuoZhangJie($arrXiaoShuoZhangJie); + unset($ZhangJieQueryList); + // 延时 3 秒 + //sleep(3); + + } catch (\Throwable $T) { + throw $T; + } + } +} diff --git a/code/app/task/collection/dadi/DaDiDianyingCol.php b/code/app/task/collection/dadi/DaDiDianyingCol.php new file mode 100644 index 0000000..de2131f --- /dev/null +++ b/code/app/task/collection/dadi/DaDiDianyingCol.php @@ -0,0 +1,498 @@ +TaskCore; + // 1-75 + for ($i = 1; $i <= 75; $i++) { + echo "当前值: $i\n"; + $arrTask = [ + 'callback' => [self::class, 'getVideoPage'], + 'data' => [ + 'video_page_url' => 'https://www.czdadi.net/vodshow/dy--------'.$i.'---.html', + 'video_class_id' => 1 + ] + ]; + $TaskCore->set($arrTask); + } + //5-25 https://www.czdadi.net/vodshow/duanju-----------.html + for ($i = 1; $i <= 25; $i++) { + echo "当前值: $i\n"; + $arrTask = [ + 'callback' => [self::class, 'getVideoPage'], + 'data' => [ + 'video_page_url' => 'https://www.czdadi.net/vodshow/duanju--------'.$i.'---.html', + 'video_class_id' => 5 + ] + ]; + $TaskCore->set($arrTask); + } + + // 2--18 https://www.czdadi.net/vodshow/dsj--------18---.html + for ($i = 1; $i <= 18; $i++) { + echo "当前值: $i\n"; + $arrTask = [ + 'callback' => [self::class, 'getVideoPage'], + 'data' => [ + 'video_page_url' => 'https://www.czdadi.net/vodshow/dsj--------'.$i.'---.html', + 'video_class_id' => 2 + ] + ]; + $TaskCore->set($arrTask); + } + // 3--11 https://www.czdadi.net/vodshow/zy--------11---.html + for ($i = 1; $i <= 11; $i++) { + echo "当前值: $i\n"; + $arrTask = [ + 'callback' => [self::class, 'getVideoPage'], + 'data' => [ + 'video_page_url' => 'https://www.czdadi.net/vodshow/zy--------'.$i.'---.html', + 'video_class_id' => 3 + ] + ]; + $TaskCore->set($arrTask); + } + // 4--29 https://www.czdadi.net/vodshow/dm-----------.html + for ($i = 1; $i <= 29; $i++) { + echo "当前值: $i\n"; + $arrTask = [ + 'callback' => [self::class, 'getVideoPage'], + 'data' => [ + 'video_page_url' => 'https://www.czdadi.net/vodshow/dm--------'.$i.'---.html', + 'video_class_id' => 4 + ] + ]; + $TaskCore->set($arrTask); + } + + + + } + + # 获取分页里面的视频列表 + public function getVideoPage($arrData) + { + $TaskCore = $this->TaskCore; + $Client = $this->Client; + $strUrl= $arrData['video_page_url']; + $intClassId = $arrData['video_class_id']; + $strSiteUrl = $this->get5cccDomain(); + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($strUrl); + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + $Response = $Client->request('GET', $strUrl, [ + 'headers' => [ + 'User-Agent' => $userAgent, + 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language' => 'en-US,en;q=0.5', + ], + 'cookies' => $CookieJar, + // 'proxy' => $proxy, + 'timeout' => 30, + ]); + + $strResult = (string)$Response->getBody(); + + $QueryList = QueryList::html($strResult); + + //$arrVideo = []; + // 检查是否找到元素 + if ($QueryList->find('.stui-vodlist li .stui-vodlist__detail a')->count() > 0) { + $QueryList->find('.stui-vodlist li .stui-vodlist__detail a ')->map(function ($Video) use (&$arrVideo,$intClassId,&$TaskCore) { + + // $arrVideo[] = [ + // 'mingzi' => $Video->text(), + // 'url' => $Video->attr('href'), + // ]; + if(!empty($Video->text()) && !empty($Video->attr('href'))){ + $arrTask = [ + 'callback' => [self::class, 'getVideoInfo'], + 'data' => [ + 'class_id' => $intClassId, + 'video_href' => $Video->attr('href'), + 'video_name' => $Video->text(), + ] + ]; + $TaskCore->set($arrTask); + echo "视频投递成功 : " . $Video->text() . PHP_EOL; + } + }); + + + // foreach ($arrVideo as $intVideoNum => $arrVideoOne) { + // $arrTask = [ + // 'callback' => [self::class, 'getVideoInfo'], + // 'data' => [ + // 'class_id' => $intClassId, + // 'video_href' => $arrVideoOne['url'], + // 'video_name' => $arrVideoOne['mingzi'], + // ] + // ]; + // $TaskCore->set($arrTask); + + // } + + // 输出最终结果 + // var_dump($arrVideo); + } else { + echo "No elements found for .stui-vodlist a" . PHP_EOL; + } + } + + public function getVideoInfo($arrData) + { + $TaskCore = $this->TaskCore; + $Client = $this->Client; + $strSiteUrl = $this->getDadiDomain(); + $strUrl = $strSiteUrl . $arrData['video_href'] ; + $intClassId = $arrData['class_id']; + $strVideoName = $arrData['video_name']; + + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($strUrl); + + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + $Response = $Client->request('GET', $strUrl, [ + 'headers' => [ + 'User-Agent' => $userAgent, + 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language' => 'en-US,en;q=0.5', + ], + 'cookies' => $CookieJar, + // 'proxy' => $proxy, + 'timeout' => 30, + ]); + + $strResult = (string)$Response->getBody(); + + $QueryList = QueryList::html($strResult); + + $strCover = $QueryList->find('.stui-content__thumb img')->eq(0)->attr("data-original"); + if (strpos($strCover, 'http') === false) { + $strCover = $strSiteUrl . $strCover; + } + $strCoverUri = $strCover; + // try { + // $strCoverUri = ""; + // $strCoverUri = ImageProcessor::getInstance()->downloadImage( $intXiaoShuoSourceId,$strCover, 'dadi'); + // } catch (\Throwable $t) { + // $strErr = sprintf("采集[%s]小说图片错误,异常:%s", $strCover, $t->getMessage()); + // echo $strErr; + // } + $arrCover = [ + 'code' => 'DADI_YINGSHI_COVER', + // 'uri' => getUriByUrl($strCover), + 'uri' => $strCoverUri, + ]; + + $strLanguage = ""; + // if (strlen($strLanguage) > 0) { + // VideoLeixinModel::addVideoLeixin(['vc_id' => $intClassId, 'vla_name' => $strLanguage]); + // } + + // 提取评分 + $strPinfen = $QueryList->find('h1.title .score')->text(); + // 提取类型-入库 + $strLeixin = $QueryList->find('.col-pd a')->eq(1)->text(); + + if(strlen($strLeixin) > 0){ + VideoLeixinModel::addVideoLeixin(['vc_id'=>$intClassId,'vl_name'=>$strLeixin]); + } + + // 提取 HTML 的第一段

+ $dataNode = $QueryList->find('p.data')->eq(0); + + // 提取“类型”内容:确保只匹配 `href` 中包含 `/vodsearch/----` + $leixinNodes = $dataNode->find('a[href^="/vodsearch/----"]'); + $strJuqing = $leixinNodes->map(function ($node) { + return $node->text(); + })->all(); + + // 提取“地区”内容:确保只匹配 `href` 中包含 `/vodsearch/--`,但不包含 `/vodsearch/----` + $diquNodes = $dataNode->find('a[href^="/vodsearch/--"]')->not('a[href^="/vodsearch/----"]'); + $strDiqu = $diquNodes->map(function ($node) { + return $node->text(); + })->all(); + + // 提取“年份”内容:确保只匹配 `href` 中包含 `/vodsearch/-------------` + $yearsNode = $dataNode->find('a[href^="/vodsearch/-------------"]'); + $strYears = $yearsNode->text(); + if (!empty(trim($strYears))) { + $strYears = [trim($strYears)]; + } else { + $strYears = []; + } + + // 过滤掉“地区”和“年份”中的数据 + $strJuqing = array_filter($strJuqing, function ($value) use ($strDiqu, $strYears) { + return !in_array($value, array_merge($strDiqu, $strYears)); + }); + + // **在过滤后将“类型”数据入库** + foreach ($strJuqing as $value) { + if(strlen($value) > 0){ + VideoJuqingModel::add(['vc_id' => $intClassId, 'vj_name' => $value]); + } + } + + // 将“地区”数据入库 + foreach ($strDiqu as $value) { + if(strlen($value) > 0){ + VideoDiquModel::add(['vc_id' => $intClassId, 'vd_name' => $value]); + } + } + + // 将“年份”数据入库 + foreach ($strYears as $value) { + if(strlen($value) > 0){ + VideoYearsModel::add(['vc_id' => $intClassId, 'vy_name' => $value]); + } + + } + + // 提取主演 + $strZhuyan = $QueryList->find('p.data:contains("主演") a')->map(function ($item) { + return $item->text(); + })->implode(', '); // 使用逗号分隔主演 + + // 提取导演 + $strDaoyan = $QueryList->find('p.data:contains("导演") a')->map(function ($item) { + return $item->text(); + })->implode(', '); // 使用逗号分隔主演 + + + // 提取更新时间 + $strLastDate = $QueryList->find('p.data.hidden-sm:contains("更新")')->text(); + // 去掉“更新:”前缀 + $strLastDate = str_replace('更新:', '', $strLastDate); + + // 提取简介 + $strDescription = $QueryList->find('#desc>.stui-pannel-box>.stui-pannel_bd>.col-pd')->text(); + + // 角标 + $strJiaoBiao = $QueryList->find('.stui-content__thumb .text-right')->eq(0)->text(); + + $strPinyinId = extractFilename($strUrl); + + $arrVideoInfo = [ + 'v_name' => $strVideoName, + 'v_cover' => json_encode($arrCover), + 'vc_id' => $intClassId, + 'v_pinyin' => $strPinyinId, + 'v_leixin' => $strLeixin , + 'v_juqing' => implode(', ', $strJuqing), + 'v_diqu' => implode(', ', $strDiqu), + 'v_years' => implode(', ', $strYears), + 'v_language' => $strLanguage, + 'v_daoyan' => $strZhuyan, + 'v_zhuyan' => $strDaoyan, + 'update_time' => $strLastDate, + 'v_description'=>$strDescription, + 'v_pingfen' => $strPinfen, + 'v_orurl' => $strUrl, + 'v_jiaobiao'=> $strJiaoBiao, + 'v_md5' => md5($intClassId.$strVideoName.$strSiteUrl.$strUrl), + ]; + + $VideoInfoModel = VideoInfoModel::addVideoXiangQing($arrVideoInfo); + + $intVid = $VideoInfoModel->v_id; + $intChapterIndex = 0 ; + $arrZhangjie = []; + // // 检查是否找到元素 + if ($QueryList->find('.stui-content__playlist a')->count() > 0) { + $QueryList->find('.stui-content__playlist a')->map(function ($ZhangJie) use (&$arrZhangjie, &$intChapterIndex ,&$intVid) { + //echo "Processing index $intChapterIndex: " . $ZhangJie->text() . PHP_EOL; + + $arrZhangjie[] = [ + 'v_id' => $intVid, + 'index' => $intChapterIndex, + 'mingzi' => $ZhangJie->text(), + 'url' => $ZhangJie->attr('href'), + ]; + $intChapterIndex++; + }); + + //var_dump($arrZhangjie); + foreach ($arrZhangjie as $intZhangJieNum => $arrZhangjieOne) { + var_dump($intZhangJieNum); + + // 如果数据库里的章节最大索引大于当前索引,说明已经入库,不需要入队列了 + // if($intMaxXiaoShuoZhangJiePaixu > $intZhangJieNum){ + // var_dump("小说章节已经入库,不再推送任务"); + // continue;// 如果任务已存在,直接跳过 break + // } + //if($intZhangJieNum<=3){ + $arrTask = [ + 'callback' => [self::class, 'getNovelReader'], + 'data' => [ + 'v_id' => $intVid, + 'vp_sort' => $intZhangJieNum, + 'vp_name' => $arrZhangjieOne['mingzi'], + 'vp_url' => $strSiteUrl . $arrZhangjieOne['url'] + ] + ]; + $TaskCore->set($arrTask); + //} + + } + } else { + echo "No elements found for .listmain a" . PHP_EOL; + } + + } catch (\Throwable $T) { + throw $T; + } + // sleep(10); + } + + public function getNovelFengMian($arrData) + { + //var_dump('getNovelFengMian'); + //var_dump($arrData); + $Client = $this->Client; + $TaskCore = $this->TaskCore; + + // 获取 Redis 实例 + $redis = Cache::store('redis')->handler(); + $intXiaoShuoSourceId = $arrData['xiaoshuo_id']; + $intXiaoShuoSourceSeoId = $arrData['xiaoshuo_seo_id']; + $redisKey = "task:novel_source_id:" . $intXiaoShuoSourceId; + + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($arrData['xiaoshuo_url']); + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $strSiteUrl = $this->getAilisiDomain(); + + + $strCover = $QueryList->find('#fmimg img')->eq(0)->attr("src"); + + if (strpos($strCover, 'http') === false) { + $strCover = $strSiteUrl . $strCover; + } + $strCoverUri = $strCover; + + try { + $strCoverUri = ""; + $strCoverUri = ImageProcessor::getInstance()->downloadAndEncryptImage($strCover, 'xs'); + $arrCover = [ + 'code' => 'AI_LI_SI_COVER', + // 'uri' => getUriByUrl($strCover), + 'uri' => $strCoverUri, + + ]; + + $arrXiaoShuoInfo = [ + 'xsxq_feng_mian' => json_encode($arrCover), + + ]; + $XiaoShuoXiangQingModel = XiaoShuoXiangQingModel::addXiaoShuoXiangQing($arrXiaoShuoInfo); + } catch (\Throwable $t) { + $strErr = sprintf("采集[%s]小说图片错误,异常:%s", $strCover, $t->getMessage()); + echo $strErr; + } + + + + } catch (\Throwable $T) { + throw $T; + } + } + + public function getNovelReader($arrData) + { + if (Cache::has('video_no_m3u8_' . $arrData['v_id'])) { + echo "跳过抓取,视频ID已在缓存中: " . $arrData['v_id'] . "\n"; + return; // 跳过抓取逻辑 + } + + $strMuluHref = $arrData['vp_url']; + var_dump($strMuluHref); + $Client = $this->Client; + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($strMuluHref); + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + $Response = $Client->request('GET', $strMuluHref, [ + 'headers' => [ + 'User-Agent' => $userAgent, + 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language' => 'en-US,en;q=0.5', + ], + 'cookies' => $CookieJar, + // 'proxy' => $proxy, + 'timeout' => 30, + ]); + + $strResult = (string)$Response->getBody(); + unset($Response); + $QueryList = QueryList::html($strResult); + //提取
', $strNeiRong); + + $strNeiRong = $arrNeiRong[1]; + + $arrNeiRong = explode('

', $strNeiRong); + + $arrEnCode = []; + foreach ($arrNeiRong as $intNeiRongNum => $strNeiRongOne) { + $strEnCode = Base64Helper::encode('

' . $strNeiRongOne . '

'); + $arrEnCode[] = $strEnCode; + } + + $strNeiRong = implode(';;;', $arrEnCode); + + # '/novel/123yqw/分类id/小说源id/小说源章节id.txt' + $strNeiRongTxtPath = config("filesystem.novel") . '/novel/630zwxs/' . $intFenleiId . '/' . $intXiaoShuoId . '/' . $intZhangJiePaiXu . '/' . $intZhangJieSort . '.txt'; + // 调用函数 + $result = saveCompressAndDeleteTxt($strNeiRongTxtPath, $strNeiRong); + + // 输出状态 + if ($result['status']) { + var_dump("Success: " . $result['message']); + } else { + var_dump("Error: " . $result['message']); + } + + $arrXiaoShuoZhangJie = [ + 'xsxq_id' => $intXiaoShuoId, + 'xszj_pai_xu' => $intZhangJiePaiXu, + 'xszj_ming_zi' => $strZhangJieName, + 'xszj_nei_rong' => $strNeiRongTxtPath, + 'xszj_source_id' => $strZhangJieSourceId, + 'xszj_source_code' => $strXszjSourceCode, + 'xszj_sort' => $intZhangJieSort, + + ]; + if ($strZhangJieName) { + XiaoShuoZhangJieModel::addXiaoShuoZhangJie($arrXiaoShuoZhangJie); + } + + unset($ZhangJieQueryList); + //sleep(3); + + + } catch (\Throwable $T) { + $arrTask = [ + 'callback' => [self::class, 'getNovelReader'], + 'data' => [ + 'xszj_source_id' => $strZhangJieSourceId, + 'xszj_paixu' => $intZhangJiePaiXu, + 'xszj_name' => $strZhangJieName, + 'xszj_url' => $strZhangJieUrl, + 'xszj_source_code' => $strXszjSourceCode, + 'xsxq_id' => $intXiaoShuoId, + 'xsfl_id' => $intFenleiId, + 'intZhangJieSort' => $intZhangJieSort, + ] + ]; + + $TaskCore->set($arrTask); + throw $T; + } + } +} diff --git a/code/app/task/collection/seo/GenerateSiteMapCol.php b/code/app/task/collection/seo/GenerateSiteMapCol.php new file mode 100644 index 0000000..1f9cb21 --- /dev/null +++ b/code/app/task/collection/seo/GenerateSiteMapCol.php @@ -0,0 +1,137 @@ +generateVideoSitemaps($chunkSize, $totalVideoCount, $strSiteDomain); + + // 生成分类的 Sitemap + $categorySitemapFiles = $this->generateCategorySitemaps($categories, $strSiteDomain); + + // 合并所有 Sitemap 文件路径 + $allSitemapFiles = array_merge($videoSitemapFiles, $categorySitemapFiles); + + // 生成 Sitemap Index 文件 + $this->buildSitemapIndex($allSitemapFiles, $strSiteDomain); + + var_dump(['message' => '所有 Sitemap 生成成功', 'files' => $allSitemapFiles]); + } + + private function generateVideoSitemaps(int $chunkSize, int $totalCount, string $strSiteDomain): array + { + $totalFiles = ceil($totalCount / $chunkSize); + $sitemapFiles = []; + + for ($i = 0; $i < $totalFiles; $i++) { + $videos = VideoInfoModel::field('v_pinyin') + ->limit($i * $chunkSize, $chunkSize) + ->select() + ->toArray(); + + $sitemapXml = $this->buildSitemap($videos, $strSiteDomain); + $filePath = public_path() . "sitemap_video_{$i}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + private function generateCategorySitemaps(array $categories, string $strSiteDomain): array + { + $sitemapFiles = []; + + foreach ($categories as $category) { + $vcId = $category['vc_id']; + $vcNicheng = $category['vc_nicheng']; + $vcName = $category['vc_name']; + + $videoCount = VideoInfoModel::where('vc_id', $vcId)->count(); + $totalPages = ceil($videoCount / 30); + + $categoryUrls = []; + $categoryUrls[] = [ + 'url' => "/vodtype/{$vcNicheng}.html", + 'title' => "{$vcName} - 首页", + 'is_home' => true, + ]; + + for ($page = 2; $page <= $totalPages; $page++) { + $categoryUrls[] = [ + 'url' => "/vodshow/{$vcNicheng}--------{$page}---.html", + 'title' => "{$vcName} - 第{$page}页", + 'is_home' => false, + ]; + } + + $sitemapXml = $this->buildSitemap($categoryUrls, $strSiteDomain, true); + $filePath = public_path() . "sitemap_category_{$vcNicheng}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + private function buildSitemap(array $items, string $strSiteDomain, bool $isCategory = false): string + { + $xmlHeader = ''; + $urlsetStart = ''; + $urlsetEnd = ''; + + $urlEntries = ''; + foreach ($items as $item) { + $urlEntries .= ''; + $urlEntries .= 'https://' . $strSiteDomain . ($isCategory ? $item['url'] : '/voddetail/' . htmlspecialchars($item['v_pinyin'] . '.html', ENT_QUOTES)) . ''; + $urlEntries .= 'daily'; + $urlEntries .= '0.8'; + $urlEntries .= ''; + } + + return $xmlHeader . $urlsetStart . $urlEntries . $urlsetEnd; + } + + private function buildSitemapIndex(array $sitemapFiles, string $strSiteDomain): void + { + $xmlHeader = ''; + $sitemapIndexStart = ''; + $sitemapIndexEnd = ''; + + $sitemapEntries = ''; + foreach ($sitemapFiles as $file) { + $url = 'https://' . $strSiteDomain . '/' . basename($file); + $sitemapEntries .= ''; + $sitemapEntries .= '' . htmlspecialchars($url, ENT_QUOTES) . ''; + $sitemapEntries .= '' . date('Y-m-d') . ''; + $sitemapEntries .= ''; + } + + $sitemapIndexXml = $xmlHeader . $sitemapIndexStart . $sitemapEntries . $sitemapIndexEnd; + file_put_contents(public_path() . 'sitemap_index.xml', $sitemapIndexXml); + + var_dump(['message' => 'Sitemap Index 生成成功', 'file' => 'sitemap_index.xml']); + } +} diff --git a/code/app/task/collection/seo/GenerateSiteMapNovel.php b/code/app/task/collection/seo/GenerateSiteMapNovel.php new file mode 100644 index 0000000..8538841 --- /dev/null +++ b/code/app/task/collection/seo/GenerateSiteMapNovel.php @@ -0,0 +1,188 @@ +generateNovelSitemaps($chunkSize, $totalNovelCount, $strSiteDomain); + + // 生成章节的 Sitemap + $novelZjSitemapFiles = $this->generateNovelZjSitemaps($chunkSize, $totalNovelZjCount, $strSiteDomain); + + // 生成分类的 Sitemap + $categorySitemapFiles = $this->generateCategorySitemaps($categories, $strSiteDomain); + + // 合并所有 Sitemap 文件路径 + $allSitemapFiles = array_merge($novelSitemapFiles, $categorySitemapFiles,$novelZjSitemapFiles); + + // 生成 Sitemap Index 文件 + $this->buildSitemapIndex($allSitemapFiles, $strSiteDomain); + + var_dump(['message' => '所有 Sitemap 生成成功', 'files' => $allSitemapFiles]); + } + + private function generateNovelZjSitemaps(int $chunkSize, int $totalCount, string $strSiteDomain): array + { + $totalFiles = ceil($totalCount / $chunkSize); + $sitemapFiles = []; + + for ($i = 0; $i < $totalFiles; $i++) { + $Novels = XiaoShuoZhangJieModel::field(['xsxq_id','xszj_id']) //intNovelId-:intNovelSourceId-:intNovelSourceSeoId + ->limit($i * $chunkSize, $chunkSize) + ->select() + ->toArray(); + + $sitemapXml = $this->buildZjSitemap($Novels, $strSiteDomain); + $filePath = public_path() . "sitemap_novel_zj_{$i}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + + private function generateNovelSitemaps(int $chunkSize, int $totalCount, string $strSiteDomain): array + { + $totalFiles = ceil($totalCount / $chunkSize); + $sitemapFiles = []; + + for ($i = 0; $i < $totalFiles; $i++) { + $Novels = XiaoShuoXiangQingModel::field(['xsxq_id','xsxq_source_id','xsxq_source_seo_id']) //intNovelId-:intNovelSourceId-:intNovelSourceSeoId + ->limit($i * $chunkSize, $chunkSize) + ->select() + ->toArray(); + + $sitemapXml = $this->buildSitemap($Novels, $strSiteDomain); + $filePath = public_path() . "sitemap_novel_{$i}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + private function generateCategorySitemaps(array $categories, string $strSiteDomain): array + { + $sitemapFiles = []; + + foreach ($categories as $category) { + $vcId = $category['xsfl_id']; + $vcName = $category['xsfl_name']; + + $intNovelCount = XiaoShuoFenLeiModel::where('xsfl_id', $vcId)->count(); + $totalPages = ceil($intNovelCount / 30); + + $categoryUrls = []; + for ($type = 0; $type <= 3; $type++) { + for ($page = 1; $page <= $totalPages; $page++) { + $categoryUrls[] = [ + // /fenlei/1-0-1.html + 'url' => "/fenlei/{$vcId}-{$type}-{$page}.html", + 'title' => "{$vcName} - 第{$page}页", + 'is_home' => false, + ]; + } + } + + $sitemapXml = $this->buildSitemap($categoryUrls, $strSiteDomain, true); + $filePath = public_path() . "sitemap_category_{$vcId}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + private function buildZjSitemap(array $items, string $strSiteDomain, bool $isCategory = false): string + { + $xmlHeader = ''; + $urlsetStart = ''; + $urlsetEnd = ''; + // zj/18648-206.html + $urlEntries = ''; + foreach ($items as $item) { + $urlEntries .= ''; + $urlEntries .= 'https://' . $strSiteDomain . ($isCategory ? $item['url'] : '/zj/' . htmlspecialchars($item['xsxq_id'].'-'.$item['xszj_id']. '.html', ENT_QUOTES)) . ''; + $urlEntries .= 'daily'; + $urlEntries .= '0.8'; + $urlEntries .= ''; + } + + return $xmlHeader . $urlsetStart . $urlEntries . $urlsetEnd; + } + + private function buildSitemap(array $items, string $strSiteDomain, bool $isCategory = false): string + { + $xmlHeader = ''; + $urlsetStart = ''; + $urlsetEnd = ''; + // /xq/20052-16107-161071.html + $urlEntries = ''; + foreach ($items as $item) { + $urlEntries .= ''; + $urlEntries .= 'https://' . $strSiteDomain . ($isCategory ? $item['url'] : '/xq/' . htmlspecialchars($item['xsxq_id'].'-'.$item['xsxq_source_id'].'-'.$item['xsxq_source_seo_id']. '.html', ENT_QUOTES)) . ''; + $urlEntries .= 'daily'; + $urlEntries .= '1.0'; + $urlEntries .= ''; + } + + return $xmlHeader . $urlsetStart . $urlEntries . $urlsetEnd; + } + + private function buildSitemapIndex(array $sitemapFiles, string $strSiteDomain): void + { + $xmlHeader = ''; + $sitemapIndexStart = ''; + $sitemapIndexEnd = ''; + + $sitemapEntries = ''; + foreach ($sitemapFiles as $file) { + $url = 'https://' . $strSiteDomain . '/' . basename($file); + $sitemapEntries .= ''; + $sitemapEntries .= '' . htmlspecialchars($url, ENT_QUOTES) . ''; + $sitemapEntries .= '' . date('Y-m-d') . ''; + $sitemapEntries .= ''; + } + + $sitemapIndexXml = $xmlHeader . $sitemapIndexStart . $sitemapEntries . $sitemapIndexEnd; + file_put_contents(public_path() . 'sitemap_index.xml', $sitemapIndexXml); + + var_dump(['message' => 'Sitemap Index 生成成功', 'file' => 'sitemap_index.xml']); + } +} diff --git a/code/app/task/collection/seo/GenerateSiteMapNovelSk.php b/code/app/task/collection/seo/GenerateSiteMapNovelSk.php new file mode 100644 index 0000000..f9da8b4 --- /dev/null +++ b/code/app/task/collection/seo/GenerateSiteMapNovelSk.php @@ -0,0 +1,242 @@ +generateNovelSitemaps($chunkSize, $totalNovelCount, $strSiteDomain, $strXqPath); + + // 生成详情的 Sitemap 小说seo + $novelSeoSitemapFiles = $this->generateNovelSeoSitemaps($chunkSize, $totalNovelSeoCount, $strSiteDomain, $strSeoPath); + + // 生成章节的 Sitemap 小说章节 + $novelZjSitemapFiles = $this->generateNovelZjSitemaps($chunkSize, $totalNovelZjCount, $strSiteDomain, $strXqPath); + + // 生成分类的 Sitemap 小说分类 + $categorySitemapFiles = $this->generateCategorySitemaps($categories, $strSiteDomain, $strFenleiPath, $strXqPath); + + // 合并所有 Sitemap 文件路径 + $allSitemapFiles = array_merge($novelSitemapFiles, $novelSeoSitemapFiles, $categorySitemapFiles, $novelZjSitemapFiles); + + // 生成 Sitemap Index 文件 + $this->buildSitemapIndex($allSitemapFiles, $strSiteDomain); + + var_dump(['message' => '所有 Sitemap 生成成功', 'files' => $allSitemapFiles]); + } + + # 生成小说章节 xml文件 + private function generateNovelZjSitemaps(int $chunkSize, int $totalCount, string $strSiteDomain, string $strXqPath): array + { + $totalFiles = ceil($totalCount / $chunkSize); + $sitemapFiles = []; + + for ($i = 0; $i < $totalFiles; $i++) { + $Novels = XiaoShuoZhangJieModel::field(['xsxq_id', 'xszj_id']) //intNovelId-:intNovelSourceId-:intNovelSourceSeoId + ->limit($i * $chunkSize, $chunkSize) + ->select() + ->toArray(); + + $sitemapXml = $this->buildZjSitemap($Novels, $strSiteDomain, $strXqPath); + $filePath = public_path() . "sitemap_novel_zj_{$i}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + # 生成小说详情 xml文件 + private function generateNovelSitemaps(int $chunkSize, int $totalCount, string $strSiteDomain, string $strXqPath): array + { + $totalFiles = ceil($totalCount / $chunkSize); + $sitemapFiles = []; + + for ($i = 0; $i < $totalFiles; $i++) { + $Novels = XiaoShuoXiangQingModel::field(['xsxq_id', 'xsxq_source_id', 'xsxq_source_seo_id']) //intNovelId-:intNovelSourceId-:intNovelSourceSeoId + ->limit($i * $chunkSize, $chunkSize) + ->select() + ->toArray(); + + $sitemapXml = $this->buildSitemap($Novels, $strSiteDomain, $strXqPath); + $filePath = public_path() . "sitemap_novel_{$i}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + # 生成小说详情 xml文件 + private function generateNovelSeoSitemaps(int $chunkSize, int $totalCount, string $strSiteDomain, string $strSeoPath): array + { + $totalFiles = ceil($totalCount / $chunkSize); + $sitemapFiles = []; + + for ($i = 0; $i < $totalFiles; $i++) { + $Novels = NovelInfoSeoModel::field(['xsxq_id', 'nis_id']) //show/nis_id + ->limit($i * $chunkSize, $chunkSize) + ->select() + ->toArray(); + + $sitemapXml = $this->buildXiaoShuoSeoSitemap($Novels, $strSiteDomain, $strSeoPath); + $filePath = public_path() . "sitemap_novel_seo_{$i}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + // 生成分类链接 + private function generateCategorySitemaps(array $categories, string $strSiteDomain, string $strFenleiPath, string $strXqPath): array + { + $sitemapFiles = []; + + foreach ($categories as $category) { + $vcId = $category['xsfl_id']; + $vcName = $category['xsfl_name']; + + $intNovelCount = XiaoShuoFenLeiModel::where('xsfl_id', $vcId)->count(); + $totalPages = ceil($intNovelCount / 30); + + $categoryUrls = []; + for ($status = 0; $status <= 2; $status++) { + for ($sort = 0; $sort <= 4; $sort++) { + for ($page = 1; $page <= $totalPages; $page++) { + $categoryUrls[] = [ + // /fl/:intCId-:intSort-[:intPage] + 'url' => "/{$strFenleiPath}/{$vcId}-{$sort}-{$page}.html", + 'title' => "{$vcName} - 第{$page}页", + 'is_home' => false, + ]; + } + } + } + + $sitemapXml = $this->buildSitemap($categoryUrls, $strSiteDomain, $strXqPath, true); + $filePath = public_path() . "sitemap_category_{$vcId}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + //生成章节链接 + private function buildZjSitemap(array $items, string $strSiteDomain, string $strXqPath, bool $isCategory = false): string + { + $xmlHeader = ''; + $urlsetStart = ''; + $urlsetEnd = ''; + // /xq/:intNovelId/:intZhangJiePaiXu-[:strSort] + $urlEntries = ''; + foreach ($items as $item) { + $urlEntries .= ''; + $urlEntries .= 'https://' . $strSiteDomain . ($isCategory ? $item['url'] : '/' . $strXqPath . '/' . htmlspecialchars($item['xsxq_id'] . '-' . $item['xszj_pai_xu']. '-' . $item['xszj_sort'] . '.html', ENT_QUOTES)) . ''; + $urlEntries .= 'daily'; + $urlEntries .= '0.8'; + $urlEntries .= ''; + } + + return $xmlHeader . $urlsetStart . $urlEntries . $urlsetEnd; + } + + // 生成 详情链接 + private function buildSitemap(array $items, string $strSiteDomain, string $strXqPath, bool $isCategory = false): string + { + $xmlHeader = ''; + $urlsetStart = ''; + $urlsetEnd = ''; + // /xq/:intNovelId + $urlEntries = ''; + foreach ($items as $item) { + $urlEntries .= ''; + $urlEntries .= 'https://' . $strSiteDomain . ($isCategory ? $item['url'] : '/' . $strXqPath . '/' . htmlspecialchars($item['xsxq_id'] . '.html', ENT_QUOTES)) . ''; + $urlEntries .= 'daily'; + $urlEntries .= '1.0'; + $urlEntries .= ''; + } + + return $xmlHeader . $urlsetStart . $urlEntries . $urlsetEnd; + } + + // 生成详情 seo 链接 + private function buildXiaoShuoSeoSitemap(array $items, string $strSiteDomain, string $strSeoPath, bool $isCategory = false): string + { + $xmlHeader = ''; + $urlsetStart = ''; + $urlsetEnd = ''; + // /show/:intNovelId + $urlEntries = ''; + foreach ($items as $item) { + $urlEntries .= ''; + $urlEntries .= 'https://' . $strSiteDomain . ($isCategory ? $item['url'] : '/' . $strSeoPath . '/' . htmlspecialchars($item['nis_id'] . '.html', ENT_QUOTES)) . ''; + $urlEntries .= 'daily'; + $urlEntries .= '1.0'; + $urlEntries .= ''; + } + + return $xmlHeader . $urlsetStart . $urlEntries . $urlsetEnd; + } + + // 生成 xml 文件 + private function buildSitemapIndex(array $sitemapFiles, string $strSiteDomain): void + { + $xmlHeader = ''; + $sitemapIndexStart = ''; + $sitemapIndexEnd = ''; + + $sitemapEntries = ''; + foreach ($sitemapFiles as $file) { + $url = 'https://' . $strSiteDomain . '/' . basename($file); + $sitemapEntries .= ''; + $sitemapEntries .= '' . htmlspecialchars($url, ENT_QUOTES) . ''; + $sitemapEntries .= '' . date('Y-m-d') . ''; + $sitemapEntries .= ''; + } + + $sitemapIndexXml = $xmlHeader . $sitemapIndexStart . $sitemapEntries . $sitemapIndexEnd; + file_put_contents(public_path() . 'sitemap_index.xml', $sitemapIndexXml); + + var_dump(['message' => 'Sitemap Index 生成成功', 'file' => 'sitemap_index.xml']); + } +} diff --git a/code/app/task/collection/seo/GenerateSiteMapNovelZw.php b/code/app/task/collection/seo/GenerateSiteMapNovelZw.php new file mode 100644 index 0000000..4cf72b8 --- /dev/null +++ b/code/app/task/collection/seo/GenerateSiteMapNovelZw.php @@ -0,0 +1,242 @@ +generateNovelSitemaps($chunkSize, $totalNovelCount, $strSiteDomain, $strXqPath); + + // 生成详情的 Sitemap 小说seo + $novelSeoSitemapFiles = $this->generateNovelSeoSitemaps($chunkSize, $totalNovelSeoCount, $strSiteDomain, $strSeoPath); + + // 生成章节的 Sitemap 小说章节 + $novelZjSitemapFiles = $this->generateNovelZjSitemaps($chunkSize, $totalNovelZjCount, $strSiteDomain, $strXqPath); + + // 生成分类的 Sitemap 小说分类 + $categorySitemapFiles = $this->generateCategorySitemaps($categories, $strSiteDomain, $strFenleiPath, $strXqPath); + + // 合并所有 Sitemap 文件路径 + $allSitemapFiles = array_merge($novelSitemapFiles, $novelSeoSitemapFiles, $categorySitemapFiles, $novelZjSitemapFiles); + + // 生成 Sitemap Index 文件 + $this->buildSitemapIndex($allSitemapFiles, $strSiteDomain); + + var_dump(['message' => '所有 Sitemap 生成成功', 'files' => $allSitemapFiles]); + } + + # 生成小说章节 xml文件 + private function generateNovelZjSitemaps(int $chunkSize, int $totalCount, string $strSiteDomain, string $strXqPath): array + { + $totalFiles = ceil($totalCount / $chunkSize); + $sitemapFiles = []; + + for ($i = 0; $i < $totalFiles; $i++) { + $Novels = XiaoShuoZhangJieModel::field(['xsxq_id', 'xszj_id']) //intNovelId-:intNovelSourceId-:intNovelSourceSeoId + ->limit($i * $chunkSize, $chunkSize) + ->select() + ->toArray(); + + $sitemapXml = $this->buildZjSitemap($Novels, $strSiteDomain, $strXqPath); + $filePath = public_path() . "sitemap_novel_zj_{$i}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + # 生成小说详情 xml文件 + private function generateNovelSitemaps(int $chunkSize, int $totalCount, string $strSiteDomain, string $strXqPath): array + { + $totalFiles = ceil($totalCount / $chunkSize); + $sitemapFiles = []; + + for ($i = 0; $i < $totalFiles; $i++) { + $Novels = XiaoShuoXiangQingModel::field(['xsxq_id', 'xsxq_source_id', 'xsxq_source_seo_id']) //intNovelId-:intNovelSourceId-:intNovelSourceSeoId + ->limit($i * $chunkSize, $chunkSize) + ->select() + ->toArray(); + + $sitemapXml = $this->buildSitemap($Novels, $strSiteDomain, $strXqPath); + $filePath = public_path() . "sitemap_novel_{$i}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + # 生成小说详情 xml文件 + private function generateNovelSeoSitemaps(int $chunkSize, int $totalCount, string $strSiteDomain, string $strSeoPath): array + { + $totalFiles = ceil($totalCount / $chunkSize); + $sitemapFiles = []; + + for ($i = 0; $i < $totalFiles; $i++) { + $Novels = NovelInfoSeoModel::field(['xsxq_id', 'nis_id']) //show/nis_id + ->limit($i * $chunkSize, $chunkSize) + ->select() + ->toArray(); + + $sitemapXml = $this->buildXiaoShuoSeoSitemap($Novels, $strSiteDomain, $strSeoPath); + $filePath = public_path() . "sitemap_novel_seo_{$i}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + // 生成分类链接 + private function generateCategorySitemaps(array $categories, string $strSiteDomain, string $strFenleiPath, string $strXqPath): array + { + $sitemapFiles = []; + + foreach ($categories as $category) { + $vcId = $category['xsfl_id']; + $vcName = $category['xsfl_name']; + + $intNovelCount = XiaoShuoFenLeiModel::where('xsfl_id', $vcId)->count(); + $totalPages = ceil($intNovelCount / 30); + + $categoryUrls = []; + for ($status = 0; $status <= 2; $status++) { + for ($sort = 0; $sort <= 4; $sort++) { + for ($page = 1; $page <= $totalPages; $page++) { + $categoryUrls[] = [ + // /fl/:intCId-:intSort-[:intPage] + 'url' => "/{$strFenleiPath}/{$vcId}-{$sort}-{$page}.html", + 'title' => "{$vcName} - 第{$page}页", + 'is_home' => false, + ]; + } + } + } + + $sitemapXml = $this->buildSitemap($categoryUrls, $strSiteDomain, $strXqPath, true); + $filePath = public_path() . "sitemap_category_{$vcId}.xml"; + file_put_contents($filePath, $sitemapXml); + $sitemapFiles[] = $filePath; + } + + return $sitemapFiles; + } + + //生成章节链接 + private function buildZjSitemap(array $items, string $strSiteDomain, string $strXqPath, bool $isCategory = false): string + { + $xmlHeader = ''; + $urlsetStart = ''; + $urlsetEnd = ''; + // /xq/:intNovelId/:intZhangJiePaiXu-[:strSort] + $urlEntries = ''; + foreach ($items as $item) { + $urlEntries .= ''; + $urlEntries .= 'https://' . $strSiteDomain . ($isCategory ? $item['url'] : '/' . $strXqPath . '/' . htmlspecialchars($item['xsxq_id'] . '-' . $item['xszj_pai_xu']. '-' . $item['xszj_sort'] . '.html', ENT_QUOTES)) . ''; + $urlEntries .= 'daily'; + $urlEntries .= '0.8'; + $urlEntries .= ''; + } + + return $xmlHeader . $urlsetStart . $urlEntries . $urlsetEnd; + } + + // 生成 详情链接 + private function buildSitemap(array $items, string $strSiteDomain, string $strXqPath, bool $isCategory = false): string + { + $xmlHeader = ''; + $urlsetStart = ''; + $urlsetEnd = ''; + // /xq/:intNovelId + $urlEntries = ''; + foreach ($items as $item) { + $urlEntries .= ''; + $urlEntries .= 'https://' . $strSiteDomain . ($isCategory ? $item['url'] : '/' . $strXqPath . '/' . htmlspecialchars($item['xsxq_id'] . '.html', ENT_QUOTES)) . ''; + $urlEntries .= 'daily'; + $urlEntries .= '1.0'; + $urlEntries .= ''; + } + + return $xmlHeader . $urlsetStart . $urlEntries . $urlsetEnd; + } + + // 生成详情 seo 链接 + private function buildXiaoShuoSeoSitemap(array $items, string $strSiteDomain, string $strSeoPath, bool $isCategory = false): string + { + $xmlHeader = ''; + $urlsetStart = ''; + $urlsetEnd = ''; + // /show/:intNovelId + $urlEntries = ''; + foreach ($items as $item) { + $urlEntries .= ''; + $urlEntries .= 'https://' . $strSiteDomain . ($isCategory ? $item['url'] : '/' . $strSeoPath . '/' . htmlspecialchars($item['nis_id'] . '.html', ENT_QUOTES)) . ''; + $urlEntries .= 'daily'; + $urlEntries .= '1.0'; + $urlEntries .= ''; + } + + return $xmlHeader . $urlsetStart . $urlEntries . $urlsetEnd; + } + + // 生成 xml 文件 + private function buildSitemapIndex(array $sitemapFiles, string $strSiteDomain): void + { + $xmlHeader = ''; + $sitemapIndexStart = ''; + $sitemapIndexEnd = ''; + + $sitemapEntries = ''; + foreach ($sitemapFiles as $file) { + $url = 'https://' . $strSiteDomain . '/' . basename($file); + $sitemapEntries .= ''; + $sitemapEntries .= '' . htmlspecialchars($url, ENT_QUOTES) . ''; + $sitemapEntries .= '' . date('Y-m-d') . ''; + $sitemapEntries .= ''; + } + + $sitemapIndexXml = $xmlHeader . $sitemapIndexStart . $sitemapEntries . $sitemapIndexEnd; + file_put_contents(public_path() . 'sitemap_index.xml', $sitemapIndexXml); + + var_dump(['message' => 'Sitemap Index 生成成功', 'file' => 'sitemap_index.xml']); + } +} diff --git a/code/app/task/collection/tianlai/TianLaiXiaoShuoCol.php b/code/app/task/collection/tianlai/TianLaiXiaoShuoCol.php new file mode 100644 index 0000000..293552f --- /dev/null +++ b/code/app/task/collection/tianlai/TianLaiXiaoShuoCol.php @@ -0,0 +1,538 @@ +TaskCore; + $strUrl = $this->getTianLaiDomain(); + var_dump($strUrl); + $Client = $this->Client; + + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($strUrl); + + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + + + // $proxy = '127.0.0.1:8080'; // 代理地址 + // $response = fetchContentWithCurl($strUrl, [], 10, $proxy); + + $strResult = $Client->request('GET', $strUrl, [ + 'headers' => [ + 'User-Agent' => $userAgent, + 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'Accept-Language' => 'en-US,en;q=0.5', + ], + 'cookies' => $CookieJar, + 'proxy' => $proxy, + 'timeout' => 30, + ]); + $strResult = (string)$strResult->getBody(); + var_dump($strResult); + // exit; + // $strResult = $response['data']; + $QueryList = QueryList::html($strResult); + + + $QueryList->find('.nav a')->map(function ($FenLeiQueryList) use ($strUrl, $TaskCore) { + $strName = trim($FenLeiQueryList->text()); + switch ($strName) { + + case '都市言情': + $strName = "都市言情"; + break; + case '历史军事': + $strName = "历史军事"; + break; + case '玄幻奇幻': + $strName = "玄幻奇幻"; + break; + case '武侠修真': + $strName = "武侠修真"; + break; + case '女生纯爱': + $strName = "女频言情"; + break; + case '科幻网游': + $strName = "科幻网游"; + break; + case '悬疑灵异': + $strName = "悬疑灵异"; + break; + default: + $strName = "其它"; + break; + } + $strFenLeiUrl = $strUrl . $FenLeiQueryList->attr('href'); + // $intFenLeiId = extractFilename($strFenLeiUrl."index.html"); + $intFenLeiId = extractNumberFromUrl($strFenLeiUrl); + if($intFenLeiId !== null){ + + $arrClass = [ + 'xsfl_source_id' => $intFenLeiId, + 'xsfl_source_code' => 'TIANLAI_FEN_LEI_ID_' . $intFenLeiId, + 'xsfl_name' => $strName, + ]; + var_dump($arrClass); + + $XiaoShuoFenLeiModel = XiaoShuoFenLeiModel::addXiaoShuoFenLei($arrClass); + + $arrTask = [ + 'callback' => [self::class, 'getNovelPage'], + 'data' => [ + 'url' => $strFenLeiUrl, + 'xsfl_source_id' => $intFenLeiId, + 'xsfl_name' => $strName, + 'xsfl_id' => $XiaoShuoFenLeiModel->xsfl_id, + 'xsfl_page' => 1, + 'xsfl_max_page' => 3000, + ] + ]; + + $TaskCore->set($arrTask); + } + + }); + } catch (\Throwable $T) { + //var_dump($T); + throw $T; + } + } + + public function getNovelPage($arrData) + { + + + var_dump('getNovelPage'); + var_dump($arrData); + + $strBasePage = $arrData['url']; + $Client = $this->Client; + + $TaskCore = $this->TaskCore; + + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($strBasePage); + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $strSiteUrl = $this->getTianLaiDomain(); + + $intPage = $arrData['xsfl_page']; + $intMaxPage = $arrData['xsfl_max_page']; + + $strUrl = $strBasePage; + + var_dump($strUrl); + + + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + $strResult = $Client->request('GET', $strUrl, [ + 'headers' => [ + 'User-Agent' => $userAgent + ], + 'cookies' => $CookieJar, + #'proxy' => $proxy, + 'timeout' => 10, + ]); + $strResult = (string)$strResult->getBody(); + + $QueryList = QueryList::html($strResult); + + + $intMaxPage = $QueryList->find('#newscontent h2 span')->eq(1)->text(); + $intMaxPage = ceil($intMaxPage / 100); + var_dump($intMaxPage); + $intMaxPage = 2; + + + var_dump('$strUrl'); + // 如果是首页 则根据最大页面吧所有分页 追加到任务 + if($intPage == 1){ + for ($intCurrentPage = 2; $intCurrentPage <= $intMaxPage; $intCurrentPage++) { + $strNewsFenleiUrl = replaceLastPageNumber($strBasePage, $intCurrentPage); + var_dump($strNewsFenleiUrl); + $arrTask = [ + 'callback' => [self::class, 'getNovelPage'], + 'data' => [ + 'url' => $strNewsFenleiUrl, + 'xsfl_source_id' => $arrData['xsfl_source_id'], + 'xsfl_name' => $arrData['xsfl_name'], + 'xsfl_id' => $arrData['xsfl_id'], + 'xsfl_page' => $intCurrentPage, + 'xsfl_max_page' => $intMaxPage, + ] + ]; + $TaskCore->set($arrTask); + } + } + var_dump('提取小说'); + $XiaoShuoListQueryList = $QueryList->find('#newscontent li'); + + if (!$XiaoShuoListQueryList || $XiaoShuoListQueryList->count() <= 0) { + var_dump('这个分类已经市最后一页'); + return true; + } + var_dump($XiaoShuoListQueryList->count()); + var_dump('提取小说2'); + // var_dump($XiaoShuoListQueryList); + $XiaoShuoListQueryList->map(function ($XiaoShuoQueryList) use ($strSiteUrl, $arrData, $TaskCore, $strUrl) { + // 提取小说链接 + // var_dump($XiaoShuoQueryList->html());exit; + var_dump('提取小说链接'); + $A = $XiaoShuoQueryList->find('a')->eq(0); + + $strXiaoShuoUrl = $A->attr('href'); + $strXiaoShuoUrl = strpos($strXiaoShuoUrl, 'https:') === 0 ? $strXiaoShuoUrl : 'https:' . $strXiaoShuoUrl; + var_dump('$A'); + var_dump($A); + var_dump($strXiaoShuoUrl); + exit; + // var_dump($A); + // 提取作者信息 + $strZuoZhe = trim($XiaoShuoQueryList->find('.s4')->eq(0)->text()); + + // 提取小说 ID + $arrXiaoShuoId = extractNumbersFromUrl($strXiaoShuoUrl); + if (!isset($arrXiaoShuoId['first'], $arrXiaoShuoId['second'])) { + return; // 如果 ID 提取失败,直接跳过 + } + + // 准备任务数据 + $arrXiaoShuo = array_merge($arrData, [ + 'xiaoshuo_url' => $strXiaoShuoUrl, + 'xiaoshuo_id' => $arrXiaoShuoId['first'], + 'xiaoshuo_seo_id' => $arrXiaoShuoId['second'], + 'xiaoshuo_zuozhe' => $strZuoZhe, + 'url' => $strUrl + ]); + var_dump($arrXiaoShuo); + $arrTask = [ + 'callback' => [self::class, 'getNovelInfo'], + 'data' => $arrXiaoShuo, + ]; + + // 将任务加入队列 + $TaskCore->set($arrTask); + var_dump("将任务加入队列getNovelInfo-{$strXiaoShuoUrl}"); + }); + var_dump('提取小说end'); + + } catch (\Throwable $T) { + throw $T; + } + } + + + + public function getNovelInfo($arrData) + { + var_dump('getNovelInfo'); + var_dump($arrData); + $Client = $this->Client; + $TaskCore = $this->TaskCore; + + // 获取 Redis 实例 + $redis = Cache::store('redis')->handler(); + $intXiaoShuoSourceId = $arrData['xiaoshuo_id']; + $intXiaoShuoSourceSeoId = $arrData['xiaoshuo_seo_id']; + $redisKey = "task:novel_source_id:" . $intXiaoShuoSourceId; + + try { + $arrCookie = $this->getAilisiCookie(); + $strHost = getDomainFromUrl($arrData['xiaoshuo_url']); + $CookieJar = CookieJar::fromArray($arrCookie, $strHost); + + $strSiteUrl = $this->getTianLaiDomain(); + + $proxy = getRandomProxies(); + $userAgent = getRandomUserAgent(); + $Response = $Client->request('GET', $arrData['xiaoshuo_url'], [ + 'headers' => [ + 'User-Agent' => $userAgent + ], + 'cookies' => $CookieJar, + #'proxy' => $proxy, + 'timeout' => 10, + ]); + $strResult = (string)$Response->getBody(); + unset($Response); + + $QueryList = QueryList::html($strResult); + + $strMingZi = $QueryList->find('#info h1')->eq(0)->text(); + $strZhuangTai = "状态:连载中"; + $strZiShu = 0; + $strZhuangTai = getStringAfterWord($strZhuangTai, '状态:'); + + // 提取作者信息 + $strZuoZhe = trim($QueryList->find('p a')->eq(0)->text()); + + // $strLastDate = $QueryList->find('meta[property="og:novel:update_time"]')->attr('content'); + $strLastDate = $QueryList->find('#info p')->eq(2)->text(); + $strLastDate = getStringAfterWord($strLastDate, '最后更新:'); + $strLastDate = trim((string)$strLastDate); + if (!isValidDateTime($strLastDate)) { + $strLastDate = date('Y-m-d H:i:s'); + } + + $arrTag = []; + // $QueryList->find('.tg span')->map(function ($TagQuery) use (&$arrTag) { + // $arrTag[] = trim($TagQuery->text()); + // }); + + $strJieShao = $QueryList->find('#intro')->eq(0)->text(); + $strJieShao = removeScriptTags('/