作者 lyh

gx

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