作者 lyh

gx

... ... @@ -55,7 +55,7 @@ class ReplaceHtmlController extends BaseController
'old_html.required' => '替换前的html不能为空',
'project_id.required' => 'project_id不能为空',
]);
$logic->replaceHtml();
$logic->replaceTemplateMainHtml();
$this->response('success');
}
... ...
... ... @@ -12,6 +12,7 @@ namespace App\Http\Logic\Aside\Template;
use App\Http\Logic\aside\BaseLogic;
use App\Models\CustomModule\CustomModule;
use App\Models\Template\BTemplate;
use App\Models\Template\Setting;
use App\Models\Template\TemplateReplaceHtml;
use App\Models\Template\TemplateReplaceHtmlLog;
use App\Services\ProjectServer;
... ... @@ -33,8 +34,28 @@ class ReplaceHtmlLogic extends BaseLogic
* @method :post
* @time :2024/5/9 18:03
*/
public function getTemplateId(){
public function getTemplateId($typeInfo){
//获取当前template_id
$bSettingModel = new Setting();
$templateInfo = $bSettingModel->read(['project_id'=>$this->param['project_id']]);
if($templateInfo === false){
$this->fail('请先选择模版');
}
$template_id = $templateInfo['template_id'];
if($typeInfo['is_custom'] == 1){//扩展模块
$customModuleModel = new CustomModule();
$moduleInfo = $customModuleModel->read(['id'=>$typeInfo['type']],['list_customized','detail_customized']);
if($moduleInfo === false){
$this->fail('当前扩展模块不存在或已被删除');
}
if($typeInfo['is_list'] == 1 && $moduleInfo['list_customized'] == 1){
$template_id = 0;
}
if($typeInfo['is_list'] == 0 && $moduleInfo['detail_customized'] == 1){
$template_id = 0;
}
}
return $this->success($template_id);
}
/**
... ... @@ -44,25 +65,18 @@ class ReplaceHtmlLogic extends BaseLogic
* @method :post
* @time :2024/5/7 15:52
*/
public function replaceHtml(){
public function replaceTemplateMainHtml(){
ProjectServer::useProject($this->param['project_id']);
$data = $this->model->sourceType();
if(!isset($data[$this->param['name']])){
$this->fail('数据错误,请联系管理员');
$data = $this->sourceTypeInfo();
$typeInfo = $data[$this->param['name']];
if(!isset($typeInfo)){
$this->fail('当前类型不存在,请联系管理员');
}
$replaceHtmlData = [
'old_html'=>$this->param['old_html'],
'html'=>$this->param['html'],
'type'=>$data[$this->param['name']]['type'],
'is_list'=>$data[$this->param['name']]['is_list'],
'is_custom'=>$data[$this->param['name']]['is_custom'],
'template_id'=>1
];
$template_id = $this->getTemplateId($typeInfo);
//TODO::生成一条任务记录
$replaceId = $this->saveReplaceHtml($this->param);
$replaceId = $this->saveReplaceHtml($this->param,$typeInfo,$template_id);
//查询当前类型所有装修的记录
$condition = ['source'=>$this->param['type'],'is_custom'=>$this->param['is_custom'],'is_list'=>$this->param['is_list'],
'template_id'=>$this->param['template_id']];
$condition = ['source'=>$typeInfo['type'],'is_custom'=>$typeInfo['is_custom'],'is_list'=>$typeInfo['is_list'], 'template_id'=>$template_id];
$list = $this->model->list($condition);
foreach ($list as $v){
if($v['type'] == 0){
... ... @@ -85,14 +99,15 @@ class ReplaceHtmlLogic extends BaseLogic
* @method :post
* @time :2024/5/8 9:23
*/
public function saveReplaceHtml($data,$template_id){
public function saveReplaceHtml($param,$data,$template_id){
$logData = [
'type'=>$data['type'],
'is_custom'=>$data['is_custom'],
'is_list'=>$data['is_list'],
'template_id'=>$template_id,
'old_html'=>$data['old_html'],
'html'=>$data['html'],
'old_html'=>$param['old_html'],
'html'=>$param['html'],
'project_id'=>$param['project_id'],
];
return $this->model->addReturnId($logData);
}
... ... @@ -123,11 +138,11 @@ class ReplaceHtmlLogic extends BaseLogic
*/
public function reductionHtml(){
ProjectServer::useProject($this->param['project_id']);
//获取当前数据详情
$info = $this->model->read(['id'=>$this->param['id']]);
if($info === false){
$this->fail('当前数据不存在');
}
$replaceId = $this->saveResultReplaceHtml($info);
$replaceLogModel = new TemplateReplaceHtmlLog();
$logList = $replaceLogModel->list(['replace_id'=>$this->param['id']]);
$replaceArr = [];
... ... @@ -141,18 +156,39 @@ class ReplaceHtmlLogic extends BaseLogic
foreach ($templateList as $value){
if($v['type'] == 0){
$main_html = str_replace($info['html'],$info['old_html'],$value['main_html']);
$this->model->edit(['main_html'=>$main_html],['id'=>$v['id']]);
$this->model->edit(['main_html'=>$main_html],['id'=>$value['id']]);
}else{
$html = str_replace($info['html'],$info['old_html'],$value['html']);
$this->model->edit(['html'=>$html],['id'=>$v['id']]);
$this->model->edit(['html'=>$html],['id'=>$value['id']]);
}
}
$this->saveReplaceHtmlLog($replaceId,$value['id']);
}
DB::disconnect('custom_mysql');
return $this->success();
}
/**
* @remark :保存还原的html
* @name :saveResultReplaceHtml
* @author :lyh
* @method :post
* @time :2024/5/10 10:01
*/
public function saveResultReplaceHtml($info){
$logData = [
'type'=>$info['type'],
'is_custom'=>$info['is_custom'],
'is_list'=>$info['is_list'],
'template_id'=>$info['template_id'],
'old_html'=>$info['html'],
'html'=>$info['old_html'],
'project_id'=>$info['project_id'],
];
return $this->model->addReturnId($logData);
}
/**
* @remark :替换类型
* @name :sourceTypeInfo
* @author :lyh
... ...