作者 lyh

gx

... ... @@ -4,10 +4,8 @@ namespace App\Http\Logic\Aside\Template;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BCommonTemplate;
use App\Models\Template\Template;
use App\Models\Template\Setting;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
class ATemplateLogic extends BaseLogic
... ... @@ -185,49 +183,6 @@ class ATemplateLogic extends BaseLogic
if($rs === false){
$this->fail('error');
}
$html = Template::where('id', $this->param['template_id'])->value('html');
$this->splitTemplate($html);
return $this->success();
}
/**
* 保存拆分模板
* @author zbj
* @date 2023/10/11
*/
public function splitTemplate($html){
$data['main_html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');
$data['main_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
$common['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s');
$common['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s');
$common['head_style'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');
$common['footer_style'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s');
$common['other_html'] = str_replace('<header', '', characterTruncation($html,'/<link id="google-fonts-link"(.*?)<header/s'));
//保存公共部门
ProjectServer::useProject($this->param['project_id']);
$common_info = DB::connection('custom_mysql')->table('gl_web_common_template')
->where('project_id', $this->param['project_id'])
->where('template_id', $this->param['template_id'])
->first();
$common['updated_at'] = date('Y-m-d H:i:s');
if(!$common){
$common['project_id'] = $this->param['project_id'];
$common['template_id'] = $this->param['template_id'];
$common['created_at'] = date('Y-m-d H:i:s');
DB::connection('custom_mysql')->table('gl_web_common_template')->insert($common);
}else{
DB::connection('custom_mysql')->table('gl_web_common_template')
->where('project_id', $this->param['project_id'])
->where('template_id', $this->param['template_id'])
->update($common);
}
//返回main
return $data;
}
}
... ...
<?php
namespace App\Models\Template;
use App\Models\Base;
class BCommonTemplate extends Base
{
protected $table = 'gl_web_common_template';
//连接数据库
protected $connection = 'custom_mysql';
}