|
|
|
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\Ai\AiBlogList;
|
|
|
|
15
|
+use App\Models\Project\ProjectAiSetting;
|
|
|
|
16
|
+use App\Models\RouteMap\RouteMap;
|
|
|
|
17
|
+use App\Services\AiBlogService;
|
|
|
|
18
|
+use App\Services\ProjectServer;
|
|
|
|
19
|
+use Illuminate\Console\Command;
|
|
|
|
20
|
+use App\Models\Project\AiBlogTask as AiBlogTaskModel;
|
|
|
|
21
|
+use Illuminate\Support\Facades\Cache;
|
|
|
|
22
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
23
|
+use function Symfony\Component\String\s;
|
|
|
|
24
|
+
|
|
|
|
25
|
+class AiBlogListTask extends Command
|
|
|
|
26
|
+{
|
|
|
|
27
|
+ /**
|
|
|
|
28
|
+ * The name and signature of the console command.
|
|
|
|
29
|
+ *
|
|
|
|
30
|
+ * @var string
|
|
|
|
31
|
+ */
|
|
|
|
32
|
+ protected $signature = 'save_ai_blog_list {project_id}';
|
|
|
|
33
|
+
|
|
|
|
34
|
+ /**
|
|
|
|
35
|
+ * The console command description.
|
|
|
|
36
|
+ *
|
|
|
|
37
|
+ * @var string
|
|
|
|
38
|
+ */
|
|
|
|
39
|
+ protected $description = '生成blog列表';
|
|
|
|
40
|
+
|
|
|
|
41
|
+ public function handle(){
|
|
|
|
42
|
+ $project_id = $this->argument('project_id');
|
|
|
|
43
|
+ ProjectServer::useProject($project_id);
|
|
|
|
44
|
+ $projectAiSettingModel = new ProjectAiSetting();
|
|
|
|
45
|
+ $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
|
|
|
|
46
|
+ $this->updateBlogList($aiSettingInfo);
|
|
|
|
47
|
+ DB::disconnect('custom_mysql');
|
|
|
|
48
|
+ return true;
|
|
|
|
49
|
+ }
|
|
|
|
50
|
+
|
|
|
|
51
|
+ /**
|
|
|
|
52
|
+ * @remark :更新列表页数据
|
|
|
|
53
|
+ * @name :updateBlogList
|
|
|
|
54
|
+ * @author :lyh
|
|
|
|
55
|
+ * @method :post
|
|
|
|
56
|
+ * @time :2025/3/5 11:07
|
|
|
|
57
|
+ */
|
|
|
|
58
|
+ public function updateBlogList($aiSettingInfo){
|
|
|
|
59
|
+ $aiBlogService = new AiBlogService();
|
|
|
|
60
|
+ $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
|
|
|
|
61
|
+ $aiBlogService->key = $aiSettingInfo['key'];
|
|
|
|
62
|
+ $page = 1;
|
|
|
|
63
|
+ $saveData = [];
|
|
|
|
64
|
+ $result = $aiBlogService->getAiBlogList($page,15);
|
|
|
|
65
|
+ if(!isset($result['status']) && $result['status'] != 200){
|
|
|
|
66
|
+ return true;
|
|
|
|
67
|
+ }
|
|
|
|
68
|
+ $total_page = $result['data']['total_page'];
|
|
|
|
69
|
+ //组装数据保存
|
|
|
|
70
|
+ $saveData[] = [
|
|
|
|
71
|
+ 'route'=>$page,
|
|
|
|
72
|
+ 'text'=>$result['data']['section'],
|
|
|
|
73
|
+ ];
|
|
|
|
74
|
+ while ($total_page > $page){
|
|
|
|
75
|
+ $page++;
|
|
|
|
76
|
+ $result = $aiBlogService->getAiBlogList($page,15);
|
|
|
|
77
|
+ if(isset($result['status']) && $result['status'] == 200){
|
|
|
|
78
|
+ $saveData[] = [
|
|
|
|
79
|
+ 'route'=>$page,
|
|
|
|
80
|
+ 'text'=>$result['data']['section'],
|
|
|
|
81
|
+ ];
|
|
|
|
82
|
+ }
|
|
|
|
83
|
+ }
|
|
|
|
84
|
+ $aiBlogListModel = new AiBlogList();
|
|
|
|
85
|
+ if(!empty($saveData)){
|
|
|
|
86
|
+ //写一条路由信息
|
|
|
|
87
|
+ $aiBlogListModel->truncate();
|
|
|
|
88
|
+ $aiBlogListModel->insertAll($saveData);
|
|
|
|
89
|
+ }
|
|
|
|
90
|
+ return true;
|
|
|
|
91
|
+ }
|
|
|
|
92
|
+} |