作者 lyh

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

@@ -282,6 +282,10 @@ class HtmlCollect extends Command @@ -282,6 +282,10 @@ class HtmlCollect extends Command
282 protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url) 282 protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url)
283 { 283 {
284 if ($url) { 284 if ($url) {
  285 + $url = str_replace('"', '', $url);
  286 + if(strpos($url,'mailto:') !== false){
  287 + return false;
  288 + }
285 $arr = parse_url($url); 289 $arr = parse_url($url);
286 $scheme = $arr['scheme'] ?? ''; 290 $scheme = $arr['scheme'] ?? '';
287 $host = $arr['host'] ?? ''; 291 $host = $arr['host'] ?? '';
@@ -343,6 +347,7 @@ class HtmlCollect extends Command @@ -343,6 +347,7 @@ class HtmlCollect extends Command
343 $url_arr = explode('/', $vs['url_complete']); 347 $url_arr = explode('/', $vs['url_complete']);
344 $target_arr = explode('/', $new_source); 348 $target_arr = explode('/', $new_source);
345 foreach ($css_source as $vcs) { 349 foreach ($css_source as $vcs) {
  350 + $vcs = str_replace('"', '', $vcs);
346 $vcs_arr = parse_url($vcs); 351 $vcs_arr = parse_url($vcs);
347 if (isset($vcs_arr['domain'])) { 352 if (isset($vcs_arr['domain'])) {
348 //不是相对路径,不下载 353 //不是相对路径,不下载
@@ -82,10 +82,10 @@ class HtmlLanguageCollect extends Command @@ -82,10 +82,10 @@ class HtmlLanguageCollect extends Command
82 //采集html页面,下载资源到本地并替换 82 //采集html页面,下载资源到本地并替换
83 try { 83 try {
84 $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false); 84 $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false);
85 - if($html == '0'){ 85 + if ($html == '0') {
86 $collect_info->status = CollectTask::STATUS_FAIL; 86 $collect_info->status = CollectTask::STATUS_FAIL;
87 $collect_info->save(); 87 $collect_info->save();
88 - echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL; 88 + echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: no html' . PHP_EOL;
89 sleep(2); 89 sleep(2);
90 return true; 90 return true;
91 } 91 }
@@ -282,6 +282,10 @@ class HtmlLanguageCollect extends Command @@ -282,6 +282,10 @@ class HtmlLanguageCollect extends Command
282 protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url) 282 protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url)
283 { 283 {
284 if ($url) { 284 if ($url) {
  285 + $url = str_replace('"', '', $url);
  286 + if(strpos($url,'mailto:') !== false){
  287 + return false;
  288 + }
285 $arr = parse_url($url); 289 $arr = parse_url($url);
286 $scheme = $arr['scheme'] ?? ''; 290 $scheme = $arr['scheme'] ?? '';
287 $host = $arr['host'] ?? ''; 291 $host = $arr['host'] ?? '';
@@ -343,6 +347,7 @@ class HtmlLanguageCollect extends Command @@ -343,6 +347,7 @@ class HtmlLanguageCollect extends Command
343 $url_arr = explode('/', $vs['url_complete']); 347 $url_arr = explode('/', $vs['url_complete']);
344 $target_arr = explode('/', $new_source); 348 $target_arr = explode('/', $new_source);
345 foreach ($css_source as $vcs) { 349 foreach ($css_source as $vcs) {
  350 + $vcs = str_replace('"', '', $vcs);
346 $vcs_arr = parse_url($vcs); 351 $vcs_arr = parse_url($vcs);
347 if (isset($vcs_arr['domain'])) { 352 if (isset($vcs_arr['domain'])) {
348 //不是相对路径,不下载 353 //不是相对路径,不下载
@@ -357,7 +362,7 @@ class HtmlLanguageCollect extends Command @@ -357,7 +362,7 @@ class HtmlLanguageCollect extends Command
357 continue; 362 continue;
358 } 363 }
359 $path_arr = explode('.', $vcs); 364 $path_arr = explode('.', $vcs);
360 - if(in_array(end($path_arr), ['html', 'php', 'com', 'xml'])){ 365 + if (in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) {
361 continue; 366 continue;
362 } 367 }
363 368
@@ -115,6 +115,7 @@ class ProjectUpdate extends Command @@ -115,6 +115,7 @@ class ProjectUpdate extends Command
115 $page_list = array_column($data_page, 'path'); 115 $page_list = array_column($data_page, 'path');
116 } 116 }
117 117
  118 + $is_flush = 0;
118 //设置数据库 119 //设置数据库
119 $project = ProjectServer::useProject($project_id); 120 $project = ProjectServer::useProject($project_id);
120 if ($project) { 121 if ($project) {
@@ -318,6 +319,7 @@ class ProjectUpdate extends Command @@ -318,6 +319,7 @@ class ProjectUpdate extends Command
318 $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id); 319 $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id);
319 320
320 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); 321 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list);
  322 + $is_flush = 1;
321 } catch (\Exception $e) { 323 } catch (\Exception $e) {
322 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; 324 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
323 continue; 325 continue;
@@ -392,6 +394,7 @@ class ProjectUpdate extends Command @@ -392,6 +394,7 @@ class ProjectUpdate extends Command
392 $this->set_map($route, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id); 394 $this->set_map($route, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
393 395
394 CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list, $page_list); 396 CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list, $page_list);
  397 + $is_flush = 1;
395 } catch (\Exception $e) { 398 } catch (\Exception $e) {
396 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; 399 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
397 continue; 400 continue;
@@ -444,6 +447,7 @@ class ProjectUpdate extends Command @@ -444,6 +447,7 @@ class ProjectUpdate extends Command
444 $this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id); 447 $this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id);
445 448
446 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list); 449 CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list);
  450 + $is_flush = 1;
447 } catch (\Exception $e) { 451 } catch (\Exception $e) {
448 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; 452 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
449 continue; 453 continue;
@@ -462,7 +466,7 @@ class ProjectUpdate extends Command @@ -462,7 +466,7 @@ class ProjectUpdate extends Command
462 DB::disconnect('custom_mysql'); 466 DB::disconnect('custom_mysql');
463 467
464 $task->status = UpdateLog::STATUS_COM;//同步完成 468 $task->status = UpdateLog::STATUS_COM;//同步完成
465 - if($api_type == 'post' || $api_type == 'page' || $api_type == 'news' || $api_type == 'blog'){ 469 + if($is_flush){
466 $task->collect_status = UpdateLog::COLLECT_STATUS_UN; 470 $task->collect_status = UpdateLog::COLLECT_STATUS_UN;
467 } 471 }
468 $task->save(); 472 $task->save();
  1 +<?php
  2 +
  3 +namespace App\Console\Commands\Update;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Logic\Bside\Product\CategoryLogic;
  7 +use App\Models\Collect\CollectSource;
  8 +use App\Models\Collect\CollectTask;
  9 +use App\Models\Com\UpdateLog;
  10 +use App\Models\Product\Category;
  11 +use App\Models\Product\Product;
  12 +use App\Models\RouteMap\RouteMap;
  13 +use App\Services\CosService;
  14 +use App\Services\ProjectServer;
  15 +use Illuminate\Console\Command;
  16 +use Illuminate\Support\Facades\DB;
  17 +
  18 +/**
  19 + * 4.0,5.0升级到6.0,内容同步
  20 + * Class ProjectImport
  21 + * @package App\Console\Commands
  22 + * @author Akun
  23 + * @date 2023/10/9 15:04
  24 + */
  25 +class ProjectUpdateTemp extends Command
  26 +{
  27 + /**
  28 + * The name and signature of the console command.
  29 + *
  30 + * @var string
  31 + */
  32 + protected $signature = 'project_update_temp';
  33 +
  34 + /**
  35 + * The console command description.
  36 + *
  37 + * @var string
  38 + */
  39 + protected $description = '执行项目升级任务';
  40 +
  41 +
  42 + public function handle()
  43 + {
  44 + $this->start_update();
  45 + }
  46 +
  47 + protected function start_update()
  48 + {
  49 + $list = UpdateLog::where('api_type', 'post')->get();
  50 +
  51 + foreach ($list as $task) {
  52 +
  53 +
  54 + $project_id = $task->project_id;
  55 + $api_type = $task->api_type;
  56 + $api_url_arr = explode('?', $task->api_url);
  57 + $api_url = $api_url_arr[0];
  58 +
  59 + $page_size = 20;
  60 +
  61 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL;
  62 +
  63 + //设置数据库
  64 + $project = ProjectServer::useProject($project_id);
  65 + if ($project) {
  66 + if ($api_type == 'category') {
  67 + //产品分类
  68 + $url = $api_url . '?' . http_build_query(['w' => 'category']);
  69 + $data = curl_c($url);
  70 + if (isset($data['code']) && $data['code'] == 200) {
  71 + $items = $data['data'] ?? [];
  72 + $this->category_insert($project_id, $items, 0);
  73 + } else {
  74 + return true;
  75 + }
  76 + } elseif ($api_type == 'post') {
  77 + //产品
  78 + $url = $api_url . '?' . http_build_query(['w' => 'post', 'page' => 1, 'pagesize' => 0]);
  79 + $data = curl_c($url);
  80 + if (isset($data['code']) && $data['code'] == 200) {
  81 + $count = $data['data']['count'] ?? 0;
  82 +
  83 + $total_page = ceil($count / $page_size);
  84 + for ($page = 1; $page <= $total_page; $page++) {
  85 + $url_page = $api_url . '?' . http_build_query(['w' => 'post', 'page' => $page, 'pagesize' => $page_size]);
  86 + $data_page = curl_c($url_page);
  87 + if (isset($data_page['code']) && $data_page['code'] == 200) {
  88 + $items = $data_page['data']['data'] ?? [];
  89 +
  90 + $model = new Product();
  91 + $category_model = new Category();
  92 + $logic = new CategoryLogic();
  93 +
  94 + foreach ($items as $item) {
  95 + $route = $this->get_url_route($item['url'] ?? '');
  96 + if ($route) {
  97 + $product = $model->read(['route' => $route], 'id');
  98 + if ($product) {
  99 + $category_id = '';
  100 + if ($item['category'] ?? []) {
  101 + $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
  102 + $category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
  103 + }
  104 +
  105 + $model->edit(['category_id' => $category_id, 'product_type' => ''], ['id' => $product['id']]);
  106 + }
  107 + }
  108 + }
  109 + }
  110 + }
  111 + } else {
  112 + return true;
  113 + }
  114 + }
  115 + }
  116 + //关闭数据库
  117 + DB::disconnect('custom_mysql');
  118 +
  119 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL;
  120 +
  121 + sleep(2);
  122 + }
  123 + }
  124 +
  125 +
  126 + //获取地址路由
  127 + protected function get_url_route($url)
  128 + {
  129 + $arr = parse_url(urldecode($url));
  130 + if (empty($arr['path'])) {
  131 + return '';
  132 + }
  133 + $path = $arr['path'];
  134 +
  135 + if (strpos($path, '.') !== false) {
  136 + $path = substr($path, 0, strpos($path, '.'));
  137 + }
  138 +
  139 + $path_arr = explode('/', $path);
  140 +
  141 + return end($path_arr) ? end($path_arr) : $path_arr[count($path_arr) - 2];
  142 + }
  143 +
  144 + //产品多级分类入库
  145 + protected function category_insert($project_id, $items, $pid = 0)
  146 + {
  147 + $model = new Category();
  148 + foreach ($items as $item) {
  149 + $route = $this->get_url_route($item['url'] ?? '');
  150 + if ($route) {
  151 + $parent = $model->read(['pid' => $pid, 'route' => $route], 'id');
  152 + if (!$parent) {
  153 + try {
  154 + $item['name'] = $this->special2str($item['name'] ?? '');
  155 + $parent_id = $model->addReturnId([
  156 + 'project_id' => $project_id,
  157 + 'title' => $item['name'],
  158 + 'pid' => $pid,
  159 + 'keywords' => $item['keywords'] ?? '',
  160 + 'describe' => $item['description'] ?? '',
  161 + 'original_id' => $item['id'],
  162 + 'route' => $route
  163 + ]);
  164 + $this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
  165 + } catch (\Exception $e) {
  166 + echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;
  167 + continue;
  168 + }
  169 + } else {
  170 + $parent_id = $parent['id'];
  171 + }
  172 +
  173 + if (!empty($item['children'])) {
  174 + $this->category_insert($project_id, $item['children'], $parent_id);
  175 + }
  176 + }
  177 + }
  178 + }
  179 +
  180 + //特殊字符转换
  181 + protected function special2str($str)
  182 + {
  183 + if (strpos($str, ';') === false) {
  184 + return $str;
  185 + }
  186 +
  187 + $list = [
  188 + '&lt;' => '<',
  189 + '&gt;' => '>',
  190 + '&amp;' => '&',
  191 + '&acute;' => '´',
  192 + '&quot;' => '“',
  193 + '&nbsp;' => ' '
  194 + ];
  195 +
  196 + foreach ($list as $k => $v) {
  197 + $str = str_replace($k, $v, $str);
  198 + }
  199 +
  200 + return $str;
  201 + }
  202 +
  203 + //路由入库
  204 + protected function set_map($route, $source, $source_id, $project_id)
  205 + {
  206 + if ($route) {
  207 + $route_map = RouteMap::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->first();
  208 + if (!$route_map) {
  209 + $route_map = new RouteMap();
  210 + $route_map->project_id = $project_id;
  211 + $route_map->source = $source;
  212 + $route_map->source_id = $source_id;
  213 + $route_map->route = $route;
  214 +
  215 + if ($source == RouteMap::SOURCE_NEWS) {
  216 + $route_map->path = RouteMap::SOURCE_NEWS;
  217 + } elseif ($source == RouteMap::SOURCE_BLOG) {
  218 + $route_map->path = RouteMap::SOURCE_BLOG;
  219 + }
  220 +
  221 + $route_map->save();
  222 + }
  223 + }
  224 + }
  225 +}
@@ -181,6 +181,7 @@ class LoginController extends BaseController @@ -181,6 +181,7 @@ class LoginController extends BaseController
181 */ 181 */
182 public function eventMessage(){ 182 public function eventMessage(){
183 $message = file_get_contents("php://input"); 183 $message = file_get_contents("php://input");
  184 + @file_put_contents(storage_path('logs/lyh_error.log'), var_export($message, true) . PHP_EOL, FILE_APPEND);
184 $message = simplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR); 185 $message = simplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR);
185 $jsonData = json_encode($message); 186 $jsonData = json_encode($message);
186 $arrayData = json_decode($jsonData, true); 187 $arrayData = json_decode($jsonData, true);
@@ -299,25 +300,4 @@ class LoginController extends BaseController @@ -299,25 +300,4 @@ class LoginController extends BaseController
299 } 300 }
300 return $data; 301 return $data;
301 } 302 }
302 -  
303 - public function ceshi(){  
304 - $url = 'https://demo.globalso.site/';  
305 - $contextOptions = [  
306 - 'ssl' => [  
307 - 'verify_peer' => false,  
308 - 'verify_peer_name' => false,  
309 - ],  
310 - ];  
311 - $context = stream_context_create($contextOptions);  
312 - $sourceCode = file_get_contents($url, false, $context);  
313 - $pattern = '/<style\b[^>]*>(.*?)<\/style>/s'; // 定义匹配`<style>`标签及其内容的正则表达式  
314 - $strippedContent = preg_replace($pattern, '', $sourceCode); // 删除`<style>`标签及其内容  
315 - $pattern = '/<link\b[^>]*>/'; // 定义匹配 `<link>` 标签的正则表达式  
316 - $strippedContent = preg_replace($pattern, '', $strippedContent); // 删除 `<link>` 标签  
317 - $pattern = '/>([^<]+)</'; // 定义匹配中间内容不是标签的正则表达式  
318 - $matches = array();  
319 - preg_match_all($pattern, $strippedContent, $matches);  
320 - $textContentArray = $matches[1];  
321 - var_dump($textContentArray);  
322 - }  
323 } 303 }
@@ -46,7 +46,7 @@ class VisualizationLogic extends BaseLogic @@ -46,7 +46,7 @@ class VisualizationLogic extends BaseLogic
46 $source = $data['source']; 46 $source = $data['source'];
47 $source_id = $data['source_id']; 47 $source_id = $data['source_id'];
48 $type = $this->getType($source,$source_id); 48 $type = $this->getType($source,$source_id);
49 - $typeArray = [1,3,5,7];//单页数据 49 + $typeArray = [BTemplate::TYPE_ONE,BTemplate::TYPE_THREE,BTemplate::TYPE_FIVE,BTemplate::TYPE_SEVEN];//单页数据
50 if(in_array($type,$typeArray)){ 50 if(in_array($type,$typeArray)){
51 $bTemplateModel = new BTemplate(); 51 $bTemplateModel = new BTemplate();
52 $info = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]); 52 $info = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]);
@@ -54,7 +54,7 @@ class VisualizationLogic extends BaseLogic @@ -54,7 +54,7 @@ class VisualizationLogic extends BaseLogic
54 $html = ''; 54 $html = '';
55 }else{ 55 }else{
56 $html = $info['html']; 56 $html = $info['html'];
57 - } 57 + }
58 }else{//模块数据 58 }else{//模块数据
59 $bTemplateMainModel = new BTemplateMain(); 59 $bTemplateMainModel = new BTemplateMain();
60 $info = $bTemplateMainModel->read(['type'=>$type]); 60 $info = $bTemplateMainModel->read(['type'=>$type]);
@@ -67,6 +67,13 @@ class VisualizationLogic extends BaseLogic @@ -67,6 +67,13 @@ class VisualizationLogic extends BaseLogic
67 return $this->success(['html'=>$html]); 67 return $this->success(['html'=>$html]);
68 } 68 }
69 69
  70 + /**
  71 + * @remark :根据type获取source类型
  72 + * @name :getSource
  73 + * @author :lyh
  74 + * @method :post
  75 + * @time :2023/12/6 11:25
  76 + */
