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