ReplaceHtmlLog.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* @remark :
* @name :ReplaceHtmlLog.php
* @author :lyh
* @method :post
* @time :2024/5/10 17:53
*/
namespace App\Console\Commands\ReplaceHtml;
use App\Models\Template\BTemplate;
use App\Models\Template\TemplateReplaceHtml;
use App\Models\Template\TemplateReplaceHtmlLog;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ReplaceHtmlLog extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'replace_html_log';
/**
* The console command description.
*
* @var string
*/
protected $description = '替换html代码';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
$replaceHtmlLogModel = new TemplateReplaceHtmlLog();
$replaceHtmlList = $replaceHtmlLogModel->list(['status'=>$replaceHtmlLogModel::STATUS]);
foreach ($replaceHtmlList as $k => $v){
ProjectServer::useProject($v['project_id']);
echo '开始,任务id:'.$v['id'].PHP_EOL;
$this->replaceHtml($v);
//修改当前主任务状态为待执行
$replaceHtmlLogModel->edit(['status'=>$replaceHtmlLogModel::STATUS_END],['id'=>$v['id']]);
echo '结束'.PHP_EOL;
DB::disconnect('custom_mysql');
}
return true;
}
/**
* @remark :替换html
* @name :replaceHtml
* @author :lyh
* @method :post
* @time :2024/5/10 17:56
*/
public function replaceHtml($info){
$bTemplateModel = new BTemplate();
$condition = ['source'=>$info['source'],'source_id'=>$info['source_id'],
'template_id'=>$info['template_id'],'is_custom'=>$info['is_custom'],'is_list'=>$info['is_list']];
$old_html = $info['old_html'];
$html = $info['html'];
if($info['template_id'] == 0){
$bTemplateModel->formatQuery($condition)->update(['html' => DB::raw("REPLACE(html, '$old_html', '$html')")]);
}else{
$bTemplateModel->formatQuery($condition)->update(['main_html' => DB::raw("REPLACE(main_html, '$old_html', '$html')")]);
}
}
}