作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

@@ -39,15 +39,14 @@ class HtmlCollect extends Command @@ -39,15 +39,14 @@ class HtmlCollect extends Command
39 39
40 public function handle() 40 public function handle()
41 { 41 {
42 -// while (true) { 42 + while (true) {
43 $this->start_collect(); 43 $this->start_collect();
44 -// } 44 + }
45 } 45 }
46 46
47 protected function start_collect() 47 protected function start_collect()
48 { 48 {
49 -// $task_id = $this->get_task();  
50 - $task_id = '595_41517'; 49 + $task_id = $this->get_task();
51 if ($task_id === false) { 50 if ($task_id === false) {
52 //所有项目采集完成 51 //所有项目采集完成
53 sleep(60); 52 sleep(60);
@@ -336,62 +336,73 @@ class HtmlLanguageCollect extends Command @@ -336,62 +336,73 @@ class HtmlLanguageCollect extends Command
336 ]); 336 ]);
337 $html = str_replace($vs['url'], getImageUrl($new_source), $html); 337 $html = str_replace($vs['url'], getImageUrl($new_source), $html);
338 338
  339 + if (substr($new_source, -3, 3) == 'css' || substr($new_source, -2, 2) == 'js') {
  340 +
  341 + $source_html = curl_c(getImageUrl($new_source), false);
  342 +
339 if (substr($new_source, -3, 3) == 'css') { 343 if (substr($new_source, -3, 3) == 'css') {
340 - // 下载css文件中的资源  
341 - $css_html = curl_c($vs['url_complete'], false);  
342 - preg_match_all("/url\(['\"](\s*[^>]+?)['\"]\)/i", $css_html, $result_css_source);  
343 - $css_source = $result_css_source[1] ?? [];  
344 -  
345 - $url_arr = explode('/', $vs['url_complete']);  
346 - $target_arr = explode('/', $new_source);  
347 - foreach ($css_source as $vcs) {  
348 - $vcs = str_replace('"', '', $vcs);  
349 - $vcs_arr = parse_url($vcs);  
350 - if (isset($vcs_arr['domain'])) {  
351 - //不是相对路径,不下载  
352 - continue; 344 + preg_match_all("/url\(['\"]?(\s*[^>]+?)['\"]?\)/i", $source_html, $result_source);
  345 + } else {
  346 + preg_match_all("/[large|thumb]+URL:['\"]+(\s*[^>]+?)['\"]+,/i", $source_html, $result_source);
353 } 347 }
354 348
355 - $vcs = $vcs_arr['path'] ?? '';  
356 - if (!$vcs) {  
357 - continue;  
358 - }  
359 - if (strpos($vcs, '.') === false) {  
360 - continue;  
361 - }  
362 - $path_arr = explode('.', $vcs);  
363 - if (in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) {  
364 - continue; 349 + $js_css_source = $result_source[1] ?? [];
  350 + if ($js_css_source) {
  351 + foreach ($js_css_source as $vjs) {
  352 + if (substr($vjs, 0, 2) == './') {
  353 + //相对路径
  354 + $url_arr = explode('/', $vs['url']);
  355 + $url_arr[count($url_arr) - 1] = substr($vjs, 2);
  356 + $vjs = implode('/', $url_arr);
365 } 357 }
366 -  
367 - $source_info = CollectSource::where('project_id', $project_id)->where('origin', $vcs)->first();  
368 - if ($source_info) {  
369 - //已存在,不下载 358 + $vjs_result = $this->url_check($vjs, $project_id, $domain, $web_url_domain, $home_url);
  359 + if (!$vjs_result) {
370 continue; 360 continue;
371 } 361 }
372 362
373 - $url_arr[count($url_arr) - 1] = $vcs;  
374 - $url_css_complete = implode('/', $url_arr);  
375 - $target_arr[count($target_arr) - 1] = $vcs;  
376 - $path = implode('/', $target_arr);  
377 -  
378 - $new_source_css = CosService::uploadRemote($project_id, 'source', $url_css_complete, $path);  
379 - if ($new_source_css) { 363 + if ($vjs_result['download']) {
  364 + $new_vjs = CosService::uploadRemote($project_id, 'source', $vjs_result['url_complete']);
  365 + if ($new_vjs) {
380 CollectSource::insert([ 366 CollectSource::insert([
381 'project_id' => $project_id, 367 'project_id' => $project_id,
382 - 'origin' => $vcs,  
383 - 'target' => $new_source_css, 368 + 'origin' => $vjs_result['url'],
  369 + 'target' => $new_vjs,
384 'created_at' => date('Y-m-d H:i:s'), 370 'created_at' => date('Y-m-d H:i:s'),
385 'updated_at' => date('Y-m-d H:i:s'), 371 'updated_at' => date('Y-m-d H:i:s'),
386 ]); 372 ]);
  373 + $source_html = str_replace($vjs, getImageUrl($new_vjs), $source_html);
387 } 374 }
  375 + } else {
  376 + $source_html = str_replace($vjs, getImageUrl($vjs_result['url_complete']), $source_html);
  377 + }
  378 + }
  379 +
  380 + CosService::uploadRemote($project_id, 'source', $new_source, $new_source, $source_html);
  381 + }
  382 + }
  383 + }
  384 + } else {
  385 + $html = str_replace($vs['url'], getImageUrl($vs['url_complete']), $html);
  386 +
  387 + if (substr($vs['url_complete'], -3, 3) == 'css' || substr($vs['url_complete'], -2, 2) == 'js') {
  388 +
  389 + $source_html = curl_c(getImageUrl($vs['url_complete']), false);
  390 +
  391 + if (substr($vs['url_complete'], -3, 3) == 'css') {
  392 + preg_match_all("/url\(['\"]?(\s*[^>]+?)['\"]?\)/i", $source_html, $result_source);
  393 + } else {
  394 + preg_match_all("/[large|thumb]+URL:['\"]+(\s*[^>]+?)['\"]+,/i", $source_html, $result_source);
  395 + }
  396 +
  397 + $js_css_source = $result_source[1] ?? [];
  398 + if ($js_css_source) {
  399 + foreach ($js_css_source as $vjs) {
  400 + if (substr($vjs, 0, 2) == './') {
  401 + //相对路径
  402 + $url_arr = explode('/', $vs['url']);
  403 + $url_arr[count($url_arr) - 1] = substr($vjs, 2);
  404 + $vjs = implode('/', $url_arr);
388 } 405 }
389 - } elseif (substr($new_source, -2, 2) == 'js') {  
390 - $js_html = curl_c(getImageUrl($new_source), false);  
391 - preg_match_all("/[large|thumb]+URL:['\"]+(\s*[^>]+?)['\"]+,/i", $js_html, $result_js_source);  
392 - $js_source = $result_js_source[1] ?? [];  
393 - if ($js_source) {  
394 - foreach ($js_source as $vjs) {  
395 $vjs_result = $this->url_check($vjs, $project_id, $domain, $web_url_domain, $home_url); 406 $vjs_result = $this->url_check($vjs, $project_id, $domain, $web_url_domain, $home_url);
396 if (!$vjs_result) { 407 if (!$vjs_result) {
397 continue; 408 continue;
@@ -407,19 +418,16 @@ class HtmlLanguageCollect extends Command @@ -407,19 +418,16 @@ class HtmlLanguageCollect extends Command
407 'created_at' => date('Y-m-d H:i:s'), 418 'created_at' => date('Y-m-d H:i:s'),
408 'updated_at' => date('Y-m-d H:i:s'), 419 'updated_at' => date('Y-m-d H:i:s'),
409 ]); 420 ]);
410 - $js_html = str_replace($vjs, getImageUrl($new_vjs), $js_html); 421 + $source_html = str_replace($vjs, getImageUrl($new_vjs), $source_html);
411 } 422 }
412 } else { 423 } else {
413 - $js_html = str_replace($vjs, getImageUrl($vjs_result['url_complete']), $js_html); 424 + $source_html = str_replace($vjs, getImageUrl($vjs_result['url_complete']), $source_html);
414 } 425 }
415 } 426 }
416 427
417 - CosService::uploadRemote($project_id, 'source', $new_source, $new_source, $js_html);  
418 - } 428 + CosService::uploadRemote($project_id, 'source', $vs['url_complete'], $vs['url_complete'], $source_html);
419 } 429 }
420 } 430 }
421 - } else {  
422 - $html = str_replace($vs['url'], getImageUrl($vs['url_complete']), $html);  
423 } 431 }
424 } 432 }
425 433
@@ -112,7 +112,7 @@ class OptimizeController extends BaseController @@ -112,7 +112,7 @@ class OptimizeController extends BaseController
112 'gl_project_online_check.go_question AS go_question', 112 'gl_project_online_check.go_question AS go_question',
113 'gl_project_online_check.optimist_status AS optimist_status', 113 'gl_project_online_check.optimist_status AS optimist_status',
114 'gl_project_online_check.qa_status AS qa_status', 114 'gl_project_online_check.qa_status AS qa_status',
115 - 'gl_project_online_check.created_at AS online_created_at', 115 + 'gl_project_online_check.updated_at AS online_updated_at',
116 'gl_project_payment.amount AS amount', 116 'gl_project_payment.amount AS amount',
117 'gl_project_deploy_build.dept_id AS dept_id', 117 'gl_project_deploy_build.dept_id AS dept_id',
118 'gl_project_deploy_build.keyword_num AS key', 118 'gl_project_deploy_build.keyword_num AS key',
@@ -153,6 +153,9 @@ class OptimizeController extends BaseController @@ -153,6 +153,9 @@ class OptimizeController extends BaseController
153 if(isset($this->map['level']) && !empty($this->map['level'])){ 153 if(isset($this->map['level']) && !empty($this->map['level'])){
154 $query = $query->whereRaw("FIND_IN_SET(?, gl_project.level) > 0", [$this->map['level']]); 154 $query = $query->whereRaw("FIND_IN_SET(?, gl_project.level) > 0", [$this->map['level']]);
155 } 155 }
  156 + if(isset($this->map['online_updated_at']) && !empty($this->map['online_updated_at'])){
  157 + $query = $query->whereBetween('gl_project_deploy_optimize.updated_at', $this->map['online_updated_at']);
  158 + }
156 if(isset($this->map['special']) && !empty($this->map['special'])){ 159 if(isset($this->map['special']) && !empty($this->map['special'])){
157 $query = $query->where('gl_project_deploy_optimize.special','like','%'.$this->map['special'].'%'); 160 $query = $query->where('gl_project_deploy_optimize.special','like','%'.$this->map['special'].'%');
158 } 161 }