103 lines
4.5 KiB
PHP
103 lines
4.5 KiB
PHP
<?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'];
|
|
}
|
|
|
|
$oArticle = new \app\common\Article;
|
|
//返回数组
|
|
$aResult = ['status' => 1,'msg' => 'AI review successful'];
|
|
//数据库参数
|
|
$aFields = ['journal_scope_assessment','journal_scope_explanation','other_journal_assessment','other_journal_issn','other_journal_explanation','attribute_assessment','attribute_explanation','contradiction_assessment','contradiction_explanation','unreasonable_assessment','unreasonable_explanation','ethics_assessment','ethics_explanation','academic_assessment','academic_explanation','conclusion_assessment','conclusion_explanation','fund_number','hotspot','submit_direction','references_past_three','references_num','references_past_five','references_ratio_JCR1','references_ratio_JCR2','registration_assessment','registration_explanation','cite_rate','article_field_assessment','article_field_explanation','is_finish','article_id','journal_id'];
|
|
foreach ($aParam as $key => $value) {
|
|
if(empty($value)){
|
|
continue;
|
|
}
|
|
if(!in_array($key, $aFields)){
|
|
continue;
|
|
}
|
|
$value = is_array($value) ? json_encode($value) : $value;
|
|
$aInsert[$key] = $value;
|
|
}
|
|
if(empty($aInsert)){
|
|
return ['status' => 3,'msg' => 'Data is empty'];
|
|
}
|
|
//查询文章审核内容-判断新增或修改
|
|
$aWhere = ['article_id' => $iArticleId,'journal_id' => $iJournalId];
|
|
$aAiReview = Db::name('article_ai_review')->field('id')->where($aWhere)->find();
|
|
$iLogId = empty($aAiReview['id']) ? 0 : $aAiReview['id'];
|
|
//新增
|
|
if(empty($iLogId)){
|
|
$aInsert['create_time'] = time();
|
|
$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'] = time();
|
|
if(!Db::name('article_ai_review')->where($aWhere)->limit(1)->update($aInsert)){
|
|
$aResult = ['status' => 5,'msg' => 'Failed to add AI audit content'];
|
|
}
|
|
$aResult['data'] = $aInsert;
|
|
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::name('article_ai_review')->where($aWhere)->find();
|
|
if(!empty($aAiReview)){
|
|
$sCreateTime = empty($aAiReview['create_time']) ? '' : $aAiReview['create_time'];
|
|
if(!empty($sCreateTime)){
|
|
$aAiReview['create_time'] = strtotime($sCreateTime) !== false ? $sCreateTime : date('Y-m-d H:i:s',$sCreateTime);
|
|
}else{
|
|
$aAiReview['create_time'] = '';
|
|
}
|
|
|
|
$sUpdateTime = empty($aAiReview['update_time']) ? '' : $aAiReview['update_time'];
|
|
if(!empty($sUpdateTime)){
|
|
$aAiReview['update_time'] = strtotime($sUpdateTime) !== false ? $sUpdateTime : date('Y-m-d H:i:s',$sUpdateTime);
|
|
}else{
|
|
$aAiReview['update_time'] = '';
|
|
}
|
|
}
|
|
|
|
return ['status' => 1,'msg' => 'Successfully obtained article review content','data' => $aAiReview];
|
|
}
|
|
}
|