作者 李小龙

拷贝C端生成页面服务

要显示太多修改。

为保证性能只显示 11 of 11+ 个文件。

  1 +<?php
  2 +
  3 +
  4 +namespace App\Services\Html;
  5 +
  6 +use App\Models\Blog\Blog;
  7 +use App\Models\News\News;
  8 +use App\Models\Product\Category;
  9 +use App\Models\Product\CategoryRelated;
  10 +use App\Models\Product\Keyword;
  11 +use App\Models\Product\Product;
  12 +use App\Models\RouteMap;
  13 +use App\Models\WebSetting\WebSetting;
  14 +use App\Models\WebSetting\WebSettingAmp;
  15 +use App\Models\WebSetting\WebSettingNum;
  16 +use App\Models\WebSetting\WebSettingSeo;
  17 +
  18 +class AmpService
  19 +{
  20 + /**
  21 + * 获取首页html
  22 + * @param $project
  23 + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
  24 + * @author Akun
  25 + * @date 2024/03/14 15:04
  26 + */
  27 + public static function getIndexHtml($project)
  28 + {
  29 + //站点配置
  30 + $project_config = self::getProjectConfig($project->id);
  31 +
  32 + //产品所有分类
  33 + $category = self::getProductsCategory($project->id);
  34 +
  35 + //排序最前的3个产品
  36 + $products = self::getProductsList($project->id, 1, 3)['data'];
  37 +
  38 + //排序最前的3篇新闻
  39 + $news = self::getNewsBlogList($project->id, 1, 1, 3)['data'];
  40 +
  41 + //排序最前的3篇博客
  42 + $blogs = AmpService::getNewsBlogList($project->id, 2, 1, 3)['data'];
  43 +
  44 + //当前页面地址
  45 + $current_url = self::getCurrentUrl($project->domain);
  46 +
  47 + return view('amp/index', compact('project_config', 'category', 'products', 'news', 'blogs', 'current_url'));
  48 + }
  49 +
  50 + /**
  51 + * 获取路由页html
  52 + * @param $project
  53 + * @param $route
  54 + * @param $source
  55 + * @param $page
  56 + * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
  57 + * @author Akun
  58 + * @date 2024/03/14 15:05
  59 + */
  60 + public static function getHtmlByRoute($project, $route, $source, $page)
  61 + {
  62 + //站点配置
  63 + $project_config = self::getProjectConfig($project->id);
  64 +
  65 + //产品所有分类
  66 + $category = self::getProductsCategory($project->id);
  67 +
  68 + //固定菜单页面
  69 + if ($route == '404') {
  70 + //404页面
  71 + $current_url = self::getCurrentUrl($project->domain, '/404/');
  72 + return view('amp/404', compact('project_config', 'category', 'current_url'));
  73 + } elseif ($route == 'contact-us') {
  74 + //contact-us页面
  75 + $current_url = self::getCurrentUrl($project->domain, '/contact-us/');
  76 + return view('amp/contact', compact('project_config', 'category', 'current_url'));
  77 + } elseif ($route == 'about-us') {
  78 + //about-us页面
  79 + $current_url = self::getCurrentUrl($project->domain, '/aboout-us/');
  80 + return view('amp/about', compact('project_config', 'category', 'current_url'));
  81 + } elseif ($route == 'products') {
  82 + //产品列表
  83 + $products = self::getProductsList($project->id, $page, 8);
  84 +
  85 + //当前分类详情
  86 + $category_info = self::getCategoryInfo($project->id, 0);
  87 +
  88 + $current_url = self::getCurrentUrl($project->domain, '/' . $category_info['route'] . '/' . ($page > 1 ? $page . '/' : ''));
  89 +
  90 + return view('amp/products', compact('project_config', 'category', 'products', 'category_info', 'page', 'current_url'));
  91 + } elseif ($route == 'news') {
  92 + //新闻列表
  93 + $news = self::getNewsBlogList($project->id, 1, $page, 5);
  94 +
  95 + $current_url = self::getCurrentUrl($project->domain, '/news/' . ($page > 1 ? $page . '/' : ''));
  96 + return view('amp/news', compact('project_config', 'category', 'news', 'page', 'current_url'));
  97 + } elseif ($route == 'blog') {
  98 + //博客列表
  99 + $blogs = self::getNewsBlogList($project->id, 2, $page, 5);
  100 +
  101 + $current_url = self::getCurrentUrl($project->domain, '/blog/' . ($page > 1 ? $page . '/' : ''));
  102 + return view('amp/blogs', compact('project_config', 'category', 'blogs', 'page', 'current_url'));
  103 + } elseif (strpos($route, 'top-search') !== false) {
  104 + //top-search页面
  105 + $pageService = new PageService();
  106 + $search_list = $pageService->getProductKeywordsByLetter($project, $route, $page);
  107 +
  108 + //处理路由后缀为-tag的关键词
  109 + foreach ($search_list['pageInfo']['pageListData'] as &$v) {
  110 + if (substr($v['route'], -4, 4) == '-tag') {
  111 + $v['route'] = substr($v['route'], 0, -4);
  112 + }
  113 + }
  114 +
  115 + //俄语站没有首字母筛选
  116 + if ($project->serve_id == 3) {
  117 + $search_list['keywordsLabel'] = [];
  118 + }
  119 +
  120 + $total_page = count($search_list['pageInfo']['pageNum']);
  121 + $search_list['pageInfo']['center_pages'] = page_init($page, $total_page);
  122 + $search_list['pageInfo']['prev'] = max($page - 1, 1);
  123 + $search_list['pageInfo']['next'] = min($page + 1, $total_page);
  124 +
  125 + $current_url = self::getCurrentUrl($project->domain, '/' . $route . '/' . ($page > 1 ? $page . '/' : ''));
  126 + return view('amp/top_search', compact('project_config', 'category', 'search_list', 'page', 'route', 'current_url'));
  127 + } else {
  128 + //剩下的页面:产品分类,产品详情,新闻详情,关键词详情
  129 + $map = ['route' => $route];
  130 + if ($source) {
  131 + $map['source'] = $source;
  132 + }
  133 + $route_info = RouteMap::where($map)->orderByRaw("FIELD(source, 'product_category','product','news','blog','product_keyword')")->first();
  134 + if (!$route_info) {
  135 + //特殊情况:关键词后缀为-tag
  136 + $map['route'] = $route . '-tag';
  137 + $map['source'] = 'product_keyword';
  138 + $route_info = RouteMap::where($map)->first();
  139 + }
  140 + if (!$route_info) {
  141 + $current_url = self::getCurrentUrl($project->domain, '/404/');
  142 + return view('amp/404', compact('project_config', 'category', 'current_url'));
  143 + }
  144 +
  145 + switch ($route_info->source) {
  146 + case 'product_category':
  147 + //产品列表
  148 + $products = self::getProductsList($project->id, $page, 8, $route_info->source_id);
  149 +
  150 + //当前分类详情
  151 + $category_info = self::getCategoryInfo($project->id, $route_info->source_id);
  152 +
  153 + $current_url = self::getCurrentUrl($project->domain, '/' . $category_info['route'] . '/' . ($page > 1 ? $page . '/' : ''));
  154 + return view('amp/products', compact('project_config', 'category', 'products', 'category_info', 'page', 'current_url'));
  155 + case 'product':
  156 + //获取产品详情
  157 + $product_info = self::getProductInfo($project->id, $route_info->source_id);
  158 +
  159 + //获取关联产品
  160 + $relate_products = self::getRelateProducts($project->id, $product_info['id'], $product_info['category_id'], 8);
  161 +
  162 + $current_url = self::getCurrentUrl($project->domain, '/' . $product_info['route'] . '/');
  163 + return view('amp/product_info', compact('project_config', 'category', 'product_info', 'relate_products', 'current_url'));
  164 + case 'news':
  165 + //新闻详情
  166 + $news_info = self::getNewsBlogInfo($project->id, 1, $route_info->source_id);
  167 +
  168 + $current_url = self::getCurrentUrl($project->domain, '/news/' . $news_info['url'] . '/');
  169 + return view('amp/news_info', compact('project_config', 'category', 'news_info', 'current_url'));
  170 + case 'blog':
  171 + //博客详情
  172 + $blog_info = self::getNewsBlogInfo($project->id, 2, $route_info->source_id);
  173 +
  174 + $current_url = self::getCurrentUrl($project->domain, '/blog/' . $blog_info['url'] . '/');
  175 + return view('amp/blog_info', compact('project_config', 'category', 'blog_info', 'current_url'));
  176 + case 'product_keyword':
  177 + //获取关键词详情
  178 + $tag_info = self::getTagInfo($project->id, $route_info->source_id);
  179 +
  180 + //获取关联产品和热门产品
  181 + $pageService = new PageService();
  182 + $products = $pageService->getRecommendAndHotProducts($project, $tag_info['route']) ?: [];
  183 +
  184 + //获取关联新闻
  185 + $news = self::getNewsBlogList($project->id, 1, 1, 2)['data'];
  186 +
  187 + //随机获取关键词列表
  188 + $relate_tags = self::getRelateTags($project->id);
  189 +
  190 + $current_url = self::getCurrentUrl($project->domain, '/' . $tag_info['route'] . '/');
  191 + return view('amp/tag', compact('project_config', 'category', 'tag_info', 'products', 'news', 'relate_tags', 'current_url'));
  192 + default:
  193 + $current_url = self::getCurrentUrl($project->domain, '/404/');
  194 + return view('amp/404', compact('project_config', 'category', 'current_url'));
  195 + }
  196 + }
  197 + }
  198 +
  199 + /**
  200 + * 拼接当前页面完整路径
  201 + * @param $domain
  202 + * @param $path
  203 + * @return string
  204 + * @author Akun
  205 + * @date 2024/03/15 15:48
  206 + */
  207 + public static function getCurrentUrl($domain, $path = '')
  208 + {
  209 + $host_array = explode('.', $domain);
  210 + if (count($host_array) <= 2) {
  211 + array_unshift($host_array, 'm');
  212 + } else {
  213 + $host_array[0] = 'm';
  214 + }
  215 + $amp_domain = implode('.', $host_array);
  216 +
  217 + return 'https://' . $amp_domain . $path;
  218 + }
  219 +
  220 + /**
  221 + * 获取站点amp配置
  222 + * @param $project_id
  223 + * @return mixed
  224 + * @author Akun
  225 + * @date 2024/01/26 16:07
  226 + */
  227 + public static function getProjectConfig($project_id)
  228 + {
  229 + $config_amp = WebSettingAmp::where('project_id', $project_id)->first();
  230 +
  231 + $config_index = WebSetting::where('project_id', $project_id)->first();
  232 +
  233 + $config_seo = WebSettingSeo::where('project_id', $project_id)->first();
  234 +
  235 + $show_news = News::where('project_id', $project_id)->where('status', 1)->count('id');
  236 +
  237 + $show_blogs = Blog::where('project_id', $project_id)->where('status', 1)->count('id');
  238 +
  239 + return [
  240 + 'show_news' => $show_news,
  241 + 'show_blogs' => $show_blogs,
  242 + 'top_backgroundcolor' => $config_amp->top_backgroundcolor ?? '',
  243 + 'web_icon' => $config_amp->web_icon ?? '',
  244 + 'top_logo' => $config_amp->top_logo ?? [],
  245 + 'index_banner' => $config_amp->index_banner ?? [],
  246 + 'index_intro' => $config_amp->index_intro ?? '',
  247 + 'company_image' => $config_amp->company_image ?? [],
  248 + 'company_about' => $config_amp->company_about ?? '',
  249 + 'company_email' => $config_amp->company_email ?? '',
  250 + 'company_address' => $config_amp->company_address ?? '',
  251 + 'company_tel' => $config_amp->company_tel ?? '',
  252 + 'third_code' => $config_amp->third_code ?? '',
  253 + 'index_title' => $config_index->title ?? '',
  254 + 'index_description' => $config_index->remark ?? '',
  255 + 'index_keywords' => $config_index->keyword ?? '',
  256 + 'single_page_suffix' => $config_seo->single_page_suffix ?? '',
  257 + 'tab_suffix' => $config_seo->tab_suffix ?? '',
  258 + 'tab_prefix' => $config_seo->tab_prefix ?? '',
  259 + 'product_cate_suffix' => $config_seo->product_cate_suffix ?? '',
  260 + 'product_cate_prefix' => $config_seo->product_cate_prefix ?? '',
  261 + 'product_suffix' => $config_seo->product_suffix ?? '',
  262 + 'product_prefix' => $config_seo->product_prefix ?? '',
  263 + ];
  264 + }
  265 +
  266 + /**
  267 + * 获取分类列表
  268 + * @param $project_id
  269 + * @return array
  270 + * @author Akun
  271 + * @date 2024/01/29 11:25
  272 + */
  273 + public static function getProductsCategory($project_id)
  274 + {
  275 + $category = [];
  276 + $result = Category::where('project_id', $project_id)->where('title', '!=', 'Featured Products')->where('status', 1)->orderBy("sort", "desc")->orderBy("id", "desc")->get();
  277 + if ($result->count() > 0) {
  278 + $result_tree = list_to_tree($result->toArray());
  279 + foreach ($result_tree as $cate) {
  280 + if ($cate['title'] == 'Products' || $cate['title'] == 'products') {
  281 + foreach ($cate['_child'] as $child) {
  282 + $category[] = $child;
  283 + }
  284 + } else {
  285 + $category[] = $cate;
  286 + }
  287 + }
  288 + }
  289 +
  290 +
  291 + return $category;
  292 + }
  293 +
  294 + /**
  295 + * 获取分类详情
  296 + * @param $project_id
  297 + * @param $category_id
  298 + * @return array
  299 + * @author Akun
  300 + * @date 2024/01/29 11:31
  301 + */
  302 + public static function getCategoryInfo($project_id, $category_id)
  303 + {
  304 + if ($category_id > 0) {
  305 + $category_info = Category::where('project_id', $project_id)->where('id', $category_id)->first();
  306 + } else {
  307 + $category_info = Category::where('project_id', $project_id)->whereIn('title', ['Products', 'products'])->first();
  308 + if ($category_info) {
  309 + $category_info->id = 0;
  310 + } else {
  311 + return [
  312 + 'id' => 0,
  313 + 'route' => 'products',
  314 + 'title' => 'Products',
  315 + 'keywords' => '',
  316 + 'describe' => '',
  317 + 'seo_title' => '',
  318 + 'seo_keywords' => '',
  319 + 'seo_description' => '',
  320 + ];
  321 + }
  322 + }
  323 +
  324 + return [
  325 + 'id' => $category_info->id ?? 0,
  326 + 'route' => $category_info->route ?? '',
  327 + 'title' => $category_info->title ?? '',
  328 + 'keywords' => $category_info->keywords ?? '',
  329 + 'describe' => $category_info->describe ?? '',
  330 + 'seo_title' => $category_info->seo_title ?? '',
  331 + 'seo_keywords' => $category_info->seo_keywords ?? '',
  332 + 'seo_description' => $category_info->seo_des ?? '',
  333 + ];
  334 + }
  335 +
  336 + /**
  337 + * 根据分类id获取产品id
  338 + * @param $category_id
  339 + * @return mixed
  340 + * @author Akun
  341 + * @date 2024/01/29 11:26
  342 + */
  343 + public static function getProductIdByCategory($category_id)
  344 + {
  345 + return CategoryRelated::where('cate_id', $category_id)->pluck('product_id')->toArray();
  346 + }
  347 +
  348 + /**
  349 + * 获取产品列表
  350 + * @param int $project_id
  351 + * @param int $page
  352 + * @param int $limit
  353 + * @param int $category_id
  354 + * @param string $search
  355 + * @return array
  356 + * @author Akun
  357 + * @date 2024/01/26 16:07
  358 + */
  359 + public static function getProductsList($project_id, $page = 1, $limit = 20, $category_id = 0, $search = '')
  360 + {
  361 + $total_page = 0;
  362 + $products = [];
  363 +
  364 + $model = Product::where('project_id', $project_id)->where('status', 1);
  365 + //根据分类id获取关联的产品id
  366 + if ($category_id > 0) {
  367 + $product_ids = self::getProductIdByCategory($category_id);
  368 + if ($product_ids) {
  369 + $model = $model->whereIn('id', $product_ids);
  370 + }
  371 + } else {
  372 + //获取所有产品需要排除掉Featured Products分类
  373 + $fp_cate_id = Category::where('title', 'Featured Products')->value('id');
  374 + $model->where('category_id', '!=', ',' . $fp_cate_id . ',');
  375 + }
  376 + //搜索条件
  377 + if ($search) {
  378 + if (strpos($search, '\\') !== false) {
  379 + $search = str_replace('\\', '\\\\', $search);
  380 + }
  381 + $model = $model->where('title', 'like', "%$search%");
  382 + }
  383 +
  384 + $count = $model->count('id');
  385 + if ($count > 0) {
  386 + $total_page = (int)ceil($count / $limit);
  387 +
  388 + //获取产品自定义排序规则
  389 + $sort_rule = self::getProductSortRule($project_id);
  390 + foreach ($sort_rule as $rk => $rv) {
  391 + $model = $model->orderBy($rk, $rv);
  392 + }
  393 +
  394 + $result = $model->select(['id', 'title', 'thumb', 'intro', 'content', 'route'])->offset(($page - 1) * $limit)->limit($limit)->get();
  395 + if ($result->count() > 0) {
  396 + foreach ($result as $value) {
  397 + $thumb = [];
  398 + if ($value->thumb) {
  399 + $thumb_arr = json_decode($value->thumb, true);
  400 + $thumb = [
  401 + 'alt' => (isset($thumb_arr['alt']) && $thumb_arr['alt']) ? $thumb_arr['alt'] : $value->title,
  402 + 'url' => getImageUrl($thumb_arr['url'] ?? '')
  403 + ];
  404 + }
  405 + $intro = $value->intro ?: $value->content;
  406 + $intro = strip_tags(special2str($intro));
  407 + $products[] = [
  408 + 'id' => $value->id,
  409 + 'title' => $value->title,
  410 + 'thumb' => $thumb,
  411 + 'route' => $value->route,
  412 + 'intro' => strlen($intro) > 200 ? substr($intro, 0, 200) . '...' : $intro,
  413 + ];
  414 + }
  415 + }
  416 + }
  417 +
  418 + $pre = max($page - 1, 1);
  419 + $next = min($page + 1, $total_page);
  420 + $center_pages = page_init($page, $total_page);
  421 +
  422 + return ['data' => $products, 'total_page' => $total_page, 'prev' => $pre, 'next' => $next, 'center_pages' => $center_pages];
  423 + }
  424 +
  425 + /**
  426 + * 获取产品自定义排序规则
  427 + * @param $project_id
  428 + * @return array|string[]
  429 + * @author Akun
  430 + * @date 2024/03/21 11:13
  431 + */
  432 + public static function getProductSortRule($project_id)
  433 + {
  434 + $order_list = [];
  435 + $orderDataFirst = WebSettingNum::where('project_id', $project_id)->where('type', 10)->first();
  436 + if ($orderDataFirst && $orderDataFirst->data) {
  437 + $orderData = json_decode($orderDataFirst->data, true);
  438 + foreach ($orderData as $key => $orderDataItem) {
  439 + $orderKey = $key == "created_at" ? "send_time" : $key;
  440 + $order_list[$orderKey] = $orderDataItem;
  441 + if ($key != "id") {
  442 + $order_list['id'] = 'desc';
  443 + }
  444 + }
  445 + } else {
  446 + $order_list = [
  447 + 'sort' => 'desc',
  448 + 'id' => 'desc'
  449 + ];
  450 + }
  451 +
  452 + return $order_list;
  453 + }
  454 +
  455 + /**
  456 + * 获取产品详情
  457 + * @param $project_id
  458 + * @param $id
  459 + * @return array
  460 + * @author Akun
  461 + * @date 2024/01/30 9:22
  462 + */
  463 + public static function getProductInfo($project_id, $id)
  464 + {
  465 + $gallery = [];
  466 + $seo = [
  467 + 'title' => '',
  468 + 'keywords' => '',
  469 + 'description' => ''
  470 + ];
  471 + $product_info = Product::where('project_id', $project_id)->where('status', 1)->where('id', $id)->first();
  472 + if ($product_info) {
  473 + if ($product_info->gallery) {
  474 + $gallery_arr = json_decode($product_info->gallery, true);
  475 + foreach ($gallery_arr as $vg) {
  476 + $gallery[] = [
  477 + 'alt' => (isset($vg['alt']) && $vg['alt']) ? $vg['alt'] : $product_info->title,
  478 + 'url' => getImageUrl($vg['url'] ?? '')
  479 + ];
  480 + }
  481 + }
  482 +
  483 + if ($product_info->seo_mate) {
  484 + $seo_arr = json_decode($product_info->seo_mate, true);
  485 + $seo['title'] = $seo_arr['title'] ?? '';
  486 + $seo['keywords'] = $seo_arr['keywords'] ?? '';
  487 + $seo['description'] = $seo_arr['description'] ?? '';
  488 + }
  489 + }
  490 +
  491 + return [
  492 + 'id' => $product_info->id ?? 0,
  493 + 'route' => $product_info->route ?? '',
  494 + 'gallery' => $gallery,
  495 + 'title' => $product_info->title ?? '',
  496 + 'intro' => $product_info->intro ?? '',
  497 + 'content' => $product_info->content ?? '',
  498 + 'seo' => $seo,
  499 + 'category_id' => $product_info->category_id ?? ''
  500 + ];
  501 + }
  502 +
  503 + /**
  504 + * 获取关联产品
  505 + * @param $project_id
  506 + * @param $id
  507 + * @param $category_id
  508 + * @param $limit
  509 + * @return array
  510 + * @author Akun
  511 + * @date 2024/01/30 9:34
  512 + */
  513 + public static function getRelateProducts($project_id, $id, $category_id, $limit = 2)
  514 + {
  515 + if (is_string($category_id)) {
  516 + $category_id = explode(',', $category_id);
  517 + }
  518 +
  519 + $relate_ids = CategoryRelated::whereIn('cate_id', $category_id)->where('product_id', '!=', $id)->limit($limit)->pluck('product_id')->toArray();
  520 +
  521 + $relate_products = [];
  522 + if ($relate_ids) {
  523 + $result = Product::where('project_id', $project_id)->whereIn('id', $relate_ids)->where('status', 1)->orderBy('sort', 'desc')->limit(8)->get();
  524 + if ($result->count() == 0) {
  525 + $result = Product::where('project_id', $project_id)->where('status', 1)->inRandomOrder()->take(8)->get();
  526 + }
  527 + if ($result->count() > 0) {
  528 + foreach ($result as $value) {
  529 + $thumb = '';
  530 + if ($value->thumb) {
  531 + $thumb_arr = json_decode($value->thumb, true);
  532 + $thumb = [
  533 + 'alt' => (isset($thumb_arr['alt']) && $thumb_arr['alt']) ? $thumb_arr['alt'] : $value->title,
  534 + 'url' => getImageUrl($thumb_arr['url'] ?? '')
  535 + ];
  536 + }
  537 + $relate_products[] = [
  538 + 'id' => $value->id,
  539 + 'route' => $value->route,
  540 + 'title' => $value->title,
  541 + 'thumb' => $thumb
  542 + ];
  543 + }
  544 + }
  545 + }
  546 +
  547 + return $relate_products;
  548 + }
  549 +
  550 + /**
  551 + * 获取新闻博客列表
  552 + * @param $project_id
  553 + * @param int $type
  554 + * @param int $page
  555 + * @param int $limit
  556 + * @return array
  557 + * @author Akun
  558 + * @date 2024/01/26 16:38
  559 + */
  560 + public static function getNewsBlogList($project_id, $type = 1, $page = 1, $limit = 10)
  561 + {
  562 + $total_page = 0;
  563 + $news = [];
  564 +
  565 + if ($type == 1) {
  566 + $model = new News();
  567 + } else {
  568 + $model = new Blog();
  569 + }
  570 + $count = $model->where('project_id', $project_id)->where('status', 1)->count('id');
  571 + if ($count > 0) {
  572 + $total_page = (int)ceil($count / $limit);
  573 +
  574 + $result = $model->select(['id', 'name', 'image', 'remark', 'text', 'release_at', 'created_at', 'url'])->where('project_id', $project_id)->where('status', 1)->orderBy('sort', 'desc')->orderBy('id', 'desc')->offset(($page - 1) * $limit)->limit($limit)->get();
  575 + if ($result->count() > 0) {
  576 + foreach ($result as $value) {
  577 + $remark = $value->remark ?: $value->text;
  578 + $remark = strip_tags(special2str($remark));
  579 + $news[] = [
  580 + 'type' => $type,
  581 + 'id' => $value->id,
  582 + 'name' => $value->name,
  583 + 'url' => $value->url,
  584 + 'image' => getImageUrl($value->image),
  585 + 'remark' => strlen($remark) > 200 ? substr($remark, 0, 200) . '...' : $remark,
  586 + 'release_at' => $value->release_at ? $value->release_at : $value->created_at
  587 + ];
  588 + }
  589 + }
  590 + }
  591 +
  592 + $pre = max($page - 1, 1);
  593 + $next = min($page + 1, $total_page);
  594 + $center_pages = page_init($page, $total_page);
  595 +
  596 +
  597 + return ['data' => $news, 'total_page' => $total_page, 'prev' => $pre, 'next' => $next, 'center_pages' => $center_pages];
  598 + }
  599 +
  600 + /**
  601 + * 获取新闻博客详情
  602 + * @param $project_id
  603 + * @param $type
  604 + * @param $id
  605 + * @return array
  606 + * @author Akun
  607 + * @date 2024/01/30 11:17
  608 + */
  609 + public static function getNewsBlogInfo($project_id, $type, $id)
  610 + {
  611 + if ($type == 1) {
  612 + $model = new News();
  613 + } else {
  614 + $model = new Blog();
  615 + }
  616 +
  617 + $news_info = $model->where('project_id', $project_id)->where('status', 1)->where('id', $id)->first();
  618 +
  619 + $release_at = '';
  620 + if (isset($news_info->release_at) && $news_info->release_at) {
  621 + $release_at = $news_info->release_at;
  622 + } elseif (isset($news_info->created_at) && $news_info->created_at) {
  623 + $release_at = $news_info->created_at;
  624 + }
  625 +
  626 + return [
  627 + 'id' => $news_info->id ?? 0,
  628 + 'name' => $news_info->name ?? '',
  629 + 'sort' => $news_info->sort ?? 0,
  630 + 'url' => $news_info->url ?? 0,
  631 + 'text' => $news_info->text ?? '',
  632 + 'image' => getImageUrl($news_info->image ?? ''),
  633 + 'seo_title' => $news_info->seo_title ?? '',
  634 + 'seo_keywords' => $news_info->seo_keywords ?? '',
  635 + 'seo_description' => $news_info->seo_description ?? '',
  636 + 'release_at' => $release_at
  637 + ];
  638 + }
  639 +
  640 + /**
  641 + * 获取关键词详情
  642 + * @param $project_id
  643 + * @param $id
  644 + * @return array
  645 + * @author Akun
  646 + * @date 2024/01/30 16:17
  647 + */
  648 + public static function getTagInfo($project_id, $id)
  649 + {
  650 + $tag_info = Keyword::where('project_id', $project_id)->where('status', 1)->where('id', $id)->first();
  651 +
  652 + return [
  653 + 'id' => $tag_info->id ?? 0,
  654 + 'route' => $tag_info->route ?? '',
  655 + 'title' => $tag_info->title ?? '',
  656 + 'keyword_title' => $tag_info->keyword_title ?? '',
  657 + 'keyword_content' => $tag_info->keyword_content ?? '',
  658 + 'seo_title' => $tag_info->seo_title ?? '',
  659 + 'seo_keywords' => $tag_info->seo_keywords ?? '',
  660 + 'seo_description' => $tag_info->seo_description ?? '',
  661 + ];
  662 + }
  663 +
  664 + /**
  665 + * 获取关联关键词
  666 + * @param $project_id
  667 + * @return mixed
  668 + * @author Akun
  669 + * @date 2024/01/30 18:30
  670 + */
  671 + public static function getRelateTags($project_id)
  672 + {
  673 + return Keyword::select(['id', 'title', 'route'])->where('project_id', $project_id)->where('status', 1)->inRandomOrder()->take(10)->get()->toArray();
  674 + }
  675 +}
  1 +<?php
  2 +
  3 +
  4 +namespace App\Services\Html;
  5 +
  6 +use App\Console\Commands\ProjectService;
  7 +use App\Helper\Translate;
  8 +use App\Models\Project\DeployBuild;
  9 +use App\Models\Project\DeployOptimize;
  10 +use App\Models\Project\DomainInfo;
  11 +use App\Models\Project\Project;
  12 +use App\Models\Project\UpdateProgressModel;
  13 +use App\Models\RouteMap;
  14 +use App\Models\WebSetting\WebLanguage;
  15 +use App\Models\WebSetting\WebProofreading;
  16 +use App\Models\WebSetting\WebSetting;
  17 +use App\Models\WebSetting\WebSettingCountry;
  18 +use App\Models\WebSetting\WebSettingHtml;
  19 +use App\Models\WebSetting\WebSettingText;
  20 +use App\Models\WebSetting\WebTemplateCommon;
  21 +use Illuminate\Support\Facades\Redis;
  22 +use phpQuery;
  23 +
  24 +/**
  25 + * 生成静态页相关
  26 + */
  27 +class CommonService
  28 +{
  29 +
  30 + /**
  31 + * 翻译
  32 + */
  33 + public function webHtmlTranslate($project,$content, $lang,$domain)
  34 + {
  35 + //翻译过滤器
  36 + $lang = $lang == "zh-ct" ? "zh-TW" : $lang;
  37 + $tlsList = Translate::$tls_list;
  38 + if (isset($tlsList[$lang])){
  39 + $main_lang = $project->main_lang_id;
  40 + $mainLangInfo = WebLanguage::getProjectMainLang($main_lang);
  41 + $master_lang = $mainLangInfo ? $mainLangInfo->short : 'en';
  42 + //翻译
  43 + if ($master_lang != 'en') {
  44 + $result = Translate::translate($content, $lang, $master_lang);
  45 + $content = $result[0]['texts'] ?? '';
  46 + } else {
  47 + $content = Translate::tran($content, $lang);
  48 + }
  49 + // 翻译有时会返回空数据 再翻译一次 FIXME 后续需要重新封装
  50 + if (empty($content)) {
  51 + $result = Translate::translate($content, $lang, $master_lang);
  52 + $content = $result[0]['texts'] ?? '';
  53 + }
  54 +
  55 + //翻译校对
  56 + $content = $this->translationProofread($project,$content,$lang,$domain);
  57 + }
  58 + return $content;
  59 + }
  60 +
  61 + /**
  62 + * 翻译校对
  63 + */
  64 + public function translationProofread($project, $content, $lang,$domain)
  65 + {
  66 + $webProofreading = WebProofreading::where("project_id",$project->id)->where("alias",$lang)->get();
  67 + if (!empty($webProofreading)){
  68 + foreach ($webProofreading as $item){
  69 + $content = str_ireplace($item->text,$item->translate,$content);
  70 + }
  71 + }
  72 + return $content;
  73 + }
  74 +
  75 + /**
  76 + * 处理第三方代码
  77 + */
  78 + public function thirdPartyCodeHandle($project,$content,$route,$routeMap=null): string
  79 + {
  80 + if (Redis::get("project_".$project->id."_third_party_code") != null){
  81 + $webSettingHtml = json_decode(Redis::get("project_".$project->id."_third_party_code"));
  82 + }else{
  83 + $webSettingHtml = WebSettingHtml::where("project_id",$project->id)->first();
  84 + Redis::set("project_".$project->id."_third_party_code", json_encode($webSettingHtml));
  85 + Redis::expire("project_".$project->id."_third_party_code", WebSetting::$redisExpireTime);
  86 + }
  87 + $phpQueryDom = phpQuery::newDocument($content);
  88 +
  89 + //处理自定义页面样式问题
  90 +// if ($globalsojsSyles != ""){
  91 +// $phpQueryDom->find("#globalsojs-styles")->remove();
  92 +// $phpQueryDom->find('head')->append($globalsojsSyles);
  93 +// }
  94 +
  95 + //网站icon
  96 + $webIcon = WebSetting::where("project_id",$project->id)->first();
  97 + if (!empty($webIcon)){
  98 + $iconDom = $phpQueryDom->find("link[rel=icon]");
  99 + if (count($iconDom) >= 1){
  100 + if (isset($webIcon->web_site_icon) && !empty($webIcon->web_site_icon) && $webIcon->web_site_icon != "" && $webIcon->web_site_icon != 0){
  101 + $iconDom->attr("href",$webIcon->web_site_icon);
  102 + }else{
  103 + $iconDom->attr("href","");
  104 + }
  105 + }
  106 + }
  107 +
  108 + //第三方代码(网页顶部,中间,底部),以后启用位置
  109 + if (!empty($webSettingHtml)) {
  110 + $phpQueryDom->find('head')->append($webSettingHtml->head_html?:'');
  111 + $phpQueryDom->find('body')->append($webSettingHtml->body_html?:'');
  112 + $phpQueryDom->find('html')->append($webSettingHtml->footer_html?:'');
  113 + }
  114 +
  115 +
  116 + //A端添加的网站追踪代码
  117 + $deployOptimize = DeployOptimize::where("project_id",$project->id)->first();
  118 + if (!empty($deployOptimize)){
  119 + if (isset($deployOptimize->meta) && !empty($deployOptimize->meta)){
  120 + $phpQueryDom->find('head')->append($deployOptimize->meta);
  121 + }
  122 + }
  123 +
  124 + //去掉非index页面header上面的headerindex属性
  125 + //if ($route != "index"){
  126 + //$phpQueryDom->find('header')->removeAttr("headerindex");
  127 + //}
  128 + //首页头部独立样式
  129 + if ($route == "index"){
  130 + $phpQueryDom->find('header')->attr("headerprivate","");
  131 + }
  132 +
  133 + //处理header顶部搜索跳转链接
  134 + $phpQueryDom->find('header form')->attr("action", "/search/");
  135 +
  136 +
  137 + //生成锚点,以后启用位置
  138 + //$content = $this->anchorTextHandle($project,$route,$content);
  139 +
  140 + //C端访问埋点
  141 + $isBodyEnd = $phpQueryDom->find('body')->eq(0);
  142 + if (count($isBodyEnd)>=1){
  143 + $phpQueryDom->find('body')->append("<script src='https://ecdn6.globalso.com/public/customerVisit.min.js'></script>");
  144 + }else{
  145 + $phpQueryDom->find('html')->append("<script src='https://ecdn6.globalso.com/public/customerVisit.min.js'></script>");
  146 + }
  147 + $data = date("Y-m-d H:i:s");
  148 + $phpQueryDom->find('html')->append("<!-- Globalso Cache file was created on ".$data." -->");
  149 + //这个功能其他类型页面移到面包屑导航处理
  150 + if ($route == "index" || (!empty($routeMap) && $routeMap->source == WebTemplateCommon::$pageName)){
  151 + $phpQueryDom->find('head')->append('<script>var currentPage = "'.$route.'"</script>');
  152 + }
  153 +
  154 + if ($route == "search"){
  155 + //暂时先去掉小语种按钮显示
  156 + $phpQueryDom->find(".change-language")->remove();
  157 + $phpQueryDom->find('head')->append('<meta name="robots" content="noindex, nofollow"/>');
  158 + }
  159 + $phpQueryDom->find('body')->attr("unevents","");
  160 +
  161 + $content = $phpQueryDom->htmlOuter();
  162 + unset($phpQueryDom);
  163 + phpQuery::unloadDocuments();
  164 +
  165 + //处理全部内容,如果有上线正式域名,则把所有的测试域名替换为正式域名
  166 + $projectDomainInfo = DomainInfo::where("project_id",$project->id)->first();
  167 + if (!empty($projectDomainInfo)){
  168 + $deployBuild = DeployBuild::where("project_id",$project->id)->first();
  169 + if (!empty($deployBuild)){
  170 + $parsedUrl = parse_url($deployBuild->test_domain);
  171 + $domain = $projectDomainInfo->domain;
  172 + $testDomain = $parsedUrl['host'];
  173 + if ($domain != '' && $testDomain != ''){
  174 + $content = str_replace($testDomain,$domain,$content);
  175 + }
  176 + }
  177 + }
  178 + return $content;
  179 + }
  180 +
  181 + /**
  182 + * 处理锚文本
  183 + */
  184 + public function anchorTextHandle($project,$route,$content): string
  185 + {
  186 + $source = "";
  187 + //解析路由
  188 + if ($route != "index"){
  189 + $routerNewsMap = RouteMap::where("project_id",$project->id)->where("route",$route)->first();
  190 + if (!empty($routerNewsMap)){
  191 + $source = $routerNewsMap->source;
  192 + }
  193 + }else{
  194 + $source = "index";
  195 + }
  196 +
  197 + //判断来源类型
  198 + switch ($source) {
  199 + case 'news_category' || 'news':
  200 + $num = 4;
  201 + break;
  202 + case 'product_category' || 'product':
  203 + $num = 2;
  204 + break;
  205 + case 'blog_category' || 'blog':
  206 + $num = 6;
  207 + break;
  208 + case 'page':
  209 + $num = 1;
  210 + break;
  211 + default:
  212 + $num = 1;
  213 + }
  214 +
  215 + //网站设置锚文本
  216 + $webSetting = WebSetting::getWebSetting($project);
  217 + if (!empty($webSetting)){
  218 + $anchorIsEnable = $webSetting->anchor_is_enable;
  219 + if ($anchorIsEnable == 0){
  220 + $anchorSetting = $webSetting->anchor_setting;
  221 + $anchorSettingArr = explode(',', substr($anchorSetting, 1, -1));
  222 + foreach ($anchorSettingArr as $item){
  223 + $itemArr = explode('"', substr($item, 1, -1));
  224 + $tracingText[] = intval($itemArr[0]);
  225 + }
  226 + if (in_array($num, $tracingText)) {
  227 + $webSettingText = WebSettingText::getWebSettingText($project);
  228 + $phpQueryDom=phpQuery::newDocument($content);
  229 + $mainElement = $phpQueryDom->find('main');
  230 + $con = $mainElement->html();
  231 + if (!empty($webSettingText)){
  232 + foreach ($webSettingText as $v){
  233 + $con = str_replace( $v->key_words, '<a target="_blank" href="'. $v->url.'">'. $v->key_words.'</a>', $con);
  234 + }
  235 + }
  236 + $mainElement->html($con);
  237 + return $phpQueryDom->htmlOuter();
  238 + }
  239 + }
  240 + }
  241 + return $content;
  242 + }
  243 +
  244 + /**
  245 + * 链接项目
  246 + */
  247 + public function connectProject($updateData)
  248 + {
  249 + $project = null;
  250 + $projectIn = Project::getProjectByDomain($updateData->domain);
  251 + if (!empty($projectIn)){
  252 + $project = Project::where("id",$projectIn->project_id)->first();
  253 + if (!empty($project)){
  254 + $project->domain = $updateData->domain;
  255 + }
  256 + ProjectService::useProject($project->id,$updateData->domain);
  257 + }
  258 + return $project;
  259 + }
  260 +
  261 + /**
  262 + * 获取小语种更新国家
  263 + */
  264 + public function getMinorLanguage($updateData)
  265 + {
  266 + $minorLanguage = [];
  267 + $updateProgressQuery = UpdateProgressModel::find($updateData->id);
  268 + if (!empty($updateProgressQuery)){
  269 + $extends = $updateProgressQuery->extends;
  270 + if (!empty($extends)){
  271 + $extends = json_decode($extends);
  272 + if (isset($extends->language) && !empty($extends->language)){
  273 + $language = $extends->language;
  274 + foreach ($language as $lang){
  275 + $minorLanguage[] = (int)$lang;
  276 + }
  277 + }
  278 + }
  279 + }
  280 + return WebSettingCountry::whereIn("id", $minorLanguage)->get();
  281 + }
  282 +}
