作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace App\Http\Controllers\Aside\Optimize; 3 namespace App\Http\Controllers\Aside\Optimize;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
  6 +use App\Helper\Arr;
6 use App\Http\Controllers\Aside\BaseController; 7 use App\Http\Controllers\Aside\BaseController;
7 use App\Http\Logic\Aside\Optimize\OptimizeLogic; 8 use App\Http\Logic\Aside\Optimize\OptimizeLogic;
8 use App\Http\Logic\Aside\Project\ProjectLogic; 9 use App\Http\Logic\Aside\Project\ProjectLogic;
@@ -47,6 +48,7 @@ class OptimizeController extends BaseController @@ -47,6 +48,7 @@ class OptimizeController extends BaseController
47 $data = $rankDataModel->read(['project_id'=>$v['id'],'lang'=>''],['first_page_num','indexed_pages_num']); 48 $data = $rankDataModel->read(['project_id'=>$v['id'],'lang'=>''],['first_page_num','indexed_pages_num']);
48 $v['first_page_num'] = $data['first_page_num'] ?? 0; 49 $v['first_page_num'] = $data['first_page_num'] ?? 0;
49 $v['indexed_pages_num'] = $data['indexed_pages_num'] ?? 0; 50 $v['indexed_pages_num'] = $data['indexed_pages_num'] ?? 0;
  51 + $v['g'] = $this->getGNum($v['id']);
