队列提取公共方法
This commit is contained in:
97
application/common/Aireview.php
Normal file
97
application/common/Aireview.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace app\common;
|
||||
use think\Db;
|
||||
/**
|
||||
* @title AI审核文章公共方法
|
||||
* @description 对接OPENAI接口
|
||||
*/
|
||||
class Aireview
|
||||
{
|
||||
/**
|
||||
* @title AI审核内容入库
|
||||
* @param article_id 文章ID
|
||||
*/
|
||||
public function addAiReview($aParam = array()){
|
||||
|
||||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||
if(empty($iArticleId)){
|
||||
return ['status' => 2,'msg' => 'Please select the article to be reviewed'];
|
||||
}
|
||||
$iJournalId = empty($aParam['journal_id']) ? 0 : $aParam['journal_id'];
|
||||
if(empty($iJournalId)){
|
||||
return ['status' => 2,'msg' => 'The journal to which the article belongs cannot be empty'];
|
||||
}
|
||||
//返回数组
|
||||
$aResult = ['status' => 1,'msg' => 'AI review successful'];
|
||||
//数据库参数
|
||||
$aFields = ['journal_scope','attribute','contradiction','unreasonable','ethics','academic','conclusion','fund_number','hotspot','submit_direction','references_past_three','references_past_five','references_ratio_JCR1','references_ratio_JCR2','registration_assessment','cite_rate','references_num','article_field'];
|
||||
foreach ($aParam as $key => $value) {
|
||||
if(empty($value)){
|
||||
continue;
|
||||
}
|
||||
if(is_array($value)){
|
||||
if(!empty($value['assessment'])){
|
||||
$sField = $key.'_'.'assessment';
|
||||
$sAssessment = empty($value['assessment']) ? '' : $value['assessment'];
|
||||
if(!empty($sAssessment)){
|
||||
$sAssessment = is_array($sAssessment) ? json_encode($sAssessment) : htmlspecialchars($value['assessment']);
|
||||
}
|
||||
$aInsert[$sField] = $sAssessment;
|
||||
}
|
||||
if(!empty($value['explanation'])){
|
||||
$sField = $key.'_'.'explanation';
|
||||
$aInsert[$sField] = empty($value['explanation']) ? '' : htmlspecialchars($value['explanation']);
|
||||
}
|
||||
}else{
|
||||
$aInsert[$key] = empty($value) ? '' : htmlspecialchars($value);
|
||||
}
|
||||
}
|
||||
if(empty($aInsert)){
|
||||
return ['status' => 3,'msg' => 'Data is empty'];
|
||||
}
|
||||
|
||||
//查询文章审核内容-判断新增或修改
|
||||
$aWhere = ['article_id' => $iArticleId,'journal_id' => $iJournalId];
|
||||
$aAiReview = Db::table('t_article_ai_review')->field('id')->where($aWhere)->find();
|
||||
$iLogId = empty($aAiReview['id']) ? 0 : $aAiReview['id'];
|
||||
//新增
|
||||
if(empty($iLogId)){
|
||||
$aInsert['create_time'] = date('Y-m-d H:i:s');
|
||||
$aInsert['content'] = $iArticleId;
|
||||
$iLogId = Db::name('article_ai_review')->insertGetId($aInsert);
|
||||
if(empty($iLogId)){
|
||||
$aResult = ['status' => 4,'msg' => 'Failed to add AI audit content'];
|
||||
}
|
||||
$aResult['data'] = ['id' => $iLogId];
|
||||
return $aResult;
|
||||
}
|
||||
if(!empty($iLogId)){
|
||||
$aWhere = ['id' => $iLogId];
|
||||
$aInsert['update_time'] = date('Y-m-d H:i:s');
|
||||
if(!Db::name('article_ai_review')->where($aWhere)->limit(1)->update($aInsert)){
|
||||
$aResult = ['status' => 5,'msg' => 'Failed to add AI audit content'];
|
||||
}
|
||||
$aAiReview = Db::table('t_article_ai_review')->where($aWhere)->find();
|
||||
$aResult['data'] = $aAiReview;
|
||||
return $aResult;
|
||||
}
|
||||
return ['status' => 6,'msg' => 'illegal request'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 文章AI审核内容查询
|
||||
* @param article_id 文章ID
|
||||
*/
|
||||
public function get($aParam = []){
|
||||
|
||||
//获取参数
|
||||
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||
if(empty($aParam['article_id'])){
|
||||
return ['status' => 2,'msg' => 'Please select an article'];
|
||||
}
|
||||
//查询文章审核内容
|
||||
$aWhere = ['article_id' => $aParam['article_id']];
|
||||
$aAiReview = Db::table('t_article_ai_review')->where($aWhere)->find();
|
||||
return ['status' => 1,'msg' => 'Successfully obtained article review content','data' => $aAiReview];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user