1 <?php 1 <?php
2 -/**  
3 - * Created by PhpStorm.  
4 - * User: zhl  
5 - * Date: 2024/2/19  
6 - * Time: 15:46  
7 - */  
8 -namespace App\Services\Html;  
9 -  
10 -use App\Models\Project\Project;  
11 -use App\Models\RouteMap\RouteMap;  
12 -use App\Services\TdkService;  
13 -  
14 -class CreateHtmlService  
15 -{  
16 - public function __construct(){}  
17 -  
18 - /**  
19 - * 返回最终需要的HTML  
20 - * @return string  
21 - */  
22 - public function getHtml($project_id, $route, $lang = [], $page = 0)  
23 - {  
24 - $projectModel = new Project();  
25 - $projectInfo = $projectModel->with(['payment', 'deploy_build'])->where(['id'=>$project_id])->first()->toArray();  
26 - $routeMapModel = new RouteMap();  
27 - $routeInfo = $routeMapModel->read(['route'=>$route]);  
28 - if($routeInfo === false){  
29 - if($route == 'top-search' || $route == 'products' || $route == 'news' || $route == 'blog'){  
30 - $html = '';  
31 - }else{  
32 - $html = '';  
33 - }  
34 - }else{  
35 - //TODO::5.0,6.0获取html,自定义页面还需要单独处理  
36 - if(($routeInfo['source'] == RouteMap::SOURCE_PAGE) && ($route != 'index')){  
37 - $customTemplateService = new CustomTemplateService();  
38 - $data = $customTemplateService->getHtml($projectInfo,$routeInfo['source_id']);  
39 - if($data === false){  
40 - return false;  
41 - }  
42 - $html = $data['html'];  
43 - }else{  
44 - $generatePageService = new GeneratePageService();  
45 - $data = $generatePageService->generateHtml($projectInfo,$routeInfo);  
46 - if($data === false){  
47 - return false;  
48 - }  
49 - $html = $data['html'];  
50 - }  
51 - }  
52 - //处理页面tdk  
53 - $tdkService = new TdkService();  
54 - $html = $tdkService->pageTdkHandle($projectInfo,$html,$routeInfo['source'],$routeInfo);  
55 - return ['html'=>$html];  
56 - }  
57 2
58 - /**  
59 - * 返回6.0页面最终HTML  
60 - * @return mixed  
61 - */  
62 - public function getHtmlV6($project_id,$route)  
63 - {  
64 - // 初始化后续需要渲染页面需要的数据 路由、主语种、tdk、嵌入等信息  
65 - $origin_html = $this->originHtml($project_id,$route);  
66 - $html = $this->renderData($origin_html);  
67 - $html = $this->plugHead($html);  
68 - $html = $this->processFinal($html);  
69 - /** ... 调用其他方法, 直至返回完整的正确的HTML */  
70 - return $html;  
71 - }  
72 -  
73 - /**  
74 - * 根据路由信息 返回 路由属性及详细信息  
75 - * @param string $route  
76 - * @return array  
77 - */  
78 - public function getInfoByRoute($route)  
79 - {  
80 - $routeMapModel = new RouteMap();  
81 - $routeInfo = $routeMapModel->read(['route'=>$route]);  
82 - if($routeInfo === false){  
83 - if($route == 'top-search' || $route == 'products' || $route == 'news' || $route == 'blog'){  
84 - $routeInfo = $route;  
85 - }else{  
86 - $routeInfo = [];  
87 - }  
88 - }  
89 - // TODO 获取详情需要通过路由查下路由信息, 以及数据信息, 要处理特殊几个路由: top-search、products、news、blog, 这几个如果存在就用查下的信息, 如果不存在要初始化信息  
90 - return $routeInfo;  
91 - } 3 +namespace App\Services\Html;
92 4
93 - /**  
94 - * 获取可视化HTML  
95 - * @return string  
96 - */  
97 - public function originHtml($project_id,$route)  
98 - {  
99 5
100 - }  
101 6
102 - /**  
103 - * 补充其他信息  
104 - * TDK mate信息等  
105 - * @param $html  
106 - * @return mixed  
107 - */  
108 - public function plugHead($html)  
109 - {  
110 - /** 渲染tdk信息、 mate信息、 嵌入信息、 图标信息*/  
111 - return $html;  
112 - }  
113 -  
114 - /**  
115 - * 处理最终信息  
116 - * 处理标签、最后代码标识、特殊规则或者字符等  
117 - * @param string $html  
118 - * @return string  
119 - */  
120 - public function processFinal($html)  
121 - {  
122 - return $html;  
123 - } 7 +use phpDocumentor\Reflection\Project;
124 8
  9 +/**
  10 + * 生成页面
  11 + */
  12 +class CreateHtmlService{
125 /** 13 /**
126 - * 渲染页面数据  
127 - * @param string $html  
128 - * @return string 14 + * 获取页面
129 */ 15 */
130 - public function renderData($html, $page) 16 + public function getHtml($projectId, $route, $lang = "", $page = null)
131 { 17 {
132 - /**  
133 - * 根据可视化HTML中关键词渲染数据  
134 - * 这个方法还需要进行拆分, 这个功能内容应该会比较多  
135 - * 并且还会根据路由信息和分页信息不同, 渲染不同数据, 只要针对列表页面  
136 - */  
137 - return $html; 18 + $project = Project::find($projectId);
  19 + $createPageService = new CreatePageService();
  20 + return $createPageService->getPageByLangRoutePage($project,$route,$page);
138 } 21 }
139 } 22 }
  1 +<?php
  2 +
  3 +
  4 +namespace App\Services\Html;
  5 +
  6 +use App\Helper\Str;
  7 +use App\Models\Blog\Blog;
  8 +use App\Models\Module\Module;
  9 +use App\Models\Module\ModuleCategory;
  10 +use App\Models\News\News;
  11 +use App\Models\News\NewsCategory;
  12 +use App\Models\Product\Category;
  13 +use App\Models\Product\CategoryRelated;
  14 +use App\Models\Product\Keyword;
  15 +use App\Models\Product\Product;
  16 +use App\Models\Project\CollectTask;
  17 +use App\Models\Project\Country;
  18 +use App\Models\Project\CountryCustom;
  19 +use App\Models\Project\DeployBuild;
  20 +use App\Models\Project\DomainInfo;
  21 +use App\Models\Project\Notify;
  22 +use App\Models\Project\Project;
  23 +use App\Models\Project\UpdateHtmlModel;
  24 +use App\Models\Project\UpdateMasterWebsiteModel;
  25 +use App\Models\Project\UpdateMinorLanguagesModel;
  26 +use App\Models\Project\UpdateProgressModel;
  27 +use App\Models\RouteMap;
  28 +use App\Models\Template\BSetting;
  29 +use App\Models\WebSetting\WebCustom;
  30 +use App\Models\WebSetting\WebLanguage;
  31 +use App\Models\WebSetting\WebSettingNum;
  32 +use App\Models\WebSetting\WebTemplate;
  33 +use App\Models\WebSetting\WebTemplateCommon;
  34 +use App\Repositories\StaticHtmlRepository;
  35 +use Illuminate\Support\Facades\File;
  36 +use phpQuery;
  37 +use stdClass;
  38 +
  39 +/**
  40 + * C端生成页面服务
  41 + */
  42 +class CreatePageService{
  43 +
  44 + /**
  45 + * 获取升级项目小语种采集的页面
  46 + * @param $project
  47 + * @param $route
  48 + * @param $source
  49 + * @param $lang
  50 + * @return string
  51 + * @author Akun
  52 + * @date 2024/01/08 11:40
  53 + */
  54 + public function getMinorLanguagePage($project,$route,$source,$lang){
  55 + if($project['update_info']['is_language_update'] == 0){
  56 + return '';
  57 + }
  58 +
  59 + if ($source == 'news' || $source == 'blog' || $source == 'product' || $source == 'page' || $source == 'module'){
  60 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("source",$source)->first();
  61 + }elseif($source == ''){
  62 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->whereIn("source",["product","page","module"])->orderBy('source','desc')->first();
  63 + }else{
  64 + return '';
  65 + }
  66 +
  67 + if($routerMap) {
  68 + switch ($routerMap->source) {
  69 + //产品详情
  70 + case WebTemplateCommon::$productName:
  71 + $detail = Product::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
  72 + break;
  73 + //博客详情
  74 + case WebTemplateCommon::$blogName:
  75 + $detail = Blog::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
  76 + break;
  77 + //新闻详情
  78 + case WebTemplateCommon::$newsName:
  79 + $detail = News::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
  80 + break;
  81 + //自定义模块详情
  82 + case WebTemplateCommon::$extendName:
  83 + $detail = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
  84 + break;
  85 + default:
  86 + //单页详情
  87 + $detail = WebCustom::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
  88 + }
  89 + if($detail && $detail->six_read){
  90 + return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
  91 + }else{
  92 + return '';
  93 + }
  94 + }else{
  95 + return '';
  96 + }
  97 + }
  98 +
  99 + /**
  100 + * 根据语言,路由,分页数,获取页面内容
  101 + */
  102 + public function getPageByLangRoutePage($project,$route,$page=null,$source=""): string
  103 + {
  104 + $html = "";
  105 + $page = $page == null ? null : (int)$page;
  106 + $router = $route == "" ? "404" : $route;
  107 +
  108 + $productKeywordRouter = new Keyword();
  109 + $productKeywordRouters = $productKeywordRouter->product_keyword_route;
  110 + if (in_array($router, $productKeywordRouters)) {
  111 + $html = $this->getProductKeywordListPage($project,$router,$page);
  112 + unset($productKeywordRouter);
  113 + } else {
  114 + //新增:products,news,blog 三个路由为C端固定路由,数据库路由表没有路由也可以访问或调数据
  115 + if ($router == "products" || $router == "news" || $router == "blog"){
  116 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$router)->first();
  117 + $routerMapRegular = new stdClass();
  118 + if (empty($routerMap)){
  119 + if ($router == "products"){
  120 + $routerMapRegular->source = WebTemplateCommon::$productCategoryName;
  121 + $routerMapRegular->route = "products";
  122 + }
  123 + if ($router == "news"){
  124 + $routerMapRegular->source = WebTemplateCommon::$newsCategoryName;
  125 + $routerMapRegular->route = "news";
  126 + }
  127 + if ($router == "blog"){
  128 + $routerMapRegular->source = WebTemplateCommon::$blogCategoryName;
  129 + $routerMapRegular->route = "blog";
  130 + }
  131 + $routerMapRegular->source_id = 0;
  132 + $routerMapRegular->project_id = $project->id;
  133 + $routerMap = $routerMapRegular;
  134 + unset($routerMapRegular);
  135 + }
  136 + }else{
  137 + if ($project->update_info["is_update"] == 1){
  138 + if ($source != ""){
  139 + //$source可能值:news,blog,news_category,blog_category
  140 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$router)->where("source",$source)->first();
  141 + }else{
  142 + //product_category,product,page,product_keyword,module_category,module
  143 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$router)->whereIn("source",["product","product_category","page","module_category","module","product_keyword"])->orderByRaw("FIELD(source, 'product_category','product','module_category','module','page','product_keyword')")->first();
  144 + }
  145 + if (empty($routerMap)){
  146 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$router)->first();
  147 + }
  148 + }else{
  149 + //6.0
  150 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$router)->first();
  151 + }
  152 + }
  153 +
  154 + if (!empty($routerMap)){
  155 + $type = $routerMap->source;
  156 + switch ($type) {
  157 + //产品详情
  158 + case WebTemplateCommon::$productName:
  159 + $html = $this->getProductPage($project,$routerMap);
  160 + break;
  161 + //产品列表
  162 + case WebTemplateCommon::$productCategoryName:
  163 + $html = $this->getProductListPage($project,$routerMap,$page);
  164 + break;
  165 + //博客详情
  166 + case WebTemplateCommon::$blogName:
  167 + $html = $this->getBlogPage($project,$routerMap);
  168 + break;
  169 + //博客列表
  170 + case WebTemplateCommon::$blogCategoryName:
  171 + $html = $this->getBlogListPage($project,$routerMap,$page);
  172 + break;
  173 + //新闻详情
  174 + case WebTemplateCommon::$newsName:
  175 + $html = $this->getNewsPage($project,$routerMap);
  176 + break;
  177 + //新闻列表
  178 + case WebTemplateCommon::$newsCategoryName:
  179 + $html = $this->getNewsListPage($project,$routerMap,$page);
  180 + break;
  181 + //自定义模块列表
  182 + case WebTemplateCommon::$extendCategoryName:
  183 + $html = $this->getModuleListPage($project,$routerMap,$page);
  184 + break;
  185 + //自定义模块详情
  186 + case WebTemplateCommon::$extendName:
  187 + $html = $this->getModulePage($project,$routerMap);
  188 + break;
  189 + //聚合页
  190 + case WebTemplateCommon::$productKeywordName:
  191 + $html = $this->getProductKeywordPage($project,$routerMap);
  192 + break;
  193 + case WebTemplateCommon::$pageName:
  194 + if ($router == WebTemplateCommon::$indexName){
  195 + //首页
  196 + $html = $this->getIndexPage($project,$routerMap);
  197 + }else{
  198 + //单页面
  199 + $html = $this->getSinglePage($project,$routerMap);
  200 + }
  201 + break;
  202 + default:
  203 + $html = $this->getSinglePage($project,$routerMap);
  204 + }
  205 + }
  206 + }
  207 + return $html;
  208 + }
  209 +
  210 + /**
  211 + * 获取首页html
  212 + */
  213 + public function getIndexPage($project,$routerMap): string
  214 + {
  215 + $pageService = new PageService();
  216 + $commonService = new CommonService();
  217 + $tdkService = new TdkService();
  218 + //首页模板
  219 + $info = BSetting::where("project_id",$project->id)->first();
  220 + if (empty($info)){
  221 + return "";
  222 + }
  223 +
  224 + $webIndexTemplate = WebTemplate::where("project_id",$project->id)->where("template_id",$info->template_id)->where("source",1)->first();
  225 + if (!empty($webIndexTemplate)){
  226 + $html = $pageService->isAndGetVisualizationHtml($project,WebTemplateCommon::$indexName,$routerMap);
  227 + if ($html == ""){
  228 + //组装首页页面
  229 + $html = $pageService->assembleIndexPage($project,$webIndexTemplate);
  230 + }
  231 +
  232 +// $filePath = public_path("6666.html");
  233 +// file_put_contents($filePath, $html);
  234 +// dd(5656);
  235 + //公共处理
  236 + $html = $pageService->publicHtmlHandle($html,$project->id);
  237 + $isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$indexName);
  238 + if ((int)$isVisual == 1 || $isVisual == null){
  239 + //产品,产品分类,新闻,博客(section模板通用数据模块处理)
  240 + $html = $pageService->generalTemplateProcessingForDataModules($html,$project->id);
  241 + }
  242 + //第三方
  243 + $html = $commonService->thirdPartyCodeHandle($project,$html,WebTemplateCommon::$indexName);
  244 + //TDK处理
  245 + $html = $tdkService->pageTdkHandle($project,$html,WebTemplateCommon::$indexName,$routerMap);
  246 + //特殊首页模块处理
  247 +// $html = $pageService->specialIndexModuleHandle($project,$html);
  248 + //处理URL等,处理html链接a标签href
  249 + if (!empty($html)){
  250 + return $this->pageUrlHandle($project,$routerMap,$html);
  251 + }else{
  252 + return "";
  253 + }
  254 + }else{
  255 + return "";
  256 + }
  257 + }
  258 +
  259 + /**
  260 + * 获取产品列表页html
  261 + */
  262 + public function getProductListPage($project,$routerMap,$page): string
  263 + {
  264 + $pageService = new PageService();
  265 + $commonService = new CommonService();
  266 + $tdkService = new TdkService();
  267 + //公共拼接页面方法
  268 + $webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$productCategoryName,$routerMap);
  269 + //公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
  270 + $webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$productCategoryName,$routerMap,$page);
  271 + //是否开启可视化
  272 + $isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$productCategoryName);
  273 + if ((int)$isVisual == 1 || $isVisual == null){
  274 + //产品,产品分类,新闻,博客(section模板通用数据模块处理)
  275 + $webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
  276 + }
  277 + $webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$productCategoryName,$routerMap);
  278 + $webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
  279 + unset($pageService);
  280 + $html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routerMap->route);
  281 + //处理URL等,处理html链接a标签href
  282 + if (!empty($html)){
  283 + return $this->pageUrlHandle($project,$routerMap,$html,"",$page);
  284 + }else{
  285 + return "";
  286 + }
  287 + }
  288 +
  289 + /**
  290 + * 获取产品页html
  291 + */
  292 + public function getProductPage($project,$routerMap,$lang=''): string
  293 + {
  294 + $pageService = new PageService();
  295 + $commonService = new CommonService();
  296 + $products_detail = Product::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->whereNotNull('route')->first();
  297 + if($project['update_info']['is_update'] && $products_detail && $products_detail->six_read){
  298 + return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
  299 + }else{
  300 + $products_detail = $pageService->productDataHandle($project,$products_detail);
  301 + if (!empty($products_detail)){
  302 + //公共拼接页面方法
  303 + $webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$productName,$routerMap);
  304 + //公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
  305 + $webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,"product",$routerMap,null);
  306 + $isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$productName);
  307 + if ((int)$isVisual == 1 || $isVisual == null){
  308 + //产品,产品分类,新闻,博客(section模板通用数据模块处理)
  309 + $webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
  310 + }
  311 + $webCustomHtml = $pageService->productsDetailTdkHandle($project,$webCustomHtml,$products_detail);
  312 + $webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
  313 + unset($pageService);
  314 + $html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routerMap->route);
  315 + //处理URL等,处理html链接a标签href
  316 + if (!empty($html)){
  317 + return $this->pageUrlHandle($project,$routerMap,$html);
  318 + }else{
  319 + return "";
  320 + }
  321 + }else{
  322 + return "";
  323 + }
  324 + }
  325 + }
  326 +
  327 + /**
  328 + * 获取产品关键词页html
  329 + */
  330 + public function getProductKeywordPage($project,$routerMap): string
  331 + {
  332 + $pageService = new PageService();
  333 + $commonService = new CommonService();
  334 + $keywordModel = new Keyword();
  335 + $tdkService = new TdkService();
  336 + $routePath = $routerMap->route;
  337 +
  338 + //公共头部底部
  339 + $publicTemplate = $pageService->getPublicTemplate($project);
  340 + $headerHtml = $publicTemplate->headerHtml;
  341 + $footerHtml = $publicTemplate->footerHtml;
  342 + //关键词详情
  343 + $keywordsDetails = $pageService->getKeywordDetails($project, $routerMap->route);
  344 + if (!empty($keywordsDetails)){
  345 + if (!empty($keywordsDetails->embed_code)){
  346 + $videoUrl = $keywordsDetails->embed_code;
  347 + preg_match('/src="([^"]+)"/', $videoUrl, $matches);
  348 + $src = $matches[1];
  349 + $keywordsDetails->video = $src;
  350 + }
  351 + //随机获取关键词列表
  352 + $productsKeywordsList = $keywordModel->getProductsKeywordsList($project);
  353 + //调整为相关产品
  354 + $productsRecommendAndHot = $pageService->getRecommendAndHotProducts($project,$routePath);
  355 + //博客新闻数据
  356 + $blogT = $pageService->getProductsBlogNews($project);
  357 + $viewPath = isset($keywordsDetails->video) && !empty($keywordsDetails->video) ? "products/products_video_keywords" : "products/products_keywords";
  358 + $html = view($viewPath, compact("headerHtml", "footerHtml", "routePath", "productsKeywordsList", "productsRecommendAndHot", "blogT","keywordsDetails"))->__toString();
  359 + $html = $pageService->publicHtmlHandle($html, $project->id);
  360 + //生成静态页
  361 + $webCustomHtml = $commonService->thirdPartyCodeHandle($project, $html, $routerMap->route);
  362 + //TDK
  363 + unset($html,$productsKeywordsList,$productsRecommendAndHot,$blogT);
  364 + $html = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$productKeywordName,$routerMap);
  365 + //处理URL等,处理html链接a标签href
  366 + if (!empty($html)){
  367 + return $this->pageUrlHandle($project,$routerMap,$html);
  368 + }else{
  369 + return "";
  370 + }
  371 + }else{
  372 + return "";
  373 + }
  374 + }
  375 +
  376 + /**
  377 + * 获取产品新闻列表页html
  378 + */
  379 + public function getNewsListPage($project,$routerMap,$page): string
  380 + {
  381 + $pageService = new PageService();
  382 + $commonService = new CommonService();
  383 + $tdkService = new TdkService();
  384 + $routePath = $routerMap->route;
  385 + //公共拼接页面方法
  386 + $webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$newsCategoryName,$routerMap);
  387 + //公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
  388 + $webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$newsCategoryName,$routerMap,$page);
  389 + $isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$newsCategoryName);
  390 + if ((int)$isVisual == 1 || $isVisual == null){
  391 + //产品,产品分类,新闻,博客(section模板通用数据模块处理)
  392 + $webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
  393 + }
  394 + $webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$newsCategoryName,$routerMap);
  395 + $webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
  396 + unset($pageService);
  397 + $html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routePath);
  398 + //处理URL等,处理html链接a标签href
  399 + if (!empty($html)){
  400 + return $this->pageUrlHandle($project,$routerMap,$html,"",$page);
  401 + }else{
  402 + return "";
  403 + }
  404 +
  405 + }
  406 +
  407 + /**
  408 + * 自定义模块列表
  409 + */
  410 + public function getModuleListPage($project,$routerMap,$page): string
  411 + {
  412 + $pageService = new PageService();
  413 + $commonService = new CommonService();
  414 + $tdkService = new TdkService();
  415 + $routePath = $routerMap->route;
  416 + //公共拼接页面方法
  417 + $webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$extendCategoryName,$routerMap);
  418 + //公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
  419 + $webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$extendCategoryName,$routerMap,$page);
  420 + $moduleCategoryInfo = ModuleCategory::getModuleCategoryAndExtendById($project->id,$routerMap->source_id);
  421 + if (isset($moduleCategoryInfo->getExtend->list_visualization) && $moduleCategoryInfo->getExtend->list_visualization == 1){
  422 + //产品,产品分类,新闻,博客(section模板通用数据模块处理)
  423 + $webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
  424 + }
  425 +
  426 + $webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$extendCategoryName,$routerMap);
  427 + $webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
  428 + unset($pageService);
  429 + $html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routePath);
  430 + //处理URL等,处理html链接a标签href
  431 + if (!empty($html)){
  432 + return $this->pageUrlHandle($project,$routerMap,$html,"",$page);
  433 + }else{
  434 + return "";
  435 + }
  436 + }
  437 +
  438 + /**
  439 + * 获取产品新闻页html
  440 + */
  441 + public function getNewsPage($project,$routerMap,$lang=''): string
  442 + {
  443 + $pageService = new PageService();
  444 + $commonService = new CommonService();
  445 + $tdkService = new TdkService();
  446 + //页面路由
  447 + $routePath = $routerMap->route;
  448 + $news_detail = News::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
  449 + if (!empty($news_detail)){
  450 + if($project['update_info']['is_update'] && $news_detail->six_read){
  451 + return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
  452 + }else{
  453 + //公共拼接页面方法
  454 + $webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$newsName,$routerMap);
  455 + //公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
  456 + $webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$newsName,$routerMap,null);
  457 + $isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$newsName);
  458 + if ((int)$isVisual == 1 || $isVisual == null){
  459 + //产品,产品分类,新闻,博客(section模板通用数据模块处理)
  460 + $webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
  461 + }
  462 + //TDK处理
  463 + $webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$newsName,$routerMap);
  464 + //网页公共部分
  465 + $webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
  466 + unset($pageService);
  467 + $html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routePath);
  468 + //处理URL等,处理html链接a标签href
  469 + if (!empty($html)){
  470 + return $this->pageUrlHandle($project,$routerMap,$html);
  471 + }else{
  472 + return "";
  473 + }
  474 + }
  475 + }else{
  476 + return "";
  477 + }
  478 + }
  479 +
  480 + /**
  481 + * 自定义模块详情
  482 + */
  483 + public function getModulePage($project,$routerMap,$lang=''): string
  484 + {
  485 + $pageService = new PageService();
  486 + $commonService = new CommonService();
  487 + $tdkService = new TdkService();
  488 + //页面路由
  489 + $routePath = $routerMap->route;
  490 + $module_detail = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
  491 + if (!empty($module_detail)){
  492 + if($project['update_info']['is_update'] && $module_detail->six_read){
  493 + return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
  494 + }else{
  495 + //公共拼接页面方法
  496 + $webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$extendName,$routerMap);
  497 + //公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
  498 + $webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$extendName,$routerMap,null);
  499 + $moduleCategoryInfo = Module::getModuleCategory($project->id,$module_detail);
  500 + if (isset($moduleCategoryInfo->getExtend->detail_visualization) && $moduleCategoryInfo->getExtend->detail_visualization == 1){
  501 + //产品,产品分类,新闻,博客(section模板通用数据模块处理)
  502 + $webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
  503 + }
  504 + //TDK处理
  505 + $webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$extendName,$routerMap);
  506 + //网页公共部分
  507 + $webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
  508 + unset($pageService);
  509 + $html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routePath);
  510 + //处理URL等,处理html链接a标签href
  511 + if (!empty($html)){
  512 + return $this->pageUrlHandle($project,$routerMap,$html);
  513 + }else{
  514 + return "";
  515 + }
  516 + }
  517 + }else{
  518 + return "";
  519 + }
  520 + }
  521 +
  522 + /**
  523 + * 获取博客列表页html
  524 + */
  525 + public function getBlogListPage($project,$routerMap,$page): string
  526 + {
  527 + $pageService = new PageService();
  528 + $commonService = new CommonService();
  529 + $tdkService = new TdkService();
  530 + //公共拼接页面方法
  531 + $webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$blogCategoryName,$routerMap);
  532 + //公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
  533 + $webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$blogCategoryName,$routerMap,$page);
  534 + $isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$blogCategoryName);
  535 + if ((int)$isVisual == 1 || $isVisual == null){
  536 + //产品,产品分类,新闻,博客(section模板通用数据模块处理)
  537 + $webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
  538 + }
  539 + $webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$blogCategoryName,$routerMap);
  540 + $webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
  541 + unset($pageService);
  542 + $html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routerMap->route);
  543 + //处理URL等,处理html链接a标签href
  544 + if (!empty($html)){
  545 + return $this->pageUrlHandle($project,$routerMap,$html,"",$page);
  546 + }else{
  547 + return "";
  548 + }
  549 + }
  550 +
  551 + /**
  552 + * 获取博客页html
  553 + */
  554 + public function getBlogPage($project,$routerMap,$lang=''): string
  555 + {
  556 + $pageService = new PageService();
  557 + $commonService = new CommonService();
  558 + $tdkService = new TdkService();
  559 + $blog_detail = Blog::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
  560 + if (!empty($blog_detail)){
  561 + if($project['update_info']['is_update'] && $blog_detail->six_read){
  562 + return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
  563 + }else{
  564 + //公共拼接页面方法
  565 + $webCustomHtml = $pageService->publicMontagePage($project,WebTemplateCommon::$blogName,$routerMap);
  566 + //公共面包屑导航,左侧导航处理,内页banner背景图,列表页分页
  567 + $webCustomHtml = $pageService->publicMdAndLeftNavInnerImageListDetailsDataHandle($webCustomHtml,$project,WebTemplateCommon::$blogName,$routerMap,null);
  568 + $isVisual = $pageService->isOpenVisualization($project,WebTemplateCommon::$blogName);
  569 + if ((int)$isVisual == 1 || $isVisual == null){
  570 + //产品,产品分类,新闻,博客(section模板通用数据模块处理)
  571 + $webCustomHtml = $pageService->generalTemplateProcessingForDataModules($webCustomHtml,$project->id);
  572 + }
  573 + $webCustomHtml = $tdkService->pageTdkHandle($project,$webCustomHtml,WebTemplateCommon::$blogName,$routerMap);
  574 + $webCustomHtml = $pageService->publicHtmlHandle($webCustomHtml,$project->id);
  575 + unset($pageService);
  576 + //生成静态页
  577 + $html = $commonService->thirdPartyCodeHandle($project,$webCustomHtml,$routerMap->route);
  578 + //处理URL等,处理html链接a标签href
  579 + if (!empty($html)){
  580 + return $this->pageUrlHandle($project,$routerMap,$html);
  581 + }else{
  582 + return "";
  583 + }
  584 + }
  585 + }else{
  586 + return "";
  587 + }
  588 + }
  589 +
  590 + /**
  591 + * 获取单页面html
  592 + */
  593 + public function getSinglePage($project,$routerMap,$lang=''): string
  594 + {
  595 + $pageService = new PageService();
  596 + $commonService = new CommonService();
  597 + $tdkService = new TdkService();
  598 + //页面路由
  599 + $routePath = $routerMap->route;
  600 + $webCustom = WebCustom::where("id",$routerMap->source_id)->where("status",1)->first();
  601 + if (!empty($webCustom)){
  602 + if($project['update_info']['is_update'] && $webCustom->six_read){
  603 + return $this->getOldHtml($project,$routerMap,$project['update_info']['old_domain_test'],$project['update_info']['old_domain_online'],$lang);
  604 + }else{
  605 + //公共拼接页面方法
  606 + $content = $pageService->publicMontagePage($project,WebTemplateCommon::$pageName,$routerMap);
  607 + //公共左侧导航处理
  608 + $phpQueryDom=phpQuery::newDocument($content);
  609 + $pageService->leftNavSideNavHandle($project,WebTemplateCommon::$pageName,$phpQueryDom,$routerMap);
  610 + $content = $phpQueryDom->htmlOuter();
  611 + unset($phpQueryDom);
  612 + //产品,产品分类,新闻,博客(section模板通用数据模块处理)
  613 + $content = $pageService->generalTemplateProcessingForDataModules($content,$project->id);
  614 + //生成静态页
  615 + $content = $tdkService->pageTdkHandle($project,$content,WebTemplateCommon::$pageName,$routerMap);
  616 + $content = $pageService->publicHtmlHandle($content,$project->id);
  617 + unset($pageService);
  618 + $html = $commonService->thirdPartyCodeHandle($project,$content,$routePath,$routerMap);
  619 + //处理URL等,处理html链接a标签href
  620 + if (!empty($html)){
  621 + return $this->pageUrlHandle($project,$routerMap,$html);
  622 + }else{
  623 + return "";
  624 + }
  625 + }
  626 + }else{
  627 + return "";
  628 + }
  629 + }
  630 +
  631 + /**
  632 + * 获取关键词列表页面
  633 + */
  634 + public function getProductKeywordListPage($project,$router,$page): string
  635 + {
  636 + if (isset($router->route) && $router->route != null) {
  637 + $routePath = $router->route;
  638 + } else {
  639 + $routePath = $router;
  640 + }
  641 + //公共头部底部
  642 + $pageService = new PageService();
  643 + $commonService = new CommonService();
  644 + $publicTemplate = $pageService->getPublicTemplate($project);
  645 + $headerHtml = $publicTemplate->headerHtml;
  646 + $footerHtml = $publicTemplate->footerHtml;
  647 +
  648 + //获取字母开头关键词列表
  649 + $keywords = $pageService->getProductKeywordsByLetter($project,$router,$page);
  650 + $html = view("products/products_keywords_list",compact("headerHtml","footerHtml","keywords","routePath"))->__toString();
  651 + $html = $pageService->publicHtmlHandle($html, $project->id);
  652 + //生成静态页
  653 + $webCustomHtml = $commonService->thirdPartyCodeHandle($project, $html, $routePath);
  654 + //top-search TDK处理,分页link索引处理
  655 + $webCustomHtml = $pageService->productKeywordListTdkHandle($webCustomHtml,$project,$routePath,$keywords,$page);
  656 + //处理URL等,处理html链接a标签href
  657 + if (!empty($html)){
  658 + $webCustomHtml = $this->pageUrlHandle($project,$routePath,$webCustomHtml);
  659 + }else{
  660 + return "";
  661 + }
  662 + unset($keywords);
  663 + unset($html);
  664 + return $webCustomHtml;
  665 + }
  666 +
  667 + /**
  668 + * TODO:处理URL等,处理html链接a标签href,获取最终html
  669 + */
  670 + public function pageUrlHandle($project,$routerMap,$html,$lang="",$page=null): string
  671 + {
  672 + if (isset($routerMap->route) && $routerMap->route != null) {
  673 + $route = $routerMap->route;
  674 + } else {
  675 + $route = $routerMap;
  676 + }
  677 + $pageService = new PageService();
  678 + $phpQueryDom=phpQuery::newDocument($html);
  679 + $domainEnd = $project->domain_end;
  680 + //主站a链接处理
  681 + $this->masterWebATagHandle($phpQueryDom,$project,$domainEnd);
  682 +
  683 + //html 标签处理
  684 + $this->htmlTagHandle($phpQueryDom,$project);
  685 +
  686 + //888项目禁用鼠标右键点击,查看元素
  687 +// $this->prohibitRightMouseClick($phpQueryDom,$project);
  688 +
  689 + //国家
  690 + $webCountry = $pageService->getCountryList($project->id);
  691 +
  692 + //语种 alternate
  693 + $this->setHrefLang($phpQueryDom,$project,$route,$page,$lang,$webCountry);
  694 +
  695 + //以-tag的聚合页结尾的路由加上 <meta name="robots" content="noindex">
  696 + $this->setTagRobotsNoindex($phpQueryDom,$routerMap);
  697 +
  698 + //<meta name="cookie_consent_banner" content="参数值"> 配置
  699 + $this->setCookieConsentBanner($phpQueryDom,$project);
  700 +
  701 + $html = $phpQueryDom->htmlOuter();
  702 + unset($phpQueryDom);
  703 + phpQuery::unloadDocuments();
  704 +
  705 + //根据配置读取不同的资源路径功能
  706 + $html = $this->setResourcePath($project,$html);
  707 + //网站语种列表
  708 + return $pageService->publicCountryLanguageHandle($html,$project,$route);
  709 + }
  710 +
  711 + /**
  712 + * html 标签处理
  713 + */
  714 + public function htmlTagHandle($phpQueryDom,$project)
  715 + {
  716 + $phpQueryDom->find("html")->attr("dir","ltr");
  717 + $mainLang = WebLanguage::getProjectMainLang($project->main_lang_id);
  718 + if ($mainLang->short == "ru"){
  719 + $phpQueryDom->find('main .keyword_search')->remove();
  720 + }
  721 + $lang = $mainLang ? $mainLang->short : 'en';
  722 + $phpQueryDom->find("html")->attr("lang",$lang);
  723 + }
  724 +
  725 + /**
  726 + * 888项目禁用鼠标右键点击,查看元素
  727 + */
  728 + public function prohibitRightMouseClick($phpQueryDom,$project)
  729 + {
  730 + if ($project->id == 888){
  731 + $phpQueryDom->find("body")->attr("ondragstart","window.event.returnValue=false");
  732 + $phpQueryDom->find("body")->attr("oncontextmenu","window.event.returnValue=false");
  733 + $phpQueryDom->find("body")->attr("onselectstart","event.returnValue=false");
  734 + }
  735 + }
  736 +
  737 + /**
  738 + *主站a链接处理
  739 + */
  740 + public function masterWebATagHandle($phpQueryDom,$project,$domainEnd)
  741 + {
  742 + foreach ($phpQueryDom->find('a') as $a) {
  743 + $href = pq($a)->attr('href');
  744 + //a标签href字符串是否有http://或者https://等协议头,有的话不做处理
  745 + if (strpos($href, 'http://') !== false || strpos($href, 'https://') !== false || strpos($href, 'javascript') !== false || strpos($href, 'javasctipt') !== false || strpos($href, '#') !== false || empty($href) || strpos($href, '.zip') !== false || strpos($href, '.txt') !== false || strpos($href, 'tel:') !== false || strpos($href, 'mailto') !== false || strpos($href, '.pdf') !== false || strpos($href, '.tar') !== false || strpos($href, '.jpg') !== false || strpos($href, '.png') !== false || strpos($href, '.jpeg') !== false || strpos($href, '.xml') !== false || strpos($href, 'skype:') !== false || strpos($href, 'whatsapp:') !== false) {
  746 + $domain = $project->domain;
  747 + $domain = str_replace("http://","",$domain);
  748 + $domain = str_replace("https://","",$domain);
  749 + $domain = str_replace("/","",$domain);
  750 + $domainArr = parse_url($domain);
  751 + if (strpos($href, '#') !== false || strpos($href, '.xml') !== false){}else{
  752 + if (isset($domainArr["path"]) && !empty($domainArr["path"])){
  753 + if (strpos($href, 'http://') !== false || strpos($href, 'https://') !== false){
  754 + $domain = $domainArr["path"];
  755 + if (strpos($href, $domain) !== false){
  756 + $href = str_replace("http://","",$href);
  757 + $href = str_replace("https://","",$href);
  758 + $href = str_replace($domain,"",$href);
  759 + if ($domainEnd == Project::$domainEndSlash){
  760 + //以斜杠结尾
  761 + $href = substr($href, -1) === '/' ? $href : $href . "/";
  762 + }else{
  763 + //不以斜杠结尾
  764 + if (substr($href, -1) === '/') {
  765 + if ($href != "/"){
  766 + $href = rtrim($href, '/');
  767 + }
  768 + }
  769 + }
  770 + }
  771 + }
  772 + }
  773 + }
  774 + pq($a)->attr('href', $href);
  775 + }else{
  776 + if ($domainEnd == Project::$domainEndSlash){
  777 + //以斜杠结尾
  778 + $href = substr($href, -1) === '/' ? $href : $href . "/";
  779 + if (strpos($href, ".html") !== false || strpos($href, ".htm") !== false){
  780 + $href = rtrim($href, '/');
  781 + }
  782 + }else{
  783 + //不以斜杠结尾
  784 + if (substr($href, -1) === '/') {
  785 + if ($href != "/"){
  786 + $href = rtrim($href, '/');
  787 + }
  788 + }
  789 + }
  790 + }
  791 + pq($a)->attr('href', $href);
  792 + }
  793 + }
  794 +
  795 + /**
  796 + * <meta name="cookie_consent_banner" content="参数值"> 配置
  797 + */
  798 + public function setCookieConsentBanner($phpQueryDom,$project)
  799 + {
  800 + $deployBuildInfo = DeployBuild::where("project_id",$project->id)->first();
  801 + if (!empty($deployBuildInfo)){
  802 + $phpQueryDom->find('head')->append('<meta name="cookie_consent_banner" content="'.$deployBuildInfo->cookie_consent_banner.'">');
  803 + }
  804 + }
  805 +
  806 + /**
  807 + * 语种 alternate
  808 + */
  809 + public function setHrefLang($phpQueryDom,$project,$route,$page,$lang,$webCountry)
  810 + {
  811 + //处理源代码语言url
  812 + $countryUrl = [];
  813 + $createPageService = new CreatePageService();
  814 + $domain = $createPageService->domainHandle($project->domain);
  815 + $mainLang = WebLanguage::getProjectMainLang($project->main_lang_id);
  816 + if (!empty($webCountry)) {
  817 + foreach ($webCountry as $key => $item) {
  818 + //语种列表调整,新增自定义跳转链接
  819 + if (isset($item->country_custom) && !empty($item->country_custom)){
  820 + if ($item->country_custom->is_create == 1){
  821 + $page = (int)$page != null && (int)$page != 0 ? (int)$page . "/" : "";
  822 + if (!empty($mainLang) && $item->short != $mainLang->short){
  823 + $countryUrl[$key]["url"] = "https://" . $item->country_custom->custom_domain . "/" . $route . "/" . $page;
  824 + }else{
  825 + $countryUrl[$key]["url"] = "https://" . $domain . "/" . $route . "/" . $page;
  826 + }
  827 + }else{
  828 + $countryUrl[$key]["url"] = "https://" . $item->country_custom->custom_domain . "/";
  829 + }
  830 + $countryUrl[$key]["alias"] = $item->short;
  831 + }else{
  832 + if (!empty($mainLang) && $item->short != $mainLang->short){
  833 + $langShort = $item->short."/";
  834 + }else{
  835 + $langShort = "";
  836 + }
  837 + if ((int)$page != null) {
  838 + $countryUrl[$key]["url"] = "https://" . $domain . "/" .$langShort . $route . "/" . (int)$page . "/";
  839 + } else {
  840 + $countryUrl[$key]["url"] = $route == "index" ? "https://" . $domain . "/" . $langShort : "https://" . $domain . "/" . $langShort. $route . "/";
  841 + }
  842 + $countryUrl[$key]["alias"] = $item->short;
  843 + }
  844 +
  845 + //之前
  846 +// $langShort = $item->short == "en" ? "" : $item->short."/";
  847 +// if ((int)$page != null) {
  848 +// $countryUrl[$key]["url"] = "https://" . $domain . "/" .$langShort . $route . "/" . (int)$page . "/";
  849 +// } else {
  850 +// $countryUrl[$key]["url"] = $route == "index" ? "https://" . $domain . "/" . $langShort : "https://" . $domain . "/" . $langShort. $route . "/";
  851 +// }
  852 +// $countryUrl[$key]["alias"] = $item->short;
  853 + }
  854 + }
  855 +
  856 + //路径
  857 + if ($route == "index") {
  858 + $webUrl = "https://" . $domain . "/";
  859 + } else {
  860 + if ((int)$page != null || (int)$page != 0) {
  861 + if ($lang != "") {
  862 + $langShort = $lang == "en" ? "" : $lang."/";
  863 + $webUrl = "https://" . $domain . "/" .$langShort. $route . "/" . (int)$page . "/";
  864 + } else {
  865 + $webUrl = "https://" . $domain . "/" . $route . "/" . (int)$page . "/";
  866 + }
  867 + } else {
  868 + if ($lang != "") {
  869 + $langShort = $lang == "en" ? "" : $lang."/";
  870 + $webUrl = "https://" . $domain . "/" . $langShort . $route . "/";
  871 + } else {
  872 + $webUrl = "https://" . $domain . "/" . $route . "/";
  873 + }
  874 + }
  875 + }
  876 +
  877 + $phpQueryDom->find('head')->append("<meta property='og:url' content='$route'/>");
  878 + $phpQueryDom->find('head')->append("<link rel='canonical' href='$webUrl' />");
  879 + if (!empty($countryUrl)){
  880 + foreach ($countryUrl as $item){
  881 + if (isset($item['alias']) && isset($item['url'])){
  882 + $phpQueryDom->find('head')->append("<link rel='alternate' hreflang='".$item['alias']."' href='".$item['url']."'>");
  883 + }
  884 + }
  885 + }
  886 + }
  887 +
  888 + /**
  889 + * 以-tag的聚合页结尾的路由加上 <meta name="robots" content="noindex">
  890 + */
  891 + public function setTagRobotsNoindex($phpQueryDom,$routerMap)
  892 + {
  893 + if (isset($routerMap->source) && $routerMap->source == WebTemplateCommon::$productKeywordName){
  894 + $routerSuffix = substr($routerMap->route, -4);
  895 + $routerLength = strlen($routerMap->route);
  896 + if ($routerLength >= 4 && $routerSuffix == "-tag"){
  897 + $phpQueryDom->find('head')->append('<meta name="robots" content="noindex,nofollow">');
  898 + }
  899 + }
  900 + }
  901 +
  902 + /**
  903 + * 配置资源路径
  904 + */
  905 + public function setResourcePath($project,$html)
  906 + {
  907 + $projectLocation = $project->project_location;
  908 + $storageType = $project->storage_type;
  909 + if ($projectLocation == Project::$projectLocationZero){
  910 + //普通项目
  911 + if ($storageType == Project::$storageTypeZero){
  912 + //压缩项目
  913 + $html = str_replace(Project::$storageTypeOneFileFix,Project::$storageTypeZeroFileFix,$html);
  914 + }else{
  915 + //非压缩项目
  916 + $html = str_replace(Project::$storageTypeZeroFileFix,Project::$storageTypeOneFileFix,$html);
  917 + }
  918 + }else{
  919 + //危险项目
  920 + $html = str_replace(Project::$storageTypeOneFileFix,Project::$projectLocationDangerousFileFix,$html);
  921 + $html = str_replace(Project::$storageTypeZeroFileFix,Project::$projectLocationDangerousFileFix,$html);
  922 + }
  923 + return $html;
  924 + }
  925 +
  926 + /**
  927 + * 放入文件
  928 + */
  929 + public function putHtmlToPageFile($project,$lang,$route,$page,$html,$routeType=""): bool
  930 + {
  931 + if (empty($html) || $html == ""){
  932 + return true;
  933 + }
  934 + if (strpos($route, '.php') !== false || strpos($route, '.env') !== false || strpos($route, '.jpg') !== false || strpos($route, '.asp') !== false || strpos($route, '.png') !== false || strpos($route, '.gif') !== false ){
  935 + return true;
  936 + }
  937 + $domain = $project->domain;
  938 + $domain = str_replace("https://","",$domain);
  939 + $domain = str_replace("http://","",$domain);
  940 + $domain = str_replace("/","",$domain);
  941 + $originLang = $lang;
  942 + $lang = $lang == "zh-TW" ? "zh-ct" : $lang;
  943 + $lang = $lang=="" ? "" : "/".$lang;
  944 + $page = $page == null || (int)$page == 1 ? null : "/".(int)$page;
  945 +
  946 + //是否是5.0升级项目
  947 + if (isset($project->update_info["is_update"]) && $project->update_info["is_update"] == 1){
  948 + //5.0生成路径
  949 + $path = $this->getProjectRoutePath5($project,$domain,$route,$routeType,$lang,$page);
  950 + }else{
  951 + //6.0生成路径
  952 + $path = $this->getProjectRoutePath6($project,$domain,$route,$routeType,$lang,$page);
  953 + }
  954 + try {
  955 + //$filePath = iconv("UTF-8", "GBK", $path);
  956 + $filePath = $path;
  957 + if (!file_exists(public_path($filePath))) {
  958 + mkdir(public_path($filePath), 0777, true);
  959 + }
  960 + if (strpos($route, ".html") !== false || strpos($route, ".htm") !== false) {
  961 + file_put_contents(public_path($filePath . ".html"), $html);
  962 + chmod(public_path($filePath . ".html"), 0777);
  963 + }else{
  964 + file_put_contents(public_path($filePath . "/index.html"), $html);
  965 + chmod(public_path($filePath . "/index.html"), 0777);
  966 + }
  967 + } catch (\Exception $e) {
  968 + return true;
  969 + }
  970 +
  971 + return true;
  972 + }
  973 +
  974 + /**
  975 + * 6.0生成路径
  976 + */
  977 + public function getProjectRoutePath6($project,$domain,$route,$routeType,$lang,$page): string
  978 + {
  979 + if ($routeType == "news" || $routeType == "blogs"){
  980 + if ($routeType == "blogs"){
  981 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->whereIn('path', ['blog','blogs',''])->first();
  982 + }else{
  983 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path",$routeType)->first();
  984 + }
  985 + }else{
  986 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->first();
  987 + }
  988 + if (!empty($routerMap)){
  989 + if ($routerMap->source == "news"){
  990 + $route = "/news/".$route;
  991 + }elseif($routerMap->source == "blog"){
  992 + $route = "/blogs/".$route;
  993 + }elseif($routerMap->source == "module"){
  994 + $modules = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
  995 + $moduleCategoryInfo = Module::getModuleCategory($project->id,$modules);
  996 + if (isset($moduleCategoryInfo->route) && !empty($moduleCategoryInfo->route)){
  997 + $route = "/".$moduleCategoryInfo->route."/".$route;
  998 + }
  999 + }else{
  1000 + $route = $route == "index" ? "" : "/".$route;
  1001 + }
  1002 + }else{
  1003 + $route = $route == "index" ? "" : "/".$route;
  1004 + }
  1005 + $route = str_replace(".html","",$route);
  1006 + $route = str_replace(".htm","",$route);
  1007 + return $domain.$lang.$route.$page;
  1008 + }
  1009 +
  1010 + /**
  1011 + * 5.0生成路径
  1012 + */
  1013 + public function getProjectRoutePath5($project,$domain,$route,$routeType,$lang,$page): string
  1014 + {
  1015 + if ($routeType == "news" || $routeType == "blogs"){
  1016 + if ($routeType == "blogs"){
  1017 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->whereIn('path', ['blog','blogs',''])->first();
  1018 + }else{
  1019 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path",$routeType)->first();
  1020 + }
  1021 + }else{
  1022 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path","")->first();
  1023 + if (empty($routerMap)){
  1024 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->first();
  1025 + }
  1026 + }
  1027 + if (!empty($routerMap)){
  1028 + if ($routerMap->source == "news"){
  1029 + $route = "/news/".$route;
  1030 + }elseif($routerMap->source == "blog" || $routerMap->source == "blogs"){
  1031 + $route = "/blogs/".$route;
  1032 + }elseif ($routerMap->source == "news_category"){
  1033 + if ($route == "news"){
  1034 + $route = $page == null || $page == 1 ? "/".$route : "/".$route . "/page";
  1035 + }else{
  1036 + $route = $page == null || $page == 1 ? "/news_catalog/".$route : "/news_catalog/".$route."/page";
  1037 + }
  1038 + }elseif ($routerMap->source == "blog_category"){
  1039 + if ($route == "blog"){
  1040 + $route = $page == null || $page == 1 ? "/".$route : "/".$route."/page";
  1041 + }else{
  1042 + $route = $page == null || $page == 1 ? "/blog_catalog/".$route : "/blog_catalog/".$route."/page";
  1043 + }
  1044 + }elseif ($routerMap->source == "product_category"){
  1045 + $route = $page == null || $page == 1 ? "/".$route : "/".$route."/page";
  1046 + }elseif ($routerMap->source == "module_category"){
  1047 + $moduleCategory = ModuleCategory::getModuleCategoryAndExtendById($project->id,$routerMap->source_id);
  1048 + if (!empty($moduleCategory->getExtend->route)){
  1049 + if ($moduleCategory->getExtend->route == $route){
  1050 + $route = "/".$moduleCategory->route;
  1051 + }else{
  1052 + $route = "/".$moduleCategory->getExtend->route."_catalog/".$moduleCategory->route."/page";
  1053 + }
  1054 + }else{
  1055 + $route = "/".$moduleCategory->route."/page";
  1056 + }
  1057 + }elseif ($routerMap->source == "module"){
  1058 + $modules = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
  1059 + $moduleCategoryInfo = Module::getModuleCategory($project->id,$modules);
  1060 + if (isset($moduleCategoryInfo->getExtend->route) && !empty($moduleCategoryInfo->getExtend->route)){
  1061 + $route = "/".$moduleCategoryInfo->route."/".$modules->route;
  1062 + }else{
  1063 + $route = "/".$modules->route;
  1064 + }
  1065 + }else{
  1066 + $route = $route == "index" ? "" : "/".$route;
  1067 + }
  1068 + }else{
  1069 + if ($route == "products"){
  1070 + if ($page == null || $page == 1){
  1071 + $route = "/".$route;
  1072 + }else{
  1073 + $route = "/".$route."/page";
  1074 + }
  1075 + }elseif ($route == "news"){
  1076 + $route = $page == null || $page == 1 ? "/".$route : "/".$route;
  1077 + }elseif ($route == "blog"){
  1078 + $route = $page == null || $page == 1 ? "/blog_catalog/".$route : "/blog_catalog/".$route."/page";
  1079 + }else{
  1080 + $route = $route == "index" ? "" : "/".$route;
  1081 + }
  1082 + }
  1083 + $route = str_replace(".html","",$route);
  1084 + $route = str_replace(".htm","",$route);
  1085 + return $domain.$lang.$route.$page;
  1086 + }
  1087 +
  1088 + /**
  1089 + * 从主站拿页面
  1090 + */
  1091 + public function getHtmlToPageFile($project,$lang,$route,$page,$routeType = "")
  1092 + {
  1093 + $domain = $project->domain;
  1094 + $domain = str_replace("https://","",$domain);
  1095 + $domain = str_replace("http://","",$domain);
  1096 + $domain = str_replace("/","",$domain);
  1097 + $lang = $lang=="" ? "" : "/".$lang;
  1098 + $page = $page == null || (int)$page == 1 ? null : "/".(int)$page;
  1099 +
  1100 + //是否是5.0升级项目
  1101 + if (isset($project->update_info["is_update"]) && $project->update_info["is_update"] == 1){
  1102 + //取5.0生成路径
  1103 + $path = $this->getProjectRoutePagePath5($project,$domain,$route,$routeType,$lang,$page);
  1104 + }else{
  1105 + //取6.0生成路径
  1106 + $path = $this->getProjectRoutePagePath6($project,$domain,$route,$routeType,$lang,$page);
  1107 + }
  1108 +
  1109 + try {
  1110 + $filePath = iconv("UTF-8", "GBK", $path);
  1111 + if (file_exists(public_path($filePath . "/index.html"))) {
  1112 + $html = file_get_contents(public_path($filePath . "/index.html"));
  1113 + }else{
  1114 + $html = "";
  1115 + }
  1116 + } catch (\Exception $e) {
  1117 + $html = "";
  1118 + }
  1119 + return $html;
  1120 + }
  1121 +
  1122 + /**
  1123 + * 拿6.0页面
  1124 + */
  1125 + public function getProjectRoutePagePath6($project,$domain,$route,$routeType,$lang,$page): string
  1126 + {
  1127 + if ($routeType == "news" || $routeType == "blogs"){
  1128 + if ($routeType == "blogs"){
  1129 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->whereIn('path', ['blog','blogs',''])->first();
  1130 + }else{
  1131 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path",$routeType)->first();
  1132 + }
  1133 +
  1134 + }else{
  1135 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path","")->first();
  1136 + if (empty($routerMap)){
  1137 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->first();
  1138 + }
  1139 + }
  1140 + if (!empty($routerMap)){
  1141 + if ($routerMap->source == "news"){
  1142 + $route = "/news/".$route;
  1143 + }elseif($routerMap->source == "blog"){
  1144 + $route = "/blogs/".$route;
  1145 + }elseif($routerMap->source == "module"){
  1146 + $modules = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
  1147 + $moduleCategoryInfo = Module::getModuleCategory($project->id,$modules);
  1148 + if (isset($moduleCategoryInfo->route) && !empty($moduleCategoryInfo->route)){
  1149 + $route = "/".$moduleCategoryInfo->route."/".$route;
  1150 + }
  1151 + }else{
  1152 + $route = $route == "index" ? "" : "/".$route;
  1153 + }
  1154 + }else{
  1155 + $route = $route == "index" ? "" : "/".$route;
  1156 + }
  1157 + return $domain.$lang.$route.$page;
  1158 + }
  1159 +
  1160 + /**
  1161 + * 拿5.0页面
  1162 + */
  1163 + public function getProjectRoutePagePath5($project,$domain,$route,$routeType,$lang,$page): string
  1164 + {
  1165 + if ($routeType == "news" || $routeType == "blogs"){
  1166 + if ($routeType == "blogs"){
  1167 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->whereIn('path', ['blog','blogs',''])->first();
  1168 + }else{
  1169 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path",$routeType)->first();
  1170 + }
  1171 +
  1172 + }else{
  1173 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->where("path","")->first();
  1174 + if (empty($routerMap)){
  1175 + $routerMap = RouteMap::where("project_id",$project->id)->where("route",$route)->first();
  1176 + }
  1177 + }
  1178 + if (!empty($routerMap)){
  1179 + if ($routerMap->source == "news"){
  1180 + $route = "/news/".$route;
  1181 + }elseif($routerMap->source == "blog" || $routerMap->source == "blogs"){
  1182 + $route = "/blogs/".$route;
  1183 + }elseif ($routerMap->source == "news_category"){
  1184 + $route = "/news_catalog/".$route."/page";
  1185 + }elseif ($routerMap->source == "blog_category"){
  1186 + $route = "/blog_catalog/".$route."/page";
  1187 + }elseif ($routerMap->source == "product_category"){
  1188 + $route = "/".$route."/page";
  1189 + }elseif ($routerMap->source == "module"){
  1190 + $modules = Module::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",0)->first();
  1191 + $moduleCategoryInfo = Module::getModuleCategory($project->id,$modules);
  1192 + if (isset($moduleCategoryInfo->getExtend->route) && !empty($moduleCategoryInfo->getExtend->route)){
  1193 + $route = "/".$moduleCategoryInfo->getExtend->route."_catalog/".$moduleCategoryInfo->route."/page";
  1194 + }else{
  1195 + $route = "/extend_catalog/".$moduleCategoryInfo->route."/page";
  1196 + }
  1197 + }else{
  1198 + $route = $route == "index" ? "" : "/".$route;
  1199 + }
  1200 + }else{
  1201 + $route = $route == "index" ? "" : "/".$route;
  1202 + }
  1203 + return $domain.$lang.$route.$page;
  1204 + }
  1205 +
  1206 + /**
  1207 + * 翻译
  1208 + */
  1209 + public function translateWebPage($project,$html,$lang,$domain,$route="",$page=null,$countryLang=null): string
  1210 + {
  1211 + if (empty($html) || $html == ""){
  1212 + return $html;
  1213 + }
  1214 + $staticHtmlRepository = new StaticHtmlRepository();
  1215 + try {
  1216 +//非主站处理html语言
  1217 + $htmlOld = $this->langUrlHandle($project,$lang,$html,$route,$page,$countryLang);
  1218 + $phpQueryDomOld = phpQuery::newDocument($htmlOld);
  1219 + $langDomContent = $phpQueryDomOld->find("header .change-language")->eq(0)->html();
  1220 + $footerFormDomContent = $phpQueryDomOld->find(".form-footer-inquiry-block")->eq(0)->html();
  1221 + $mainFormDomContent = $phpQueryDomOld->find(".section-form-wrap-block")->eq(0)->html();
  1222 + $popFormDomContent = $phpQueryDomOld->find(".pop-box.inquiry-box")->eq(0)->html();
  1223 + $topSearchDomContent = $phpQueryDomOld->find("main .top-search-title-first-letter-list")->eq(0)->html();
  1224 + $langDomContent5 = $phpQueryDomOld->find(".prisna-wp-translate-seo")->eq(0)->html();
  1225 + unset($phpQueryDomOld);
  1226 + phpQuery::unloadDocuments();
  1227 +
  1228 + $newHtml = "";
  1229 + if ($lang != '') {
  1230 + //翻译测试成功,用下面第二红最新翻译
  1231 +// 第一种翻译
  1232 +// $commonService = new CommonService();
  1233 +// $htmlNew = $commonService->webHtmlTranslate($project,$htmlOld,$lang,$domain);
  1234 +// 第二种翻译
  1235 + $htmlNew = $staticHtmlRepository->getTranHtml($project,$htmlOld,$lang,$route,$page);
  1236 + $phpQueryDomNew = phpQuery::newDocument($htmlNew);
  1237 + unset($htmlOld);
  1238 + $phpQueryDomNew->find("header .change-language")->eq(0)->html($langDomContent);
  1239 + //取消根据翻译状态,翻译tag状态显示主站小语种列表功能(2024.02.27)
  1240 +// $phpQueryDomNew->find("header div[data-module=2]")->find(".change-language-cont")->removeAttr("style");
  1241 + $phpQueryDomNew->find(".form-footer-inquiry-block")->eq(0)->html($footerFormDomContent);
  1242 + $phpQueryDomNew->find(".section-form-wrap-block")->eq(0)->html($mainFormDomContent);
  1243 + $phpQueryDomNew->find(".pop-box.inquiry-box")->eq(0)->html($popFormDomContent);
  1244 + $phpQueryDomNew->find("main .top-search-title-first-letter-list")->eq(0)->html($topSearchDomContent);
  1245 + $phpQueryDomNew->find(".prisna-wp-translate-seo")->eq(0)->html($langDomContent5);
  1246 + $newHtml = $phpQueryDomNew->htmlOuter();
  1247 + unset($phpQueryDomNew,$htmlNew,$langDomContent,$footerFormDomContent,$mainFormDomContent,$popFormDomContent);
  1248 + }
  1249 + phpQuery::unloadDocuments();
  1250 + } catch (\Exception $e) {
  1251 + $newHtml = $staticHtmlRepository->getTranHtml($project,$html,$lang,$route,$page);
  1252 + }
  1253 +
  1254 + return $newHtml;
  1255 + }
  1256 +
  1257 + /**
  1258 + * 小语种url处理
  1259 + */
  1260 + public function langUrlHandle($project,$lang,$html,$route="",$page=null,$countryLang=null)
  1261 + {
  1262 +// $html = str_replace("\n","",$html);
  1263 + $content = $html;
  1264 + //主站翻译,不进行小语种链接和页面处理
  1265 + if ($project->is_lang_translate == 1){
  1266 + $langInfo = WebLanguage::getProjectMainLang($project->main_lang_id);
  1267 + if ($langInfo->short == $lang){
  1268 + return $content;
  1269 + }
  1270 + }
  1271 + //当前语言国徽背景图片处理
  1272 + if ($lang != ""){
  1273 + $oldLang = $lang;
  1274 + $oldRoute = $route;
  1275 + $phpQueryDom = phpQuery::newDocument($content);
  1276 + //去掉小语种搜索框
  1277 + $phpQueryDom->find("header .search")->remove();
  1278 + $phpQueryDom->find("header .btn--search")->remove();
  1279 + $phpQueryDom->find("header .btn-search")->remove();
  1280 + $phpQueryDom->find("header .head-search")->remove();
  1281 +
  1282 + $page = $page == null ? "" : $page."/";
  1283 + $route = $route == "index" || $route == "" ? "" : $route."/";
  1284 + $lang = $lang."/";
  1285 + $langUrl = "https://".$project->domain."/".$lang.$route.$page;
  1286 + $phpQueryDom->find("link[rel=canonical]")->attr("href",$langUrl);
  1287 +
  1288 + //翻译版块当前小语种显示
  1289 + $countryDom = $phpQueryDom->find("header div[data-module=2]");
  1290 + $langInfo = WebLanguage::where("short",$oldLang)->first();
  1291 + if (!empty($langInfo)){
  1292 + $countryDom->find(".change-language-title span")->text($langInfo->english);
  1293 + }
  1294 + $oldTwLang = $oldLang == "zh-ct" ? "zh-TW" : $oldLang;
  1295 + $countryDom->find(".change-language-title .country-flag")->attr("class","country-flag language-flag-".$oldTwLang);
  1296 +
  1297 + //html 标签处理
  1298 + if ($oldLang == "ar" || $oldLang == "ug"){
  1299 + $phpQueryDom->find("html")->attr("dir","rtl");
  1300 + }else{
  1301 + $phpQueryDom->find("html")->attr("dir","ltr");
  1302 + }
  1303 +
  1304 + $phpQueryDom->find("html")->attr("lang",$oldLang);
  1305 + //1:2级目录 2:2级域名
  1306 + $linkingFormat = 1;
  1307 + $mainLang = null;
  1308 + $projectBuild = $project->deployBuild;
  1309 + if (!empty($projectBuild)){
  1310 + $linkingFormat = $projectBuild->linking_format;
  1311 + }
  1312 +
  1313 + if (isset($project->main_lang_id) && !empty($project->main_lang_id)){
  1314 + $mainLang = WebLanguage::getProjectMainLang($project->main_lang_id);
  1315 + }
  1316 + //小语种自定义跳转
  1317 + $countryCustomInfo = CountryCustom::getCountryCustomByProjectId($project->id);
  1318 + $countryCustomInfoNew = [];
  1319 + if (!empty($countryCustomInfo)){
  1320 + foreach ($countryCustomInfo as $countryCustomInfoItem){
  1321 + if (isset($countryCustomInfoItem->country_custom_language->short)){
  1322 + $countryCustomInfoNew[$countryCustomInfoItem->country_custom_language->short]["custom_domain"] = $countryCustomInfoItem->custom_domain;
  1323 + }
  1324 + }
  1325 + }
  1326 + // 1、处理A标签跳过图标 2、获取图标HTML a标签处理完成 还原图标HTML
  1327 + //a标签路径问题
  1328 + foreach ($phpQueryDom->find('a') as $a) {
  1329 + $class =pq($a)->attr('class');
  1330 + if (strpos($class, 'language-flag') !== false){
  1331 + continue;
  1332 + }
  1333 + $href = pq($a)->attr('href');
  1334 + //a标签href字符串是否有http://或者https://等协议头,有的话不做处理
  1335 + if (strpos($href, 'http://') !== false || strpos($href, 'https://') !== false || strpos($href,'javascript') !== false || strpos($href, 'javasctipt') !== false || $href == "#" || empty($href) || strpos($href, '.zip') !== false || strpos($href, '.txt') !== false || strpos($href, 'tel:') !== false || strpos($href, 'mailto') !== false || strpos($href, '.pdf') !== false || strpos($href, '.tar') !== false || strpos($href, '.jpg') !== false || strpos($href, '.png') !== false || strpos($href, '.jpeg') !== false || strpos($href, '.xml') !== false || strpos($href, 'skype:') !== false || strpos($href, 'whatsapp:') !== false) {
  1336 + }else{
  1337 + if ($lang != ''){
  1338 + if (!empty($mainLang)){
  1339 + if ($lang != $mainLang->short){
  1340 + //小语种自定义链接
  1341 + if (isset($countryCustomInfoNew[$oldLang])){
  1342 + continue;
  1343 + }
  1344 + if ($linkingFormat == 1){
  1345 + $hrefNew = '/'.$lang . ltrim($href, '/');
  1346 + }else{
  1347 + $hrefNew = '/' . ltrim($href, '/');
  1348 + }
  1349 + }else{
  1350 + $hrefNew = '/' . ltrim($href, '/');
  1351 + }
  1352 + pq($a)->attr('href', $hrefNew);
  1353 + }
  1354 + }
  1355 + }
  1356 + }
  1357 +
  1358 + $data = date("Y-m-d H:i:s");
  1359 + $phpQueryDom->find('html')->append("<!-- Globalso translate Cache file was created on ".$data." -->");
  1360 + $content = $phpQueryDom->htmlOuter();
  1361 + unset($html,$phpQueryDom);
  1362 + phpQuery::unloadDocuments();
  1363 + return $content;
  1364 + }
  1365 + return $content;
  1366 + }
  1367 +
  1368 + /**
  1369 + * 生成robots
  1370 + * @param Project $project
  1371 + * @return bool
  1372 + */
  1373 + public function createRobots($project)
  1374 + {
  1375 + if (!empty($project)){
  1376 + $robotTxtPath = public_path($project->domain."/robots.txt");
  1377 + $createSitemapService = new CreateSitemapService();
  1378 + //A端是否开启允许robots爬虫爬取
  1379 + if ($project->robots == 0){
  1380 + $sitemapContent = $this->getRefuseRobotsStr($project->domain);
  1381 + }else{
  1382 + $sitemapContent = $this->getAllowRobotsStr($project->domain);
  1383 + }
  1384 + $domainPath = public_path($project->domain);
  1385 + if (!file_exists($domainPath)){
  1386 + mkdir($domainPath, 0777, true);
  1387 + }
  1388 + $res = $createSitemapService->putSitemapFile($robotTxtPath,$sitemapContent);
  1389 + if ($res){
  1390 + return true;
  1391 + }
  1392 + }
  1393 + return true;
  1394 + }
  1395 +
  1396 + /**
  1397 + * 生成允许爬虫爬取robots内容
  1398 + * @param $domain
  1399 + * @return string
  1400 + */
  1401 + public function getAllowRobotsStr($domain)
  1402 + {
  1403 + $domain_arr = config('custom.robots_disallow_domain');
  1404 + $disallow = '';
  1405 + if (in_array($domain, $domain_arr)) {
  1406 + $langArr = WebLanguage::pluck('short');
  1407 + foreach ($langArr as $val) {
  1408 + if ($val == 'en')
  1409 + continue;
  1410 + $disallow .= 'Disallow: /' . $val . '/' . PHP_EOL;
  1411 + }
  1412 + }
  1413 + $trans_string = is_file(public_path($domain . '/trans_sitemap.xml')) ? "Sitemap: https://".$domain."/trans_sitemap.xml" : '';
  1414 + return "User-agent: *
  1415 +Allow: /
  1416 +Disallow: /404/
  1417 +
  1418 +".$disallow."
  1419 +User-agent: MSNBot
  1420 +Disallow: /
  1421 +User-agent: YoudaoBot
  1422 +Disallow: /
  1423 +User-agent: JikeSpider
  1424 +Disallow: /
  1425 +User-agent: EasouSpider
  1426 +Disallow: /
  1427 +User-agent: AhrefsBot
  1428 +Disallow: /
  1429 +User-agent: MJ12bot
  1430 +Disallow: /
  1431 +User-agent: YYSpider
  1432 +Disallow: /
  1433 +User-agent: Teoma
  1434 +Disallow: /
  1435 +User-agent: rogerbot
  1436 +Disallow: /
  1437 +User-agent: exabot
  1438 +Disallow: /
  1439 +User-agent: DotBot
  1440 +Disallow: /
  1441 +User-agent: gigabot
  1442 +Disallow: /
  1443 +User-agent: BLEXBot
  1444 +Disallow: /
  1445 +User-agent: DOCOMO Sprider
  1446 +Disallow: /
  1447 +User-agent: Applebot
  1448 +Disallow: /
  1449 +User-agent: SeznamBot
  1450 +Disallow: /
  1451 +User-agent: SemrushBot
  1452 +Disallow: /
  1453 +
  1454 +Sitemap: https://".$domain."/sitemap.xml
  1455 +$trans_string";
  1456 + }
  1457 +
  1458 + /**
  1459 + * 获取允许爬虫爬取robots内容
  1460 + */
  1461 + public function getRefuseRobotsStr($domain): string
  1462 + {
  1463 + return "User-agent: *
  1464 +Disallow: /";
  1465 + }
  1466 +
  1467 + /**
  1468 + * 升级项目,并且以老版本展示
  1469 + * @param $project
  1470 + * @param $routerMap
  1471 + * @param $old_domain_test
  1472 + * @param $old_domain_online
  1473 + * @param $language
  1474 + * @return string
  1475 + * @author Akun
  1476 + * @date 2023/11/29 14:52
  1477 + */
  1478 + public function getOldHtml($project, $routerMap, $old_domain_test, $old_domain_online, $language=''){
  1479 + $collect_info = CollectTask::where('project_id',$project->id)->where('language',$language)->where('source',$routerMap->source)->where('source_id',$routerMap->source_id)->where('status',CollectTask::STATUS_COM)->first();
  1480 + if($collect_info){
  1481 + $html = $collect_info->html;
  1482 + if(strpos($html,'404 Not Found') !== false){
  1483 + return '';
  1484 + }
  1485 + //替换域名
  1486 + $html = str_replace("http://".$old_domain_test,"",$html);
  1487 + $html = str_replace("https://".$old_domain_test,"",$html);
  1488 + $html = str_replace("http://".$old_domain_online,"",$html);
  1489 + $html = str_replace("https://".$old_domain_online,"",$html);
  1490 +// //暂时隐藏小语种
  1491 +// $html = str_replace('<div class="change-language ensemble">','<div class="change-language ensemble" style="display: none">',$html);
  1492 +// $html = str_replace('<div class="language_more">','<div class="language_more" style="display: none">',$html);
  1493 + //处理搜索
  1494 + preg_match_all('/<form\s+[^>]*?action\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_search);
  1495 + $search = $result_search[2] ?? [];
  1496 + foreach ($search as $vc) {
  1497 + if((strpos($vc,'search.php') !== false) || (strpos($vc,'index.php') !== false)){
  1498 + $html = str_replace($vc,'/search/',$html);
  1499 + }
  1500 + }
  1501 + //增加统计代码
  1502 + $html = str_replace('</body>','<script src="https://ecdn6.globalso.com/public/customerVisit.min.js"></script></body>',$html);
  1503 + return $html;
  1504 + }else{
  1505 + return '';
  1506 + }
  1507 + }
  1508 +
  1509 + /**
  1510 + * 更新获取路由
  1511 + */
  1512 + public function getRouters($updateNotifyData,$pageNum): array
  1513 + {
  1514 + $routers = null;
  1515 + $perPage = 100;
  1516 + $offset = ($pageNum - 1) * $perPage;
  1517 + $updateNotifyQuery = UpdateHtmlModel::where("project_id",$updateNotifyData->project_id);
  1518 + if ($updateNotifyData->route == Notify::ROUTE_ALL){
  1519 + //所有更新
  1520 + if ($updateNotifyData->type == Notify::TYPE_MASTER){
  1521 + $updateNotifyQuery->where("status","<",2)->update(['status' => 2]);
  1522 + $routers = RouteMap::where("project_id",$updateNotifyData->project_id)->offset($offset)->limit($perPage)->get()->sortBy(function($item) {
  1523 + return array_search($item->source, ['page', 'product_category', 'product', 'news_category', 'news', 'blog_category', 'blog', 'product_keyword']);
  1524 + });
  1525 + }else{
  1526 + $updateNotifyQuery->where("minor_languages_status","<",2)->update(['minor_languages_status' => 2]);
  1527 + $routers = RouteMap::where("project_id",$updateNotifyData->project_id)->where("source","!=","product_keyword")->offset($offset)->limit($perPage)->get()->sortBy(function($item) {
  1528 + return array_search($item->source, ['page', 'product_category', 'product', 'news_category', 'news', 'blog_category', 'blog']);
  1529 + });
  1530 + }
  1531 + }else if($updateNotifyData->route == Notify::ROUTE_PRODUCT_KEYWORD){
  1532 + //产品聚合页更新
  1533 + $routers = RouteMap::where("project_id",$updateNotifyData->project_id)->where("source","product_keyword")->offset($offset)->limit($perPage)->get();
  1534 + }else if($updateNotifyData->route == Notify::ROUTE_PRODUCT_VIDEO_KEYWORD){
  1535 + //产品视频聚合页更新
  1536 + $videoKeywordIdList = Keyword::where("project_id",$updateNotifyData->project_id)->where("status",1)->whereNotNull("route")->whereNotNull("video")->pluck("id")->toArray();
  1537 + if (!empty($videoKeywordIdList)){
  1538 + $routers = RouteMap::where("project_id",$updateNotifyData->project_id)->where("source","product_keyword")->whereIn("source_id",$videoKeywordIdList)->offset($offset)->limit($perPage)->get();
  1539 + }
  1540 + }else if($updateNotifyData->route == Notify::ROUTE_NOT_TRANSLATE){
  1541 + //漏翻译
  1542 + if ($updateNotifyData->type == Notify::TYPE_MINOR){
  1543 + $routers = RouteMap::where("project_id",$updateNotifyData->project_id)->offset($offset)->limit($perPage)->get()->sortBy(function($item) {
  1544 + return array_search($item->source, ['page', 'product_category', 'product', 'news_category', 'news', 'blog_category', 'blog', 'product_keyword']);
  1545 + });
  1546 + }
  1547 + }else if($updateNotifyData->route == Notify::ROUTE_NEED){
  1548 + //按需更新
  1549 + if ($updateNotifyData->type == Notify::TYPE_MASTER){
  1550 + $routers = $updateNotifyQuery->where("status","<",2)->offset($offset)->limit($perPage)->get();
  1551 + $updateNotifyQuery->where("status","<",2)->update(['status' => 2]);
  1552 + }else{
  1553 + $routers = $updateNotifyQuery->where("minor_languages_status","<",2)->offset($offset)->limit($perPage)->get();
  1554 + $updateNotifyQuery->where("minor_languages_status","<",2)->update(['minor_languages_status' => 2]);
  1555 + }
  1556 + }else{
  1557 + //按url更新
  1558 + $urlArrMap = [];
  1559 + $dataJson = json_decode($updateNotifyData->data);
  1560 + $urlArr = $dataJson->url;
  1561 + if (!empty($urlArr)){
  1562 + if (count($urlArr) != 0){
  1563 + foreach ($urlArr as $key => $item){
  1564 + if (strpos($item, 'http://') !== false || strpos($item, 'https://') !== false) {
  1565 + $pathUrl = parse_url($item);
  1566 + if (isset($pathUrl["path"])){
  1567 + $pathUrl = $pathUrl["path"];
  1568 + if ($pathUrl == "/"){
  1569 + $urlArrMap[] = "index";
  1570 + }
  1571 + }else{
  1572 + $urlArrMap[] = "index";
  1573 + }
  1574 + $pathInfo = urldecode($pathUrl);
  1575 + $pageService = new PageService();
  1576 + $analysisRouteArr = $pageService->analysisRoute($pathInfo);
  1577 + if (isset($analysisRouteArr["router"])){
  1578 + $urlArrMap[] = $analysisRouteArr["router"];
  1579 + }
  1580 + }else{
  1581 + $urlArrMap[] = $item;
  1582 + }
  1583 + }
  1584 + }
  1585 + $pageNum = 0;
  1586 + }
  1587 +
  1588 + $routeNew = [];
  1589 + if (!empty($urlArrMap)){
  1590 + foreach ($urlArrMap as $v){
  1591 + $routerItem = RouteMap::where("project_id",$updateNotifyData->project_id)->where("route",$v)->first();
  1592 + if (!empty($routerItem)){
  1593 + $routeNew[] = $v;
  1594 + }
  1595 + }
  1596 + }
  1597 + if (!empty($routeNew)){
  1598 + $routeNew = array_values(array_unique(array_filter($routeNew)));
  1599 + $routers = RouteMap::where("project_id",$updateNotifyData->project_id)->whereIn("route",$routeNew)->get();
  1600 + }
  1601 + }
  1602 + $routersInfo["routers"] = $routers;
  1603 + $routersInfo["pageNum"] = $pageNum;
  1604 + return $routersInfo;
  1605 + }
  1606 +
  1607 + /**
  1608 + * 数据详情入库数据处理
  1609 + */
  1610 + public function htmlPageQueryDataHandle($routers,$updateNotifyData,$task_id,$isHasData = true)
  1611 + {
  1612 + $page = null;
  1613 + $updateData = [];
  1614 + $data = json_decode($updateNotifyData->data, true);
  1615 + $updateNotifyData->domain = $data['domain'];
  1616 + if ($updateNotifyData->route == Notify::ROUTE_ALL || $updateNotifyData->route == Notify::ROUTE_URL || $updateNotifyData->route == Notify::ROUTE_PRODUCT_KEYWORD || $updateNotifyData->route == Notify::ROUTE_NOT_TRANSLATE){
  1617 + //全部更新
  1618 + if ($isHasData && !empty($routers) && !$routers->isEmpty()){
  1619 + foreach ($routers as $item){
  1620 + $count = $this->isListAndGetCount($item,$updateNotifyData);
  1621 + if ($count == 0 || $item->route == "index"){
  1622 + $updateData['project_id'] = $updateNotifyData->project_id;
  1623 + $updateData['id'] = $task_id;
  1624 + $updateData['type'] = $item->source;
  1625 + $updateData['route'] = $item->route;
  1626 + $updateData['page'] = $page;
  1627 + $updateData['domain'] =$updateNotifyData->domain;
  1628 + $updateDataJson = json_encode($updateData);
  1629 + //更新页面
  1630 + $this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
  1631 + }else{
  1632 + for ($i = 1; $i <= $count; $i++) {
  1633 + if ($i == 1){
  1634 + $updateData['page'] = null;
  1635 + }else{
  1636 + $updateData['page'] = $i;
  1637 + }
  1638 + $updateData['project_id'] = $updateNotifyData->project_id;
  1639 + $updateData['id'] = $task_id;
  1640 + $updateData['type'] = $item->source;
  1641 + $updateData['route'] = $item->route;
  1642 + $updateData['domain'] =$updateNotifyData->domain;
  1643 + $updateDataJson = json_encode($updateData);
  1644 + //更新页面
  1645 + $this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
  1646 + }
  1647 + }
  1648 + }
  1649 + }
  1650 +
  1651 + if (!$isHasData){
  1652 + //判断products,news,blog三个列表页是否存在路由,不存在主动更新
  1653 + //手动更新所有关键词列表页(自定义top-search系列页面)
  1654 + $this->checkProductsNewsBlogListAndGetCount($updateNotifyData,$task_id);
  1655 + if ($updateNotifyData->type == Notify::TYPE_MASTER){
  1656 + $this->productKeywordListAdnGetCount($updateNotifyData,$task_id);
  1657 + }else{
  1658 + if ($updateNotifyData->route == Notify::ROUTE_PRODUCT_KEYWORD){
  1659 + $this->productKeywordListAdnGetCount($updateNotifyData,$task_id);
  1660 + }
  1661 + }
  1662 + }
  1663 + }else{
  1664 + //按需更新
  1665 + if ($isHasData && !empty($routers) && !$routers->isEmpty()){
  1666 + foreach ($routers as $item){
  1667 + $count = $this->isListAndGetCount($item,$updateNotifyData);
  1668 + if ($count == 0 || $item->type == "index"){
  1669 + $updateData['project_id'] = $updateNotifyData->project_id;
  1670 + $updateData['id'] = $task_id;
  1671 + if ($item->type == "index"){
  1672 + $updateData['type'] = "page";
  1673 + $updateData['route'] = "index";
  1674 + }else{
  1675 + $updateData['type'] = $item->type;
  1676 + $updateData['route'] = $item->route;
  1677 + }
  1678 + $updateData['page'] = $page;
  1679 + $updateData['domain'] =$updateNotifyData->domain;
  1680 + $updateDataJson = json_encode($updateData);
  1681 + //更新页面
  1682 + $this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
  1683 + }else{
  1684 + for ($i = 1; $i <= $count; $i++) {
  1685 + if ($i == 1){
  1686 + $updateData['page'] = null;
  1687 + }else{
  1688 + $updateData['page'] = $i;
  1689 + }
  1690 + $updateData['project_id'] = $updateNotifyData->project_id;
  1691 + $updateData['id'] = $task_id;
  1692 + $updateData['type'] = $item->type;
  1693 + $updateData['route'] = $item->route;
  1694 + $updateData['domain'] =$updateNotifyData->domain;
  1695 + $updateDataJson = json_encode($updateData);
  1696 + //更新页面
  1697 + $this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
  1698 + }
  1699 + }
  1700 + }
  1701 + }
  1702 +
  1703 + if (!$isHasData){
  1704 + //判断products,news,blog三个列表页是否存在路由,不存在主动更新
  1705 + $this->checkProductsNewsBlogListAndGetCount($updateNotifyData,$task_id);
  1706 + }
  1707 +
  1708 + }
  1709 + unset($routers);
  1710 + }
  1711 +
  1712 + /**
  1713 + * 是否是列表,并返回页数
  1714 + */
  1715 + public function isListAndGetCount($router,$updateNotifyData)
  1716 + {
  1717 + $count = 0;
  1718 + $newsQuery = News::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1);
  1719 + $blogQuery = Blog::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1);
  1720 + $productsQuery = Product::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1)->whereNotNull('route');
  1721 + if ($updateNotifyData->route == Notify::ROUTE_ALL || $updateNotifyData->route == Notify::ROUTE_URL){
  1722 + if ($router->source == "news_category"){
  1723 + if ($router->route == "news"){
  1724 + $count = $newsQuery->count();
  1725 + }else{
  1726 + $count = $newsQuery->where("category_id","like","%".",".$router->source_id.","."%")->count();
  1727 + }
  1728 + }
  1729 + if ($router->source == "blog_category"){
  1730 + if ($router->route == "blog"){
  1731 + $count = $blogQuery->count();
  1732 + }else{
  1733 + $count = $blogQuery->where("category_id","like","%".",".$router->source_id.","."%")->count();
  1734 + }
  1735 +
  1736 + }
  1737 + if ($router->source == "product_category"){
  1738 + if ($router->route == "products"){
  1739 + $count =$productsQuery->count();
  1740 + }else{
  1741 + $ids = [];
  1742 + $productCategoryList = Category::getAllSonCategoryById($updateNotifyData->project_id,(int)$router->source_id);
  1743 + if (!empty($productCategoryList)){
  1744 + $productList = CategoryRelated::whereIn("cate_id",$productCategoryList)->get();
  1745 + if (!empty($productList)){
  1746 + foreach ($productList as $productV){
  1747 + $ids[] = $productV->product_id;
  1748 + }
  1749 + }
  1750 + }
  1751 + $count =$productsQuery->whereIn("id",$ids)->count();
  1752 + }
  1753 +
  1754 + }
  1755 + }else{
  1756 + $routerMap = RouteMap::where("project_id",$updateNotifyData->project_id)->where("route",$router->route)->first();
  1757 + if (!empty($routerMap)){
  1758 + if ($router->type == "news_category"){
  1759 + if ($router->route == "news"){
  1760 + $count = $newsQuery->count();
  1761 + }else{
  1762 + $count = $newsQuery->where("category_id","like","%".",".$routerMap->source_id.","."%")->count();
  1763 + }
  1764 + }
  1765 + if ($router->type == "blog_category"){
  1766 + if ($router->route == "blog"){
  1767 + $count = $blogQuery->count();
  1768 + }else{
  1769 + $count = $blogQuery->where("category_id","like","%".",".$routerMap->source_id.","."%")->count();
  1770 + }
  1771 +
  1772 + }
  1773 + if ($router->type == "product_category"){
  1774 + if ($router->route == "products"){
  1775 + $count = $productsQuery->count();
  1776 + }else{
  1777 + $count = $productsQuery->where("category_id","like","%,".(string)$routerMap->source_id.",%")->count();
  1778 + }
  1779 +
  1780 + }
  1781 + }
  1782 + }
  1783 +
  1784 + if ($count != 0){
  1785 + if ($router->type == "product_category"){
  1786 + $webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$productListType)->orderBy("id","desc")->first();
  1787 + if (!empty($webSettingNum)){
  1788 + $perPage = (int)$webSettingNum->num;
  1789 + }else{
  1790 + $perPage = Category::$productCategoryPagePercent; //产品每页条数
  1791 + }
  1792 + $total = (int)ceil($count / $perPage); //产品分类总页数
  1793 + }elseif($router->type == "news_category"){
  1794 + $webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$newsListType)->orderBy("id","desc")->first();
  1795 + if (!empty($webSettingNum)){
  1796 + $perPage = (int)$webSettingNum->num;
  1797 + }else{
  1798 + $perPage = NewsCategory::$newsCategoryPagePercent; //新闻每页条数
  1799 + }
  1800 + $total = (int)ceil($count / $perPage); //新闻总页数
  1801 + }else{
  1802 + $webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$blogListType)->orderBy("id","desc")->first();
  1803 + if (!empty($webSettingNum)){
  1804 + $perPage = (int)$webSettingNum->num;
  1805 + }else{
  1806 + $perPage = NewsCategory::$newsCategoryPagePercent; //博客每页条数
  1807 + }
  1808 + $total = (int)ceil($count / $perPage); //博客总页数
  1809 + }
  1810 + $count = $total;
  1811 + }
  1812 + return $count;
  1813 +
  1814 + }
  1815 +
  1816 + /**
  1817 + * 需要更新的页面,主站页面或者小语种页面
  1818 + */
  1819 + public function pushHtmlPage($updateNotifyData, $updateDataJson,$taskId)
  1820 + {
  1821 + //更新页面
  1822 + $mysqlData["created_at"] = now();
  1823 + $mysqlData["updated_at"] = now();
  1824 + $mysqlData["data"] =$updateDataJson;
  1825 + $mysqlData["task_id"] =$taskId;
  1826 + $data = json_decode($updateDataJson);
  1827 + if (!empty($data->page)){
  1828 + $page =",分页:".$data->page;
  1829 + }else{
  1830 + $page = "";
  1831 + }
  1832 + echo "创建项目路由:任务ID:" . $taskId .",项目ID:".$data->project_id.",域名:".$data->domain.",路由:".$data->route.$page. PHP_EOL;
  1833 +
  1834 + if ($updateNotifyData->type == Notify::TYPE_MASTER){
  1835 + UpdateMasterWebsiteModel::insertGetId($mysqlData);
  1836 + }else{
  1837 + UpdateMinorLanguagesModel::insertGetId($mysqlData);
  1838 + }
  1839 + }
  1840 +
  1841 + /**
  1842 + * 判断products,news,blog三个列表页是否存在路由,不存在主动更新
  1843 + */
  1844 + public function checkProductsNewsBlogListAndGetCount($updateNotifyData,$task_id)
  1845 + {
  1846 + $productsCount = 0;
  1847 + $newsCount = 0;
  1848 + $blogCount = 0;
  1849 + //产品
  1850 + $routerProductsMap = RouteMap::where("project_id",$updateNotifyData->project_id)->where("route","products")->first();
  1851 + if (empty($routerProductsMap)){
  1852 + $productsCount = Product::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1)->whereNotNull('route')->orderBy("id","DESC")->count();
  1853 + if ($productsCount != 0){
  1854 + $webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$productListType)->orderBy("id","desc")->first();
  1855 + if (!empty($webSettingNum)){
  1856 + $perPage = (int)$webSettingNum->num;
  1857 + }else{
  1858 + $perPage = Category::$productCategoryPagePercent; //产品每页条数
  1859 + }
  1860 + $productsTotal = (int)ceil($productsCount / $perPage);
  1861 + if ($productsTotal>=1){
  1862 + for ($i = 1; $i <= $productsTotal; $i++) {
  1863 + $updateData = [];
  1864 + if ($i == 1){
  1865 + $updateData['page'] = null;
  1866 + }else{
  1867 + $updateData['page'] = $i;
  1868 + }
  1869 + $updateData['project_id'] = $updateNotifyData->project_id;
  1870 + $updateData['id'] = $task_id;
  1871 + $updateData['type'] = "product_category";
  1872 + $updateData['route'] = "products";
  1873 + $updateData['domain'] =$updateNotifyData->domain;
  1874 + $updateDataJson = json_encode($updateData);
  1875 + //更新页面
  1876 + $this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
  1877 + }
  1878 + }
  1879 + }
  1880 + }
  1881 +
  1882 + //新闻
  1883 + $routerNewsMap = RouteMap::where("project_id",$updateNotifyData->project_id)->where("route","news")->first();
  1884 + if (empty($routerNewsMap)){
  1885 + $newsCount = News::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1)->orderBy("id","DESC")->count();
  1886 + $webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$newsListType)->orderBy("id","desc")->first();
  1887 + if (!empty($webSettingNum)){
  1888 + $perPage = (int)$webSettingNum->num;
  1889 + }else{
  1890 + $perPage = NewsCategory::$newsCategoryPagePercent;
  1891 + }
  1892 + $NewsTotal = (int)ceil($newsCount / $perPage);
  1893 + if ($NewsTotal>=1){
  1894 + for ($i = 1; $i <= $NewsTotal; $i++) {
  1895 + $updateData = [];
  1896 + if ($i == 1){
  1897 + $updateData['page'] = null;
  1898 + }else{
  1899 + $updateData['page'] = $i;
  1900 + }
  1901 + $updateData['project_id'] = $updateNotifyData->project_id;
  1902 + $updateData['id'] = $task_id;
  1903 + $updateData['type'] = "news_category";
  1904 + $updateData['route'] = "news";
  1905 + $updateData['domain'] =$updateNotifyData->domain;
  1906 + $updateDataJson = json_encode($updateData);
  1907 + //更新页面
  1908 + $this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
  1909 + }
  1910 + }
  1911 + }
  1912 +
  1913 + //博客
  1914 + $routerBlogMap = RouteMap::where("project_id",$updateNotifyData->project_id)->where("route","blog")->first();
  1915 + if (empty($routerBlogMap)){
  1916 + $blogCount = Blog::where("project_id",$updateNotifyData->project_id)->select("id")->where("status",1)->orderBy("id","DESC")->count();
  1917 + $webSettingNum = WebSettingNum::where("project_id",$updateNotifyData->project_id)->where("type",WebSettingNum::$blogListType)->orderBy("id","desc")->first();
  1918 + if (!empty($webSettingNum)){
  1919 + $perPage = (int)$webSettingNum->num;
  1920 + }else{
  1921 + $perPage = NewsCategory::$newsCategoryPagePercent;
  1922 + }
  1923 + $BlogTotal = (int)ceil($blogCount / $perPage);
  1924 + if ($BlogTotal>=1){
  1925 + for ($i = 1; $i <= $BlogTotal; $i++) {
  1926 + $updateData = [];
  1927 + if ($i == 1){
  1928 + $updateData['page'] = null;
  1929 + }else{
  1930 + $updateData['page'] = $i;
  1931 + }
  1932 + $updateData['project_id'] = $updateNotifyData->project_id;
  1933 + $updateData['id'] = $task_id;
  1934 + $updateData['type'] = "blog_category";
  1935 + $updateData['route'] = "blog";
  1936 + $updateData['domain'] =$updateNotifyData->domain;
  1937 + $updateDataJson = json_encode($updateData);
  1938 + //更新页面
  1939 + $this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
  1940 + }
  1941 + }
  1942 + }
  1943 +
  1944 + }
  1945 +
  1946 + /**
  1947 + * 手动更新所有关键词列表页(自定义top-search系列页面)
  1948 + */
  1949 + public function productKeywordListAdnGetCount($updateNotifyData,$task_id)
  1950 + {
  1951 + $productKeywordInfo = $this->projectProductKeywordsDataAndHandle($updateNotifyData->project_id);
  1952 + if (isset($productKeywordInfo["productKeywordListInfo"]) && !empty($productKeywordInfo["productKeywordListInfo"])){
  1953 + foreach ($productKeywordInfo["productKeywordListInfo"] as $productKeywordItem){
  1954 + if ($productKeywordItem['total']>=1){
  1955 + for ($i = 1; $i <= $productKeywordItem['total']; $i++) {
  1956 + if ($i == 1){
  1957 + $updateData['page'] = null;
  1958 + }else{
  1959 + $updateData['page'] = $i;
  1960 + }
  1961 + $updateData['project_id'] = $updateNotifyData->project_id;
  1962 + $updateData['id'] = $task_id;
  1963 + $updateData['type'] = "product_keyword_list";
  1964 + $updateData['route'] = $productKeywordItem['route'];
  1965 + $updateData['domain'] =$updateNotifyData->domain;
  1966 + $updateDataJson = json_encode($updateData);
  1967 + //更新页面
  1968 + $this->pushHtmlPage($updateNotifyData,$updateDataJson,$task_id);
  1969 + }
  1970 + }
  1971 + }
  1972 + }
  1973 + unset($productKeywordInfo);
  1974 + }
  1975 +
  1976 + /**
  1977 + * 获取更新进度表
  1978 + */
  1979 + public function getUpdateProgress($projectId,$type)
  1980 + {
  1981 + $updateProgressQuery = UpdateProgressModel::where("project_id",(int)$projectId)->orderBy("id","desc");
  1982 + if ($type == "master_website"){
  1983 + $updateProgressQuery = $updateProgressQuery->where("type",1)->first();
  1984 + }else{
  1985 + $updateProgressQuery = $updateProgressQuery->where("type",2)->first();
  1986 + }
  1987 + return $updateProgressQuery;
  1988 + }
  1989 +
  1990 + /**
  1991 + * 项目产品关键词列表路由,及数据处理
  1992 + */
  1993 + public function projectProductKeywordsDataAndHandle($projectId): array
  1994 + {
  1995 + $keywordsArr = [];
  1996 + $keywordModel = new Keyword();
  1997 + $keywords = $keywordModel->where("project_id",$projectId)->get();
  1998 +
  1999 + if (!empty($keywords)){
  2000 + foreach ($keywords->toArray() as $item){
  2001 + $firstLetter = mb_strtolower(mb_substr($item['title'], 0, 1, 'utf-8'), 'utf-8');
  2002 + $keywordsArr["top-search"][] = $item;
  2003 + if (in_array($firstLetter, $keywordModel->routeZ)){
  2004 + $keywordsArr["top-search-0"][] = $item;
  2005 + }else{
  2006 + $keywordsArr["top-search-".$firstLetter][] = $item;
  2007 + }
  2008 + }
  2009 + }
  2010 + return [
  2011 + "productKeywordListInfo"=>$this->projectProductKeywordsDataAndTotalPageHandle($keywordsArr),
  2012 + "productKeywords"=>$keywords,
  2013 + ];
  2014 + }
  2015 +
  2016 + /**
  2017 + * 项目产品关键词列表路由数据及总页数
  2018 + */
  2019 + public function projectProductKeywordsDataAndTotalPageHandle($data): array
  2020 + {
  2021 + $projectProjectKeywords = [];
  2022 + $perPage = 80;
  2023 + if (!empty($data)){
  2024 + foreach ($data as $key => $item){
  2025 + $count = count($item);
  2026 + $total = (int)ceil($count / $perPage);
  2027 + $projectProjectKeywords[$key]["route"] =$key;
  2028 + $projectProjectKeywords[$key]["total"] =$total;
  2029 + }
  2030 + }
  2031 + return $projectProjectKeywords;
  2032 + }
  2033 +
  2034 + /**
  2035 + * 站点域名处理
  2036 + */
  2037 + public function domainHandle($domain)
  2038 + {
  2039 + $langDomain = str_replace("http://","",$domain);
  2040 + $langDomain = str_replace("https://","",$langDomain);
  2041 + $langDomain = str_replace("/","",$langDomain);
  2042 + return $langDomain;
  2043 + }
  2044 +
  2045 + /**
  2046 + * 小语种自定义创建站点目录页面拷贝
  2047 + */
  2048 + public function copyPageMinorWebsiteToCreateDomainDirectory($project)
  2049 + {
  2050 + $countryCustomInfo = CountryCustom::with("countryCustomLanguage")->where("language_id","!=",$project->main_lang_id)->where("project_id",$project->id)->where("status",1)->where("is_create",1)->get();
  2051 + if (!empty($countryCustomInfo)){
  2052 + $langDomain = $this->domainHandle($project->domain);
  2053 + foreach ($countryCustomInfo as $countryCustomInfoItem){
  2054 + $publicLangPath = public_path($langDomain."/".$countryCustomInfoItem->countryCustomLanguage->short);
  2055 + $publicCreatePath = public_path($countryCustomInfoItem->custom_domain);
  2056 + if (file_exists($publicLangPath)){
  2057 + if (!file_exists($publicCreatePath)){
  2058 + mkdir($publicCreatePath,0777);
  2059 + }
  2060 + File::copyDirectory($publicLangPath, $publicCreatePath);
  2061 + }
  2062 + }
  2063 + }
  2064 + }
  2065 +}
