CheckProjectIndustry.php
3.0 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
<?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 Illuminate\Console\Command;
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('AI指令未配置');
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;
}
$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();
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分析行业失败');
}
}
}
/**
* 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);
}
public function output($msg)
{
echo date('Y-m-d H:i:s') . ' | ' . $msg . PHP_EOL;
}
}