新增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否 //是否查询作者 1是2否
$iSelectAuthor = empty($aParam['is_select_author']) ? 2 : $aParam['is_select_author']; $iSelectAuthor = empty($aParam['is_select_author']) ? 2 : $aParam['is_select_author'];
//查询AI生成的文章内容 //查询AI生成的文章内容
$aWhere = ['is_delete' => 2,'is_generate' => 1]; $aWhere = ['is_delete' => 2];//,'is_generate' => 1
if(!empty($iArticleId)){ if(!empty($iArticleId)){
$aWhere['article_id'] = $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 处理作者数据 * @title 处理作者数据
@@ -376,7 +379,14 @@ class Aiarticle extends Base
//获取参数 //获取参数
$aParam = empty($aParam) ? $this->request->post() : $aParam; $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文章内容 //更新AI文章内容
$oArticle = new \app\common\Article; $oArticle = new \app\common\Article;
$aResult = json_decode($oArticle->updateAiArticle($aParam),true); $aResult = json_decode($oArticle->updateAiArticle($aParam),true);
@@ -385,66 +395,101 @@ class Aiarticle extends Base
return json_encode($aResult); 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 = empty($aParam['author_list']) ? []: $aParam['author_list'];
$aAuthorList = is_array( $aAuthorList) ? $aAuthorList: json_decode($aAuthorList,true); $aAuthorList = is_array( $aAuthorList) ? $aAuthorList: json_decode($aAuthorList,true);
if(empty($aAuthorList)){ if(empty($aAuthorList) && empty($aResultInfo)){
return json_encode($aResult); return json_encode($aResult);
} }
//根据邮箱查询作者信息 //根据邮箱查询作者信息
$aAuthorList = array_column($aAuthorList, null,'email'); if(!empty($aAuthorList)){
$aEmail = array_keys($aAuthorList); $aAuthorList = array_column($aAuthorList, null,'email');
if(empty($aEmail)){ $aEmail = array_keys($aAuthorList);
return json_encode($aResult); if(empty($aEmail)){
} return json_encode($aResult);
$aUserParam = ['email' => ['in',$aEmail]]; }
$aUserInfo = Db::name('user')->field('email,user_id')->where($aUserParam)->select(); $aUserParam = ['email' => ['in',$aEmail]];
if(empty($aUserInfo)){ $aUserInfo = Db::name('user')->field('email,user_id')->where($aUserParam)->select();
return json_encode($aResult); if(empty($aUserInfo)){
} return json_encode($aResult);
}
//查询用户附表 //查询用户附表
$aUserId = array_column($aUserInfo, 'user_id'); $aUserId = array_column($aUserInfo, 'user_id');
$aWhere = ['reviewer_id' => ['in',$aUserId]]; $aWhere = ['reviewer_id' => ['in',$aUserId]];
$aUserReviewer = Db::name('user_reviewer_info')->where($aWhere)->column('reviewer_id'); $aUserReviewer = Db::name('user_reviewer_info')->where($aWhere)->column('reviewer_id');
//更新用户信息 //更新用户信息
Db::startTrans(); Db::startTrans();
foreach ($aUserInfo as $key => $value) { foreach ($aUserInfo as $key => $value) {
$aUser = empty($aAuthorList[$value['email']]) ? [] : $aAuthorList[$value['email']]; $aUser = empty($aAuthorList[$value['email']]) ? [] : $aAuthorList[$value['email']];
if(empty($aUser)){ if(empty($aUser)){
continue; continue;
}
//更新作者名字
if(isset($aUser['author_name'])){
$aUpdate = ['localname' => $aUser['author_name']];
Db::name('user')->where('user_id',$value['user_id'])->update($aUpdate);
}
//更新作者简介和单位
$aUpdateReviewer = [];
if(isset($aUser['technical'])){
$aUpdateReviewer['technical'] = $aUser['technical'];
}
if(isset($aUser['introduction'])){
$aUpdateReviewer['introduction'] = $aUser['introduction'];
}
if(isset($aUser['company'])){
$aUpdateReviewer['company'] = $aUser['company'];
}
if(isset($aUpdateReviewer)){
if(in_array($value['user_id'], $aUserReviewer)){//更新
Db::name('user_reviewer_info')->where('reviewer_id',$value['user_id'])->limit(1)->update($aUpdateReviewer);
} }
if(!in_array($value['user_id'], $aUserReviewer)){//插入 //更新作者名字
$aUpdateReviewer['reviewer_id'] = $value['user_id']; if(isset($aUser['author_name'])){
Db::name('user_reviewer_info')->insert($aUpdateReviewer); $aUpdate = ['localname' => $aUser['author_name']];
Db::name('user')->where('user_id',$value['user_id'])->update($aUpdate);
}
//更新作者简介和单位
$aUpdateReviewer = [];
if(isset($aUser['technical'])){
$aUpdateReviewer['technical'] = $aUser['technical'];
}
if(isset($aUser['introduction'])){
$aUpdateReviewer['introduction'] = $aUser['introduction'];
}
if(isset($aUser['company'])){
$aUpdateReviewer['company'] = $aUser['company'];
}
if(isset($aUpdateReviewer)){
if(in_array($value['user_id'], $aUserReviewer)){//更新
Db::name('user_reviewer_info')->where('reviewer_id',$value['user_id'])->limit(1)->update($aUpdateReviewer);
}
if(!in_array($value['user_id'], $aUserReviewer)){//插入
$aUpdateReviewer['reviewer_id'] = $value['user_id'];
Db::name('user_reviewer_info')->insert($aUpdateReviewer);
}
} }
} }
Db::commit();
} }
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); return json_encode($aResult);
} }