CheckProjectIndustry.php
5.6 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
<?php
namespace App\Console\Commands\Industry;
use App\Helper\Arr;
use App\Helper\Common;
use App\Helper\Gpt;
use App\Models\Ai\AiCommand;
use App\Models\Domain\DomainInfo;
use App\Models\Industry\ProjectIndustry;
use App\Models\Industry\ProjectIndustryRelated;
use App\Models\WebSetting\WebSetting;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class CheckProjectIndustry extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check_project_industry';
/**
* The console command description.
*
* @var string
*/
protected $description = '匹配上线项目所属行业';
public function handle()
{
$ai_command = AiCommand::where('key', 'project_industry')->value('ai');
if (!$ai_command) {
$this->output('project_industry指令未配置');
return;
}
$ai_command_new = AiCommand::where('key', 'project_industry2')->value('ai');
if (!$ai_command_new) {
$this->output('project_industry2指令未配置');
return;
}
$industry_list = ProjectIndustry::where('status', 1)->pluck('industry_name')->toArray();
if (!$industry_list) {
$this->output('行业匹配数据为空');
return;
}
$industry_names = implode(',', $industry_list);
$domainModel = new DomainInfo();
$list = $domainModel->select(['id', 'domain', 'project_id'])->where('status', 1)->where('project_id', '>', 0)->get()->toArray();
foreach ($list as $value) {
$project_id = $value['project_id'];
$domain = $value['domain'];
$has_related_count = ProjectIndustryRelated::select(['id'])->where('project_id', $project_id)->count();
if ($has_related_count > 0) {
$this->output('project_id:' . $project_id . ' , domain:' . $domain . ' | 已分析过滤');
continue;
}
$is_industry = false;
$project = ProjectServer::useProject($project_id);
if ($project) {
$webSettingModel = new WebSetting();
$web_setting = $webSettingModel->read(['project_id' => $project_id], ['title', 'keyword']);
if (isset($web_setting['title']) && $web_setting['title'] && isset($web_setting['keyword']) && $web_setting['keyword']) {
$project_industry = $this->getIndustryByAINew($ai_command_new, $industry_names, $web_setting['title'], $web_setting['keyword']);
if ($project_industry) {
$project_industry_name = Arr::splitFilterToArray($project_industry);
$project_industry_id = ProjectIndustry::where('status', 1)->whereIn('industry_name', $project_industry_name)->pluck('id')->toArray();
if ($project_industry_id) {
ProjectIndustryRelated::saveRelated($project_id, $project_industry_id);
$is_industry = true;
$this->output('project_id:' . $project_id . ' , domain:' . $domain . ' | success');
}
}
}
DB::disconnect('custom_mysql');
}
if (!$is_industry) {
$project_industry = $this->getIndustryByAI($ai_command, $industry_names, $domain);
if ($project_industry) {
$project_industry_name = Arr::splitFilterToArray($project_industry);
$project_industry_id = ProjectIndustry::where('status', 1)->whereIn('industry_name', $project_industry_name)->pluck('id')->toArray();
if ($project_industry_id) {
ProjectIndustryRelated::saveRelated($project_id, $project_industry_id);
$this->output('project_id:' . $project_id . ' , domain:' . $domain . ' | success');
} else {
$this->output('project_id:' . $project_id . ' , domain:' . $domain . ' | AI分析行业失败');
}
} else {
$this->output('project_id:' . $project_id . ' , domain:' . $domain . ' | AI分析行业失败');
}
}
}
}
/**
* AI分析行业
* @param $ai_command
* @param $industry_names
* @param $domain
* @return string|string[]
* @author Akun
* @date 2025/03/05 10:42
*/
public function getIndustryByAI($ai_command, $industry_names, $domain)
{
$ai_command = str_replace('{domain}', 'https://' . $domain, $ai_command);
$ai_command = str_replace('{industry}', $industry_names, $ai_command);
$text = Gpt::instance()->openai_chat_qqs($ai_command);
return Common::deal_str($text);
}
/**
* AI分析行业2.0
* @param $ai_command
* @param $industry_names
* @param $title
* @param $keyword
* @return string|string[]
* @author Akun
* @date 2025/08/01 10:10
*/
public function getIndustryByAINew($ai_command, $industry_names, $title, $keyword)
{
$ai_command = str_replace('{industry}', $industry_names, $ai_command);
$ai_command = str_replace('{title}', $title, $ai_command);
$ai_command = str_replace('{keyword}', $keyword, $ai_command);
$text = Gpt::instance()->openai_chat_qqs($ai_command);
return Common::deal_str($text);
}
public function output($msg)
{
echo date('Y-m-d H:i:s') . ' | ' . $msg . PHP_EOL;
}
}