50 $v = $this->handleParam($v); 52 $v = $this->handleParam($v);
51 $lists['list'][$k] = $v; 53 $lists['list'][$k] = $v;
52 } 54 }
@@ -55,6 +57,27 @@ class OptimizeController extends BaseController @@ -55,6 +57,27 @@ class OptimizeController extends BaseController
55 } 57 }
56 58
57 /** 59 /**
  60 + * @remark :统计数量
  61 + * @name :getGNum
  62 + * @author :lyh
  63 + * @method :post
  64 + * @time :2024/1/6 11:12
  65 + */
  66 + public function getGNum($project_id){
  67 + $num = 0;
  68 + $list = RankData::where('project_id', $project_id)->where('lang', '')->value('data') ?: [];
  69 + if(!empty($list)){
  70 + foreach ($list as $v) {
  71 + $last = Arr::last($v);
  72 + if(isset($last['g']) && ($last['g'] == 1)){
  73 + $num = $num+1;
  74 + }
  75 + }
  76 + }
  77 + return $num;
  78 + }
  79 +
  80 + /**
58 * @remark :参数处理 81 * @remark :参数处理
59 * @name :handleParam 82 * @name :handleParam
60 * @author :lyh 83 * @author :lyh
@@ -176,9 +176,6 @@ class BTemplateLogic extends BaseLogic @@ -176,9 +176,6 @@ class BTemplateLogic extends BaseLogic
176 $this->fail('定制页面,请先上传代码块'); 176 $this->fail('定制页面,请先上传代码块');
177 } 177 }
178 $commonInfo = $this->getCustomizedCommonHtml($type);//获取定制头部 178 $commonInfo = $this->getCustomizedCommonHtml($type);//获取定制头部
179 - if($this->user['project_id'] == 655){  
180 - return $customHtmlInfo['main_html'];  
181 - }  
182 if($commonInfo !== false){ 179 if($commonInfo !== false){
183 $customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']); 180 $customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);
184 } 181 }
@@ -264,12 +264,36 @@ class InitHtmlLogic extends BaseLogic @@ -264,12 +264,36 @@ class InitHtmlLogic extends BaseLogic
264 if($info === false){ 264 if($info === false){
265 $html = ''; 265 $html = '';
266 }else{ 266 }else{
  267 + $type = $this->getCustomizedType($this->param['type'],$is_list);
  268 + $commonTemplateModel = new BTemplateCommon();
  269 + $commonInfo = $commonTemplateModel->read(['template_id' => 0,'type'=>$type]);
  270 + if($commonInfo !== false){
  271 + $info['main_html'] = $this->handleAllHtml($commonInfo,$info['main_html']);
  272 + }
267 $html = $info['main_html']; 273 $html = $info['main_html'];
268 } 274 }
  275 + //更新头部底部
269 return $this->success(['html'=>$html]); 276 return $this->success(['html'=>$html]);
270 } 277 }
271 278
272 /** 279 /**
  280 + * @remark :返回整个html截取代码
  281 + * @name :handleAllHtml
  282 + * @author :lyh
  283 + * @method :post
  284 + * @time :2023/12/13 15:39
  285 + */
  286 + public function handleAllHtml($commonInfo,$html){
  287 + if(!empty($commonInfo)){
  288 + $html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $commonInfo['head_html'], $html);
  289 + $html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $commonInfo['footer_html'], $html);
  290 + $html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $commonInfo['head_css'], $html);
  291 + $html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $commonInfo['footer_css'], $html);
  292 + }
  293 + return $html;
  294 + }
  295 +
  296 + /**
273 * @remark :保存定制html 297 * @remark :保存定制html
274 * @name :saveHtml 298 * @name :saveHtml
275 * @author :lyh 299 * @author :lyh
@@ -292,6 +316,8 @@ class InitHtmlLogic extends BaseLogic @@ -292,6 +316,8 @@ class InitHtmlLogic extends BaseLogic
292 }else{ 316 }else{
293 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]); 317 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
294 } 318 }
  319 + //更新头部底部
  320 + $this->saveCustomizeCommon($this->param['html'],$this->param['type'],$is_list);
295 }catch (\Exception $exception){ 321 }catch (\Exception $exception){
296 $this->fail('保存失败,请联系开发人员'); 322 $this->fail('保存失败,请联系开发人员');
297 } 323 }
@@ -299,6 +325,68 @@ class InitHtmlLogic extends BaseLogic @@ -299,6 +325,68 @@ class InitHtmlLogic extends BaseLogic
299 } 325 }
300 326
301 /** 327 /**
  328 + * @remark :定制代码更新头部信息
  329 + * @name :saveCustomizeCommon
  330 + * @author :lyh
  331 + * @method :post
  332 + * @time :2024/1/6 10:29
  333 + */
  334 + public function saveCustomizeCommon($html,$source,$is_list){
  335 + $type = $this->getCustomizedType($source,$is_list);
  336 + $templateCommonModel = new BTemplateCommon();
  337 + $commonInfo = $templateCommonModel->read(['template_id'=>0,'type'=>$type]);//查看当前头部是否存在
  338 + $handleInfo = $this->handleCommonParam($html);
  339 + if($commonInfo === false){
  340 + $data = [
  341 + 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],
  342 + 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
  343 + 'type'=>$type,'template_id'=>0, 'project_id'=>$this->user['project_id'],
  344 + ];
  345 + $templateCommonModel->add($data);
  346 + }else{
  347 + $data = [
  348 + 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],
  349 + 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
  350 + ];
  351 + $templateCommonModel->edit($data,['id'=>$commonInfo['id']]);
  352 + }
  353 + return $this->success();
  354 + }
  355 +
  356 + /**
  357 + * @remark :定制页面头部类型---根据source获取type类型
  358 + * @name :getType
  359 + * @author :lyh
  360 + * @method :post
  361 + * @time :2023/11/16 11:20
  362 + */
  363 + public function getCustomizedType($source,$is_list){
  364 + $type = BTemplate::TYPE_HOME;
  365 + if($source == BTemplate::SOURCE_PRODUCT){
  366 + if($is_list == BTemplate::IS_LIST){
  367 + $type = BTemplate::TYPE_PRODUCT_LIST;
  368 + }else{
  369 + $type = BTemplate::TYPE_PRODUCT_DETAIL;
  370 + }
  371 + }
  372 + if($source == BTemplate::SOURCE_BLOG){
  373 + if($is_list == BTemplate::IS_LIST){
  374 + $type = BTemplate::TYPE_BLOG_LIST;
  375 + }else{
  376 + $type = BTemplate::TYPE_BLOG_DETAIL;
  377 + }
  378 + }
  379 + if($source == BTemplate::SOURCE_NEWS){
  380 + if($is_list == BTemplate::IS_LIST){
  381 + $type = BTemplate::TYPE_NEWS_LIST;
  382 + }else{
  383 + $type = BTemplate::TYPE_NEWS_DETAIL;
  384 + }
  385 + }
  386 + return $type;
  387 + }
  388 +
  389 + /**
302 * @remark :前端获取设置模块(侧边栏) 390 * @remark :前端获取设置模块(侧边栏)
303 * @name :getInitModuleMain 391 * @name :getInitModuleMain
304 * @author :lyh 392 * @author :lyh