作者 lyh

gx

... ... @@ -67,12 +67,12 @@ class ReplaceHtml extends Command
ProjectServer::useProject($v['project_id']);
echo '开始,任务id:'.$v['id'].PHP_EOL;
if($v['source'] == 9){//单页面
$this->createReplacePageHtmlLog($v);
$count = $this->createReplacePageHtmlLog($v);
}else{
$this->createReplaceHtmlLog($v);
$count = $this->createReplaceHtmlLog($v);
}
//修改当前主任务状态为待执行
$replaceHtmlModel->edit(['status'=>$replaceHtmlModel::STATUS_START],['id'=>$v['id']]);
$replaceHtmlModel->edit(['status'=>$replaceHtmlModel::STATUS_START,'count'=>$count],['id'=>$v['id']]);
echo '结束'.PHP_EOL;
DB::disconnect('custom_mysql');
}
... ... @@ -113,7 +113,7 @@ class ReplaceHtml extends Command
$templateHtmlLogModel = new TemplateReplaceHtmlLog();
$templateHtmlLogModel->insert($saveData);
}
return true;
return count($saveData);
}
/**
... ... @@ -125,10 +125,15 @@ class ReplaceHtml extends Command
*/
public function createReplaceHtmlLog($info){
$bTemplateModel = new BTemplate();
$condition = ['template_id'=>$info['template_id'],'is_custom'=>$info['is_custom'],'is_list'=>$info['is_list']];
if($info['source'] != BTemplate::STATUS){
$condition = ['is_custom'=>$info['is_custom'], 'is_list'=>$info['is_list'], 'template_id'=>$info['template_id']];
if($info['source'] != 0){
$condition['source'] = $info['source'];
}
if($info['template_id'] != 0){
$condition['main_html'] = ['like','%'.$info['old_html'].'%'];
}else{
$condition['html'] = ['like','%'.$info['old_html'].'%'];
}
$bTemplateList = $bTemplateModel->list($condition,'id',['id','source_id']);
$saveData = [];
foreach ($bTemplateList as $v){
... ... @@ -140,7 +145,7 @@ class ReplaceHtml extends Command
$templateHtmlLogModel = new TemplateReplaceHtmlLog();
$templateHtmlLogModel->insert($saveData);
}
return true;
return count($saveData);
}
/**
... ...
... ... @@ -126,7 +126,6 @@ class ReplaceHtmlLogic extends BaseLogic
$data = $this->sourceTypeInfo($this->param['project_id']);
$typeInfo = $data[$this->param['name']];
ProjectServer::useProject($this->param['project_id']);
$bTemplateModel = new BTemplate();
if($typeInfo['source'] == 0){//所有页面
$bSettingModel = new Setting();
$templateInfo = $bSettingModel->read(['project_id'=>$this->param['project_id']]);
... ... @@ -134,18 +133,11 @@ class ReplaceHtmlLogic extends BaseLogic
$this->fail('请先选择模版');
}
$template_id = $templateInfo['template_id'];
$condition = ['template_id'=>$template_id,'main_html'=>['like','%'.$this->param['old_html'].'%']];
$total_num = $bTemplateModel->formatQuery($condition)->count();
}else{
$template_id = $this->getTemplateId($typeInfo);
$condition = ['source'=>$typeInfo['source'],'is_custom'=>$typeInfo['is_custom'], 'is_list'=>$typeInfo['is_list'],
'template_id'=>$template_id,'main_html'=>['like','%'.$this->param['old_html'].'%']];
$total_num = $bTemplateModel->formatQuery($condition)->count();
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($total_num, true) . PHP_EOL, FILE_APPEND);
}
DB::disconnect('custom_mysql');
$replaceId = $this->saveReplaceHtml($this->param,$typeInfo,$template_id,$total_num ?? 0);
$replaceId = $this->saveReplaceHtml($this->param,$typeInfo,$template_id);
return $this->success(['id'=>$replaceId]);
}
... ... @@ -156,7 +148,7 @@ class ReplaceHtmlLogic extends BaseLogic
* @method :post
* @time :2024/5/8 9:23
*/
public function saveReplaceHtml($param,$typeInfo,$template_id,$total_num){
public function saveReplaceHtml($param,$typeInfo,$template_id){
$logData = [
'source'=>$typeInfo['source'],
'is_custom'=>$typeInfo['is_custom'],
... ... @@ -166,7 +158,7 @@ class ReplaceHtmlLogic extends BaseLogic
'old_html'=>$param['old_html'],
'html'=>$param['html'],
'project_id'=>$param['project_id'],
'total_num'=>$total_num,
'total_num'=>0,
'operator_id'=>$this->manager['id']
];
return $this->model->addReturnId($logData);
... ...