作者 赵彬吉
@@ -38,7 +38,7 @@ class CategoryController extends BaseController @@ -38,7 +38,7 @@ class CategoryController extends BaseController
38 if(!empty($list)){ 38 if(!empty($list)){
39 foreach ($list as $k =>$v){ 39 foreach ($list as $k =>$v){
40 $v['url'] = $this->user['domain'] . $v['route']; 40 $v['url'] = $this->user['domain'] . $v['route'];
41 - $v['product_num'] = Product::where('category_id','like' ,'%,'.$v['id'].',%')->count(); 41 + $v['product_num'] = Product::where('category_id','like' ,'%,'.$v['id'].',%')->where(['status'=>1])->count();
42 $v['image_link'] = getImageUrl($v['image']); 42 $v['image_link'] = getImageUrl($v['image']);
43 $list[$k] = $v; 43 $list[$k] = $v;
44 } 44 }
@@ -9,6 +9,7 @@ use App\Models\Product\Category; @@ -9,6 +9,7 @@ use App\Models\Product\Category;
9 use App\Models\Product\Product; 9 use App\Models\Product\Product;
10 use App\Models\RouteMap\RouteMap; 10 use App\Models\RouteMap\RouteMap;
11 use App\Models\Service\Service as ServiceSettingModel; 11 use App\Models\Service\Service as ServiceSettingModel;
  12 +use App\Models\Template\BTemplateCommon;
12 use App\Models\Template\Setting; 13 use App\Models\Template\Setting;
13 use App\Models\Template\BTemplate; 14 use App\Models\Template\BTemplate;
14 use App\Models\Template\BTemplateLog; 15 use App\Models\Template\BTemplateLog;
@@ -121,23 +122,34 @@ class BTemplateLogic extends BaseLogic @@ -121,23 +122,34 @@ class BTemplateLogic extends BaseLogic
121 * @time :2023/7/25 16:40 122 * @time :2023/7/25 16:40
122 */ 123 */
123 public function productHtml($info,$source,$source_id){ 124 public function productHtml($info,$source,$source_id){
  125 + $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
  126 + if($homeTemplateInfo === false){
  127 + $this->fail('请先装修首页');
  128 + }
124 //查看当前模板是否已编辑保存web_template 129 //查看当前模板是否已编辑保存web_template
125 $TemplateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id); 130 $TemplateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id);
126 if($TemplateInfo === false){ 131 if($TemplateInfo === false){
127 - //获取首页数据  
128 - $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);  
129 - if($homeTemplateInfo === false){  
130 - $this->fail('请先装修首页'); 132 + //兼容老数据
  133 + $commonTemplateModel = new BTemplateCommon();
  134 + $commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id']]);
  135 + if($commonInfo !== false){
  136 + $html = $commonInfo['head_css']."<style id='globalsojs-styles'></style>".$commonInfo['head_css'].$commonInfo['other'].
  137 + $commonInfo['head_html'].$this->getProductModule().$commonInfo['footer_html'];
  138 + }else{
  139 + $html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', "<style id='globalsojs-styles'></style>", $homeTemplateInfo['html']);
  140 + $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', "<main>{$this->getProductModule()}</main>", $html);
131 } 141 }
132 - $html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', "<style id='globalsojs-styles'></style>", $homeTemplateInfo['html']);  
133 - $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', "<main>{$this->getProductModule()}</main>", $html);  
134 }else{ 142 }else{
135 - $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);  
136 - if($homeTemplateInfo === false){  
137 - $this->fail('请先装修首页'); 143 + //兼容老数据
  144 + $commonTemplateModel = new BTemplateCommon();
  145 + $commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id']]);
  146 + if($commonInfo !== false){
  147 + $html = $commonInfo['head_css'].$TemplateInfo['main_css'].$commonInfo['head_css'].$commonInfo['other'].
  148 + $commonInfo['head_html'].$TemplateInfo['main_html'].$commonInfo['footer_html'];
  149 + }else{
  150 + $html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', $TemplateInfo['main_css'], $homeTemplateInfo['html']);
  151 + $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s',$TemplateInfo['main_html'] , $html);
138 } 152 }
139 - $html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', $TemplateInfo['main_css'], $homeTemplateInfo['html']);  
140 - $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s',$TemplateInfo['main_html'] , $html);  
141 } 153 }
142 $TemplateInfo['html'] = $this->getHeadFooter($html);//组装数据 154 $TemplateInfo['html'] = $this->getHeadFooter($html);//组装数据
143 return $this->success($TemplateInfo); 155 return $this->success($TemplateInfo);
@@ -186,12 +198,13 @@ class BTemplateLogic extends BaseLogic @@ -186,12 +198,13 @@ class BTemplateLogic extends BaseLogic
186 $info = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],$this->param['source_id']); 198 $info = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],$this->param['source_id']);
187 //字符串截取 199 //字符串截取
188 $this->param = $this->stringProcessing($this->param); 200 $this->param = $this->stringProcessing($this->param);
189 - $this->param = $this->templateSaveParam($this->param); 201 + $this->param = $this->templateSaveParam($this->param);//组装数据
190 if($info === false){ 202 if($info === false){
191 $this->model->add($this->param); 203 $this->model->add($this->param);
192 }else{ 204 }else{
193 $this->model->edit($this->param,['id'=>$info['id']]); 205 $this->model->edit($this->param,['id'=>$info['id']]);
194 } 206 }
  207 + $this->saveCommonTemplate($this->param);