70 public function getSource($type){ 77 public function getSource($type){
71 $source_id = 0; 78 $source_id = 0;
72 if ($type == 2){$source = 2;$source_id = 1; 79 if ($type == 2){$source = 2;$source_id = 1;
@@ -98,10 +105,8 @@ class VisualizationLogic extends BaseLogic @@ -98,10 +105,8 @@ class VisualizationLogic extends BaseLogic
98 $templateInfo = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]); 105 $templateInfo = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]);
99 if($templateInfo === false){ 106 if($templateInfo === false){
100 $data = [ 107 $data = [
101 - 'html'=>$this->param['html'],  
102 - 'project_id'=>$this->user['project_id'],  
103 - 'source'=>$source,  
104 - 'source_id'=>$source_id, 108 + 'html'=>$this->param['html'], 'project_id'=>$this->user['project_id'],
  109 + 'source'=>$source, 'source_id'=>$source_id,
105 ]; 110 ];
106 $bTemplateModel->add($data); 111 $bTemplateModel->add($data);
107 }else{ 112 }else{
@@ -139,51 +144,83 @@ class VisualizationLogic extends BaseLogic @@ -139,51 +144,83 @@ class VisualizationLogic extends BaseLogic
139 $page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面 144 $page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面
140 //查看当前类型是否是定制界面 145 //查看当前类型是否是定制界面
141 if(in_array($type,$page_array)){//是定制界面 146 if(in_array($type,$page_array)){//是定制界面
142 - if(in_array($type,[1,3,5,7])){//单页  
143 - $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块  
144 - if($templateInfo === false){ 147 + return $this->getVisualizationHtml($type);
  148 + }else{//非定制界面
  149 + return $this->getTemplateHtml();
  150 + }
  151 + }
  152 +
  153 + /**
  154 + * @remark :定制界面获取html
  155 + * @name :getVisualizationHtml
  156 + * @author :lyh
  157 + * @method :post
  158 + * @time :2023/12/6 11:47
  159 + */
  160 + public function getVisualizationHtml($type){
  161 + if(in_array($type,[1,3,5,7])){//单页
  162 + $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块
  163 + if($templateInfo === false){
  164 + $this->fail('请先上传定制代码块');
  165 + }
  166 + return ['html'=>$templateInfo['html']];
  167 + }else{//模块页
  168 + $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前页面是否可视化
  169 + if($templateInfo === false){//获取代码块
  170 + $bTemplateMainModel = new BTemplateMain();
  171 + $mainInfo = $bTemplateMainModel->read(['type'=>$type]);
  172 + if($mainInfo === false){
145 $this->fail('请先上传定制代码块'); 173 $this->fail('请先上传定制代码块');
146 } 174 }
147 - return ['html'=>$templateInfo['html']];  
148 - }else{//模块页  
149 - $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前页面是否可视化  
150 - if($templateInfo === false){//获取代码块  
151 - $bTemplateMainModel = new BTemplateMain();  
152 - $mainInfo = $bTemplateMainModel->read(['type'=>$type]);  
153 - if($mainInfo === false){  
154 - $this->fail('请先上传定制代码块');  
155 - }  
156 - return ['html'=>$mainInfo['main_html']];  
157 - }  
158 - return ['html'=>$templateInfo['html']]; 175 + return ['html'=>$mainInfo['main_html']];
159 } 176 }
160 - }else{//非定制界面  
161 - $bSettingModel = new Setting();  
162 - $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);  
163 - if($settingInfo === false){  
164 - $this->fail('请先选择模版'); 177 + //替换为公共头部和底部
  178 + $templateCommonModel = new BTemplateCommon();
  179 + $headerFooterHtml = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
  180 + $html = $templateInfo['html'];
  181 + if($headerFooterHtml !== false){
  182 + $html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $headerFooterHtml['head_html'], $html);
  183 + $html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $headerFooterHtml['footer_html'], $html);
  184 + $html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $headerFooterHtml['head_css'], $html);
  185 + $html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $headerFooterHtml['footer_css'], $html);
