|
@@ -53,23 +53,36 @@ class lyhDemo extends Command |
|
@@ -53,23 +53,36 @@ class lyhDemo extends Command |
|
53
|
$projectModel = new Project();
|
53
|
$projectModel = new Project();
|
|
54
|
$lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4,6]]], 'id', ['id']);
|
54
|
$lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4,6]]], 'id', ['id']);
|
|
55
|
foreach ($lists as $val) {
|
55
|
foreach ($lists as $val) {
|
|
|
|
56
|
+ $aiSettingInfo = $this->getSetting($val['id']);
|
|
|
|
57
|
+ if($aiSettingInfo === false){
|
|
|
|
58
|
+ echo '当前项目未注册。'.$val['id'].PHP_EOL;
|
|
|
|
59
|
+ continue;
|
|
|
|
60
|
+ }
|
|
|
|
61
|
+ $aiBlogTaskModel = new AiBlogTask();
|
|
|
|
62
|
+ $blog_lists = $aiBlogTaskModel->list(['type'=>2,'status'=>2,'project_id'=>$val['id']]);
|
|
|
|
63
|
+ if(empty($blog_lists)){
|
|
|
|
64
|
+ echo '未获取到ao_blog'.PHP_EOL;
|
|
|
|
65
|
+ continue;
|
|
|
|
66
|
+ }
|
|
56
|
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
|
67
|
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
|
|
57
|
ProjectServer::useProject($val['id']);
|
68
|
ProjectServer::useProject($val['id']);
|
|
|
|
69
|
+ $aiBlogService = new AiBlogService($val['id']);
|
|
|
|
70
|
+ foreach ($blog_lists as $item) {
|
|
58
|
$aiBlogModel = new AiBlog();
|
71
|
$aiBlogModel = new AiBlog();
|
|
59
|
- $aiLists = $aiBlogModel->list(['status'=>2],'id',['id','seo_description']);
|
|
|
|
60
|
- if(!empty($aiLists)){
|
|
|
|
61
|
- foreach ($aiLists as $item){
|
|
|
|
62
|
- if(!empty($item['seo_description'])){
|
|
|
|
63
|
- //查看当前是否包含句号。
|
|
|
|
64
|
- $result = $this->hasAnyPeriod($item['seo_description']);
|
|
|
|
65
|
- if($result === false){
|
|
|
|
66
|
- $text = $this->trimToLastFullWord($item['seo_description']);
|
|
|
|
67
|
- }else{
|
|
|
|
68
|
- $arr = explode('.',$item['seo_description']);
|
|
|
|
69
|
- $text = $arr[0].'.';
|
72
|
+ $aiBlogInfo = $aiBlogModel->read(['task_id' => $item['task_id']], ['id']);
|
|
|
|
73
|
+ if ($aiBlogInfo === false) {
|
|
|
|
74
|
+ continue;
|
|
70
|
}
|
75
|
}
|
|
71
|
- $aiBlogModel->edit(['seo_description'=>$text],['id'=>$item['id']]);
|
76
|
+ try {
|
|
|
|
77
|
+ $aiBlogService->task_id = $item['task_id'];
|
|
|
|
78
|
+ //拉取文章数据
|
|
|
|
79
|
+ $result = $aiBlogService->getDetail();
|
|
|
|
80
|
+ if (isset($result) && ($result['status'] == 200)) {
|
|
|
|
81
|
+ $aiBlogModel->edit(['seo_description' => $result['data']['description']], ['task_id' => $item['task_id']]);
|
|
72
|
}
|
82
|
}
|
|
|
|
83
|
+ } catch (\Exception $e) {
|
|
|
|
84
|
+ echo '跳过。' . PHP_EOL;
|
|
|
|
85
|
+ continue;
|
|
73
|
}
|
86
|
}
|
|
74
|
}
|
87
|
}
|
|
75
|
DB::disconnect('custom_mysql');
|
88
|
DB::disconnect('custom_mysql');
|
|
@@ -78,17 +91,38 @@ class lyhDemo extends Command |
|
@@ -78,17 +91,38 @@ class lyhDemo extends Command |
|
78
|
return true;
|
91
|
return true;
|
|
79
|
}
|
92
|
}
|
|
80
|
|
93
|
|
|
81
|
- public function trimToLastFullWord($text) {
|
|
|
|
82
|
- // 去掉结尾非字母数字字符
|
|
|
|
83
|
- $text = rtrim($text);
|
|
|
|
84
|
- // 如果最后一个单词被截断,就删除它
|
|
|
|
85
|
- if (preg_match('/^(.*?\b)\w*$/', $text, $matches)) {
|
|
|
|
86
|
- return $matches[1];
|
94
|
+ public function _action(){
|
|
|
|
95
|
+ $aiBlogTaskModel = new AiBlogTask();
|
|
|
|
96
|
+ $lists = $aiBlogTaskModel->list(['type'=>2,'status'=>2,'project_id'=>467]);
|
|
|
|
97
|
+ foreach ($lists as $item){
|
|
|
|
98
|
+ echo date('Y-m-d H:i:s') . '开始--项目的id:'. $item['project_id'] . PHP_EOL;
|
|
|
|
99
|
+ ProjectServer::useProject($item['project_id']);
|
|
|
|
100
|
+ $aiBlogModel = new AiBlog();
|
|
|
|
101
|
+ $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id','route']);
|
|
|
|
102
|
+ if($aiBlogInfo === false){
|
|
|
|
103
|
+ continue;
|
|
|
|
104
|
+ }
|
|
|
|
105
|
+ try {
|
|
|
|
106
|
+ $aiBlogService = new AiBlogService($item['project_id']);
|
|
|
|
107
|
+ $aiBlogService->task_id = $item['task_id'];
|
|
|
|
108
|
+ //拉取文章数据
|
|
|
|
109
|
+ $result = $aiBlogService->getDetail();
|
|
|
|
110
|
+ if(isset($result) && ($result['status'] == 200)){
|
|
|
|
111
|
+ $aiBlogModel->edit(['seo_description'=>$result['data']['description']],['task_id'=>$item['task_id']]);
|
|
|
|
112
|
+ }
|
|
|
|
113
|
+ }catch (\Exception $e){
|
|
|
|
114
|
+ echo '跳过。'.PHP_EOL;
|
|
|
|
115
|
+ }
|
|
|
|
116
|
+ DB::disconnect('custom_mysql');
|
|
|
|
117
|
+ echo date('Y-m-d H:i:s') . '结束--项目的id:'. $item['project_id'] . PHP_EOL;
|
|
87
|
}
|
118
|
}
|
|
88
|
- return trim($text); // fallback
|
|
|
|
89
|
}
|
119
|
}
|
|
90
|
|
120
|
|
|
91
|
- public function hasAnyPeriod($text) {
|
|
|
|
92
|
- return strpos($text, '.') !== false || mb_strpos($text, '。') !== false;
|
121
|
+ public function getSetting($project_id)
|
|
|
|
122
|
+ {
|
|
|
|
123
|
+ $projectAiSettingModel = new ProjectAiSetting();
|
|
|
|
124
|
+ $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
|
|
|
|
125
|
+ return $aiSettingInfo;
|
|
93
|
}
|
126
|
}
|
|
|
|
127
|
+
|
|
94
|
} |
128
|
} |