lyhDemo.php
14.9 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
/**
* @remark :
* @name :lyhDemo.php
* @author :lyh
* @method :post
* @time :2025/3/24 9:38
*/
namespace App\Console\Commands\LyhTest;
use App\Helper\OaGlobalsoApi;
use App\Models\Ai\AiBlog;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Project\AggregateKeywordAffix;
use App\Models\Project\AiBlogTask;
use App\Models\Project\DeployBuild;
use App\Models\Project\KeywordPrefix;
use App\Models\Project\Payment;
use App\Models\Project\Project;
use App\Models\Project\ProjectAiSetting;
use App\Models\Project\ProjectWhiteHatAffix;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplateMain;
use App\Models\Template\TemplateTypeMain;
use App\Models\WebSetting\Translate;
use App\Models\WebSetting\TranslateData;
use App\Models\WebSetting\WebSetting;
use App\Models\WorkOrder\TicketLog;
use App\Models\WorkOrder\Tickets;
use App\Services\AiBlogService;
use App\Services\CosService;
use App\Services\Geo\GeoService;
use App\Services\MidJourneyService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
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(){
return $this->translate_action();
}
/**
* @remark :查看路由是否为空
* @name :_actionRoute
* @author :lyh
* @method :post
* @time :2025/7/22 15:14
*/
public function _actionRoute(){
$projectModel = new Project();
$lists = $projectModel->list(['delete_status' => 0,'is_ai_blog'=>1,'project_type'=>0,'extend_type'=>0,'type'=>['in',[1,2,3,4,6]]], 'id', ['id']);
$data = [];
foreach ($lists as $item){
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $item['id'] . PHP_EOL;
ProjectServer::useProject($item['id']);
$aiBlogModel = new AiBlog();
$info = $aiBlogModel->read(['text'=>['like','%href="blog/%']],['id']);
if($info !== false){
echo '需要处理->项目id:'.$item['id'].PHP_EOL;
$data[] = $item['id'];
}
echo 'end';
DB::disconnect('custom_mysql');
}
dd($data);
}
public function _actionTemplateMain(){
$data = [];
$projectModel = new Project();
$lists = $projectModel->list(['delete_status' => 0,'project_type'=>0,'extend_type'=>0,'type'=>['in',[2,3,4,6]]], 'id', ['id']);
foreach ($lists as $val){
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
ProjectServer::useProject($val['id']);
$bTemplateMainModel = new BTemplateMain();
$info = $bTemplateMainModel->read(['type'=>2,'is_list'=>1],['id']);
$categoryModel = new Category();
$count = $categoryModel->counts(['id'=>['>',0]]);
if(($info === false) && ($count > 0)){
$mainModel = new TemplateTypeMain();
$mainInfo = $mainModel->read(['type'=>2,'is_list'=>1]);
$main_html = $mainInfo['main_html'];
$main_css = "<style id='globalsojs-styles'></style>";
//写入一条初始数据
$bTemplateMainModel->addReturnId(['type'=>2,'is_list'=>1,'is_custom'=>0,'project_id'=>$val['id'],'main_html'=>$main_html,'main_css'=>$main_css]);
$data[] = $val['id'];
}
DB::disconnect('custom_mysql');
echo date('Y-m-d H:i:s') . '结束--项目的id:'. $val['id'] . PHP_EOL;
}
dd($data);
}
public function _action_ai_blog(){
$projectModel = new Project();
$lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[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 '开始执行...' . PHP_EOL;
ProjectServer::useProject(565);
$table = 'gl_product_category';
$connection = DB::connection('custom_mysql');
$dbName = $connection->getDatabaseName();
$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)));
// 获取文本字段
$columns = $connection->table('information_schema.columns')
->where('table_schema', $dbName)
->where('table_name', $table)
->whereIn('data_type', ['varchar', 'text', 'mediumtext', 'longtext'])
->pluck('column_name')
->toArray();
if (empty($columns)) {
echo "未找到文本字段,退出。" . PHP_EOL;
return;
}
foreach ($columns as $field) {
$sqlField = "`$field`";
// 构造第一轮REPLACE表达式(原样品牌)
$replaceExprRaw = $sqlField;
foreach ($brands as $brand) {
$safeBrand = addslashes($brand);
$replaceExprRaw = "REPLACE(REPLACE($replaceExprRaw, '$safeBrand-', ''), '$safeBrand', '')";
}
// 构造第二轮REPLACE表达式(小写品牌)
$lowerBrands = array_map('strtolower', $brands);
$replaceExprLower = $sqlField;
foreach ($lowerBrands as $brand) {
$safeBrand = addslashes($brand);
$replaceExprLower = "REPLACE(REPLACE($replaceExprLower, '$safeBrand-', ''), '$safeBrand', '')";
}
// 先执行原样品牌替换
$sqlRaw = "UPDATE `$table` SET $sqlField = $replaceExprRaw WHERE $sqlField IS NOT NULL AND $sqlField != ''";
echo "执行字段(品牌原样替换):$field" . PHP_EOL;
try {
$connection->update($sqlRaw);
} catch (\Exception $e) {
echo "字段 $field 原样替换出错:" . $e->getMessage() . PHP_EOL;
}
// 再执行小写品牌替换
$sqlLower = "UPDATE `$table` SET $sqlField = $replaceExprLower WHERE $sqlField IS NOT NULL AND $sqlField != ''";
echo "执行字段(品牌小写替换):$field" . PHP_EOL;
try {
$connection->update($sqlLower);
} catch (\Exception $e) {
echo "字段 $field 小写替换出错:" . $e->getMessage() . PHP_EOL;
}
}
echo '执行结束' . PHP_EOL;
DB::disconnect('custom_mysql');
}
public function translate_action()
{
ProjectServer::useProject(655);
$this->model = new Translate();
$lists = DB::connection('custom_mysql')->table('gl_translate_copy1')->where('url','!=','All')->get()->toArray();
foreach ($lists as $item) {
$item = (array)$item;
$sourceInfo = $this->getRouteSource($item['url']);
$info = $this->model->read(['language_id'=>$item['language_id'],'source_id'=>$sourceInfo['source_id'],'url'=>$item['url'],'project_id'=>655,'type'=>$item['type']]);
if($info === false){
$param = [
'type'=>$item['type'] ?? 1,
'project_id'=>655,
'url'=>$item['url'],
'language_id'=>$item['language_id'],
'alias'=>$item['alias'],
'source'=>$sourceInfo['source'],
'source_id'=>$sourceInfo['source_id'],
'is_list'=>$sourceInfo['is_list'],
'is_custom'=>$sourceInfo['is_custom'],
'page'=>$sendData['page'] ?? 0
];
$id = $this->model->addReturnId($param);
TranslateData::insert(['trans_id'=>$id,'data'=>$item['data']]);
}else{
TranslateData::where(['trans_id'=>$info['id']])->update(['data'=>$item['data']]);
}
}
DB::disconnect('custom_mysql');
}
public function getRouteSource($route){
$routes = $route;
$data = ['source'=>0,'source_id'=>0,'is_list'=>0,'is_custom'=>0,'page'=>0];
if(strtolower($route) == 'all'){
return $data;
}
if($route == 'index' || $route == '/'){
$data['source'] = 1;
return $data;
}
$route = basename($route);
$page = 0;
if (is_numeric($route)) {
$arr = explode('/',$routes);
$page = $route;
$route = $arr[0];
}
$routeModel = new RouteMap();
$routeInfo = $routeModel->read(['route'=>$route]);
if($routeInfo === false){
if(in_array($route,['products','news','blog'])){
//固定路由
$data['page'] = $page;
$data['is_list'] = 1;
if($route == 'products'){
$data['source'] = 2;
}elseif ($route == 'news'){
$data['source'] = 4;
}else{
$data['source'] = 3;
}
return $data;
}
return $data;
}
$data = $this->resultData($routeInfo,$data);
$data['page'] = $page;
return $data;
}
public function resultData($routeInfo,$data){
if($routeInfo['source'] == RouteMap::SOURCE_PAGE){
if($routeInfo['source_id']){
$data = ['source'=>9,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_PRODUCT){
if($routeInfo['source_id']){
$data = ['source'=>2,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_PRODUCT_CATE){
if($routeInfo['source_id']){
$data = ['source'=>2,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_BLOG){
if($routeInfo['source_id']){
$data = ['source'=>3,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_BLOG_CATE){
if($routeInfo['source_id']){
$data = ['source'=>3,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_NEWS){
if($routeInfo['source_id']){
$data = ['source'=>4,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_NEWS_CATE){
if($routeInfo['source_id']){
$data = ['source'=>4,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_PRODUCT_KEYWORD){
if($routeInfo['source_id']){
$data = ['source'=>8,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_MODULE){
if($routeInfo['source_id']){
$data = ['source'=>7,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>1];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_MODULE_CATE){
if($routeInfo['source_id']){
$data = ['source'=>7,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>1];
}
}
return $data;
}
}