作者 lyh

gx

@@ -29,6 +29,13 @@ class BTemplateController extends BaseController @@ -29,6 +29,13 @@ class BTemplateController extends BaseController
29 * @time :2023/6/29 9:40 29 * @time :2023/6/29 9:40
30 */ 30 */
31 public function getPublicTemplate(BTemplateLogic $BTemplateLogic){ 31 public function getPublicTemplate(BTemplateLogic $BTemplateLogic){
  32 + $this->request->validate([
  33 + 'source'=>'required',
  34 + 'source_id'=>'required',
  35 + ],[
  36 + 'source.required' => 'source不能为空',
  37 + 'source_id.required' => 'source_id不能为空',
  38 + ]);
32 $info = $BTemplateLogic->getTemplate(); 39 $info = $BTemplateLogic->getTemplate();
33 $this->response('success',Code::SUCCESS,$info); 40 $this->response('success',Code::SUCCESS,$info);
34 } 41 }
@@ -55,54 +55,80 @@ class BTemplateLogic extends BaseLogic @@ -55,54 +55,80 @@ class BTemplateLogic extends BaseLogic
55 $info = $bSettingModel->read(['project_id'=>$this->user['project_id']]); 55 $info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
56 $TemplateInfo = []; 56 $TemplateInfo = [];
57 if($info !== false){ 57 if($info !== false){
58 - if($this->param['source'] == 1){//首页  
59 - //查看当前模板是否已编辑保存web_template  
60 - $TemplateInfo = $this->model->read([  
61 - 'template_id'=>$info['template_id'],  
62 - 'source'=>!isset($this->param['source']) ? 1 : $this->param['source'],  
63 - 'project_id'=>$this->user['project_id'],  
64 - 'source_id'=>!isset($this->param['source_id']) ? 0 : $this->param['source_id'],  
65 - ]);  
66 - if($TemplateInfo === false){  
67 - //获取模板详情  
68 - $ATemplateModel = new Template();  
69 - $TemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']]);  
70 - }  
71 - $TemplateInfo['html'] = $this->getHeadFooter($TemplateInfo['html']);  
72 - }else{  
73 - //查看当前模板是否已编辑保存web_template  
74 - $TemplateInfo = $this->model->read([  
75 - 'template_id'=>$info['template_id'],  
76 - 'source'=>$this->param['source'],  
77 - 'project_id'=>$this->user['project_id'],  
78 - 'source_id'=>$this->param['source_id'],  
79 - ]);  
80 - if($TemplateInfo === false){  
81 - //查看当前模板是否已编辑保存web_template  
82 - $TemplateInfo = $this->model->read([  
83 - 'template_id'=>$info['template_id'],  
84 - 'source'=>1,  
85 - 'project_id'=>$this->user['project_id'],  
86 - ]);  
87 - if($TemplateInfo === false){  
88 - $this->fail('请先装修首页');  
89 - }  
90 - $TemplateInfo['html'] = preg_replace('/<style id="vvvebjs-styles">(.*?)<\/style>/s', "<style id='vvvebjs-styles'></style>", $TemplateInfo['html']);  
91 - $TemplateInfo['html'] = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', "<main></main>", $TemplateInfo['html']);  
92 - $TemplateInfo['html'] = $this->getHeadFooter($TemplateInfo['html']);  
93 - }else{  
94 - //查看当前模板是否已编辑保存web_template  
95 - $TemplateInfo = $this->model->read([  
96 - 'template_id'=>$info['template_id'],  
97 - 'source'=>1,  
98 - 'project_id'=>$this->user['project_id'],  
99 - ]);  
100 - $TemplateInfo['html'] = preg_replace('/<style id="vvvebjs-styles">(.*?)<\/style>/s', $TemplateInfo['main_css'], $TemplateInfo['html']);  
101 - $TemplateInfo['html'] = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s',$TemplateInfo['main_html'] , $TemplateInfo['html']);  
102 - $TemplateInfo['html'] = $this->getHeadFooter($TemplateInfo['html']);  
103 - } 58 + if($this->param['source'] == $this->model::SOURCE_HOME){//首页
  59 + $TemplateInfo = $this->homeHtml($info,$this->param['source'],$this->param['source_id']);
104 } 60 }
  61 + if($this->param['source'] == $this->model::SOURCE_PRODUCT){//产品页
  62 + $TemplateInfo = $this->productHtml($info,$this->param['source'],$this->param['source_id']);
  63 + }
  64 + }
  65 + return $this->success($TemplateInfo);
  66 + }
  67 +
  68 + /**
  69 + * @remark :根据参数获取数据详情
  70 + * @name :webTemplateInfo
  71 + * @author :lyh
  72 + * @method :post
  73 + * @time :2023/7/25 16:41
  74 + */
  75 + public function webTemplateInfo($template_id,$source,$source_id){
  76 + //查看当前模板是否已编辑保存web_template
  77 + $TemplateInfo = $this->model->read([
  78 + 'template_id'=>$template_id,
  79 + 'source'=>$source,
  80 + 'project_id'=>$this->user['project_id'],
  81 + 'source_id'=>$source_id,
  82 + ]);
  83 + return $this->success($TemplateInfo);
  84 + }
  85 +
  86 + /**
  87 + * @remark :处理首页数据
  88 + * @name :homeHtml
  89 + * @author :lyh
  90 + * @method :post
  91 + * @time :2023/7/25 16:36
  92 + */
  93 + public function homeHtml($info,$source,$source_id){
  94 + //查看当前模板是否已编辑保存web_template
  95 + $TemplateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id);
  96 + if($TemplateInfo === false){
  97 + //获取模板详情
  98 + $ATemplateModel = new Template();
  99 + $TemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']]);
105 } 100 }
  101 + $TemplateInfo['html'] = $this->getHeadFooter($TemplateInfo['html']);
  102 + return $this->success($TemplateInfo);
  103 + }
  104 +
  105 + /**
  106 + * @remark :处理产品页数据
  107 + * @name :ProductHtml
  108 + * @author :lyh
  109 + * @method :post
  110 + * @time :2023/7/25 16:40
  111 + */
  112 + public function productHtml($info,$source,$source_id){
  113 + //查看当前模板是否已编辑保存web_template
  114 + $TemplateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id);
  115 + if($TemplateInfo === false){
  116 + //获取首页数据
  117 + $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
  118 + if($homeTemplateInfo === false){
  119 + $this->fail('请先装修首页');
  120 + }
  121 + $html = preg_replace('/<style id="vvvebjs-styles">(.*?)<\/style>/s', "<style id='vvvebjs-styles'></style>", $homeTemplateInfo['html']);
  122 + $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', "<main></main>", $html);
  123 + }else{
  124 + $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
  125 + if($homeTemplateInfo === false){
  126 + $this->fail('请先装修首页');
  127 + }
  128 + $html = preg_replace('/<style id="vvvebjs-styles">(.*?)<\/style>/s', $TemplateInfo['main_css'], $homeTemplateInfo['html']);
  129 + $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s',$TemplateInfo['main_html'] , $html);
  130 + }
  131 + $TemplateInfo['html'] = $this->getHeadFooter($html);//组装数据
