作者 赵彬吉

update

@@ -4,10 +4,11 @@ namespace App\Http\Logic\Aside\Template; @@ -4,10 +4,11 @@ namespace App\Http\Logic\Aside\Template;
4 4
5 use App\Http\Logic\Aside\BaseLogic; 5 use App\Http\Logic\Aside\BaseLogic;
6 use App\Models\Service\Service as ServiceSettingModel; 6 use App\Models\Service\Service as ServiceSettingModel;
  7 +use App\Models\Template\BCommonTemplate;
7 use App\Models\Template\Template; 8 use App\Models\Template\Template;
8 use App\Models\Template\Setting; 9 use App\Models\Template\Setting;
  10 +use App\Services\ProjectServer;
9 use Illuminate\Support\Facades\DB; 11 use Illuminate\Support\Facades\DB;
10 -use mysql_xdevapi\Exception;  
11 12
12 class ATemplateLogic extends BaseLogic 13 class ATemplateLogic extends BaseLogic
13 { 14 {
@@ -141,7 +142,7 @@ class ATemplateLogic extends BaseLogic @@ -141,7 +142,7 @@ class ATemplateLogic extends BaseLogic
141 ]; 142 ];
142 $serviceSettingModel->insert($data); 143 $serviceSettingModel->insert($data);
143 DB::commit(); 144 DB::commit();
144 - }catch (Exception $e){ 145 + }catch (\Exception $e){
145 DB::rollBack(); 146 DB::rollBack();
146 $this->fail('error'); 147 $this->fail('error');
147 } 148 }
@@ -184,6 +185,49 @@ class ATemplateLogic extends BaseLogic @@ -184,6 +185,49 @@ class ATemplateLogic extends BaseLogic
184 if($rs === false){ 185 if($rs === false){
185 $this->fail('error'); 186 $this->fail('error');
186 } 187 }
  188 + $html = Template::where('id', $this->param['template_id'])->value('html');
  189 +
  190 + $this->splitTemplate($html);
  191 +
187 return $this->success(); 192 return $this->success();
188 } 193 }
  194 +
  195 + /**
  196 + * 保存拆分模板
  197 + * @author zbj
  198 + * @date 2023/10/11
  199 + */
  200 + public function splitTemplate($html){
  201 + $data['main_html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');
  202 + $data['main_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
  203 +
  204 + $common['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s');
  205 + $common['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s');
  206 + $common['head_style'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');
  207 + $common['footer_style'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s');
  208 + $common['other_html'] = str_replace('<header', '', characterTruncation($html,'/<link id="google-fonts-link"(.*?)<header/s'));
  209 +
  210 + //保存公共部门
  211 + ProjectServer::useProject($this->param['project_id']);
  212 + $common_info = DB::connection('custom_mysql')->table('gl_web_common_template')
  213 + ->where('project_id', $this->param['project_id'])
  214 + ->where('template_id', $this->param['template_id'])
  215 + ->first();
  216 +
  217 + $common['updated_at'] = date('Y-m-d H:i:s');
  218 + if(!$common){
  219 + $common['project_id'] = $this->param['project_id'];
  220 + $common['template_id'] = $this->param['template_id'];
  221 + $common['created_at'] = date('Y-m-d H:i:s');
  222 + DB::connection('custom_mysql')->table('gl_web_common_template')->insert($common);
  223 + }else{
  224 + DB::connection('custom_mysql')->table('gl_web_common_template')
  225 + ->where('project_id', $this->param['project_id'])
  226 + ->where('template_id', $this->param['template_id'])
  227 + ->update($common);
  228 + }
  229 +
  230 + //返回main
  231 + return $data;
  232 + }
189 } 233 }
  1 +<?php
  2 +
  3 +namespace App\Models\Template;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class BCommonTemplate extends Base
  8 +{
  9 + protected $table = 'gl_web_common_template';
  10 + //连接数据库
  11 + protected $connection = 'custom_mysql';
  12 +
  13 +
  14 +}