|
...
|
...
|
@@ -53,23 +53,36 @@ class lyhDemo extends Command |
|
|
|
$projectModel = new Project();
|
|
|
|
$lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4,6]]], 'id', ['id']);
|
|
|
|
foreach ($lists as $val) {
|
|
|
|
$aiSettingInfo = $this->getSetting($val['id']);
|
|
|
|
if($aiSettingInfo === false){
|
|
|
|
echo '当前项目未注册。'.$val['id'].PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$aiBlogTaskModel = new AiBlogTask();
|
|
|
|
$blog_lists = $aiBlogTaskModel->list(['type'=>2,'status'=>2,'project_id'=>$val['id']]);
|
|
|
|
if(empty($blog_lists)){
|
|
|
|
echo '未获取到ao_blog'.PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
|
|
|
|
ProjectServer::useProject($val['id']);
|
|
|
|
$aiBlogModel = new AiBlog();
|
|
|
|
$aiLists = $aiBlogModel->list(['status'=>2],'id',['id','seo_description']);
|
|
|
|
if(!empty($aiLists)){
|
|
|
|
foreach ($aiLists as $item){
|
|
|
|
if(!empty($item['seo_description'])){
|
|
|
|
//查看当前是否包含句号。
|
|
|
|
$result = $this->hasAnyPeriod($item['seo_description']);
|
|
|
|
if($result === false){
|
|
|
|
$text = $this->trimToLastFullWord($item['seo_description']);
|
|
|
|
}else{
|
|
|
|
$arr = explode('.',$item['seo_description']);
|
|
|
|
$text = $arr[0].'.';
|
|
|
|
}
|
|
|
|
$aiBlogModel->edit(['seo_description'=>$text],['id'=>$item['id']]);
|
|
|
|
$aiBlogService = new AiBlogService($val['id']);
|
|
|
|
foreach ($blog_lists as $item) {
|
|
|
|
$aiBlogModel = new AiBlog();
|
|
|
|
$aiBlogInfo = $aiBlogModel->read(['task_id' => $item['task_id']], ['id']);
|
|
|
|
if ($aiBlogInfo === false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$aiBlogService->task_id = $item['task_id'];
|
|
|
|
//拉取文章数据
|
|
|
|
$result = $aiBlogService->getDetail();
|
|
|
|
if (isset($result) && ($result['status'] == 200)) {
|
|
|
|
$aiBlogModel->edit(['seo_description' => $result['data']['description']], ['task_id' => $item['task_id']]);
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo '跳过。' . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DB::disconnect('custom_mysql');
|
|
...
|
...
|
@@ -78,17 +91,38 @@ class lyhDemo extends Command |
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function trimToLastFullWord($text) {
|
|
|
|
// 去掉结尾非字母数字字符
|
|
|
|
$text = rtrim($text);
|
|
|
|
// 如果最后一个单词被截断,就删除它
|
|
|
|
if (preg_match('/^(.*?\b)\w*$/', $text, $matches)) {
|
|
|
|
return $matches[1];
|
|
|
|
public function _action(){
|
|
|
|
$aiBlogTaskModel = new AiBlogTask();
|
|
|
|
$lists = $aiBlogTaskModel->list(['type'=>2,'status'=>2,'project_id'=>467]);
|
|
|
|
foreach ($lists as $item){
|
|
|
|
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $item['project_id'] . PHP_EOL;
|
|
|
|
ProjectServer::useProject($item['project_id']);
|
|
|
|
$aiBlogModel = new AiBlog();
|
|
|
|
$aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id','route']);
|
|
|
|
if($aiBlogInfo === false){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$aiBlogService = new AiBlogService($item['project_id']);
|
|
|
|
$aiBlogService->task_id = $item['task_id'];
|
|
|
|
//拉取文章数据
|
|
|
|
$result = $aiBlogService->getDetail();
|
|
|
|
if(isset($result) && ($result['status'] == 200)){
|
|
|
|
$aiBlogModel->edit(['seo_description'=>$result['data']['description']],['task_id'=>$item['task_id']]);
|
|
|
|
}
|
|
|
|
}catch (\Exception $e){
|
|
|
|
echo '跳过。'.PHP_EOL;
|
|
|
|
}
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
echo date('Y-m-d H:i:s') . '结束--项目的id:'. $item['project_id'] . PHP_EOL;
|
|
|
|
}
|
|
|
|
return trim($text); // fallback
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAnyPeriod($text) {
|
|
|
|
return strpos($text, '.') !== false || mb_strpos($text, '。') !== false;
|
|
|
|
public function getSetting($project_id)
|
|
|
|
{
|
|
|
|
$projectAiSettingModel = new ProjectAiSetting();
|
|
|
|
$aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
|
|
|
|
return $aiSettingInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
...
|
...
|
|