作者 赵彬吉
... ... @@ -33,9 +33,8 @@ class BTemplateLogController extends BaseController
* @time :2023/8/23 11:05
*/
public function lists(BTemplateLog $bTemplateLog){
unset($this->map['template_id']);
// unset($this->map['template_id']);
$this->map['project_id'] = $this->user['project_id'];
$this->map['source'] = 1;
$this->map['is_custom'] = 0;
$lists = $bTemplateLog->lists($this->map,$this->page,$this->row,$this->order,['id','template_id','operator_id','source','created_at','updated_at']);
if(!empty($lists['list'])){
... ...
... ... @@ -6,6 +6,8 @@ use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\BTemplate\CustomTemplateLogic;
use App\Http\Requests\Bside\Template\CustomTemplateRequest;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateLog;
/**
* @remark :自定义模块
... ... @@ -107,4 +109,39 @@ class CustomTemplateController extends BaseController
$customTemplateLogic->saveHtml();
$this->response('success');
}
/**
* @remark :获取自定义界面的保存记录
* @name :getCustomTemplateLog
* @author :lyh
* @method :post
* @time :2024/4/23 11:07
*/
public function getCustomTemplateLog(BTemplateLog $bTemplateLog){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$this->map['source'] = 9;
$lists = $bTemplateLog->lists($this->map,$this->page,$this->row);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :还原单页面记录
* @name :rollbackVersion
* @author :lyh
* @method :post
* @time :2024/4/23 13:58
*/
public function rollbackVersion(CustomTemplateLogic $logic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => '模版ID不能为空',
]);
$logic->saveRollbackVersion();
$this->response('success');
}
}
... ...
... ... @@ -353,6 +353,7 @@ class ProjectLogic extends BaseLogic
if(empty($zh)){
continue;
}
//获取小语种达标天数
$result['language'] = $zh['chinese'];
$result['lang'] = $v['lang'];
$result['created_at'] = date('Y-m-d H:i:s');
... ...
... ... @@ -10,6 +10,7 @@
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Project\PageSetting;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
... ... @@ -39,38 +40,76 @@ class BTemplateLogLogic extends BaseLogic
$this->fail('error');
}
$bTemplateModel = new BTemplate();
if($info['template_id'] == 0){//定制项目
//TODO::还原头部+底部
$bTemplateModel->edit(['html'=>$info['text']],['template_id'=>$info['template_id'],'source'=>$info['source'],'source_id'=>$info['source_id']]);
return $this->success();
}
//演示项目,不允许其他号码编辑
if(($this->user['project_id'] == 1) && (!in_array($this->user['mobile'],$bTemplateModel->mobile)) && ($info['source'] == 1)){
$this->fail('演示项目仅支持演示功能,无法更改首页');
}
//获取当前项目的模版
if($info['template_id'] == 0) {//todo::定制项目
return $this->rollBackCustomized($info);
}
//TODO::非定制项目,获取当前项目的模版
return $this->rollBackNoCustomized($info);
}
/**
* @remark :定制页面还原
* @name :rollBackCustomized
* @author :lyh
* @method :post
* @time :2024/4/23 14:36
*/
public function rollBackCustomized($info){
$bTemplateModel = new BTemplate();
$condition = ['template_id'=>0,'source'=>$info['source'],'source_id'=>$info['source_id'],
'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']];
//TODO::还原头部+底部
$bTemplateModel->edit(['html'=>$info['text']],$condition);
$commonData = [
'head_html'=>$info['head_html'], 'head_css'=>$info['head_css'],
'footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css']
];
$type = $this->getCustomizedType($info['source'],$info['is_list']);
$commonTemplateModel = new BTemplateCommon();
$commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>$type,'project_id'=>$this->user['project_id']]);
return $this->success();
}
/**
* @remark :非定制界面还原
* @name :rollBackNoCustomized
* @author :lyh
* @method :post
* @time :2024/4/23 14:38
*/
public function rollBackNoCustomized($info){
$bSettingModel = new Setting();
$settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
if($settingInfo === false){
$this->fail('请先选择模版');
}
//切换模版
if($info['template_id'] != $settingInfo['template_id']){
$bSettingModel->edit(['template_id'=>$info['template_id']],['id'=>$settingInfo['id']]);
}
$bTemplateModel = new BTemplate();
try {
$data = $this->setParam($info);
$bTemplateModel->edit($data,['template_id'=>$info['template_id'],'source'=>$info['source'],'source_id'=>$info['source_id']]);
$commonData = $this->setCommonParam($info);
//切换模版
if($info['template_id'] != $settingInfo['template_id']){
$bSettingModel->edit(['template_id'=>$info['template_id']],['id'=>$settingInfo['id']]);
}
$data = ['main_html'=>$info['main_html'], 'main_css'=>$info['main_css']];
$condition = ['template_id'=>$info['template_id'],'source'=>$info['source'],'source_id'=>$info['source_id'],
'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']];
$bTemplateModel->edit($data,$condition);
//还原头部+底部
$commonData = [
'head_html'=>$info['head_html'], 'head_css'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css']
];
$commonTemplateModel = new BTemplateCommon();
$commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>1,'project_id'=>$this->user['project_id']]);
//更新所有界面的other
$type = $this->getType($info['source'],$info['is_list'],$info['is_custom']);
$commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>$type,'project_id'=>$this->user['project_id']]);
if(!empty($info['other'])){
$commonTemplateModel->edit(['other'=>$info['other']],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id']]);
$commonTemplateModel->edit(['other'=>$info['other']],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id'],'type'=>$info['type']]);
}else{
$footer_other = str_replace('<header','',characterTruncation($info['text'],'/<style id="globalsojs-footer">(.*?)<header/s'));
$other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
$commonTemplateModel->edit(['other'=>$other],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id']]);
$commonTemplateModel->edit(['other'=>$other],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id'],'type'=>$type]);
}
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
... ... @@ -79,35 +118,67 @@ class BTemplateLogLogic extends BaseLogic
}
/**
* @remark :设置回滚参数
* @name :setParam
* @remark :定制页面头部类型---根据source获取type类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/8/23 14:18
* @time :2023/11/16 11:20
*/
public function setParam($info){
$data = [
'main_html'=>$info['main_html'],
'main_css'=>$info['main_css'],
];
return $this->success($data);
public function getCustomizedType($source,$is_list){
$type = BTemplate::TYPE_HOME;
if($source == BTemplate::SOURCE_PRODUCT){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_PRODUCT_LIST;
}else{
$type = BTemplate::TYPE_PRODUCT_DETAIL;
}
}
if($source == BTemplate::SOURCE_BLOG){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_BLOG_LIST;
}else{
$type = BTemplate::TYPE_BLOG_DETAIL;
}
}
if($source == BTemplate::SOURCE_NEWS){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_NEWS_LIST;
}else{
$type = BTemplate::TYPE_NEWS_DETAIL;
}
}
return $type;
}
/**
* @remark :设置回滚公共参数参数
* @name :setParam
* @remark :(非定制)保存时获取获取设置的类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/8/23 14:18
* @time :2023/10/21 17:29
*/
public function setCommonParam($info){
$data = [
'head_html'=>$info['head_html'],
'head_css'=>$info['head_css'],
'footer_html'=>$info['footer_html'],
'footer_css'=>$info['footer_css']
];
return $this->success($data);
public function getType($source,$is_list,$is_custom = 0){
$type = BTemplate::SOURCE_HOME;//首页公共头部底部
$is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部
return $this->success($type);
}
//查看页面是否设置自定义头部底部
if($is_head != BTemplate::IS_NO_HEADER) {
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
if ($pageInfo === false) {
return $this->success($type);
}
if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::TYPE_PRODUCT_DETAIL;}}
else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::TYPE_PRODUCT_LIST;}}}
if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::TYPE_BLOG_DETAIL;}}
else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::TYPE_BLOG_LIST;}}}
if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::TYPE_NEWS_DETAIL;}}
else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::TYPE_NEWS_LIST;}}}
if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}
}
return $this->success($type);
}
/**
... ...
... ... @@ -417,7 +417,7 @@ class BTemplateLogic extends BaseLogic
}
//更新头部信息
$this->saveCommonHtml($this->param['html'],$this->param['source'],$this->param['is_list'],$this->param['template_id'],$this->param['is_custom']);
$this->setOperationRecords($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id'],$this->param['is_custom']);
$this->setOperationRecords($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id'],$this->param['is_custom'],$this->param['is_list']);
//通知更新
$this->homeOrProduct($this->param['source'],$this->param['source_id'],$this->param['is_custom'],$this->param['is_list']);
return $this->success();
... ... @@ -607,6 +607,7 @@ class BTemplateLogic extends BaseLogic
$param['main_css'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
return $this->success($param);
}
/**
* @remark :(非定制)保存时获取获取设置的类型
* @name :getType
... ... @@ -646,7 +647,7 @@ class BTemplateLogic extends BaseLogic
* @method :post
* @time :2023/8/23 11:16
*/
public function setOperationRecords($html,$source,$source_id,$template_id,$is_custom,$type = 0){
public function setOperationRecords($html,$source,$source_id,$template_id,$is_custom = 0,$is_list = 0,$type = 0){
if($is_custom != BTemplate::IS_NO_CUSTOM){
return true;
}
... ... @@ -657,6 +658,7 @@ class BTemplateLogic extends BaseLogic
'text'=>$html,
'type'=>$type,
'is_custom'=>$is_custom,
'is_list'=>$is_list,
'source'=>$source,
'source_id'=>$source_id,
'main_html' => characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s'),
... ...
... ... @@ -113,7 +113,7 @@ class CustomTemplateLogic extends BaseLogic
$this->param['html_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
$this->setTemplateLog($bSettingInfo['template_id'],$html,$this->param['id']);
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
$rs = $this->model->edit($this->param,['id'=>$this->param['id'],'project_id'=>$this->user['project_id']]);
if($rs === false){
$this->fail('系统错误,请联系管理');
}
... ... @@ -364,4 +364,37 @@ class CustomTemplateLogic extends BaseLogic
}
return $this->success($data);
}
/**
* @remark :单页面还原
* @name :saveRollbackVersion
* @author :lyh
* @method :post
* @time :2024/4/23 14:00
*/
public function saveRollbackVersion(){
//获取当前数据记录详情
$log = new BTemplateLog();
$logInfo = $log->read(['id'=>$this->param['id']]);
if($logInfo === false){
$this->fail('未获取到当前记录');
}
//获取当前数据详情
$info = $this->model->read(['id'=>$logInfo['source_id']],['is_visualization']);
if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){
//还原头部底部
$type = $this->getType();
//还原头部+底部
$commonData = [
'head_html'=>$logInfo['head_html'],
'head_css'=>$logInfo['head_css'],
'footer_html'=>$logInfo['footer_html'],
'footer_css'=>$logInfo['footer_css']
];
$commonTemplateModel = new BTemplateCommon();
$commonTemplateModel->edit($commonData,['template_id'=>$logInfo['template_id'],'type'=>$type,'project_id'=>$this->user['project_id']]);
}
$this->model->edit(['html'=>$logInfo['main_html'],'html_style'=>$logInfo['main_css']],['id'=>$logInfo['source_id']]);
return $this->success();
}
}
... ...
... ... @@ -92,10 +92,11 @@ class RankDataLogic extends BaseLogic
$data['langs'][$lang['language'] ?? ''] = [
'lang_text' => $lang['language'],
'keyword_num' => $lang['keywords'] ?? 0,
'reach_day' => $lang_data[$lang['language']]['dabiao_day'] ?? 0,
'home_cnt' => $lang_data[$lang['language']]['home_cnt'] ?? 0,
'reach_day' => $lang_data[$lang['lang']]['dabiao_day'] ?? 0,
'home_cnt' => $lang_data[$lang['lang']]['home_cnt'] ?? 0,
'remain_day' => ($lang['type']??0) == 1 ? $data['project']['remain_day'] : $lang['service_day'] - $remain_day,
'type' => $lang['type'] ?? 0, //1 项目关键词 项目天数 2 保证首页关键词 项目达标天数
'service_day' => $lang['service_day'] ?? 0, //1 项目关键词 项目天数 2 保证首页关键词 项目达标天数
];
}
}
... ... @@ -463,8 +464,6 @@ class RankDataLogic extends BaseLogic
$first_ten_pages_num ++;
}
}
$where = [
'project_id' => $project_id,
'lang' => $lang
... ... @@ -473,13 +472,11 @@ class RankDataLogic extends BaseLogic
if(!$model){
$model = new RankData();
}
//关键词达标天数
//保证关键词数
$keyword_num = DeployBuild::where('project_id', $project_id)->value('keyword_num');
$type = Project::where('id', $project_id)->value('type');
$model->is_compliance = 0;
//是否达标
$is_compliance = $first_page_num >= $keyword_num;
if(in_array($project_id, $without_extension_project_ids)){
... ... @@ -487,20 +484,17 @@ class RankDataLogic extends BaseLogic
}
if ($keyword_num && $type == Project::TYPE_TWO && $is_compliance) {
Log::channel('rank_data')->info('项目' . $project_id . ':关键词达标'. $keyword_num .' - ' . $first_page_num . ' - ' . $first_page_without_extension_num);
//项目表更新
if (($model->updated_date != date('Y-m-d') || empty($model->is_compliance)) && !$lang) {
$compliance_day = Project::where(['id' => $project_id])->value('finish_remain_day') ?: 0;
Project::where('id', $project_id)->update(['is_remain_today' => 1, 'finish_remain_day' => $compliance_day + 1]);
Log::channel('rank_data')->info('项目' . $project_id . '达标天数+1:'. ($compliance_day + 1));
}
$model->compliance_day = $model->compliance_day + 1;
$model->is_compliance = 1;
} else {
Log::channel('rank_data')->info('项目' . $project_id . ':关键词未达标'. $keyword_num .' - ' . $first_page_num);
}
$model->project_id = $project_id;
$model->first_num = $first_num;
$model->first_page_num = $first_page_num;
... ...
... ... @@ -396,6 +396,8 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/saveHtml', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'saveHtml'])->name('custom_saveHtml');
Route::any('/statusNum', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'statusNumber'])->name('custom_statusNum');
Route::any('/del', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'del'])->name('custom_del');
Route::any('/rollbackVersion', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'rollbackVersion'])->name('custom_rollbackVersion');
Route::any('/getCustomTemplateLog', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'getCustomTemplateLog'])->name('custom_getCustomTemplateLog');
});
// 菜单组
Route::prefix('nav_group')->group(function () {
... ...