新增AI结论数据查询和更新

This commit is contained in:
chengxl
2025-09-29 17:50:32 +08:00
parent 525a96974f
commit 376d961037

View File

@@ -264,7 +264,7 @@ class Aiarticle extends Base
//是否查询作者 1是2否
$iSelectAuthor = empty($aParam['is_select_author']) ? 2 : $aParam['is_select_author'];
//查询AI生成的文章内容
$aWhere = ['is_delete' => 2,'is_generate' => 1];
$aWhere = ['is_delete' => 2];//,'is_generate' => 1
if(!empty($iArticleId)){
$aWhere['article_id'] = $iArticleId;
}
@@ -292,7 +292,10 @@ class Aiarticle extends Base
}
}
return json_encode(['status' => 1,'msg' => 'success','data' => ['ai_article' => $aAiArticle,'ai_article_author' => $aAiAuthor]]);
//查询结论
$aWhere = ['article_id' => $iArticleId,'is_delete' => 2];
$aArticleResult = DB::name('ai_article_results')->field('id,title,content')->where($aWhere)->select();
return json_encode(['status' => 1,'msg' => 'success','data' => ['ai_article' => $aAiArticle,'ai_article_author' => $aAiAuthor,'ai_article_results' => $aArticleResult]]);
}
/**
* @title 处理作者数据
@@ -376,7 +379,14 @@ class Aiarticle extends Base
//获取参数
$aParam = empty($aParam) ? $this->request->post() : $aParam;
//文章ID
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
//查询内容是否存在
$aWhere = ['is_delete' => 2];
if(empty($iArticleId)){
return json_encode(['status' => 2,'msg' => 'Please select the article to be modified']);
}
//更新AI文章内容
$oArticle = new \app\common\Article;
$aResult = json_decode($oArticle->updateAiArticle($aParam),true);
@@ -385,15 +395,19 @@ class Aiarticle extends Base
return json_encode($aResult);
}
//结论信息
$aResultInfo = empty($aParam['results']) ? [] : $aParam['results'];
$aResultInfo = is_array( $aResultInfo) ? $aResultInfo : json_decode($aResultInfo,true);
//更新作者信息
$aAuthorList = empty($aParam['author_list']) ? []: $aParam['author_list'];
$aAuthorList = is_array( $aAuthorList) ? $aAuthorList: json_decode($aAuthorList,true);
if(empty($aAuthorList)){
if(empty($aAuthorList) && empty($aResultInfo)){
return json_encode($aResult);
}
//根据邮箱查询作者信息
if(!empty($aAuthorList)){
$aAuthorList = array_column($aAuthorList, null,'email');
$aEmail = array_keys($aAuthorList);
if(empty($aEmail)){
@@ -444,7 +458,38 @@ class Aiarticle extends Base
}
}
Db::commit();
$aResult['data'] = $aParam;
}
//更新结论
if(!empty($aResultInfo)){
Db::startTrans();
foreach ($aResultInfo as $key => $value) {
//记录ID
$iRecordId = empty($value['record_id']) ? 0 : $value['record_id'];
if(empty($iRecordId)){
continue;
}
//标题
$sTitle = empty($value['title']) ? '' : $value['title'];
//内容
$sContent = empty($value['content']) ? '' : $value['content'];
if(empty($sTitle) && empty($sContent)){
continue;
}
if(!empty($sTitle)){
$aUpdate['title'] = $sTitle;
}
if(!empty($sContent)){
$aUpdate['content'] = $sContent;
}
if(!empty($aUpdate)){
$aUpdate['update_time'] = time();
$aWhere = ['article_id' => $iArticleId,'id' => $iRecordId];
$result = DB::name('ai_article_results')->where($aWhere)->limit(1)->update($aUpdate);
}
}
Db::commit();
}
// $aResult['data'] = $aParam;
return json_encode($aResult);
}