lyhDemo.php
6.4 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
<?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\AiBlogAuthor;
use App\Models\Com\NoticeLog;
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\RouteMap\RouteMap;
use App\Models\Visit\Visit;
use App\Models\WebSetting\WebLanguage;
use App\Models\WebSetting\WebSetting;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
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(){
$projectIds = DB::table('gl_project_ai_setting')
->whereIn('mch_id', function ($query) {
$query->select('mch_id')
->from('gl_project_ai_setting')
->groupBy('mch_id')
->havingRaw('COUNT(*) > 1');
})
->pluck('project_id');
$projectIds[] = 811;
$projectIds[] = 1367;
$projectIds[] = 1370;
$projectIds[] = 2201;
$projectIds[] = 2260;
$projectIds[] = 2259;
// $aiSettingModel = new ProjectAiSetting();
// foreach ($projectIds as $item){
// $info = $aiSettingModel->read(['project_id'=>$item]);
// if($info === false){
// echo '项目id:'.$item.PHP_EOL;
// }else{
// $this->createAuthor($item,$info['mch_id'],$info['key']);
// }
// }
// return true;
$aiSettingModel = new ProjectAiSetting();
$aiSettingModel->del(['project_id'=>['in',$projectIds]]);
$projectModel = new Project();
$logic = new ProjectLogic();
$lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'id'=>['in',$projectIds]], 'id', ['id']);
$title = [];
foreach ($lists as $val) {
//清空作者
ProjectServer::useProject($val['id']);
AiBlogAuthor::truncate();
$routeMapModel = new RouteMap();
$routeMapModel->del(['source'=>$routeMapModel::SOURCE_AI_BLOG_AUTHOR]);
DB::disconnect('custom_mysql');
//重新创建项目拉取作者
$info = $logic->getProjectInfo($val['id']);
$title[] = $info['company']?:$info['title'];
if(empty($info['main_lang_id'])){
$info['main_lang_id'] = 1;
}
if(empty($info['is_ai_blog'])){
$info['is_ai_blog'] = 1;
}
try {
$this->setAiBlog($info['id'],$info['main_lang_id'],$info['is_ai_blog'] ?? 0,
$info['company']??"", $info['deploy_optimize']['company_en_name'] ?? '',
$info['deploy_optimize']['company_en_description'] ?? '',$info['is_ai_video'] ?? 0,$info['is_related_video'] ?? 0);
}catch (\Exception $e){
continue;
}
}
return true;
}
public function setAiBlog($project_id,$main_lang_id,$is_ai_blog,$company,$company_en_name,$company_en_description,$is_ai_video = 0,$is_related_video = 0){
if(empty($main_lang_id) || (empty($is_ai_blog) && empty($is_ai_video))){
echo '创建失败:'.$project_id.PHP_EOL;
}
$projectInfo = $this->model->read(['id'=>$project_id],['title','main_lang_id','company']);
$projectOptimize = DeployOptimize::where('project_id', $project_id)->first();
//获取项目主语种
$languageModel = new WebLanguage();
$languageInfo = $languageModel->read(['id'=>$main_lang_id],['short']);
if($languageInfo == false){
echo '创建失败:'.$project_id.PHP_EOL;
}
$aiSettingModel = new ProjectAiSetting();
$aiSettingInfo = $aiSettingModel->read(['project_id'=>$project_id]);
if($aiSettingInfo === false){
$aiBlogService = new AiBlogService();
$result = $aiBlogService->createProject($projectInfo['company']?:$projectInfo['title'],$languageInfo['short'],$company_en_description,$company_en_name,$is_related_video);
if(isset($result['status']) && $result['status'] == 200){
//查看当前项目是否已有记录
$resData = [
'project_id'=>$project_id,
'mch_id'=>$result['data']['mch_id'],
'key'=>$result['data']['key'],
];
$aiSettingModel->add($resData);
$this->createAuthor($project_id,$result['data']['mch_id'],$result['data']['key']);
}else{
echo '创建失败:'.$project_id.PHP_EOL;
}
}else{
//有信息更新
if(($projectInfo['company'] != $company) || ($projectInfo['main_lang_id'] != $main_lang_id)
|| ($projectOptimize['company_en_name'] != $company_en_name) || ($projectOptimize['company_en_description'] != $company_en_description)){
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->updatedProject($projectInfo['company']?:$projectInfo['title'],$languageInfo['short'],$company_en_description,$company_en_name,$is_related_video);
}
}
return true;
}
public function createAuthor($project_id,$mch_id,$key){
//查看当前项目是否已经创建了作者
$aiBlogTaskModel = new AiBlogTask();
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $mch_id;
$aiBlogService->key = $key;
$result = $aiBlogService->createAuthor();
if($result['status'] == 200){
//查看当前是否已有未执行的
$aiBlogTaskModel->add(['project_id'=>$project_id,'status'=>1,'type'=>1]);
}
return true;
}
}