此 diff 太大无法显示。
1 -<?php  
2 -/**  
3 - * @remark :  
4 - * @name :CustomTemplateService.php  
5 - * @author :lyh  
6 - * @method :post  
7 - * @time :2024/3/11 16:15  
8 - */  
9 -  
10 -namespace App\Services\Html;  
11 -  
12 -use App\Models\Project\PageSetting;  
13 -use App\Models\Service\Service as ServiceSettingModel;  
14 -use App\Models\Template\BTemplate;  
15 -use App\Models\Template\BTemplateCommon;  
16 -use App\Models\Template\Setting;  
17 -  
18 -class CustomTemplateService  
19 -{  
20 - /**  
21 - * @remark :获取当前自定义界面详情  
22 - * @name :customTemplateInfo  
23 - * @author :lyh  
24 - * @method :post  
25 - * @time :2023/6/29 16:23  
26 - */  
27 - public function getHtml($projectInfo,$custom_id){  
28 - $info = $this->model->read(['id'=>$custom_id]);  
29 - if($info === false){  
30 - return false;  
31 - }  
32 - if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){  
33 - $html = $this->getBodyHeaderFooter($projectInfo,$info['html'],$info['html_style']);  
34 - $info['html'] = $this->getHeadFooter($html);  
35 - }  
36 - return ['html'=>$info['html']];  
37 - }  
38 -  
39 - /**  
40 - * @remark :获取body的详情  
41 - * @name :getBodyHeaderFooter  
42 - * @author :lyh  
43 - * @method :post  
44 - * @time :2023/7/21 18:08  
45 - */  
46 - public function getBodyHeaderFooter($projectInfo,$preg_html,$html_style){  
47 - if(empty($preg_html)){  
48 - $preg_html = "<main></main>";  
49 - $html_style = "<style id='globalsojs-styles'></style>";  
50 - }  
51 - //获取设置的默认模版  
52 - $bSettingModel = new Setting();  
53 - $info = $bSettingModel->read(['project_id'=>$projectInfo['id']]);  
54 - if($info === false){  
55 - return false;  
56 - }  
57 - //获取type类型  
58 - $commonInfo = $this->getCommonPage($projectInfo,$info['template_id']);  
59 - $html = $commonInfo['head_css'].$html_style.$commonInfo['footer_css'].$commonInfo['other'].  
60 - $commonInfo['head_html'].$preg_html.$commonInfo['footer_html'];  
61 - return ['html'=>$html];  
62 - }  
63 -  
64 - /**  
65 - * @remark :根据类型获取公共头和底  
66 - * @name :getCommonPage  
67 - * @author :lyh  
68 - * @method :post  
69 - */  
70 - public function getCommonPage($projectInfo,$template_id){  
71 - $is_head = $projectInfo['deploy_build']['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;  
72 - if(isset($is_head) && ($is_head != 0)) {  
73 - //查看页面是否设置自定义头部底部  
74 - $pageSettingModel = new PageSetting();  
75 - $pageInfo = $pageSettingModel->read(['project_id' => $projectInfo['id']]);  
76 - if ($pageInfo !== false) {  
77 - $commonTemplateModel = new BTemplateCommon();  
78 - if ($pageInfo['page_list'] != 0) {  
79 - //使用独立头和底  
80 - $commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $projectInfo['id'], 'type' => 9]);  
81 - }  
82 - }  
83 - }  
84 - if(!isset($commonInfo) || $commonInfo === false){  
85 - //获取首页公共的头部和底部  
86 - $commonTemplateModel = new BTemplateCommon();  
87 - $commonInfo = $commonTemplateModel->read(['template_id'=>$template_id,'project_id'=>$projectInfo['id'],'type'=>1]);  
88 - }  
89 - return $commonInfo;  
90 - }  
91 -  
92 - /**  
93 - * @remark :拼接获取公共头部底部  
94 - * @name :getHeadFooter  
95 - * @author :lyh  
96 - * @method :post  
97 - */  
98 - public function getHeadFooter($html = ''){  
99 - //获取公共主题头部底部  
100 - $serviceSettingModel = new ServiceSettingModel();  
101 - $list = $serviceSettingModel->list(['type'=>2],'created_at');  
102 - //拼接html  
103 - foreach ($list as $v){  
104 - if($v['key'] == 'head'){  
105 - $html = $v['values'].$html;  
106 - }  
107 - if($v['key'] == 'footer'){  
108 - $html = $html.$v['values'];  
109 - }  
110 - }  
111 - return $html;  
112 - }  
113 -}  
  1 +<?php
  2 +
  3 +
  4 +namespace App\Services\Html;
  5 +
  6 +use App\Models\Project\DeleteHtmlModel;
  7 +use App\Models\Project\DeployBuild;
  8 +use App\Models\Project\DeployOptimize;
  9 +use App\Models\Project\DomainInfo;
  10 +use App\Models\WebSetting\WebSetting;
  11 +use Illuminate\Support\Facades\Redis;
  12 +
  13 +/**
  14 + * C端删除页面服务
  15 + */
  16 +class DeletePageService{
  17 + /**
  18 + * 删除文件
  19 + */
  20 + public function deleteDirectory($path): bool
  21 + {
  22 + if (!is_dir($path)) {
  23 + try {
  24 + unlink($path);
  25 + } catch (\Exception $e) {
  26 + return true;
  27 + }
  28 + return true;
  29 + }
  30 + $files = array_diff(scandir($path), array('.', '..'));
  31 + foreach ($files as $file) {
  32 + $filePath = $path . '/' . $file;
  33 + if (is_dir($filePath)) {
  34 + $this->deleteDirectory($filePath);
  35 + } else {
  36 + try {
  37 + unlink($filePath);
  38 + } catch (\Exception $e) {
  39 + return true;
  40 + }
  41 + }
  42 + }
  43 + rmdir($path);
  44 + return true;
  45 + }
  46 +
  47 + /**
  48 + * 获取项目ID下正式+测试域名
  49 + */
  50 + public function getAllProjectDomain($data)
  51 + {
  52 + if (Redis::get($data->project_id."_all_project_domain") != null){
  53 + $allProjectDomain =Redis::get($data->project_id."_all_project_domain");
  54 + }else{
  55 + $domainArr = [];
  56 + $onlineProject = DeployOptimize::where('project_id',$data->project_id)->first();
  57 + if (!empty($onlineProject)){
  58 + if ($onlineProject->domain != null){
  59 + $domainInfo = DomainInfo::where("id",$onlineProject->domain)->where("status",1)->first();
  60 + if (!empty($domainInfo)){
  61 + $domainArr[] = $domainInfo->domain;
  62 + }
  63 + }
  64 + }
  65 + $testProject = DeployBuild::where('project_id',$data->project_id)->first();
  66 + if (!empty($testProject)){
  67 + $testDomain = $testProject->test_domain;
  68 + if (strpos($testDomain, 'http://') !== false){
  69 + $testDomain = str_replace('http://', '', $testDomain);
  70 + }
  71 + if (strpos($testDomain, 'https://') !== false){
  72 + $testDomain = str_replace('https://', '', $testDomain);
  73 + }
  74 + $testDomain = str_replace('/', '', $testDomain);
  75 + $domainArr[] = $testDomain;
  76 + }
  77 + if (!empty($domainArr)){
  78 + $allProjectDomain = json_encode($domainArr);
  79 + Redis::set($data->project_id."_all_project_domain", $allProjectDomain);
  80 + Redis::expire($data->project_id."_all_project_domain", WebSetting::$redisExpireTime);
  81 + }
  82 + }
  83 + return $allProjectDomain;
  84 +
  85 + }
  86 +
  87 + /**
  88 + * 构造删除路径
  89 + */
  90 + public function deleteHtmlItems($data): bool
  91 + {
  92 + $getAllProjectDomain = $this->getAllProjectDomain($data);
  93 + if ($getAllProjectDomain != null){
  94 + $getAllProjectDomain = json_decode($getAllProjectDomain);
  95 + $deleteHtml = DeleteHtmlModel::where("project_id",$data->project_id)->get();
  96 + foreach ($getAllProjectDomain as $domainItem){
  97 + if (!empty($deleteHtml)){
  98 + foreach ($deleteHtml as $v){
  99 + //国家
  100 + $pageService = new PageService();
  101 + $webCountry = $pageService->getCountryList($data->project_id);
  102 + if ($webCountry != null){
  103 + foreach ($webCountry as $item){
  104 + if ($v->route == "index"){
  105 + $path = public_path($domainItem."/".$item->alias."/index.html");
  106 + }else{
  107 + $path = public_path($domainItem."/".$item->alias."/".$v->route);
  108 + }
  109 +
  110 + if (file_exists($path)){
  111 + $this->deleteDirectory($path);
  112 + }
  113 + }
  114 + }
  115 + if ($v->route == "index"){
  116 + $path = public_path($domainItem."/index.html");
  117 + }else{
  118 + $path = public_path($domainItem."/".$v->route);
  119 + }
  120 +
  121 + if (file_exists($path)){
  122 + $this->deleteDirectory($path);
  123 + }
  124 + DeleteHtmlModel::where("project_id",$data->project_id)->where("route",$v->route)->delete();
  125 + }
  126 + }
  127 +
  128 + //删除C端固定页面
  129 + $pageService = new PageService();
  130 + $webCountry = $pageService->getCountryList($data->project_id);
  131 + if ($webCountry != null){
  132 + foreach ($webCountry as $item) {
  133 + //删除C端固定小语种页面
  134 + $productsPath = public_path($domainItem . "/" . $item->alias . "/products");
  135 + $newsPath = public_path($domainItem . "/" . $item->alias . "/news");
  136 + $blogPath = public_path($domainItem . "/" . $item->alias . "/blog");
  137 + if (file_exists($productsPath)) {
  138 + $this->deleteDirectory($productsPath);
  139 + }
  140 + if (file_exists($newsPath)) {
  141 + $this->deleteDirectory($newsPath);
  142 + }
  143 + if (file_exists($blogPath)) {
  144 + $this->deleteDirectory($blogPath);
  145 + }
  146 + }
  147 + }
  148 + //删除C端固定主站页面
  149 + $productsPath = public_path($domainItem."/products");
  150 + $newsPath = public_path($domainItem."/news");
  151 + $blogPath = public_path($domainItem."/blog");
  152 + if (file_exists($productsPath)){
  153 + $this->deleteDirectory($productsPath);
  154 + }
  155 + if (file_exists($newsPath)){
  156 + $this->deleteDirectory($newsPath);
  157 + }
  158 + if (file_exists($blogPath)){
  159 + $this->deleteDirectory($blogPath);
  160 + }
  161 + }
  162 +
  163 + }
  164 + return true;
  165 + }
  166 +}
