作者 lyh

gx

@@ -55,7 +55,7 @@ class ReplaceHtmlController extends BaseController @@ -55,7 +55,7 @@ class ReplaceHtmlController extends BaseController
55 'old_html.required' => '替换前的html不能为空', 55 'old_html.required' => '替换前的html不能为空',
56 'project_id.required' => 'project_id不能为空', 56 'project_id.required' => 'project_id不能为空',
57 ]); 57 ]);
58 - $logic->replaceHtml(); 58 + $logic->replaceTemplateMainHtml();
59 $this->response('success'); 59 $this->response('success');
60 } 60 }
61 61
@@ -12,6 +12,7 @@ namespace App\Http\Logic\Aside\Template; @@ -12,6 +12,7 @@ namespace App\Http\Logic\Aside\Template;
12 use App\Http\Logic\aside\BaseLogic; 12 use App\Http\Logic\aside\BaseLogic;
13 use App\Models\CustomModule\CustomModule; 13 use App\Models\CustomModule\CustomModule;
14 use App\Models\Template\BTemplate; 14 use App\Models\Template\BTemplate;
  15 +use App\Models\Template\Setting;
15 use App\Models\Template\TemplateReplaceHtml; 16 use App\Models\Template\TemplateReplaceHtml;
16 use App\Models\Template\TemplateReplaceHtmlLog; 17 use App\Models\Template\TemplateReplaceHtmlLog;
17 use App\Services\ProjectServer; 18 use App\Services\ProjectServer;
@@ -33,8 +34,28 @@ class ReplaceHtmlLogic extends BaseLogic @@ -33,8 +34,28 @@ class ReplaceHtmlLogic extends BaseLogic
33 * @method :post 34 * @method :post
34 * @time :2024/5/9 18:03 35 * @time :2024/5/9 18:03
35 */ 36 */
36 - public function getTemplateId(){  
37 - 37 + public function getTemplateId($typeInfo){
  38 + //获取当前template_id
  39 + $bSettingModel = new Setting();
  40 + $templateInfo = $bSettingModel->read(['project_id'=>$this->param['project_id']]);
  41 + if($templateInfo === false){
  42 + $this->fail('请先选择模版');
  43 + }
  44 + $template_id = $templateInfo['template_id'];
  45 + if($typeInfo['is_custom'] == 1){//扩展模块
  46 + $customModuleModel = new CustomModule();
  47 + $moduleInfo = $customModuleModel->read(['id'=>$typeInfo['type']],['list_customized','detail_customized']);
  48 + if($moduleInfo === false){
  49 + $this->fail('当前扩展模块不存在或已被删除');
  50 + }
  51 + if($typeInfo['is_list'] == 1 && $moduleInfo['list_customized'] == 1){
  52 + $template_id = 0;
  53 + }
  54 + if($typeInfo['is_list'] == 0 && $moduleInfo['detail_customized'] == 1){
  55 + $template_id = 0;
  56 + }
  57 + }
  58 + return $this->success($template_id);
38 } 59 }
39 60
40 /** 61 /**
@@ -44,25 +65,18 @@ class ReplaceHtmlLogic extends BaseLogic @@ -44,25 +65,18 @@ class ReplaceHtmlLogic extends BaseLogic
44 * @method :post 65 * @method :post
45 * @time :2024/5/7 15:52 66 * @time :2024/5/7 15:52
46 */ 67 */
47 - public function replaceHtml(){ 68 + public function replaceTemplateMainHtml(){
48 ProjectServer::useProject($this->param['project_id']); 69 ProjectServer::useProject($this->param['project_id']);
49 - $data = $this->model->sourceType();  
50 - if(!isset($data[$this->param['name']])){  
51 - $this->fail('数据错误,请联系管理员');  
52 - }  
53 - $replaceHtmlData = [  
54 - 'old_html'=>$this->param['old_html'],  
55 - 'html'=>$this->param['html'],  
56 - 'type'=>$data[$this->param['name']]['type'],  
57 - 'is_list'=>$data[$this->param['name']]['is_list'],  
58 - 'is_custom'=>$data[$this->param['name']]['is_custom'],  
59 - 'template_id'=>1  
60 - ]; 70 + $data = $this->sourceTypeInfo();
  71 + $typeInfo = $data[$this->param['name']];
  72 + if(!isset($typeInfo)){
  73 + $this->fail('当前类型不存在,请联系管理员');
  74 + }
  75 + $template_id = $this->getTemplateId($typeInfo);
61 //TODO::生成一条任务记录 76 //TODO::生成一条任务记录
62 - $replaceId = $this->saveReplaceHtml($this->param); 77 + $replaceId = $this->saveReplaceHtml($this->param,$typeInfo,$template_id);
63 //查询当前类型所有装修的记录 78 //查询当前类型所有装修的记录
64 - $condition = ['source'=>$this->param['type'],'is_custom'=>$this->param['is_custom'],'is_list'=>$this->param['is_list'],  
65 - 'template_id'=>$this->param['template_id']]; 79 + $condition = ['source'=>$typeInfo['type'],'is_custom'=>$typeInfo['is_custom'],'is_list'=>$typeInfo['is_list'], 'template_id'=>$template_id];
66 $list = $this->model->list($condition); 80 $list = $this->model->list($condition);
67 foreach ($list as $v){ 81 foreach ($list as $v){
68 if($v['type'] == 0){ 82 if($v['type'] == 0){
@@ -85,14 +99,15 @@ class ReplaceHtmlLogic extends BaseLogic @@ -85,14 +99,15 @@ class ReplaceHtmlLogic extends BaseLogic
85 * @method :post 99 * @method :post
86 * @time :2024/5/8 9:23 100 * @time :2024/5/8 9:23
87 */ 101 */
88 - public function saveReplaceHtml($data,$template_id){ 102 + public function saveReplaceHtml($param,$data,$template_id){
89 $logData = [ 103 $logData = [
90 'type'=>$data['type'], 104 'type'=>$data['type'],
91 'is_custom'=>$data['is_custom'], 105 'is_custom'=>$data['is_custom'],
92 'is_list'=>$data['is_list'], 106 'is_list'=>$data['is_list'],
93 'template_id'=>$template_id, 107 'template_id'=>$template_id,
94 - 'old_html'=>$data['old_html'],  
95 - 'html'=>$data['html'], 108 + 'old_html'=>$param['old_html'],
  109 + 'html'=>$param['html'],
  110 + 'project_id'=>$param['project_id'],
96 ]; 111 ];
97 return $this->model->addReturnId($logData); 112 return $this->model->addReturnId($logData);
98 } 113 }
@@ -123,11 +138,11 @@ class ReplaceHtmlLogic extends BaseLogic @@ -123,11 +138,11 @@ class ReplaceHtmlLogic extends BaseLogic
123 */ 138 */
124 public function reductionHtml(){ 139 public function reductionHtml(){
125 ProjectServer::useProject($this->param['project_id']); 140 ProjectServer::useProject($this->param['project_id']);
126 - //获取当前数据详情  
127 $info = $this->model->read(['id'=>$this->param['id']]); 141 $info = $this->model->read(['id'=>$this->param['id']]);
128 if($info === false){ 142 if($info === false){
129 $this->fail('当前数据不存在'); 143 $this->fail('当前数据不存在');
130 } 144 }
  145 + $replaceId = $this->saveResultReplaceHtml($info);
131 $replaceLogModel = new TemplateReplaceHtmlLog(); 146 $replaceLogModel = new TemplateReplaceHtmlLog();
132 $logList = $replaceLogModel->list(['replace_id'=>$this->param['id']]); 147 $logList = $replaceLogModel->list(['replace_id'=>$this->param['id']]);
133 $replaceArr = []; 148 $replaceArr = [];
@@ -141,18 +156,39 @@ class ReplaceHtmlLogic extends BaseLogic @@ -141,18 +156,39 @@ class ReplaceHtmlLogic extends BaseLogic
141 foreach ($templateList as $value){ 156 foreach ($templateList as $value){
142 if($v['type'] == 0){ 157 if($v['type'] == 0){
143 $main_html = str_replace($info['html'],$info['old_html'],$value['main_html']); 158 $main_html = str_replace($info['html'],$info['old_html'],$value['main_html']);
144 - $this->model->edit(['main_html'=>$main_html],['id'=>$v['id']]); 159 + $this->model->edit(['main_html'=>$main_html],['id'=>$value['id']]);
145 }else{ 160 }else{
146 $html = str_replace($info['html'],$info['old_html'],$value['html']); 161 $html = str_replace($info['html'],$info['old_html'],$value['html']);
147 - $this->model->edit(['html'=>$html],['id'=>$v['id']]); 162 + $this->model->edit(['html'=>$html],['id'=>$value['id']]);
148 } 163 }
149 } 164 }
  165 + $this->saveReplaceHtmlLog($replaceId,$value['id']);
150 } 166 }
151 DB::disconnect('custom_mysql'); 167 DB::disconnect('custom_mysql');
152 return $this->success(); 168 return $this->success();
153 } 169 }
154 170
155 /** 171 /**
  172 + * @remark :保存还原的html
  173 + * @name :saveResultReplaceHtml
  174 + * @author :lyh
  175 + * @method :post
  176 + * @time :2024/5/10 10:01
  177 + */
  178 + public function saveResultReplaceHtml($info){
  179 + $logData = [
  180 + 'type'=>$info['type'],
  181 + 'is_custom'=>$info['is_custom'],
  182 + 'is_list'=>$info['is_list'],
  183 + 'template_id'=>$info['template_id'],
  184 + 'old_html'=>$info['html'],
  185 + 'html'=>$info['old_html'],
  186 + 'project_id'=>$info['project_id'],
  187 + ];
  188 + return $this->model->addReturnId($logData);
  189 + }
  190 +
  191 + /**
156 * @remark :替换类型 192 * @remark :替换类型
157 * @name :sourceTypeInfo 193 * @name :sourceTypeInfo
158 * @author :lyh 194 * @author :lyh