106 return $this->success($TemplateInfo); 132 return $this->success($TemplateInfo);
107 } 133 }
108 134
@@ -140,14 +166,7 @@ class BTemplateLogic extends BaseLogic @@ -140,14 +166,7 @@ class BTemplateLogic extends BaseLogic
140 */ 166 */
141 public function templateSave(){ 167 public function templateSave(){
142 //查询当前模版是否已保存 168 //查询当前模版是否已保存
143 - $info = $this->model->read(  
144 - [  
145 - 'project_id'=>$this->user['project_id'],  
146 - 'source'=>$this->param['source'] ?? 1,  
147 - 'source_id'=>$this->param['source_id'] ?? 0,  
148 - 'template_id'=>$this->param['template_id'],  
149 - ]  
150 - ); 169 + $info = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],$this->param['source_id']);
151 if($info === false){ 170 if($info === false){
152 //字符串截取 171 //字符串截取
153 $this->StringProcessing(); 172 $this->StringProcessing();
@@ -179,12 +198,11 @@ class BTemplateLogic extends BaseLogic @@ -179,12 +198,11 @@ class BTemplateLogic extends BaseLogic
179 //同步数据 198 //同步数据
180 $this->param['name'] = $TemplateInfo['name']; 199 $this->param['name'] = $TemplateInfo['name'];
181 $this->param['image'] = $TemplateInfo['image']; 200 $this->param['image'] = $TemplateInfo['image'];
182 - if($this->param['source'] == 1){ 201 + if($this->param['source'] == 1){//首页
183 $this->param['html'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-header">(.*?)<\/footer>/s'); 202 $this->param['html'] = characterTruncation($this->param['html'],'/<style id="vvvebjs-header">(.*?)<\/footer>/s');
184 }else{ 203 }else{
185 $this->param['html'] = $this->param['main_html']; 204 $this->param['html'] = $this->param['main_html'];
186 } 205 }
187 - return true;  
188 } 206 }
189 207
190 /** 208 /**
@@ -12,5 +12,8 @@ use App\Models\Base; @@ -12,5 +12,8 @@ use App\Models\Base;
12 */ 12 */
13 class BTemplate extends Base 13 class BTemplate extends Base
14 { 14 {
  15 + const SOURCE_HOME = 1;//首页
  16 + const SOURCE_PRODUCT = 2;//产品页
  17 +
15 protected $table = 'gl_web_template'; 18 protected $table = 'gl_web_template';
16 } 19 }