作者 赵彬吉
... ... @@ -38,7 +38,7 @@ class CategoryController extends BaseController
if(!empty($list)){
foreach ($list as $k =>$v){
$v['url'] = $this->user['domain'] . $v['route'];
$v['product_num'] = Product::where('category_id','like' ,'%,'.$v['id'].',%')->count();
$v['product_num'] = Product::where('category_id','like' ,'%,'.$v['id'].',%')->where(['status'=>1])->count();
$v['image_link'] = getImageUrl($v['image']);
$list[$k] = $v;
}
... ...
... ... @@ -9,6 +9,7 @@ use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\Setting;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateLog;
... ... @@ -121,24 +122,35 @@ class BTemplateLogic extends BaseLogic
* @time :2023/7/25 16:40
*/
public function productHtml($info,$source,$source_id){
//查看当前模板是否已编辑保存web_template
$TemplateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id);
if($TemplateInfo === false){
//获取首页数据
$homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
if($homeTemplateInfo === false){
$this->fail('请先装修首页');
}
//查看当前模板是否已编辑保存web_template
$TemplateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id);
if($TemplateInfo === false){
//兼容老数据
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id']]);
if($commonInfo !== false){
$html = $commonInfo['head_css']."<style id='globalsojs-styles'></style>".$commonInfo['head_css'].$commonInfo['other'].
$commonInfo['head_html'].$this->getProductModule().$commonInfo['footer_html'];
}else{
$html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', "<style id='globalsojs-styles'></style>", $homeTemplateInfo['html']);
$html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', "<main>{$this->getProductModule()}</main>", $html);
}else{
$homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
if($homeTemplateInfo === false){
$this->fail('请先装修首页');
}
}else{
//兼容老数据
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id']]);
if($commonInfo !== false){
$html = $commonInfo['head_css'].$TemplateInfo['main_css'].$commonInfo['head_css'].$commonInfo['other'].
$commonInfo['head_html'].$TemplateInfo['main_html'].$commonInfo['footer_html'];
}else{
$html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', $TemplateInfo['main_css'], $homeTemplateInfo['html']);
$html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s',$TemplateInfo['main_html'] , $html);
}
}
$TemplateInfo['html'] = $this->getHeadFooter($html);//组装数据
return $this->success($TemplateInfo);
}
... ... @@ -186,12 +198,13 @@ class BTemplateLogic extends BaseLogic
$info = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],$this->param['source_id']);
//字符串截取
$this->param = $this->stringProcessing($this->param);
$this->param = $this->templateSaveParam($this->param);
$this->param = $this->templateSaveParam($this->param);//组装数据
if($info === false){
$this->model->add($this->param);
}else{
$this->model->edit($this->param,['id'=>$info['id']]);
}
$this->saveCommonTemplate($this->param);
$this->setTemplateLog($this->param);
DB::commit();
}catch (\Exception $e){
... ... @@ -204,6 +217,33 @@ class BTemplateLogic extends BaseLogic
}
/**
* @remark :保存头部公共数据
* @name :saveCommonTemplate
* @author :lyh
* @method :post
* @time :2023/10/13 14:27
*/
public function saveCommonTemplate($param){
$templateCommonModel = new BTemplateCommon();
$info = $templateCommonModel->read(['template_id'=>$param['template_id'],'project_id'=>$this->user['project_id']]);
$data = [
'head_html'=>$param['head_html'],
'head_css'=>$param['head_css'],
'footer_html'=>$param['footer_html'],
'footer_css'=>$param['footer_css'],
'other'=>str_replace('header','',characterTruncation($param['html'],'/<link id="google-fonts-link">(.*?)header/s')),
];
if($info === false){
$data['template_id'] = $param['template_id'];
$data['project_id'] = $this->user['project_id'];
$templateCommonModel->add($data);
}else{
$templateCommonModel->edit($data,['id'=>$info['id']]);
}
return $this->success();
}
/**
* @remark :生成记录
* @name :setTemplateLog
* @author :lyh
... ... @@ -260,11 +300,7 @@ class BTemplateLogic extends BaseLogic
*/
public function templateSaveParam($param){
$param['project_id'] = $this->user['project_id'];
if($param['source'] == 1){//首页
$param['html'] = characterTruncation($param['html'],'/<style id="globalsojs-header">(.*?)<\/footer>/s');
}else{
$param['html'] = $param['main_html'];
}
return $this->success($param);
}
... ...