From 376d96103753936b009194a4f0e490faa1ec2e12 Mon Sep 17 00:00:00 2001 From: chengxl Date: Mon, 29 Sep 2025 17:50:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EAI=E7=BB=93=E8=AE=BA=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9F=A5=E8=AF=A2=E5=92=8C=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Aiarticle.php | 141 +++++++++++++++-------- 1 file changed, 93 insertions(+), 48 deletions(-) diff --git a/application/api/controller/Aiarticle.php b/application/api/controller/Aiarticle.php index eecd549..b4520a8 100644 --- a/application/api/controller/Aiarticle.php +++ b/application/api/controller/Aiarticle.php @@ -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,66 +395,101 @@ 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); } //根据邮箱查询作者信息 - $aAuthorList = array_column($aAuthorList, null,'email'); - $aEmail = array_keys($aAuthorList); - if(empty($aEmail)){ - return json_encode($aResult); - } - $aUserParam = ['email' => ['in',$aEmail]]; - $aUserInfo = Db::name('user')->field('email,user_id')->where($aUserParam)->select(); - if(empty($aUserInfo)){ - return json_encode($aResult); - } + if(!empty($aAuthorList)){ + $aAuthorList = array_column($aAuthorList, null,'email'); + $aEmail = array_keys($aAuthorList); + if(empty($aEmail)){ + return json_encode($aResult); + } + $aUserParam = ['email' => ['in',$aEmail]]; + $aUserInfo = Db::name('user')->field('email,user_id')->where($aUserParam)->select(); + if(empty($aUserInfo)){ + return json_encode($aResult); + } - //查询用户附表 - $aUserId = array_column($aUserInfo, 'user_id'); - $aWhere = ['reviewer_id' => ['in',$aUserId]]; - $aUserReviewer = Db::name('user_reviewer_info')->where($aWhere)->column('reviewer_id'); - //更新用户信息 - Db::startTrans(); - foreach ($aUserInfo as $key => $value) { + //查询用户附表 + $aUserId = array_column($aUserInfo, 'user_id'); + $aWhere = ['reviewer_id' => ['in',$aUserId]]; + $aUserReviewer = Db::name('user_reviewer_info')->where($aWhere)->column('reviewer_id'); + //更新用户信息 + Db::startTrans(); + foreach ($aUserInfo as $key => $value) { - $aUser = empty($aAuthorList[$value['email']]) ? [] : $aAuthorList[$value['email']]; - if(empty($aUser)){ - 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); + $aUser = empty($aAuthorList[$value['email']]) ? [] : $aAuthorList[$value['email']]; + if(empty($aUser)){ + continue; } - if(!in_array($value['user_id'], $aUserReviewer)){//插入 - $aUpdateReviewer['reviewer_id'] = $value['user_id']; - Db::name('user_reviewer_info')->insert($aUpdateReviewer); + //更新作者名字 + 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']; + 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); }