1 -<?php  
2 -/**  
3 - * @remark :  
4 - * @name :GeneratePageService.php  
5 - * @author :lyh  
6 - * @method :post  
7 - * @time :2024/2/19 15:54  
8 - */  
9 -  
10 -namespace App\Services\Html;  
11 -  
12 -use App\Models\CustomModule\CustomModule;  
13 -use App\Models\CustomModule\CustomModuleCategory;  
14 -use App\Models\CustomModule\CustomModuleContent;  
15 -use App\Models\Project\PageSetting;  
16 -use App\Models\Project\Project;  
17 -use App\Models\RouteMap\RouteMap;  
18 -use App\Models\Template\BTemplate;  
19 -use App\Models\Template\BTemplateCommon;  
20 -use App\Models\Template\BTemplateMain;  
21 -use App\Models\Template\Setting;  
22 -use App\Models\Template\TemplateTypeMain;  
23 -use App\Services\ProjectServer;  
24 -use Illuminate\Support\Facades\DB;  
25 -  
26 -class GeneratePageService  
27 -{  
28 - protected $route;  
29 -  
30 - protected $param;  
31 - protected $project_id = 0;  
32 -  
33 -  
34 - /**  
35 - * @remark :生成单页数据  
36 - * @name :generateHtml  
37 - * @author :lyh  
38 - * @method :post  
39 - * @time :2024/2/19 16:57  
40 - */  
41 - public function generateHtml($projectInfo,$routeInfo){  
42 - $this->project_id = $projectInfo['id'];  
43 - $this->route = $routeInfo['route'];  
44 - ProjectServer::useProject($this->project_id);  
45 - $this->handleParam($routeInfo);  
46 - $result = $this->getTemplateHtml($projectInfo);  
47 - DB::disconnect('custom_mysql');  
48 - return $this->success($result);  
49 - }  
50 -  
51 - /**  
52 - * @remark :生成页面参数处理  
53 - * @name :generateHtml  
54 - * @author :lyh  
55 - * @method :post  
56 - * @time :2024/2/19 16:36  
57 - */  
58 - public function handleParam($routeInfo){  
59 - switch ($routeInfo['source']){  
60 - case RouteMap::SOURCE_PRODUCT:  
61 - $this->param['source'] = BTemplate::SOURCE_PRODUCT;  
62 - $this->param['is_list'] = BTemplate::IS_DETAIL;  
63 - break;  
64 - case RouteMap::SOURCE_PRODUCT_CATE:  
65 - $this->param['source'] = BTemplate::SOURCE_PRODUCT;  
66 - $this->param['is_list'] = BTemplate::IS_LIST;  
67 - break;  
68 - case RouteMap::SOURCE_BLOG:  
69 - $this->param['source'] = BTemplate::SOURCE_BLOG;  
70 - $this->param['is_list'] = BTemplate::IS_DETAIL;  
71 - break;  
72 - case RouteMap::SOURCE_BLOG_CATE:  
73 - $this->param['source'] = BTemplate::SOURCE_BLOG;  
74 - $this->param['is_list'] = BTemplate::IS_LIST;  
75 - break;  
76 - case RouteMap::SOURCE_NEWS:  
77 - $this->param['source'] = BTemplate::SOURCE_NEWS;  
78 - $this->param['is_list'] = BTemplate::IS_DETAIL;  
79 - break;  
80 - case RouteMap::SOURCE_NEWS_CATE:  
81 - $this->param['source'] = BTemplate::SOURCE_NEWS;  
82 - $this->param['is_list'] = BTemplate::IS_LIST;  
83 - break;  
84 - case RouteMap::SOURCE_MODULE:  
85 - $this->param['is_custom'] = BTemplate::IS_CUSTOM;  
86 - //TODO::获取对应模块数据  
87 - $moduleModel = new CustomModuleContent();  
88 - $moduleInfo = $moduleModel->read(['id'=>$routeInfo['source_id']],['module_id']);  
89 - $this->param['source'] = $moduleInfo['id'] ?? 0;  
90 - $this->param['is_list'] = BTemplate::IS_DETAIL;  
91 - break;  
92 - case RouteMap::SOURCE_MODULE_CATE:  
93 - $this->param['is_custom'] = BTemplate::IS_CUSTOM;  
94 - //TODO::获取对应模块数据  
95 - $moduleModel = new CustomModuleCategory();  
96 - $moduleInfo = $moduleModel->read(['id'=>$routeInfo['source_id']],['module_id']);  
97 - $this->param['source'] = $moduleInfo['id'] ?? 0;  
98 - $this->param['is_list'] = BTemplate::IS_LIST;  
99 - break;  
100 - default:  
101 - $this->param['source'] = BTemplate::SOURCE_HOME;  
102 - $this->param['is_list'] = BTemplate::IS_DETAIL;  
103 - break;  
104 - return true;  
105 - }  
106 - }  
107 -  
108 - /**  
109 - * @notes: 请简要描述方法功能  
110 - * @param array $data  
111 - * @return array  
112 - */  
113 - public function success($data = [])  
114 - {  
115 - return $data;  
116 - }  
117 -  
118 - /**  
119 - * @remark :获取html  
120 - * @name :getTemplateHtml  
121 - * @author :lyh  
122 - * @method :post  
123 - */  
124 - public function getTemplateHtml($projectInfo){  
125 - $is_custom = $this->param['is_custom'] ?? 0;//是否为扩展模块  
126 - $is_list = $this->param['is_list'] ?? 0;//是否为列表页  
127 - $template_id = $this->getSettingTemplate($projectInfo,$this->param['source'],$is_list,$is_custom);//设置的模版id  
128 - if($template_id === false){  
129 - return false;  
130 - }  
131 - $templateInfo = $this->webTemplateInfo($this->param['source'],$this->param['source_id'],$template_id,$is_custom,$is_list);  
132 - if($templateInfo === false){  
133 - if($projectInfo['is_customized'] == BTemplate::IS_VISUALIZATION){//处理定制页面初始数据  
134 - $html = $this->customizedReturnHtml($projectInfo,$this->param['source'],$template_id,$is_custom,$is_list);  
135 - if($html !== false){  
136 - return $this->success($html);  
137 - }  
138 - }  
139 - //非定制初始中间部分  
140 - $mainInfo = $this->getMAinHtml($this->param['source'],$is_custom,$is_list);//获取中间部分代码  
141 - }else{  
142 - if($templateInfo['type'] == BTemplate::ALL_HTML){//返回整个html代码  
143 - return $this->getCustomizeAllHtml($templateInfo,$template_id,$is_custom,$is_list);  
144 - }  
145 - $mainInfo = ['main_html'=>$templateInfo['main_html'], 'main_css'=>$templateInfo['main_css']];  
146 - }  
147 - $commonInfo = $this->getCommonHtml($projectInfo,$this->param['source'],$is_list,$template_id,$is_custom);//获取非定制头部  
148 - $html = $commonInfo['head_css'].$mainInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other']. $commonInfo['head_html'].$mainInfo['main_html'].$commonInfo['footer_html'];  
149 - $html = $this->getHeadFooter($html);  
150 - $result = ['html'=>$html];  
151 - return $this->success($result);  
152 - }  
153 -  
154 - /**  
155 - * @remark :获取整个html代码  
156 - * @name :getCustomizeAllHtml  
157 - * @author :lyh  
158 - * @method :post  
159 - * @time :2024/1/10 14:15  
160 - */  
161 - public function getCustomizeAllHtml($templateInfo,$template_id,$is_custom,$is_list){  
162 - if($is_custom == BTemplate::IS_CUSTOM){  
163 - $commonInfo = $this->getCustomizedCommonHtml($this->param['source'],$is_custom,$is_list);//获取定制头部  
164 - $html = $this->handleAllHtml($commonInfo,$templateInfo['html']);  
165 - }else{  
166 - $type = $this->getCustomizedType($this->param['source'],$is_list);  
167 - $commonInfo = $this->getCustomizedCommonHtml($type,$is_custom,$is_list);//获取定制头部  
168 - $html = $this->handleAllHtml($commonInfo,$templateInfo['html']);  
169 - }  
170 - return $this->success(['html'=>$html,'template_id'=>$template_id]);  
171 - }  
172 -  
173 - /**  
174 - * @remark :获取装修详情  
175 - * @name :webTemplateInfo  
176 - * @author :lyh  
177 - * @method :post  
178 - * @time :2024/1/10 13:43  
179 - */  
180 - public function webTemplateInfo($source,$source_id,$template_id,$is_custom,$is_list){  
181 - $templateInfo = $this->model->read([  
182 - 'template_id'=>$template_id, 'source'=>$source,  
183 - 'project_id'=>$this->project_id, 'source_id'=>$source_id,  
184 - 'is_custom'=>$is_custom, 'is_list'=>$is_list  
185 - ]);  
186 - return $this->success($templateInfo);  
187 - }  
188 -  
189 - /**  
190 - * @remark :定制页面获取html  
191 - * @name :customizedReturnHtml  
192 - * @author :lyh  
193 - * @method :post  
194 - * @time :2024/1/10 13:46  
195 - */  
196 - public function customizedReturnHtml($projectInfo,$source,$template_id,$is_custom,$is_list){  
197 - //TODO::扩展模块定制单独处理  
198 - if($is_custom == BTemplate::IS_CUSTOM){  
199 - $customModuleModel = new CustomModule();  
200 - $info = $customModuleModel->read(['id'=>$source]);  
201 - if($info === false){  
202 - return false;  
203 - }  
204 - //扩展模块定制  
205 - if($is_list == BTemplate::IS_LIST && $info['list_customized'] == BTemplate::IS_VISUALIZATION){  
206 - $html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom);  
207 - if($html === false){  
208 - return false;  
209 - }  
210 - return $this->success(['html'=>$html]);  
211 - }  
212 - if($is_list == BTemplate::IS_DETAIL && $info['detail_customized'] == BTemplate::IS_VISUALIZATION){  
213 - $html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom);  
214 - if($html === false){  
215 - return false;  
216 - }  
217 - return $this->success(['html'=>$html]);  
218 - }  
219 - return false;  
220 - }  
221 - //TODO::默认模块定制  
222 - $html = $this->isCustomizedPage($projectInfo,$source,$is_list,$is_custom);//获取定制页面的html  
223 - if($html !== false){  
224 - return $this->success(['html'=>$html]);  
225 - }  
226 - return false;  
227 - }  
228 -  
229 - /**  
230 - * @remark :扩展模块定制html  
231 - * @name :customModuleInfo  
232 - * @author :lyh  
233 - * @method :post  
234 - * @time :2024/1/10 9:20  
235 - */  
236 - public function customModuleCustomizeHtml($source,$is_list,$is_custom){  
237 - $bTemplateMainModel = new BTemplateMain();  
238 - //TODO::获取初始代码  
239 - $customHtmlInfo = $bTemplateMainModel->read(['type'=>$source,'is_list'=>$is_list,'is_custom'=>$is_custom]);  
240 - if($customHtmlInfo === false){  
241 - return false;  
242 - }  
243 - $commonInfo = $this->getCustomizedCommonHtml($source,$is_custom,$is_list);//获取定制头部  
244 - if($commonInfo !== false){  
245 - $customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);  
246 - }  
247 - return $customHtmlInfo['main_html'];  
248 - }  
249 -  
250 - /**  
251 - * @remark :获取中间部分的html  
252 - * @name :getMAinHtml  
253 - * @author :lyh  
254 - * @method :post  
255 - * @time :2023/12/27 15:00  
256 - */  
257 - public function getMAinHtml($type,$is_custom,$is_list){  
258 - //获取设置的默认中间部分  
259 - $bTemplateMainModel = new BTemplateMain();  
260 - $mainInfo = $bTemplateMainModel->read(['type'=>$type,'is_list'=>$is_list,'is_custom'=>$is_custom]);  
261 - if($mainInfo === false){  
262 - $main_html = $this->getInitModule($type,$is_custom,$is_list);  
263 - $main_css = "<style id='globalsojs-styles'></style>";  
264 - }else{  
265 - $main_html = $mainInfo['main_html'];  
266 - $main_css = $mainInfo['main_css'];  
267 - }  
268 - return ['main_html'=>$main_html,'main_css'=>$main_css];  
269 - }  
270 -  
271 - /**  
272 - * @remark :默认复合页数据  
273 - * @name :getProductModule  
274 - * @author :lyh  
275 - * @method :post  
276 - * @time :2023/7/27 15:08  
277 - */  
278 - public function getInitModule($type,$is_custom,$is_list){  
279 - if($is_custom == BTemplate::IS_CUSTOM) {  
280 - $type = BTemplate::SOURCE_CUSTOM;  
281 - }  
282 - $mainModel = new TemplateTypeMain();  
283 - $info = $mainModel->read(['type'=>$type,'is_list'=>$is_list]);  
284 - return $info['main_html'];  
285 - }  
286 -  
287 - /**  
288 - * @remark :返回整个html截取代码  
289 - * @name :handleAllHtml  
290 - * @author :lyh  
291 - * @method :post  
292 - * @time :2023/12/13 15:39  
293 - */  
294 - public function handleAllHtml($commonInfo,$html){  
295 - if(!empty($commonInfo)){  
296 - $html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $commonInfo['head_html'], $html);  
297 - $html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $commonInfo['footer_html'], $html);  
298 - $html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $commonInfo['head_css'], $html);  
299 - $html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $commonInfo['footer_css'], $html);  
300 - }  
301 - return $html;  
302 - }  
303 -  
304 - /**  
305 - * @remark :页面是否为定制页面获取初始代码  
306 - * @name :watchProjectIsCustomized  
307 - * @author :lyh  
308 - * @method :post  
309 - * @time :2023/12/13 10:55  
310 - */  
311 - public function isCustomizedPage($projectInfo,$source,$is_list,$is_custom)  
312 - {  
313 - $type = $this->getCustomizedType($source, $is_list);//获取定制界面类型  
314 - //查看当前页面是否定制,是否开启可视化  
315 - $page_array = (array)$projectInfo['is_visualization']->page_array;//获取所有定制界面  
316 - if (in_array($type, $page_array)) {//是定制界面  
317 - //TODO::获取初始代码  
318 - $bTemplateMainModel = new BTemplateMain();  
319 - $customHtmlInfo = $bTemplateMainModel->read(['type'=>$source,'is_custom'=>$is_custom,'is_list'=>$is_list]);  
320 - if($customHtmlInfo === false){  
321 - return false;  
322 - }  
323 - $commonInfo = $this->getCustomizedCommonHtml($type,$is_custom,$is_list);//获取定制头部  
324 - if($commonInfo !== false){  
325 - $customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);  
326 - }  
327 - return $customHtmlInfo['main_html'];  
328 - }  
329 - return false;  
330 - }  
331 -  
332 - /**  
333 - * @remark :定制项目获取头部底部  
334 - * @name :getCustomizedCommonHtml  
335 - * @author :lyh  
336 - * @method :post  
337 - * @time :2023/12/29 13:13  
338 - */  
339 - public function getCustomizedCommonHtml($type,$is_custom = 0,$is_list = 0){  
340 - $data = [  
341 - 'template_id' => 0,  
342 - 'project_id' => $this->project_id,  
343 - 'type'=>$type,  
344 - 'is_custom'=>$is_custom,  
345 - 'is_list'=>$is_list  
346 - ];  
347 - $commonTemplateModel = new BTemplateCommon();  
348 - return $commonTemplateModel->read($data);  
349 - }  
350 -  
351 - /**  
352 - * @remark :定制页面头部类型---根据source获取type类型  
353 - * @name :getType  
354 - * @author :lyh  
355 - * @method :post  
356 - * @time :2023/11/16 11:20  
357 - */  
358 - public function getCustomizedType($source,$is_list){  
359 - $type = BTemplate::TYPE_HOME;  
360 - if($source == BTemplate::SOURCE_PRODUCT){  
361 - if($is_list == BTemplate::IS_LIST){  
362 - $type = BTemplate::TYPE_PRODUCT_LIST;  
363 - }else{  
364 - $type = BTemplate::TYPE_PRODUCT_DETAIL;  
365 - }  
366 - }  
367 - if($source == BTemplate::SOURCE_BLOG){  
368 - if($is_list == BTemplate::IS_LIST){  
369 - $type = BTemplate::TYPE_BLOG_LIST;  
370 - }else{  
371 - $type = BTemplate::TYPE_BLOG_DETAIL;  
372 - }  
373 - }  
374 - if($source == BTemplate::SOURCE_NEWS){  
375 - if($is_list == BTemplate::IS_LIST){  
376 - $type = BTemplate::TYPE_NEWS_LIST;  
377 - }else{  
378 - $type = BTemplate::TYPE_NEWS_DETAIL;  
379 - }  
380 - }  
381 - return $type;  
382 - }  
383 -  
384 - /**  
385 - * @remark :获取当前项目设置的模版  
386 - * @name :getSettingTemplate  
387 - * @author :lyh  
388 - * @method :post  
389 - * @time :2023/12/13 10:48  
390 - */  
391 - public function getSettingTemplate($projectInfo,$source,$is_list,$is_custom){  
392 - $template_id = 0;  
393 - if($projectInfo['is_customized'] == BTemplate::IS_VISUALIZATION) {//定制项目  
394 - if($is_custom == BTemplate::IS_CUSTOM){  
395 - $customModuleModel = new CustomModule();  
396 - $info = $customModuleModel->read(['id'=>$source]);  
397 - if($info === false){  
398 - return false;  
399 - }  
400 - if($info['list_customized'] == BTemplate::IS_VISUALIZATION && $is_list == BTemplate::IS_LIST){  
401 - return $this->success($template_id);  
402 - }  
403 - if($info['detail_customized'] == BTemplate::IS_VISUALIZATION && $is_list == BTemplate::IS_DETAIL){  
404 - return $this->success($template_id);  
405 - }  
406 - }else{  
407 - $type = $this->getCustomizedType($source, $is_list);//获取定制界面类型  
408 - //查看当前页面是否定制,是否开启可视化  
409 - $page_array = (array)$projectInfo['is_visualization']->page_array;//获取所有定制界面  
410 - if (in_array($type, $page_array)) {//是定制界面  
411 - return $this->success($template_id);  
412 - }  
413 - }  
414 - }  
415 - $bSettingModel = new Setting();  
416 - $info = $bSettingModel->read(['project_id'=>$this->project_id]);  
417 - if($info === false){  
418 - return false;  
419 - }  
420 - $template_id = $info['template_id'];  
421 - return $this->success($template_id);  
422 - }  
423 -  
424 - /**  
425 - * @remark :根据类型获取公共头和底  
426 - * @name :getCommonPage  
427 - * @author :lyh  
428 - * @method :post  
429 - * @time :2023/10/21 16:55  
430 - */  
431 - public function getCommonHtml($ProjectInfo,$source,$is_list,$template_id,$is_custom = 0,){  
432 - $type = $this->getType($ProjectInfo,$source,$is_list,$is_custom);  
433 - $data = [  
434 - 'template_id' => $template_id,  
435 - 'project_id' => $this->project_id,  
436 - 'type'=>$type,  
437 - 'is_custom'=>0,  
438 - ];  
439 - $commonTemplateModel = new BTemplateCommon();  
440 - $commonInfo = $commonTemplateModel->read($data);  
441 - if($commonInfo === false){  
442 - $data['type'] = BTemplate::SOURCE_HOME;  
443 - $commonInfo = $commonTemplateModel->read($data);  
444 - }  
445 - return $this->success($commonInfo);  
446 - }  
447 -  
448 - /**  
449 - * @remark :(非定制)保存时获取获取设置的类型  
450 - * @name :getType  
451 - * @author :lyh  
452 - * @method :post  
453 - * @time :2023/10/21 17:29  
454 - */  
455 - public function getType($projectInfo,$source,$is_list,$is_custom = 0){  
456 - $type = BTemplate::SOURCE_HOME;//首页公共头部底部  
457 - $is_head = $projectInfo['deploy_build']['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;  
458 - if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部  
459 - return $this->success($type);  
460 - }  
461 - //查看页面是否设置自定义头部底部  
462 - if($is_head != BTemplate::IS_NO_HEADER) {  
463 - $pageSettingModel = new PageSetting();  
464 - $pageInfo = $pageSettingModel->read(['project_id' => $projectInfo['id']]);  
465 - if ($pageInfo === false) {  
466 - return $this->success($type);  
467 - }  
468 - if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::TYPE_PRODUCT_DETAIL;}}  
469 - else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::TYPE_PRODUCT_LIST;}}}  
470 - if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::TYPE_BLOG_DETAIL;}}  
471 - else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::TYPE_BLOG_LIST;}}}  
472 - if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::TYPE_NEWS_DETAIL;}}  
473 - else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::TYPE_NEWS_LIST;}}}  
474 - if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}  
475 - }  
476 - return $this->success($type);  
477 - }  
478 -  
479 -  
480 -}  
此 diff 太大无法显示。
1 <?php 1 <?php
2 2
3 -namespace App\Services; 3 +
  4 +namespace App\Services\Html;
