diff --git a/code/app/home/config/router.php b/code/app/home/config/router.php index b66888b..7db3524 100644 --- a/code/app/home/config/router.php +++ b/code/app/home/config/router.php @@ -7,6 +7,11 @@ use app\home\controller\Novel; use app\home\controller\User; use think\facade\Route; + +Route::get('article/fenlei/:category', function (\think\Request $Request) { + return view('test/test01/index.html'); +}); + /** * 路由配置文件 */ @@ -103,7 +108,7 @@ $arrRoutes = [ 'history' => ['/history', '/reading-history', '/read-record', '/lishi', '/yuedu-lishi', '/browse-past'], // 首页 'index' => ['/'], - + ], ]; @@ -196,7 +201,7 @@ foreach ($arrRoutes['prefixes'] as $platform => $prefixes) { // 首页 if ($platform == 'h5') { Route::get($strRoute, [Index::class, 'index'])->append(['boolIsMobile' => $boolIsMobile]); - }else{ + } else { Route::get($strRoute, [Index::class, 'getPcIndex'])->append(['boolIsMobile' => $boolIsMobile]); } break; diff --git a/code/app/home/config/view.php b/code/app/home/config/view.php index cd776ee..00c27a9 100644 --- a/code/app/home/config/view.php +++ b/code/app/home/config/view.php @@ -1,5 +1,5 @@ getViewConfig(); diff --git a/code/app/home/controller/Index.php b/code/app/home/controller/Index.php index 7c26c8d..a28af19 100644 --- a/code/app/home/controller/Index.php +++ b/code/app/home/controller/Index.php @@ -60,6 +60,10 @@ class Index extends BaseController $strKey = sprintf('%s:H5:INDEX:RANK:%s:%s', $Request->DomainModel->d_domain, 'total', 'finished'); $arrEndNovelRankNovel = $NovelModel->getRankNovelOnCache($strKey, 10, 0, 'total', $strStatus); + /** @var DomainModel **/ + $Request->DomainModel; + + $strHostNovelDescriptionTemplate = $Request->DomainModel->getFomartSubject('INDEX_POPULAR_NOVELS'); $strNewsNovelDescriptionTemplate = $Request->DomainModel->getFomartSubject('INDEX_NEWS_NOVELS'); $strRankNovelDescriptionTemplate = $Request->DomainModel->getFomartSubject('INDEX_RANK_NOVELS'); diff --git a/code/app/home/controller/Novel.php b/code/app/home/controller/Novel.php index 686a883..60ca360 100644 --- a/code/app/home/controller/Novel.php +++ b/code/app/home/controller/Novel.php @@ -12,6 +12,7 @@ use app\model\NovelClicksModel; use app\model\NovelModel; use think\facade\View; use app\Request; +use app\services\NovelService; use template\page\CusteomPage02; class Novel extends BaseController @@ -204,7 +205,7 @@ class Novel extends BaseController $strTemplate = 'pc/getLibrary'; } - $strBaseUrl = NovelModel::getNovelCategoryUrl($strGender, $strCategory, $strStatus, '{page}'); + $strBaseUrl = app(NovelService::class)->getNovelCategoryUrl($strGender, $strCategory, $strStatus, '{page}'); $arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtomNum); // 更新值 @@ -911,7 +912,7 @@ class Novel extends BaseController // $strSearchInfoUrlTemp = $Request->DomainModel->getFomartSubject('SEARCH_INFO_URL','',false); // $strBaseUrl = sprintf('/search.html?keyword=%s&page={page}', $strSearchKeywords); - $strBaseUrl = NovelModel::getNovelSearchUrl($strSearchKeywords, '{page}'); + $strBaseUrl = app(NovelService::class)->getNovelSearchUrl($strSearchKeywords, '{page}'); $arrPaginator = CusteomPage02::generate($intPage, $arrPage['total'], $intLimit, $strBaseUrl, $intButtomNum); // 更新值 diff --git a/code/app/model/AutoSwitchViewModel.php b/code/app/model/AutoSwitchViewModel.php deleted file mode 100644 index 93a2b84..0000000 --- a/code/app/model/AutoSwitchViewModel.php +++ /dev/null @@ -1,42 +0,0 @@ -rootDomain(); - - $DomainModel = DomainModel::getDomainOnCacheByDomain($strDomain); - - if (empty($DomainModel)) { - throw new HttpException(404, 'Site config not Found'); - } - - $TemplatesModel = TemplatesModel::getTemplateOnCacheByTId($DomainModel->t_id); - - if (empty($DomainModel)) { - throw new HttpException(500, 'Site template not Found'); - } - - $Request->DomainModel = $DomainModel; - - $Request->TemplatesModel = $TemplatesModel; - - return [ - 'type' => 'Think', - 'auto_rule' => 3, - 'view_dir_name' => 'view', - 'view_suffix' => 'html', - 'view_path' => root_path($TemplatesModel->t_path), - ]; - } -} diff --git a/code/app/model/DomainModel.php b/code/app/model/DomainModel.php index 46efb76..0e6f32b 100644 --- a/code/app/model/DomainModel.php +++ b/code/app/model/DomainModel.php @@ -92,7 +92,7 @@ class DomainModel extends BaseModel * Undocumented function * * @param string $strKey - * @return void + * @return string */ public function getFomartSubject($strKey, $strDiff = '', bool $boolJoin = true) { @@ -144,25 +144,5 @@ class DomainModel extends BaseModel } - - /** - * Undocumented function - * - * @param array $arrArgs - * @return string - */ - static public function getPageUrl($strKey, array $arrArgs): string - { - $Request = request(); - $strSfVal = $Request->DomainModel->getFomartSubject($strKey,'',false); - $arrKeys = []; - $arrVals = []; - foreach ($arrArgs as $strKey => $strVal) { - $arrKeys[] = '{' . $strKey . '}'; - $arrVals[] = $strVal; - } - - return str_replace($arrKeys, $arrVals, $strSfVal); - } } diff --git a/code/app/model/NovelModel.php b/code/app/model/NovelModel.php index 1d1a0a0..a00423c 100644 --- a/code/app/model/NovelModel.php +++ b/code/app/model/NovelModel.php @@ -482,139 +482,4 @@ class NovelModel extends MongoModel } - /** - * Undocumented function - * - * @param int $intNId - * @param string $intPinYin - * @return string - */ - static public function getNovelInfoUrl($intNId, $intPinYin): string - { - $strKey = 'NOVEL_INFO_URL'; - $strUrl = DomainModel::getPageUrl($strKey, [ - 'intNId' => $intNId, - 'strPinYin' => $intPinYin - ]); - return (string)$strUrl; - } - - /** - * Undocumented function - * 伪造小说 - * @param int $intNId - * @param string $intPinYin - * @return string - */ - static public function getForgeNovelInfoUrl($intNId, $intPinYin,$intNForgeId): string - { - $strKey = 'KAN_NOVEL_INFO_URL'; - $strUrl = DomainModel::getPageUrl($strKey, [ - 'intNId' => $intNId, - 'strPinYin' => $intPinYin, - 'intNForgeId' => $intNForgeId, - ]); - return (string)$strUrl; - } - - - /** - * Undocumented function - * - * @param int $intNId - * @param string $intPinYin - * @return string - * - */ - static public function getNovelChapterUrl($intNId, $intPinYin, $intChapterSort,$intChapterPage=1): string - { - $strKey = 'CONTENT_INFO_URL'; - $strUrl = DomainModel::getPageUrl($strKey, [ - 'intNId' => $intNId, - 'strPinYin' => $intPinYin, - 'intChapterSort' => $intChapterSort, - 'intChapterPage' => $intChapterPage, - ]); - return (string)$strUrl; - } - - /** - * Undocumented function - * - * @param int $intNId - * @param string $intPinYin - * @return string - * - */ - static public function getNovelLasterChapterUrl($intNId, $intPinYin): string - { - $strKey = 'NEWS_CONTENT_INFO_URL'; - $strUrl = DomainModel::getPageUrl($strKey, [ - 'intNId' => $intNId, - 'strPinYin' => $intPinYin, - ]); - return (string)$strUrl; - } - - /** - * Undocumented function - * 小说分类 - * @param int $intNId - * @param string $intPinYin - * @return string - * - */ - static public function getNovelCategoryUrl($strGender, $strCategory, $strStatus, $intPage): string - { - $strKey = 'CATEGORY_INFO_URL'; - $strUrl = DomainModel::getPageUrl($strKey, [ - 'strGender' => $strGender, - 'strCategory' => $strCategory, - 'strStatus' => $strStatus, - 'intPage' => $intPage, - ]); - return (string)$strUrl; - } - - - - /** - * Undocumented function - * 小说目录 - * @param int $intNId - * @param string $intPinYin - * @return string - * - */ - static public function getNovelCatalogUrl($intNId, $intPinYin, $strOrder,$intPage=1): string - { - $strKey = 'NOVEL_CATALOG_URL'; - $strUrl = DomainModel::getPageUrl($strKey, [ - 'intNId' => $intNId, - 'strPinYin' => $intPinYin, - 'strOrder' => $strOrder, - 'intPage' => $intPage, - ]); - return (string)$strUrl; - } - - - /** - * Undocumented function - * - * @param int $intPage - * @param string $strKeyWords - * @return string - */ - static public function getNovelSearchUrl($strKeyWords, $intPage = 1): string - { - $strKey = 'SEARCH_INFO_URL'; - $strUrl = DomainModel::getPageUrl($strKey, [ - 'intPage' => $intPage, - 'strSearchKeywords' => $strKeyWords - ]); - return (string)$strUrl; - } - - } diff --git a/code/app/services/ChapterService.php b/code/app/services/ChapterService.php new file mode 100644 index 0000000..48d15d0 --- /dev/null +++ b/code/app/services/ChapterService.php @@ -0,0 +1,27 @@ +ChapterModel = ChapterModel::getInstance(); + } +} diff --git a/code/app/services/NovelService.php b/code/app/services/NovelService.php new file mode 100644 index 0000000..da92556 --- /dev/null +++ b/code/app/services/NovelService.php @@ -0,0 +1,254 @@ +SiteContext = $SiteContext; + $this->NovelModel = NovelModel::getInstance(); + } + + /** + * GetNovelInfoUrl + * + * @param int $intNId + * @param string $intPinYin + * @return string + */ + public function getNovelInfoUrl($intNId, $intPinYin): string + { + $strKey = 'NOVEL_INFO_URL'; + $strUrl = $this->getPageUrl($strKey, [ + 'intNId' => $intNId, + 'strPinYin' => $intPinYin + ]); + return (string)$strUrl; + } + + /** + * GetForgeNovelInfoUrl + * 伪造小说 + * @param int $intNId + * @param string $intPinYin + * @return string + */ + public function getForgeNovelInfoUrl($intNId, $intPinYin, $intNForgeId): string + { + $strKey = 'KAN_NOVEL_INFO_URL'; + $strUrl = $this->getPageUrl($strKey, [ + 'intNId' => $intNId, + 'strPinYin' => $intPinYin, + 'intNForgeId' => $intNForgeId, + ]); + return (string)$strUrl; + } + + + /** + * GetNovelChapterUrl + * + * @param int $intNId + * @param string $intPinYin + * @return string + * + */ + public function getNovelChapterUrl($intNId, $intPinYin, $intChapterSort, $intChapterPage = 1): string + { + $strKey = 'CONTENT_INFO_URL'; + $strUrl = $this->getPageUrl($strKey, [ + 'intNId' => $intNId, + 'strPinYin' => $intPinYin, + 'intChapterSort' => $intChapterSort, + 'intChapterPage' => $intChapterPage, + ]); + return (string)$strUrl; + } + + /** + * GetNovelLasterChapterUrl + * + * @param int $intNId + * @param string $intPinYin + * @return string + * + */ + public function getNovelLasterChapterUrl($intNId, $intPinYin): string + { + $strKey = 'NEWS_CONTENT_INFO_URL'; + $strUrl = $this->getPageUrl($strKey, [ + 'intNId' => $intNId, + 'strPinYin' => $intPinYin, + ]); + return (string)$strUrl; + } + + /** + * GetNovelCategoryUrl + * 小说分类 + * @param int $intNId + * @param string $intPinYin + * @return string + * + */ + public function getNovelCategoryUrl($strGender, $strCategory, $strStatus, $intPage): string + { + $strKey = 'CATEGORY_INFO_URL'; + $strUrl = $this->getPageUrl($strKey, [ + 'strGender' => $strGender, + 'strCategory' => $strCategory, + 'strStatus' => $strStatus, + 'intPage' => $intPage, + ]); + return (string)$strUrl; + } + + + + /** + * getNovelCatalogUrl + * 小说目录 + * @param int $intNId + * @param string $intPinYin + * @return string + * + */ + public function getNovelCatalogUrl($intNId, $intPinYin, $strOrder, $intPage = 1): string + { + $strKey = 'NOVEL_CATALOG_URL'; + $strUrl = $this->getPageUrl($strKey, [ + 'intNId' => $intNId, + 'strPinYin' => $intPinYin, + 'strOrder' => $strOrder, + 'intPage' => $intPage, + ]); + return (string)$strUrl; + } + + + /** + * Undocumented function + * + * @param int $intPage + * @param string $strKeyWords + * @return string + */ + public function getNovelSearchUrl($strKeyWords, $intPage = 1): string + { + $strKey = 'SEARCH_INFO_URL'; + $strUrl = $this->getPageUrl($strKey, [ + 'intPage' => $intPage, + 'strSearchKeywords' => $strKeyWords + ]); + return (string)$strUrl; + } + + + /** + * Undocumented function + * + * @param array $arrArgs + * @return string + */ + public function getPageUrl($strKey, array $arrArgs,): string + { + $strSfVal = $this->SiteContext->DomainModel->getFomartSubject($strKey, '', false); + $arrKeys = []; + $arrVals = []; + foreach ($arrArgs as $strKey => $strVal) { + $arrKeys[] = '{' . $strKey . '}'; + $arrVals[] = $strVal; + } + + return str_replace($arrKeys, $arrVals, $strSfVal); + } + + protected $arrSortType = [ + 'day_desc' => 'daily', + 'week_desc' => 'weekly', + 'month_desc' => 'monthly', + 'total_desc' => 'total', + 'tuijian_desc' => 'total', + ]; + + protected $arrStatus = [ + 'all' => NULL, + 'lianzai' => '连载中', + 'wanjie' => '已完结', + ]; + + + /** + * 获取小说数据 + * + * @param array $arrParams + * @return void + */ + public function getNovelData(array $arrParams): array + { + // 提取参数 + $intPage = (int)$arrParams['page'] ?? 0; + $intLimit = (int)$arrParams['limit'] ?? 10; + $strNCategory = $arrParams['n_category'] ?? ''; + $strSortType = (string)$arrParams['sort_type'] ?? ''; + $strNStatus = (string) $arrParams['n_status'] ?? ''; + $strNSex = (string) $arrParams['n_sex'] ?? ''; + $strKey = (string) $arrParams['key'] ?? ''; + $strDiffKey = (string) $arrParams['diff_key'] ?? ''; + $intCacheKey = (int)$arrParams['cache_life'] ?? 0; + echo $intPage; + print_r($arrParams); + exit; + + + if ($intPage == 0) { + } else { + } + + + + // 模拟数据处理(可以根据实际需求从数据库获取数据) + $data = []; + for ($i = 1; $i <= $arrParams['limit']; $i++) { + $data[] = [ + 'id' => $i, + 'name' => "小说名称 {$i}", + 'category' => $arrParams['n_category'] ?? '默认分类', + 'status' => $arrParams['n_status'] ?? '连载中', + 'order' => $arrParams['sort_type'] ?? '默认排序', + ]; + } + + // 分页数据 + $p_data = [ + 'current_page' => $arrParams['page'], + 'total_page' => 5, + 'total_count' => 50, + ]; + + + + return [ + 'data' => $data, + 'p_data' => $p_data, + ]; + } +} diff --git a/code/app/services/SiteContext.php b/code/app/services/SiteContext.php new file mode 100644 index 0000000..9a5e11d --- /dev/null +++ b/code/app/services/SiteContext.php @@ -0,0 +1,72 @@ +Request = request(); + } + + /** + * GetViewConfig + * + * @return array + */ + public function getViewConfig(): array + { + $strDomain = $this->Request->rootDomain(); + + $this->DomainModel = DomainModel::getDomainOnCacheByDomain($strDomain); + + if (empty($this->DomainModel)) { + throw new HttpException(404, 'Site config not Found'); + } + + $this->TemplatesModel = TemplatesModel::getTemplateOnCacheByTId($this->DomainModel->t_id); + + if (empty($this->DomainModel)) { + throw new HttpException(500, 'Site template not Found'); + } + + $this->Request->DomainModel = $this->DomainModel; + + $this->Request->TemplatesModel = $this->TemplatesModel; + + return [ + 'type' => 'Think', + 'auto_rule' => 3, + 'view_dir_name' => 'view', + 'view_suffix' => 'html', + 'view_path' => root_path(ltrim($this->TemplatesModel->t_path, '/')), + ]; + } +} diff --git a/code/app/task/crawler/zw630/Scheduler.php b/code/app/task/crawler/zw630/Scheduler.php index bb3038a..b51775c 100644 --- a/code/app/task/crawler/zw630/Scheduler.php +++ b/code/app/task/crawler/zw630/Scheduler.php @@ -12,6 +12,11 @@ use app\task\crawler\zw\Scheduler as ZwScheduler; */ class Scheduler extends ZwScheduler { + + protected $intStartNSourceId = 1; + + protected $intEndNSourceId = 500000; + /** * Undocumented function * @@ -19,7 +24,7 @@ class Scheduler extends ZwScheduler */ public function init() { - $this->intSlice = 4; + $this->intSlice = 3; } /** diff --git a/code/app/task/crawler/zw630/page/Site.php b/code/app/task/crawler/zw630/page/Site.php index eb3cc5a..a3791d5 100644 --- a/code/app/task/crawler/zw630/page/Site.php +++ b/code/app/task/crawler/zw630/page/Site.php @@ -7,6 +7,7 @@ namespace app\task\crawler\zw630\page; use app\task\crawler\zw\page\Site as ZwSite; use GuzzleHttp\Promise; use GuzzleHttp\Client; + /** * @mixin think\Model */ @@ -99,10 +100,10 @@ class Site extends ZwSite if ($intPage == 0) { - $arrItem['uri'] = sprintf('/shu/%s.html', $intNSourceId); + $strUri = sprintf('/shu/%s.html', $intNSourceId); } else { - $arrItem['uri'] = sprintf('/shu/%s_%s.html', $intNSourceId, $intPage); + $strUri = sprintf('/shu/%s_%s.html', $intNSourceId, $intPage); } return $strUri; diff --git a/code/config/app.php b/code/config/app.php index 6c56163..d29d17e 100644 --- a/code/config/app.php +++ b/code/config/app.php @@ -33,6 +33,7 @@ return [ 'deny_app_list' => [ 'task', 'model', + 'services', ], // 异常页面的模板文件 diff --git a/code/config/view.php b/code/config/view.php index a436de8..e00861a 100644 --- a/code/config/view.php +++ b/code/config/view.php @@ -27,7 +27,7 @@ return [ // 自定义标签 - 'taglib_pre_load' => '\\template\\taglib\\Ad,\\template\\taglib\\Site,\\template\\taglib\\Rs', + 'taglib_pre_load' => '\\template\\taglib\\Ad,\\template\\taglib\\Site,\\template\\taglib\\Rs,\\template\\taglib\\Novel', // 模板渲染缓存 'display_cache' => env('VIEW_DISPLAY_CACHE', false), diff --git a/code/extend/template/taglib/Novel.php b/code/extend/template/taglib/Novel.php new file mode 100644 index 0000000..9594eea --- /dev/null +++ b/code/extend/template/taglib/Novel.php @@ -0,0 +1,78 @@ + ['attr' => 'page,limit,n_category,sort_type,n_status,n_sex,key,diff_key,cache_life,d_key,d_val,p_val'], + ]; + + private function customBuildVar($mixedArgs) + { + if (substr($mixedArgs, 0, 1) == '$') { + return $this->autoBuildVar($mixedArgs); + } else { + return is_numeric($mixedArgs) ? $mixedArgs : "'" . $mixedArgs . "'"; + } + } + + /** + * novel 自定义标签 + */ + public function tagList($tag, $content) + { + $page = $tag['page'] ?? '0'; + $limit = $tag['limit'] ?? '10'; + $n_category = $tag['n_category'] ?? "all"; + $sort_type = $tag['sort_type'] ?? ""; + $n_status = $tag['n_status'] ?? "all"; + $n_sex = $tag['n_sex'] ?? "all"; + $key = $tag['key'] ?? ""; + $diff_key = $tag['diff_key'] ?? ""; + $cache_life = $tag['cache_life'] ?? '0'; + $d_key = $tag['d_key'] ?? 'd_key'; + $d_val = $tag['d_val'] ?? 'd_val'; + $p_val = $tag['p_val'] ?? 'p_val'; + + $page = $this->customBuildVar($page); + $limit = $this->customBuildVar($limit); + $n_category = $this->customBuildVar($n_category); + $sort_type = $this->customBuildVar($sort_type); + $n_status = $this->customBuildVar($n_status); + $n_sex = $this->customBuildVar($n_sex); + $key = $this->customBuildVar($key); + $diff_key = $this->customBuildVar($diff_key); + $cache_life = $this->customBuildVar($cache_life); + + $parse = <<getNovelData([ + 'page' => {$page}, + 'limit' => {$limit}, + 'n_category' => {$n_category}, + 'sort_type' => {$sort_type}, + 'n_status' => {$n_status}, + 'n_sex' => {$n_sex}, + 'key' => {$key}, + 'diff_key' => {$diff_key}, + 'cache_life' => {$cache_life} +]); + +if (isset(\$novelData['data']) && is_array(\$novelData['data'])): + \${$p_val} = \$novelData['p_data'] ?? []; +?> +EOT; + $parse .= << \${$d_val}): ?> +EOT; + $parse .= $content; + $parse .= << + +EOT; + return $parse; + } +} diff --git a/code/extend/template/taglib/Site.php b/code/extend/template/taglib/Site.php index d0fc7fd..6967e5d 100644 --- a/code/extend/template/taglib/Site.php +++ b/code/extend/template/taglib/Site.php @@ -78,7 +78,7 @@ EOD; $strParse = <<getNovelInfoUrl("{$intNId}","{$strNPy}"); echo \$strUrl; ?> EOD; @@ -99,7 +99,7 @@ EOD; $strParse = <<getForgeNovelInfoUrl("{$intNId}","{$strNPy}","{$intNForgeId}"); echo \$strUrl; ?> EOD; @@ -121,7 +121,7 @@ EOD; $strParse = <<getNovelChapterUrl("{$intNId}","{$strNPy}","{$intChapterSort}","{$intChapterPage}"); echo \$strUrl; ?> EOD; @@ -141,7 +141,7 @@ EOD; $strParse = <<getNovelLasterChapterUrl("{$intNId}","{$strNPy}"); echo \$strUrl; ?> EOD; @@ -163,7 +163,7 @@ EOD; $strParse = <<getNovelCatalogUrl("{$intNId}","{$strNPy}","{$strOrder}","{$intPage}"); echo \$strUrl; ?> EOD; @@ -185,7 +185,7 @@ EOD; $strParse = <<getNovelCategoryUrl("{$strGender}","{$strCategory}","{$strStatus}","{$intPage}"); echo \$strUrl; ?> EOD; @@ -205,7 +205,7 @@ EOD; $strParse = <<getNovelSearchUrl("{$strKey}","{$intPage}"); echo \$strUrl; ?> EOD;