|
|
|
1
|
+<?php
|
|
|
|
2
|
+/**
|
|
|
|
3
|
+ * @remark :
|
|
|
|
4
|
+ * @name :AiBlogTask.php
|
|
|
|
5
|
+ * @author :lyh
|
|
|
|
6
|
+ * @method :post
|
|
|
|
7
|
+ * @time :2025/2/14 11:14
|
|
|
|
8
|
+ */
|
|
|
|
9
|
+
|
|
|
|
10
|
+namespace App\Console\Commands\AiBlog;
|
|
|
|
11
|
+
|
|
|
|
12
|
+use App\Models\Ai\AiBlog;
|
|
|
|
13
|
+use App\Models\Ai\AiBlogAuthor;
|
|
|
|
14
|
+use App\Models\Project\ProjectAiSetting;
|
|
|
|
15
|
+use App\Models\RouteMap\RouteMap;
|
|
|
|
16
|
+use App\Services\AiBlogService;
|
|
|
|
17
|
+use App\Services\ProjectServer;
|
|
|
|
18
|
+use Illuminate\Console\Command;
|
|
|
|
19
|
+use App\Models\Project\AiBlogTask as AiBlogTaskModel;
|
|
|
|
20
|
+use Illuminate\Support\Facades\Cache;
|
|
|
|
21
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
22
|
+use function Symfony\Component\String\s;
|
|
|
|
23
|
+
|
|
|
|
24
|
+class AiBlogListTask extends Command
|
|
|
|
25
|
+{
|
|
|
|
26
|
+ /**
|
|
|
|
27
|
+ * The name and signature of the console command.
|
|
|
|
28
|
+ *
|
|
|
|
29
|
+ * @var string
|
|
|
|
30
|
+ */
|
|
|
|
31
|
+ protected $signature = 'save_ai_blog_list';
|
|
|
|
32
|
+
|
|
|
|
33
|
+ /**
|
|
|
|
34
|
+ * The console command description.
|
|
|
|
35
|
+ *
|
|
|
|
36
|
+ * @var string
|
|
|
|
37
|
+ */
|
|
|
|
38
|
+ protected $description = '查询ai_blog是否已经生成';
|
|
|
|
39
|
+
|
|
|
|
40
|
+ public function handle(){
|
|
|
|
41
|
+ $aiBlogTaskModel = new AiBlogTaskModel();
|
|
|
|
42
|
+ $lists = $aiBlogTaskModel->list(['type'=>3,'status'=>1]);
|
|
|
|
43
|
+ foreach ($lists as $k => $v){
|
|
|
|
44
|
+ echo '开始->项目id:' . $v['project_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
45
|
+ $projectAiSettingModel = new ProjectAiSetting();
|
|
|
|
46
|
+ $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$v['project_id']]);
|
|
|
|
47
|
+ if($aiSettingInfo === false){
|
|
|
|
48
|
+ continue;
|
|
|
|
49
|
+ }
|
|
|
|
50
|
+ $aiBlogService = new AiBlogService();
|
|
|
|
51
|
+ $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
|
|
|
|
52
|
+ $aiBlogService->key = $aiSettingInfo['key'];
|
|
|
|
53
|
+ $page = 1;
|
|
|
|
54
|
+ $result = $aiBlogService->getAiBlogList($page,15);
|
|
|
|
55
|
+ if(!isset($result['status'])){
|
|
|
|
56
|
+ continue;
|
|
|
|
57
|
+ }
|
|
|
|
58
|
+ //保存当前项目ai_blog数据
|
|
|
|
59
|
+ ProjectServer::useProject($v['project_id']);
|
|
|
|
60
|
+
|
|
|
|
61
|
+ DB::disconnect('custom_mysql');
|
|
|
|
62
|
+ //修改任务状态
|
|
|
|
63
|
+ $aiBlogTaskModel->edit(['status'=>2],['id'=>$v['id']]);
|
|
|
|
64
|
+ echo '结束->->项目id:' . $v['project_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
65
|
+ }
|
|
|
|
66
|
+ return true;
|
|
|
|
67
|
+ }
|
|
|
|
68
|
+
|
|
|
|
69
|
+
|
|
|
|
70
|
+ /**
|
|
|
|
71
|
+ * @remark :获取项目配置
|
|
|
|
72
|
+ * @name :getSetting
|
|
|
|
73
|
+ * @author :lyh
|
|
|
|
74
|
+ * @method :post
|
|
|
|
75
|
+ * @time :2025/2/14 11:27
|
|
|
|
76
|
+ */
|
|
|
|
77
|
+ public function getSetting($project_id){
|
|
|
|
78
|
+ $ai_cache = Cache::get('ai_blog_'.$project_id);
|
|
|
|
79
|
+ if($ai_cache){
|
|
|
|
80
|
+ return $ai_cache;
|
|
|
|
81
|
+ }
|
|
|
|
82
|
+ $projectAiSettingModel = new ProjectAiSetting();
|
|
|
|
83
|
+ $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
|
|
|
|
84
|
+ Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600);
|
|
|
|
85
|
+ return $aiSettingInfo;
|
|
|
|
86
|
+ }
|
|
|
|
87
|
+
|
|
|
|
88
|
+ /**
|
|
|
|
89
|
+ * @remark :更新作者的页面
|
|
|
|
90
|
+ * @name :updateAiBlogAuthor
|
|
|
|
91
|
+ * @author :lyh
|
|
|
|
92
|
+ * @method :post
|
|
|
|
93
|
+ * @time :2025/2/21 11:53
|
|
|
|
94
|
+ */
|
|
|
|
95
|
+ public function updateAiBlogAuthor($aiSettingInfo,$author_id){
|
|
|
|
96
|
+ if(empty($author_id)){
|
|
|
|
97
|
+ return true;
|
|
|
|
98
|
+ }
|
|
|
|
99
|
+ $aiBlogService = new AiBlogService();
|
|
|
|
100
|
+ $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
|
|
|
|
101
|
+ $aiBlogService->key = $aiSettingInfo['key'];
|
|
|
|
102
|
+ $aiBlogService->author_id = $author_id;
|
|
|
|
103
|
+ $result = $aiBlogService->getAuthorDetail();
|
|
|
|
104
|
+ if(isset($result['status']) && $result['status'] == 200){
|
|
|
|
105
|
+ //当前作者的页面
|
|
|
|
106
|
+ $aiBlogAuthorModel = new AiBlogAuthor();
|
|
|
|
107
|
+ if(!empty($result['data']['section'])){
|
|
|
|
108
|
+ $aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]);
|
|
|
|
109
|
+ }
|
|
|
|
110
|
+ }
|
|
|
|
111
|
+ return true;
|
|
|
|
112
|
+ }
|
|
|
|
113
|
+} |