lyhDemo.php
6.5 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* @remark :
* @name :lyhDemo.php
* @author :lyh
* @method :post
* @time :2025/3/24 9:38
*/
namespace App\Console\Commands\LyhTest;
use App\Console\Commands\Domain\DomainInfo;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Models\Ai\AiBlog;
use App\Models\Ai\AiBlogAuthor;
use App\Models\Com\NoticeLog;
use App\Models\Com\V6WeeklyReport;
use App\Models\Project\AiBlogTask;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
use App\Models\Project\ProjectAiSetting;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\RouteMap\RouteMap;
use App\Models\Visit\Visit;
use App\Models\WebSetting\WebLanguage;
use App\Models\WebSetting\WebSetting;
use App\Models\Workchat\MessagePush;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
class lyhDemo extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'lyh_demo';
/**
* The console command description.
*
* @var string
*/
protected $description = '更新路由';
public function handle(){
$this->_actions();
dd(111);
$projectModel = new Project();
$lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4,6]]], 'id', ['id']);
foreach ($lists as $val) {
$aiSettingInfo = $this->getSetting($val['id']);
if($aiSettingInfo === false){
echo '当前项目未注册。'.$val['id'].PHP_EOL;
continue;
}
$aiBlogTaskModel = new AiBlogTask();
$blog_lists = $aiBlogTaskModel->list(['type'=>2,'status'=>2,'project_id'=>$val['id']]);
if(empty($blog_lists)){
echo '未获取到ao_blog'.PHP_EOL;
continue;
}
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
ProjectServer::useProject($val['id']);
$aiBlogService = new AiBlogService($val['id']);
foreach ($blog_lists as $item) {
$aiBlogModel = new AiBlog();
$aiBlogInfo = $aiBlogModel->read(['task_id' => $item['task_id']], ['id']);
if ($aiBlogInfo === false) {
continue;
}
try {
$aiBlogService->task_id = $item['task_id'];
//拉取文章数据
$result = $aiBlogService->getDetail();
if (isset($result) && ($result['status'] == 200)) {
$aiBlogModel->edit(['seo_description' => $result['data']['description']], ['task_id' => $item['task_id']]);
}
} catch (\Exception $e) {
echo '跳过。' . PHP_EOL;
continue;
}
}
DB::disconnect('custom_mysql');
echo date('Y-m-d H:i:s') . '结束--项目的id:'. $val['id'] . PHP_EOL;
}
return true;
}
public function _action(){
$aiBlogTaskModel = new AiBlogTask();
$lists = $aiBlogTaskModel->list(['type'=>2,'status'=>2,'project_id'=>467]);
foreach ($lists as $item){
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $item['project_id'] . PHP_EOL;
ProjectServer::useProject($item['project_id']);
$aiBlogModel = new AiBlog();
$aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id','route']);
if($aiBlogInfo === false){
continue;
}
try {
$aiBlogService = new AiBlogService($item['project_id']);
$aiBlogService->task_id = $item['task_id'];
//拉取文章数据
$result = $aiBlogService->getDetail();
if(isset($result) && ($result['status'] == 200)){
$aiBlogModel->edit(['seo_description'=>$result['data']['description']],['task_id'=>$item['task_id']]);
}
}catch (\Exception $e){
echo '跳过。'.PHP_EOL;
}
DB::disconnect('custom_mysql');
echo date('Y-m-d H:i:s') . '结束--项目的id:'. $item['project_id'] . PHP_EOL;
}
}
public function getSetting($project_id)
{
$projectAiSettingModel = new ProjectAiSetting();
$aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
return $aiSettingInfo;
}
public function _actions() {
echo '565' . PHP_EOL;
ProjectServer::useProject(565);
$table = 'gl_product_keyword';
$connection = DB::connection('custom_mysql');
$brandsStr = 'Trimos,insize,Fowler,Mahr,Starrett,Tesa,Mitutoyo,Wixey,Shars,Fisso,Spi,Grizzly,Accumaster,Accuremote,Baker,Sharpe,Compac,Earth,Etalon,Federal,Fell,Fisso,Fowler,Gem,Grizzly,Husky,iGaging,Insize,Kanetec,Magnetics,Mighty,Mitutoyo,Noga,Pittsburgh,Procheck,Saker,Scherr Tumico,Shars,Shinwa,SPI,Starrett,Tesa,Technidea,Trimos,Verdict,Wyler,Wixey';
$brands = array_unique(array_map('trim', explode(',', $brandsStr)));
// 获取文本类型字段(varchar, text等)
$columns = $connection->table('information_schema.columns')
->where('table_schema', DB::getConfig('custom_mysql.database'))
->where('table_name', $table)
->whereIn('data_type', ['varchar', 'text', 'mediumtext', 'longtext'])
->pluck('column_name')
->toArray();
dd($columns);
foreach ($columns as $field) {
$sqlField = "`$field`";
$lowerField = "LOWER($sqlField)";
$updateExpr = $lowerField;
foreach ($brands as $brand) {
$brandLower = strtolower(addslashes($brand));
$updateExpr = "REPLACE(REPLACE($updateExpr, '{$brandLower}-', ''), '{$brandLower}', '')";
}
// 替换后要保留原字段大小写格式,这里通过 CASE WHEN 判断是否替换,再更新原字段
$sql = "UPDATE `$table`
SET $sqlField = $updateExpr
WHERE $sqlField IS NOT NULL AND $sqlField != ''";
echo "执行字段:$field" . PHP_EOL;
$connection->update($sql);
}
echo '执行结束' . PHP_EOL;
DB::disconnect('custom_mysql');
}
}