165 } 186 }
166 - $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);//查看当前页面是否可视化  
167 - if($templateInfo === false){  
168 - //根据类型在获取中间部分  
169 - $mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']);  
170 - }else{  
171 - $mainData = [  
172 - 'main_html'=>$templateInfo['main_html'],  
173 - 'main_css'=>$templateInfo['main_css']  
174 - ];  
175 - }  
176 - //获取公共头部底部  
177 - $commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);  
178 - //拼接数据  
179 - $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].  
180 - $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];  
181 - $html = $this->getHeadFooter($html);  
182 - return ['html'=>$html,'template_id'=>$settingInfo['template_id']]; 187 + return ['html'=>$html];
183 } 188 }
184 } 189 }
185 190
186 /** 191 /**
  192 + * @remark :非定制项目获取html
  193 + * @name :getTemplateHtml
  194 + * @author :lyh
  195 + * @method :post
  196 + * @time :2023/12/6 11:44
  197 + */
  198 + public function getTemplateHtml(){
  199 + $bSettingModel = new Setting();
  200 + $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
  201 + if($settingInfo === false){
  202 + $this->fail('请先选择模版');
  203 + }
  204 + $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);//查看当前页面是否可视化
  205 + if($templateInfo === false){
  206 + //根据类型在获取中间部分
  207 + $mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']);
  208 + }else{
  209 + $mainData = [
  210 + 'main_html'=>$templateInfo['main_html'],
  211 + 'main_css'=>$templateInfo['main_css']
  212 + ];
  213 + }
  214 + //获取公共头部底部
  215 + $commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);
  216 + //拼接数据
  217 + $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
  218 + $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];
  219 + $html = $this->getHeadFooter($html);
  220 + return $this->success(['html'=>$html,'template_id'=>$settingInfo['template_id']]);
  221 + }
  222 +
  223 + /**
187 * @remark :拼接获取公共头部底部 224 * @remark :拼接获取公共头部底部
188 * @name :getHeadFooter 225 * @name :getHeadFooter
189 * @author :lyh 226 * @author :lyh
@@ -226,7 +263,7 @@ class VisualizationLogic extends BaseLogic @@ -226,7 +263,7 @@ class VisualizationLogic extends BaseLogic
226 } 263 }
227 264
228 /** 265 /**
229 - * @remark :获取类型 266 + * @remark :定制界面根据source+source_id获取type类型
230 * @name :getType 267 * @name :getType
231 * @author :lyh 268 * @author :lyh
232 * @method :post 269 * @method :post
@@ -247,7 +284,7 @@ class VisualizationLogic extends BaseLogic @@ -247,7 +284,7 @@ class VisualizationLogic extends BaseLogic
247 } 284 }
248 285
249 /** 286 /**
250 - * @remark :获取设置的类型 287 + * @remark :非定制获取设置头部底部的类型
251 * @name :getType 288 * @name :getType
252 * @author :lyh 289 * @author :lyh
253 * @method :post 290 * @method :post
@@ -284,7 +321,7 @@ class VisualizationLogic extends BaseLogic @@ -284,7 +321,7 @@ class VisualizationLogic extends BaseLogic
284 $type = $this->getType($this->param['source'],$this->param['source_id']); 321 $type = $this->getType($this->param['source'],$this->param['source_id']);
285 try { 322 try {
286 if(in_array($type,$page_array)){//定制页面 323 if(in_array($type,$page_array)){//定制页面
287 - $this->saveVisualizationHtml(); 324 + $this->saveVisualizationHtml($type);
288 }else{ 325 }else{
289 $this->saveTemplateHtml(); 326 $this->saveTemplateHtml();
290 } 327 }
@@ -301,23 +338,53 @@ class VisualizationLogic extends BaseLogic @@ -301,23 +338,53 @@ class VisualizationLogic extends BaseLogic
301 * @method :post 338 * @method :post
302 * @time :2023/12/5 15:42 339 * @time :2023/12/5 15:42
303 */ 340 */
304 - public function saveVisualizationHtml(){ 341 + public function saveVisualizationHtml($type){
305 $bTemplateModel = new BTemplate(); 342 $bTemplateModel = new BTemplate();
306 $templateInfo = $bTemplateModel->read([ 343 $templateInfo = $bTemplateModel->read([
307 'source'=>$this->param['source'], 'project_id'=>$this->user['project_id'], 344 'source'=>$this->param['source'], 'project_id'=>$this->user['project_id'],
308 'source_id'=>$this->param['source_id'], 'template_id'=>0 345 'source_id'=>$this->param['source_id'], 'template_id'=>0
309 ]); 346 ]);
310 - if($templateInfo === false){  
311 - $this->param['project_id'] = $this->user['project_id'];  
312 - $this->param['template_id'] = 0;  
313 -// $this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');  
314 -// $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');  
315 - $bTemplateModel->add($this->param); 347 + try {
  348 + //更新头部底部
  349 + $this->visualizationSaveHeaderFooter($type);
  350 + if($templateInfo === false){
  351 + $this->param['project_id'] = $this->user['project_id'];
  352 + $this->param['template_id'] = 0;
  353 + $bTemplateModel->add($this->param);
  354 + }else{
  355 + $param['html'] = $this->param['html'];
  356 + $bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]);
  357 + }
  358 + }catch (\Exception $e){
  359 + $this->fail('系统错误,请联系管理员');
  360 + }
  361 + return $this->success();
  362 + }
  363 +
  364 + /**
  365 + * @remark :定制界面保存头部底部
  366 + * @name :visualizationSaveHeaderFooter
  367 + * @author :lyh
  368 + * @method :post
  369 + * @time :2023/12/6 10:41
  370 + */
  371 + public function visualizationSaveHeaderFooter($type){
  372 + //更新头部底部代码
  373 + $header_footer = [
  374 + 'head_html'=>characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s'),
  375 + 'head_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s'),
  376 + 'footer_html'=>characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s'),
  377 + 'footer_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
  378 + ];
  379 + $templateCommonModel = new BTemplateCommon();
  380 + $info = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
  381 + if($info === false){
  382 + $header_footer['template_id'] = 0;
  383 + $header_footer['project_id'] = $this->user['project_id'];
  384 + $header_footer['type'] = $type;
  385 + $templateCommonModel->add($header_footer);
316 }else{ 386 }else{
317 -// $param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');  
318 -// $param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');  
319 - $param['html'] = $this->param['html'];  
320 - $bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]); 387 + $templateCommonModel->edit($header_footer,['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
321 } 388 }
322 return $this->success(); 389 return $this->success();
323 } 390 }