4 5
5 use App\Models\Blog\Blog; 6 use App\Models\Blog\Blog;
6 use App\Models\Blog\BlogCategory; 7 use App\Models\Blog\BlogCategory;
7 -use App\Models\CustomModule\CustomModule;  
8 -use App\Models\CustomModule\CustomModuleCategory;  
9 use App\Models\Module\Module; 8 use App\Models\Module\Module;
10 use App\Models\Module\ModuleCategory; 9 use App\Models\Module\ModuleCategory;
11 use App\Models\News\News; 10 use App\Models\News\News;
12 use App\Models\News\NewsCategory; 11 use App\Models\News\NewsCategory;
13 use App\Models\Product\Category; 12 use App\Models\Product\Category;
14 use App\Models\Product\Keyword; 13 use App\Models\Product\Keyword;
15 -use App\Models\RouteMap\RouteMap;  
16 -use App\Models\Template\BCustomTemplate; 14 +use App\Models\WebSetting\WebCustom;
17 use App\Models\WebSetting\WebSetting; 15 use App\Models\WebSetting\WebSetting;
18 use App\Models\WebSetting\WebSettingSeo; 16 use App\Models\WebSetting\WebSettingSeo;
19 -  
20 -use Illuminate\Support\Facades\Cache; 17 +use App\Models\WebSetting\WebTemplateCommon;
21 use phpQuery; 18 use phpQuery;
22 19
23 /** 20 /**
@@ -27,52 +24,54 @@ class TdkService{ @@ -27,52 +24,54 @@ class TdkService{
27 /** 24 /**
28 * 页面TDK处理 25 * 页面TDK处理
29 */ 26 */
30 - public function pageTdkHandle($projectInfo,$html,$type,$routerMapInfo=null): string 27 + public function pageTdkHandle($project,$html,$type,$routerMap=null): string
31 { 28 {
32 $titleContent = ""; 29 $titleContent = "";
33 $descriptionContent = ""; 30 $descriptionContent = "";
34 $keywordsContent = ""; 31 $keywordsContent = "";
35 $phpQueryDom=phpQuery::newDocument($html); 32 $phpQueryDom=phpQuery::newDocument($html);
  33 +
36 //首页TDK设置 34 //首页TDK设置
37 - if ($type == RouteMap::SOURCE_INDEX){  
38 - $tdkInfo = $this->indexTDK($projectInfo); 35 + if ($type == WebTemplateCommon::$indexName){
  36 + $tdkInfo = $this->indexTDK($project);
39 } 37 }
40 //单页面TDK设置 38 //单页面TDK设置
41 - if ($type == RouteMap::SOURCE_PAGE){  
42 - $tdkInfo = $this->pageTDK($projectInfo,$routerMapInfo); 39 + if ($type == WebTemplateCommon::$pageName){
  40 + $tdkInfo = $this->pageTDK($project,$routerMap);
43 } 41 }
44 //自定义模块列表页TDK设置 42 //自定义模块列表页TDK设置
45 - if ($type == RouteMap::SOURCE_MODULE_CATE){  
46 - $tdkInfo = $this->moduleCategoryTDK($projectInfo,$routerMapInfo); 43 + if ($type == WebTemplateCommon::$extendCategoryName){
  44 + $tdkInfo = $this->moduleCategoryTDK($project,$routerMap);
47 } 45 }
48 //自定义模块详情页TDK设置 46 //自定义模块详情页TDK设置
49 - if ($type == RouteMap::SOURCE_MODULE){  
50 - $tdkInfo = $this->moduleDetailsTDK($projectInfo,$routerMapInfo); 47 + if ($type == WebTemplateCommon::$extendName){
  48 + $tdkInfo = $this->moduleDetailsTDK($project,$routerMap);
51 } 49 }
52 //新闻详情TDK设置 50 //新闻详情TDK设置
53 - if ($type == RouteMap::SOURCE_NEWS){  
54 - $tdkInfo = $this->newsDetailsTDK($projectInfo,$routerMapInfo); 51 + if ($type == WebTemplateCommon::$newsName){
  52 + $tdkInfo = $this->newsDetailsTDK($project,$routerMap);
55 } 53 }
56 //博客详情TDK设置 54 //博客详情TDK设置
57 - if ($type == RouteMap::SOURCE_BLOG){  
58 - $tdkInfo = $this->blogDetailsTDK($projectInfo,$routerMapInfo); 55 + if ($type == WebTemplateCommon::$blogName){
  56 + $tdkInfo = $this->blogDetailsTDK($project,$routerMap);
59 } 57 }
60 //聚合页TDK设置 58 //聚合页TDK设置
61 - if ($type == RouteMap::SOURCE_PRODUCT_KEYWORD){  
62 - $tdkInfo = $this->productKeywordsTDK($projectInfo,$routerMapInfo); 59 + if ($type == WebTemplateCommon::$productKeywordName){
  60 + $tdkInfo = $this->productKeywordsTDK($project,$routerMap);
63 } 61 }
64 //新闻列表页TDK设置 62 //新闻列表页TDK设置
65 - if ($type == RouteMap::SOURCE_NEWS_CATE){  
66 - $tdkInfo = $this->newsCategoryTDK($projectInfo,$routerMapInfo); 63 + if ($type == WebTemplateCommon::$newsCategoryName){
  64 + $tdkInfo = $this->newsCategoryTDK($project,$routerMap);
67 } 65 }
68 //博客列表页TDK设置 66 //博客列表页TDK设置
69 - if ($type == RouteMap::SOURCE_BLOG_CATE){  
70 - $tdkInfo = $this->blogCategoryTDK($projectInfo,$routerMapInfo); 67 + if ($type == WebTemplateCommon::$blogCategoryName){
  68 + $tdkInfo = $this->blogCategoryTDK($project,$routerMap);
71 } 69 }
72 //产品列表页TDK设置 70 //产品列表页TDK设置
73 - if ($type == RouteMap::SOURCE_PRODUCT_CATE){  
74 - $tdkInfo = $this->productCategoryTDK($projectInfo,$routerMapInfo); 71 + if ($type == WebTemplateCommon::$productCategoryName){
  72 + $tdkInfo = $this->productCategoryTDK($project,$routerMap);
75 } 73 }
  74 +
76 if (!empty($tdkInfo)){ 75 if (!empty($tdkInfo)){
77 $titleContent = strip_tags($tdkInfo["titleContent"]); 76 $titleContent = strip_tags($tdkInfo["titleContent"]);
78 $descriptionContent = strip_tags($tdkInfo["descriptionContent"]); 77 $descriptionContent = strip_tags($tdkInfo["descriptionContent"]);
@@ -84,6 +83,7 @@ class TdkService{ @@ -84,6 +83,7 @@ class TdkService{
84 $phpQueryDom->find('head')->append("<meta property='og:title' content='".$titleContent."'/>"); 83 $phpQueryDom->find('head')->append("<meta property='og:title' content='".$titleContent."'/>");
85 $phpQueryDom->find('head')->append("<meta property='og:type' content='site'/>"); 84 $phpQueryDom->find('head')->append("<meta property='og:type' content='site'/>");
86 $phpQueryDom->find('head')->append("<meta property='og:site_name' content='".$titleContent."'/>"); 85 $phpQueryDom->find('head')->append("<meta property='og:site_name' content='".$titleContent."'/>");
  86 +
87 $content = $phpQueryDom->htmlOuter(); 87 $content = $phpQueryDom->htmlOuter();
88 unset($html,$tdkInfo,$phpQueryDom); 88 unset($html,$tdkInfo,$phpQueryDom);
89 phpQuery::unloadDocuments(); 89 phpQuery::unloadDocuments();
@@ -93,14 +93,14 @@ class TdkService{ @@ -93,14 +93,14 @@ class TdkService{
93 /** 93 /**
94 * 首页TDK 94 * 首页TDK
95 */ 95 */
96 - public function indexTDK($projectInfo): array 96 + public function indexTDK($project): array
97 { 97 {
98 $tdkInfo = []; 98 $tdkInfo = [];
99 - $webSettingInfo = $this->getWebSetting($projectInfo);  
100 - if (!empty($webSettingInfo)){  
101 - $titleContent = strip_tags($webSettingInfo['title']);  
102 - $descriptionContent = strip_tags($webSettingInfo['remark']);  
103 - $keywordsContent = strip_tags($webSettingInfo['keyword']); 99 + $webSetting = WebSetting::getWebSetting($project);
  100 + if (!empty($webSetting)){
  101 + $titleContent = strip_tags($webSetting->title);
  102 + $descriptionContent = strip_tags($webSetting->remark);
  103 + $keywordsContent = strip_tags($webSetting->keyword);
104 $tdkInfo["titleContent"] = $titleContent; 104 $tdkInfo["titleContent"] = $titleContent;
105 $tdkInfo["descriptionContent"] = $descriptionContent; 105 $tdkInfo["descriptionContent"] = $descriptionContent;
106 $tdkInfo["keywordsContent"] = $keywordsContent; 106 $tdkInfo["keywordsContent"] = $keywordsContent;
@@ -109,56 +109,37 @@ class TdkService{ @@ -109,56 +109,37 @@ class TdkService{
109 } 109 }
110 110
111 /** 111 /**
112 - * 网站设置  
113 - */  
114 - public function getWebSetting($projectInfo)  
115 - {  
116 - if (Cache::get("project_".$projectInfo['id']."_web_setting") == null) {  
117 - $webSettingModel = new WebSetting();  
118 - $webSettingInfo = $webSettingModel->read(['project_id'=>$projectInfo['id']]);  
119 - if ($webSettingInfo !== false) {  
120 - Cache::add("project_".$projectInfo['id']."_web_setting", json_encode($webSettingInfo));  
121 - return $webSettingInfo;  
122 - }  
123 - return [];  
124 - }  
125 - return (array)json_decode(Cache::get("project_".$projectInfo['id']."_web_setting"));  
126 - }  
127 -  
128 - /**  
129 * 新闻列表页TDK 112 * 新闻列表页TDK
130 */ 113 */
131 - public function newsCategoryTDK($projectInfo,$routerMapInfo): array 114 + public function newsCategoryTDK($project,$routerMap): array
132 { 115 {
133 $tdkInfo = []; 116 $tdkInfo = [];
134 $pageSuffix = ""; 117 $pageSuffix = "";
135 - $webSetting = $this->getWebSetting($projectInfo);  
136 - $newsCategoryModel = new NewsCategory();  
137 - $newsCategoryInfo = $newsCategoryModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id']]); 118 + $webSetting = WebSetting::getWebSetting($project);
  119 + $newsCategory = NewsCategory::where("project_id",$project->id)->where("id",$routerMap->source_id)->first();
138 //seo拼接 120 //seo拼接
139 - $webSeoModel = new WebSettingSeo();  
140 - $webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);  
141 - if ($webSeoInfo !== false){  
142 - $pageSuffix = !empty($webSeoInfo['single_page_suffix']) ? " ".$webSeoInfo['single_page_suffix'] : ""; 121 + $webSeo = WebSettingSeo::where("project_id",$project->id)->first();
  122 + if (!empty($webSeo)){
  123 + $pageSuffix = !empty($webSeo->single_page_suffix) ? " ".$webSeo->single_page_suffix : "";
143 } 124 }
144 - if ($newsCategoryInfo !== false){ 125 + if (!empty($newsCategory)){
145 //title 126 //title
146 - if (!empty($newsCategoryInfo['seo_title'])){  
147 - $titleContent = $newsCategoryInfo['seo_title'].$pageSuffix; 127 + if (!empty($newsCategory->seo_title)){
  128 + $titleContent = $newsCategory->seo_title.$pageSuffix;
148 }else{ 129 }else{
149 - $titleContent = $newsCategoryInfo['name'].$pageSuffix; 130 + $titleContent = $newsCategory->name.$pageSuffix;
150 } 131 }
151 //description 132 //description
152 - if (!empty($newsCategoryInfo['seo_des'])){  
153 - $descriptionContent = $newsCategoryInfo['seo_des']; 133 + if (!empty($newsCategory->seo_des)){
  134 + $descriptionContent = $newsCategory->seo_des;
154 }else{ 135 }else{
155 - $descriptionContent = !empty($webSetting['remark']) ? $webSetting['remark'] : ""; 136 + $descriptionContent = !empty($webSetting->remark) ? $webSetting->remark : "";
156 } 137 }
157 //keyword 138 //keyword
158 - if (!empty($newsCategoryInfo['seo_keywords'])){  
159 - $keywordsContent = $newsCategoryInfo['seo_keywords']; 139 + if (!empty($newsCategory->seo_keywords)){
  140 + $keywordsContent = $newsCategory->seo_keywords;
160 }else{ 141 }else{
161 - $keywordsContent = !empty($webSetting['keyword']) ? $webSetting['keyword'] : ""; 142 + $keywordsContent = !empty($webSetting->keyword) ? $webSetting->keyword : "";
162 } 143 }
163 $tdkInfo["titleContent"] = $titleContent; 144 $tdkInfo["titleContent"] = $titleContent;
164 $tdkInfo["descriptionContent"] = $descriptionContent; 145 $tdkInfo["descriptionContent"] = $descriptionContent;
@@ -170,37 +151,35 @@ class TdkService{ @@ -170,37 +151,35 @@ class TdkService{
170 /** 151 /**
171 * 博客列表页TDK 152 * 博客列表页TDK
172 */ 153 */
173 - public function blogCategoryTDK($projectInfo,$routerMapInfo): array 154 + public function blogCategoryTDK($project,$routerMap): array
174 { 155 {
175 $tdkInfo = []; 156 $tdkInfo = [];
176 $pageSuffix = ""; 157 $pageSuffix = "";
177 - $webSetting = $this->getWebSetting($projectInfo);  
178 - $blogCategoryModel = new BlogCategory();  
179 - $blogCategoryInfo = $blogCategoryModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id']]); 158 + $webSetting = WebSetting::getWebSetting($project);
  159 + $newsCategory = BlogCategory::where("project_id",$project->id)->where("id",$routerMap->source_id)->first();
180 //seo拼接 160 //seo拼接
181 - $webSeoModel = new WebSettingSeo();  
182 - $webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);  
183 - if ($webSeoInfo !== false){  
184 - $pageSuffix = !empty($webSeoInfo['single_page_suffix']) ? " ".$webSeoInfo['single_page_suffix'] : ""; 161 + $webSeo = WebSettingSeo::where("project_id",$project->id)->first();
  162 + if (!empty($webSeo)){
  163 + $pageSuffix = !empty($webSeo->single_page_suffix) ? " ".$webSeo->single_page_suffix : "";
185 } 164 }
186 - if ($blogCategoryInfo !== false){ 165 + if (!empty($newsCategory)){
187 //title 166 //title
188 - if (!empty($blogCategoryInfo['seo_title'])){  
189 - $titleContent = $blogCategoryInfo['seo_title'].$pageSuffix; 167 + if (!empty($newsCategory->seo_title)){
  168 + $titleContent = $newsCategory->seo_title.$pageSuffix;
190 }else{ 169 }else{
191 - $titleContent = $blogCategoryInfo['name'].$pageSuffix; 170 + $titleContent = $newsCategory->name.$pageSuffix;
192 } 171 }
193 //description 172 //description
194 - if (!empty($blogCategoryInfo['seo_des'])){  
195 - $descriptionContent = $blogCategoryInfo['seo_des']; 173 + if (!empty($newsCategory->seo_des)){
  174 + $descriptionContent = $newsCategory->seo_des;
196 }else{ 175 }else{
197 - $descriptionContent = !empty($webSetting['remark']) ? $webSetting['remark'] : ""; 176 + $descriptionContent = !empty($webSetting->remark) ? $webSetting->remark : "";
198 } 177 }
199 //keyword 178 //keyword
200 - if (!empty($blogCategoryInfo['seo_keywords'])){  
201 - $keywordsContent = $blogCategoryInfo['seo_keywords']; 179 + if (!empty($newsCategory->seo_keywords)){
  180 + $keywordsContent = $newsCategory->seo_keywords;
202 }else{ 181 }else{
203 - $keywordsContent = !empty($webSetting['keyword']) ? $webSetting['keyword'] : ""; 182 + $keywordsContent = !empty($webSetting->keyword) ? $webSetting->keyword : "";
204 } 183 }
205 $tdkInfo["titleContent"] = $titleContent; 184 $tdkInfo["titleContent"] = $titleContent;
206 $tdkInfo["descriptionContent"] = $descriptionContent; 185 $tdkInfo["descriptionContent"] = $descriptionContent;
@@ -212,45 +191,46 @@ class TdkService{ @@ -212,45 +191,46 @@ class TdkService{
212 /** 191 /**
213 * 产品列表页TDK 192 * 产品列表页TDK
214 */ 193 */
215 - public function productCategoryTDK($projectInfo,$routerMapInfo): array 194 + public function productCategoryTDK($project,$routerMap): array
216 { 195 {
217 $tdkInfo = []; 196 $tdkInfo = [];
218 $prefix = ""; 197 $prefix = "";
219 $suffix = ""; 198 $suffix = "";
  199 + $pageSuffix = "";
220 $webSettingTitle = ""; 200 $webSettingTitle = "";
221 $webSettingDescription = ""; 201 $webSettingDescription = "";
222 $webSettingKeyword = ""; 202 $webSettingKeyword = "";
223 - $projectCategoryModel = new Category();  
224 - $projectCategoryInfo = $projectCategoryModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id']]);  
225 - $webSetting = $this->getWebSetting($projectInfo); 203 +
  204 + $productCategory = Category::where("project_id",$project->id)->where("id",$routerMap->source_id)->first();
  205 + $webSetting = WebSetting::getWebSetting($project);
226 //seo拼接 206 //seo拼接
227 - $webSeoModel = new WebSettingSeo();  
228 - $webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);  
229 - if ($webSeoInfo !== false){  
230 - $prefix = !empty($webSeoInfo['product_cate_prefix']) ? $webSeoInfo['product_cate_prefix']." " : "";  
231 - $suffix = !empty($webSeoInfo['product_cate_suffix']) ? " ".$webSeoInfo['product_cate_suffix'] : ""; 207 + $webSeo = WebSettingSeo::where("project_id",$project->id)->first();
  208 + if (!empty($webSeo)){
  209 + $prefix = !empty($webSeo->product_cate_prefix) ? $webSeo->product_cate_prefix." " : "";
  210 + $suffix = !empty($webSeo->product_cate_suffix) ? " ".$webSeo->product_cate_suffix : "";
  211 + $pageSuffix = !empty($webSeo->single_page_suffix) ? " ".$webSeo->single_page_suffix : "";
232 } 212 }
233 - if ($webSetting !== false){  
234 - $webSettingTitle = !empty($webSetting['title']) ? $webSetting['title'] : "";  
235 - $webSettingDescription = !empty($webSetting['remark']) ? $webSetting['remark'] : "";  
236 - $webSettingKeyword = !empty($webSetting['keyword']) ? $webSetting['keyword'] : ""; 213 + if (!empty($webSetting)){
  214 + $webSettingTitle = !empty($webSetting->title) ? $webSetting->title : "";
  215 + $webSettingDescription = !empty($webSetting->remark) ? $webSetting->remark : "";
  216 + $webSettingKeyword = !empty($webSetting->keyword) ? $webSetting->keyword : "";
237 } 217 }
238 - if ($projectCategoryInfo !== false){ 218 + if (!empty($productCategory)){
239 //title 219 //title
240 - if (!empty($projectCategoryInfo['seo_title'])){  
241 - $titleContent = $prefix.$projectCategoryInfo['seo_title'].$suffix; 220 + if (!empty($productCategory->seo_title)){
  221 + $titleContent = $prefix.$productCategory->seo_title.$suffix;
242 }else{ 222 }else{
243 $titleContent = $prefix.$webSettingTitle.$suffix; 223 $titleContent = $prefix.$webSettingTitle.$suffix;
244 } 224 }
245 //description 225 //description
246 - if (!empty($projectCategoryInfo['seo_des'])){  
247 - $descriptionContent = $projectCategoryInfo['seo_des']; 226 + if (!empty($productCategory->seo_des)){
  227 + $descriptionContent = $productCategory->seo_des;
248 }else{ 228 }else{
249 $descriptionContent = $webSettingDescription; 229 $descriptionContent = $webSettingDescription;
250 } 230 }
251 //keywords 231 //keywords
252 - if (!empty($projectCategoryInfo['seo_keywords'])){  
253 - $keywordsContent = $projectCategoryInfo['seo_keywords']; 232 + if (!empty($productCategory->seo_keywords)){
  233 + $keywordsContent = $productCategory->seo_keywords;
254 }else{ 234 }else{
255 $keywordsContent = $webSettingKeyword; 235 $keywordsContent = $webSettingKeyword;
256 } 236 }
@@ -268,22 +248,22 @@ class TdkService{ @@ -268,22 +248,22 @@ class TdkService{
268 /** 248 /**
269 * 产品聚合页TDK 249 * 产品聚合页TDK
270 */ 250 */
271 - public function productKeywordsTDK($projectInfo,$routerMapInfo): array 251 + public function productKeywordsTDK($project,$routerMap): array
272 { 252 {
273 $tdkInfo = []; 253 $tdkInfo = [];
274 - $keywordModel = new Keyword();  
275 - $keywordInfo = $keywordModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id']]);  
276 - if ($keywordInfo !== false){ 254 + $keyword = Keyword::where("project_id",$project->id)->where("status",1)->where("id",$routerMap->source_id)->first();
  255 + if (!empty($keyword)){
277 //处理title 256 //处理title
278 - $title = $keywordInfo['seo_title'] ?: $keywordInfo['title']; 257 + $title = $keyword->seo_title ?: $keyword->title;
279 //seo拼接 258 //seo拼接
280 - $webSeoModel = new WebSettingSeo();  
281 - $webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);  
282 - $titleContent = $webSeoInfo ? $webSeoInfo['tab_prefix'] . " " . $title . " " . $webSeoInfo['tab_suffix'] : $title; 259 + $webSeo = WebSettingSeo::where("project_id",$project->id)->first();
  260 + $titleContent = $webSeo ? $webSeo->tab_prefix . " " . $title . " " . $webSeo->tab_suffix : $title;
  261 +
283 //处理description 262 //处理description
284 - $descriptionContent = $keywordInfo['seo_description'] ?: $keywordInfo['title']; 263 + $descriptionContent = $keyword->seo_description ?: $keyword->title;
  264 +
285 //处理keywords 265 //处理keywords
286 - $keywordsContent = $keywordInfo['seo_keywords'] ?: $keywordInfo['title']; 266 + $keywordsContent = $keyword->seo_keywords ?: $keyword->title;
287 267
288 $tdkInfo["titleContent"] = $titleContent; 268 $tdkInfo["titleContent"] = $titleContent;
289 $tdkInfo["descriptionContent"] = $descriptionContent; 269 $tdkInfo["descriptionContent"] = $descriptionContent;
@@ -295,51 +275,49 @@ class TdkService{ @@ -295,51 +275,49 @@ class TdkService{
295 /** 275 /**
296 * 新闻详情页TDK 276 * 新闻详情页TDK
297 */ 277 */
298 - public function newsDetailsTDK($projectInfo,$routerMapInfo): array 278 + public function newsDetailsTDK($project,$routerMap): array
299 { 279 {
300 $tdkInfo = []; 280 $tdkInfo = [];
301 $titleContent = ""; 281 $titleContent = "";
302 $keywordsContent = ""; 282 $keywordsContent = "";
303 $descriptionContent = ""; 283 $descriptionContent = "";
304 - $newsModel = new News();  
305 - $newsInfo = $newsModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id'],'status'=>1]);  
306 - return $this->newsBlogTdk($newsInfo, $projectInfo, $titleContent, $descriptionContent, $keywordsContent, $tdkInfo); 284 + $data = News::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
  285 + return $this->newsBlogTdk($data, $project, $titleContent, $descriptionContent, $keywordsContent, $tdkInfo);
307 } 286 }
308 287
309 /** 288 /**
310 * 新闻详情页TDK 289 * 新闻详情页TDK
311 */ 290 */
312 - public function blogDetailsTDK($projectInfo,$routerMapInfo): array 291 + public function blogDetailsTDK($project,$routerMap): array
313 { 292 {
314 $tdkInfo = []; 293 $tdkInfo = [];
315 $titleContent = ""; 294 $titleContent = "";
316 $keywordsContent = ""; 295 $keywordsContent = "";
317 $descriptionContent = ""; 296 $descriptionContent = "";
318 - $blogMode = new Blog();  
319 - $blogInfo = $blogMode->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id'],'status'=>1]);  
320 - return $this->newsBlogTdk($blogInfo, $projectInfo, $titleContent, $descriptionContent, $keywordsContent, $tdkInfo); 297 + $data = Blog::where("project_id",$project->id)->where("id",$routerMap->source_id)->where("status",1)->first();
  298 + return $this->newsBlogTdk($data, $project, $titleContent, $descriptionContent, $keywordsContent, $tdkInfo);
321 } 299 }
322 300
323 /** 301 /**
324 * 自定义模块列表页TDK 302 * 自定义模块列表页TDK
325 */ 303 */
326 - public function moduleDetailsTDK($projectInfo,$routerMapInfo): array 304 + public function moduleDetailsTDK($project,$routerMap): array
327 { 305 {
328 $tdkInfo = []; 306 $tdkInfo = [];
329 - $moduleModel = new CustomModule();  
330 - $moduleInfo = $moduleModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id'],'status'=>0]);  
331 - $webSetting = $this->getWebSetting($projectInfo);  
332 - if ($moduleInfo !== false){ 307 + $moduleInfo = Module::where("project_id",$project->id)->where("status",0)->where("id",$routerMap->source_id)->first();
  308 + $webSetting = WebSetting::getWebSetting($project);
  309 + if (!empty($moduleInfo)){
333 //title 310 //title
334 - $webSettingTitle = !empty($webSetting['title']) ? $webSetting['title'] : "";  
335 - $titleContent = !empty($moduleInfo['seo_title']) ? $moduleInfo['seo_title'] : $webSettingTitle; 311 + $webSettingTitle = !empty($webSetting->title) ? $webSetting->title : "";
  312 + $titleContent = !empty($moduleInfo->seo_title) ? $moduleInfo->seo_title : $webSettingTitle;
  313 +
336 //description 314 //description
337 - $webSettingDescription = !empty($webSetting['remark']) ? $webSetting['remark'] : "";  
338 - $descriptionContent = !empty($moduleInfo['seo_description']) ? $moduleInfo['seo_description'] : $webSettingDescription; 315 + $webSettingDescription = !empty($webSetting->remark) ? $webSetting->remark : "";
  316 + $descriptionContent = !empty($moduleInfo->seo_description) ? $moduleInfo->seo_description : $webSettingDescription;
339 317
340 //keywords 318 //keywords
341 - $webSettingKeyword = !empty($webSetting['keyword']) ? $webSetting['keyword'] : "";  
342 - $keywordsContent = !empty($moduleInfo['seo_keywords']) ? $moduleInfo['seo_keywords'] : $webSettingKeyword; 319 + $webSettingKeyword = !empty($webSetting->keyword) ? $webSetting->keyword : "";
  320 + $keywordsContent = !empty($moduleInfo->seo_keywords) ? $moduleInfo->seo_keywords : $webSettingKeyword;
343 $tdkInfo["titleContent"] = $titleContent; 321 $tdkInfo["titleContent"] = $titleContent;
344 $tdkInfo["descriptionContent"] = $descriptionContent; 322 $tdkInfo["descriptionContent"] = $descriptionContent;
345 $tdkInfo["keywordsContent"] = $keywordsContent; 323 $tdkInfo["keywordsContent"] = $keywordsContent;
@@ -350,24 +328,23 @@ class TdkService{ @@ -350,24 +328,23 @@ class TdkService{
350 /** 328 /**
351 * 自定义模块列表页TDK 329 * 自定义模块列表页TDK
352 */ 330 */
353 - public function moduleCategoryTDK($projectInfo,$routerMapInfo): array 331 + public function moduleCategoryTDK($project,$routerMap): array
354 { 332 {
355 $tdkInfo = []; 333 $tdkInfo = [];
356 - $moduleCategoryModel = new CustomModuleCategory();  
357 - $moduleCategoryInfo = $moduleCategoryModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id']]);  
358 - $webSetting = $this->getWebSetting($projectInfo);  
359 - if ($moduleCategoryInfo !== false){ 334 + $moduleCategoryInfo = ModuleCategory::getModuleCategoryAndExtendByRoute($project->id,$routerMap->route);
  335 + $webSetting = WebSetting::getWebSetting($project);
  336 + if (!empty($moduleCategoryInfo)){
360 //title 337 //title
361 - $webSettingTitle = !empty($webSetting['title']) ? $webSetting['title'] : "";  
362 - $titleContent = !empty($moduleCategoryInfo['seo_title']) ? $moduleCategoryInfo['seo_title'] : $webSettingTitle; 338 + $webSettingTitle = !empty($webSetting->title) ? $webSetting->title : "";
  339 + $titleContent = !empty($moduleCategoryInfo->seo_title) ? $moduleCategoryInfo->seo_title : $webSettingTitle;
363 340
364 //description 341 //description
365 - $webSettingDescription = !empty($webSetting['remark']) ? $webSetting['remark'] : "";  
366 - $descriptionContent = !empty($moduleCategoryInfo['seo_description']) ? $moduleCategoryInfo['seo_description'] : $webSettingDescription; 342 + $webSettingDescription = !empty($webSetting->remark) ? $webSetting->remark : "";
  343 + $descriptionContent = !empty($moduleCategoryInfo->seo_description) ? $moduleCategoryInfo->seo_description : $webSettingDescription;
367 344
368 //keywords 345 //keywords
369 - $webSettingKeyword = !empty($webSetting['keyword']) ? $webSetting['keyword'] : "";  
370 - $keywordsContent = !empty($moduleCategoryInfo['seo_keywords']) ? $moduleCategoryInfo['seo_keywords'] : $webSettingKeyword; 346 + $webSettingKeyword = !empty($webSetting->keyword) ? $webSetting->keyword : "";
  347 + $keywordsContent = !empty($moduleCategoryInfo->seo_keywords) ? $moduleCategoryInfo->seo_keywords : $webSettingKeyword;
371 $tdkInfo["titleContent"] = $titleContent; 348 $tdkInfo["titleContent"] = $titleContent;
372 $tdkInfo["descriptionContent"] = $descriptionContent; 349 $tdkInfo["descriptionContent"] = $descriptionContent;
373 $tdkInfo["keywordsContent"] = $keywordsContent; 350 $tdkInfo["keywordsContent"] = $keywordsContent;
@@ -378,49 +355,48 @@ class TdkService{ @@ -378,49 +355,48 @@ class TdkService{
378 /** 355 /**
379 * 单页面TDK 356 * 单页面TDK
380 */ 357 */
381 - public function pageTDK($projectInfo,$routerMapInfo): array 358 + public function pageTDK($project,$routerMap): array
382 { 359 {
383 $tdkInfo = []; 360 $tdkInfo = [];
384 if (!empty($routerMap)){ 361 if (!empty($routerMap)){
385 - $customModel = new BCustomTemplate();  
386 - $webCustomInfo = $customModel->read(['id'=>$routerMapInfo['source_id'],'status'=>1]); 362 + $webCustom = WebCustom::where("id",$routerMap->source_id)->where("status",1)->first();
387 //seo拼接 363 //seo拼接
388 - $webSeoModel = new WebSettingSeo();  
389 - $webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]); 364 + $webSeo = WebSettingSeo::where("project_id",$project->id)->first();
390 //网站设置 365 //网站设置
391 - $webSetting = $this->getWebSetting($projectInfo); 366 + $webSetting = WebSetting::getWebSetting($project);
  367 + $titleContent = "";
392 $descriptionContent = ""; 368 $descriptionContent = "";
393 $keywordsContent = ""; 369 $keywordsContent = "";
394 - if ($webCustomInfo !== false){ 370 + if (!empty($webCustom)){
395 //title 371 //title
396 - if ($webCustomInfo['title'] == null){ 372 + if ($webCustom->title == null){
397 if (!empty($webSeo)){ 373 if (!empty($webSeo)){
398 - $titleContent = $webCustomInfo['name']." ".$webSeoInfo['single_page_suffix']; 374 + $titleContent = $webCustom->name." ".$webSeo->single_page_suffix;
399 }else{ 375 }else{
400 - $titleContent = $webCustomInfo['name']; 376 + $titleContent = $webCustom->name;
401 } 377 }
402 }else{ 378 }else{
403 if (!empty($webSeo)){ 379 if (!empty($webSeo)){
404 - $titleContent = $webCustomInfo['title']." ".$webSeoInfo['single_page_suffix']; 380 + $titleContent = $webCustom->title." ".$webSeo->single_page_suffix;
405 }else{ 381 }else{
406 - $titleContent = $webCustomInfo['title']; 382 + $titleContent = $webCustom->title;
407 } 383 }
408 } 384 }
409 //keywords 385 //keywords
410 - if ($webCustomInfo['keywords'] == null){ 386 + if ($webCustom->keywords == null){
411 if (!empty($webSetting)){ 387 if (!empty($webSetting)){
412 - $keywordsContent = $webSetting['keyword']; 388 + $keywordsContent = $webSetting->keyword;
413 } 389 }
414 }else{ 390 }else{
415 - $keywordsContent = $webSetting['keywords']; 391 + $keywordsContent = $webCustom->keywords;
416 } 392 }
417 //description 393 //description
418 - if ($webCustomInfo['description'] == null){ 394 + if ($webCustom->description == null){
419 if (!empty($webSetting)) { 395 if (!empty($webSetting)) {
420 - $descriptionContent = $webSetting['remark']; 396 + $descriptionContent = $webSetting->remark;
421 } 397 }
422 }else{ 398 }else{
423 - $descriptionContent = $webCustomInfo['description']; 399 + $descriptionContent = $webCustom->description;
424 } 400 }
425 $tdkInfo["titleContent"] = $titleContent; 401 $tdkInfo["titleContent"] = $titleContent;
426 $tdkInfo["descriptionContent"] = $descriptionContent; 402 $tdkInfo["descriptionContent"] = $descriptionContent;
@@ -433,33 +409,33 @@ class TdkService{ @@ -433,33 +409,33 @@ class TdkService{
433 /** 409 /**
434 * 新闻博客详情通用版块 410 * 新闻博客详情通用版块
435 */ 411 */
436 - public function newsBlogTdk($info, $projectInfo, $titleContent, $descriptionContent, $keywordsContent, array $tdkInfo): array 412 + public function newsBlogTdk($data, $project, string $titleContent, $descriptionContent, $keywordsContent, array $tdkInfo): array
437 { 413 {
438 - if (!empty($info)) { 414 + if (!empty($data)) {
  415 + //处理title
439 //seo拼接 416 //seo拼接
440 $pageSuffix = ""; 417 $pageSuffix = "";
441 - $webSeoModel = new WebSettingSeo();  
442 - $webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);  
443 - $webSetting = $this->getWebSetting($projectInfo);  
444 - if (!empty($webSeoInfo)) {  
445 - $pageSuffix = !empty($webSeo['single_page_suffix']) ? " " . $webSeo['single_page_suffix'] : ""; 418 + $webSeo = WebSettingSeo::where("project_id", $project->id)->first();
  419 + $webSetting = WebSetting::getWebSetting($project);
  420 + if (!empty($webSeo)) {
  421 + $pageSuffix = !empty($webSeo->single_page_suffix) ? " " . $webSeo->single_page_suffix : "";
446 } 422 }
447 - if ($info['seo_title'] == null) {  
448 - $titleContent = !empty($info['name']) ? $info['name'] . $pageSuffix : ""; 423 + if ($data->seo_title == null) {
  424 + $titleContent = !empty($data->name) ? $data->name . $pageSuffix : "";
449 } else { 425 } else {
450 - $titleContent = $info['seo_title'] . $pageSuffix; 426 + $titleContent = $data->seo_title . $pageSuffix;
451 } 427 }
452 //处理description 428 //处理description
453 - if ($info['seo_description'] == null) {  
454 - $descriptionContent = !empty($webSetting['remark']) ? $webSetting['remark'] : ""; 429 + if ($data->seo_description == null) {
  430 + $descriptionContent = !empty($webSetting->remark) ? $webSetting->remark : "";
455 } else { 431 } else {
456 - $descriptionContent = $info['seo_description']; 432 + $descriptionContent = $data->seo_description;
457 } 433 }
458 //处理keywords 434 //处理keywords
459 - if ($info['seo_keywords'] == null) {  
460 - $keywordsContent = !empty($webSetting['keyword']) ? $webSetting['keyword'] : ""; 435 + if ($data->seo_keywords == null) {
  436 + $keywordsContent = !empty($webSetting->keyword) ? $webSetting->keyword : "";
461 } else { 437 } else {
462 - $keywordsContent = $info['seo_keywords']; 438 + $keywordsContent = $data->seo_keywords;
463 } 439 }
464 $tdkInfo["titleContent"] = $titleContent; 440 $tdkInfo["titleContent"] = $titleContent;
465 $tdkInfo["descriptionContent"] = $descriptionContent; 441 $tdkInfo["descriptionContent"] = $descriptionContent;
  1 +<?php
  2 +
  3 +
  4 +namespace App\Services\Html;
  5 +
  6 +use App\Models\Project\UpdateLog;
  7 +use App\Models\Project\UpdateOldInfo;
  8 +
  9 +class UpdateService
  10 +{
  11 + /**
  12 + * 获取项目升级情况
  13 + * @param $project_id
  14 + * @param $domain
  15 + * @return array
  16 + * @author Akun
  17 + * @date 2023/12/01 10:32
  18 + */
  19 + public static function getUpdateInfo($project_id)
  20 + {
  21 + $is_update = 0;
  22 + $is_language_update = 0;
  23 + $old_domain_online = $old_domain_test = '';
  24 +
  25 + $update_info = UpdateLog::where('project_id', $project_id)->whereNotIn('api_type', ['category', 'website_info', 'tag', 'category_news'])->get();
  26 + if ($update_info->count() > 0) {
  27 + $is_update = 1;
  28 + $is_language_update = 1;
  29 +
  30 + foreach ($update_info as $value) {
  31 + if ($value->collect_status != 1) {
  32 + $is_language_update = 0;
  33 + }
  34 + if ($value->collect_status == 0) {
  35 + $is_update = 0;
  36 + }
  37 + }
  38 +
  39 + $old_domain_arr = parse_url($update_info[0]['api_url']);
  40 + $old_info = self::getOldInfo($project_id, $old_domain_arr['host']);
  41 + $old_domain_test = $old_info['old_domain_test'];
  42 + $old_domain_online = $old_info['old_domain_online'];
  43 + }
  44 +
  45 + return [
  46 + 'is_update' => $is_update,
  47 + 'is_language_update' => $is_language_update,
  48 + 'old_domain_test' => $old_domain_test,
  49 + 'old_domain_online' => $old_domain_online
  50 + ];
  51 + }
  52 +
  53 + public static function getOldInfo($project_id, $domain)
  54 + {
  55 + $return = [
  56 + 'old_domain_test' => $domain,
  57 + 'old_domain_online' => $domain
  58 + ];
  59 +
  60 + $info = UpdateOldInfo::where('project_id', $project_id)->first();
  61 + if (!$info) {
  62 + $url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text';
  63 + $data_config = [];
  64 +
  65 + try {
  66 + $data_config = self::curlGet($url_web_config);
  67 + } catch (\Exception $e) {
  68 + }
  69 +
  70 + if ($data_config) {
  71 + $link_type = $data_config['link_type'] ?? 0;
  72 +
  73 + $home_url_arr = parse_url($data_config['home_url'] ?? '');
  74 + $old_domain_test = $home_url_arr['host'] ?? '';
  75 +
  76 + $web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
  77 + $old_domain_online = $web_url_arr['host'] ?? '';
  78 +
  79 + if ($old_domain_test || $old_domain_online) {
  80 + $info = new UpdateOldInfo();
  81 + $info->project_id = $project_id;
  82 + $info->link_type = $link_type;
  83 + $info->old_domain_test = $old_domain_test ?: $domain;
  84 + $info->old_domain_online = $old_domain_online ?: $domain;
  85 + $info->save();
  86 + }
  87 +
  88 + $old_domain_test && $return['old_domain_test'] = $old_domain_test;
  89 + $old_domain_online && $return['old_domain_test'] = $old_domain_online;
  90 + }
  91 + } else {
  92 + $return['old_domain_test'] = $info['old_domain_test'];
  93 + $return['old_domain_online'] = $info['old_domain_online'];
  94 + }
  95 +
  96 + return $return;
  97 + }
  98 +
  99 + /**
  100 + * 远程请求
  101 + * @param $url
  102 + * @return mixed
  103 + * @author Akun
  104 + * @date 2023/11/29 14:23
  105 + */
  106 + public static function curlGet($url)
  107 + {
  108 + $header = array(
  109 + 'Expect:',
  110 + 'Content-Type: application/json; charset=utf-8'
  111 + );
  112 + $ch = curl_init($url);
  113 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  114 + curl_setopt($ch, CURLOPT_HEADER, false);
  115 + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  116 + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246');
  117 + curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  118 + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
  119 + curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  120 + curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
  121 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  122 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  123 + curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
  124 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  125 + $content = curl_exec($ch);
  126 + curl_close($ch);
  127 + return json_decode($content, true);
  128 + }
  129 +}