195 $this->setTemplateLog($this->param); 208 $this->setTemplateLog($this->param);
196 DB::commit(); 209 DB::commit();
197 }catch (\Exception $e){ 210 }catch (\Exception $e){
@@ -204,6 +217,33 @@ class BTemplateLogic extends BaseLogic @@ -204,6 +217,33 @@ class BTemplateLogic extends BaseLogic
204 } 217 }
205 218
206 /** 219 /**
  220 + * @remark :保存头部公共数据
  221 + * @name :saveCommonTemplate
  222 + * @author :lyh
  223 + * @method :post
  224 + * @time :2023/10/13 14:27
  225 + */
  226 + public function saveCommonTemplate($param){
  227 + $templateCommonModel = new BTemplateCommon();
  228 + $info = $templateCommonModel->read(['template_id'=>$param['template_id'],'project_id'=>$this->user['project_id']]);
  229 + $data = [
  230 + 'head_html'=>$param['head_html'],
  231 + 'head_css'=>$param['head_css'],
  232 + 'footer_html'=>$param['footer_html'],
  233 + 'footer_css'=>$param['footer_css'],
  234 + 'other'=>str_replace('header','',characterTruncation($param['html'],'/<link id="google-fonts-link">(.*?)header/s')),
  235 + ];
  236 + if($info === false){
  237 + $data['template_id'] = $param['template_id'];
  238 + $data['project_id'] = $this->user['project_id'];
  239 + $templateCommonModel->add($data);
  240 + }else{
  241 + $templateCommonModel->edit($data,['id'=>$info['id']]);
  242 + }
  243 + return $this->success();
  244 + }
  245 +
  246 + /**
207 * @remark :生成记录 247 * @remark :生成记录
208 * @name :setTemplateLog 248 * @name :setTemplateLog
209 * @author :lyh 249 * @author :lyh
@@ -260,11 +300,7 @@ class BTemplateLogic extends BaseLogic @@ -260,11 +300,7 @@ class BTemplateLogic extends BaseLogic
260 */ 300 */
261 public function templateSaveParam($param){ 301 public function templateSaveParam($param){
262 $param['project_id'] = $this->user['project_id']; 302 $param['project_id'] = $this->user['project_id'];
263 - if($param['source'] == 1){//首页  
264 - $param['html'] = characterTruncation($param['html'],'/<style id="globalsojs-header">(.*?)<\/footer>/s');  
265 - }else{  
266 - $param['html'] = $param['main_html'];  
267 - } 303 + $param['html'] = $param['main_html'];
268 return $this->success($param); 304 return $this->success($param);
269 } 305 }
270 306