Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -796,6 +796,15 @@ class Production extends Base
|
||||
}
|
||||
}
|
||||
//推送到生成AI内容队列 chengxiaoling end 20250530
|
||||
|
||||
//推送到关联文章发送邮件提醒队列【立即发送提醒邮件给关联文章的作者及文章作者】 chengxiaoling start 20250609
|
||||
if(!empty($p_info['related'])){
|
||||
$iArticleId = empty($r_update['w_article_id']) ? 0 : $r_update['w_article_id'];
|
||||
if(!empty($iArticleId)){
|
||||
Queue::push('app\api\job\RelatedArticle@fire', ['article_id' => $iArticleId], 'RelatedArticle');
|
||||
}
|
||||
}
|
||||
//推送到关联文章发送邮件提醒队列【立即发送提醒邮件给关联文章的作者及文章作者】 chengxiaoling end 20250609
|
||||
return jsonSuccess([]);
|
||||
} else {
|
||||
return jsonError('system error:' . $res['msg']);
|
||||
|
||||
61
application/api/job/RelatedArticle.php
Normal file
61
application/api/job/RelatedArticle.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace app\api\job;
|
||||
use think\queue\Job;
|
||||
use app\common\QueueJob;
|
||||
use app\common\JournalArticle;
|
||||
class RelatedArticle
|
||||
{
|
||||
// 相关文章发送邮件任务
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
|
||||
//获取任务ID
|
||||
$iLogId = 0;
|
||||
try {
|
||||
//实例化
|
||||
$oQueueJob = new QueueJob;
|
||||
$sMsg = '获取相关文章信息成功';
|
||||
if(!empty($job->getRawBody())){
|
||||
$aJob = json_decode($job->getRawBody(), true);
|
||||
$aParam = [
|
||||
'job_id' => empty($aJob['id']) ? '' : $aJob['id'],
|
||||
'job_class' => get_class($this),
|
||||
'status' => 0,
|
||||
'create_time' => time(),
|
||||
'params' => json_encode($aJob, JSON_UNESCAPED_UNICODE)
|
||||
];
|
||||
$iLogId = $oQueueJob->addLog($aParam);
|
||||
// 步骤1:上传素材(图片)
|
||||
$iArticleId = empty($data['article_id']) ? 0 : $data['article_id'];
|
||||
if (!empty($iArticleId)) {
|
||||
//上传素材
|
||||
$oJournalArticle = new JournalArticle;
|
||||
$aResult = json_decode(JournalArticle::get($data),true);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? '获取相关文章信息失败' : $aResult['msg'];
|
||||
}
|
||||
}
|
||||
$job->delete();
|
||||
|
||||
//更新任务状态
|
||||
$aParam = ['log_id' => $iLogId,'status' => 1,'update_time' => time(),'error' => $sMsg];
|
||||
$oQueueJob->updateLog($aParam);
|
||||
// // 记录日志
|
||||
// \think\Log::info("RelatedArticle延迟任务执行成功: ".json_encode($data));
|
||||
} catch (\Exception $e) {
|
||||
|
||||
//实例化
|
||||
$oQueueJob = new QueueJob;
|
||||
//更新任务状态
|
||||
$sMsg = empty($e->getMessage()) ? '任务出错' : $e->getMessage();
|
||||
$aParam = ['log_id' => $iLogId,'status' => 2,'update_time' => time(),'error' => $sMsg];
|
||||
$oQueueJob->updateLog($aParam);
|
||||
$job->delete();
|
||||
// // 记录错误日志
|
||||
// \think\Log::error("RelatedArticle延迟任务失败: ".$e->getMessage());
|
||||
}finally {
|
||||
gc_collect_cycles(); // 强制垃圾回收
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
98
application/api/job/SendRelatedArticleEmail.php
Normal file
98
application/api/job/SendRelatedArticleEmail.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace app\api\job;
|
||||
use think\queue\Job;
|
||||
use app\common\QueueJob;
|
||||
use app\common\JournalArticle;
|
||||
class SendRelatedArticleEmail
|
||||
{
|
||||
// 相关文章发送邮件任务
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
|
||||
//获取任务ID
|
||||
$iLogId = 0;
|
||||
try {
|
||||
//实例化
|
||||
$oQueueJob = new QueueJob;
|
||||
$sMsg = '发送邮件成功';
|
||||
if(!empty($job->getRawBody())){
|
||||
$aJob = json_decode($job->getRawBody(), true);
|
||||
$aParam = [
|
||||
'job_id' => empty($aJob['id']) ? '' : $aJob['id'],
|
||||
'job_class' => get_class($this),
|
||||
'status' => 0,
|
||||
'create_time' => time(),
|
||||
'params' => json_encode($aJob, JSON_UNESCAPED_UNICODE)
|
||||
];
|
||||
$iLogId = $oQueueJob->addLog($aParam);
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($data['article_id']) ? 0 : $data['article_id'];
|
||||
//作者邮箱
|
||||
$email = empty($data['email']) ? '' : $data['email'];
|
||||
//邮件主题
|
||||
$title = empty($data['title']) ? '' : $data['title'];
|
||||
//发送来源
|
||||
$from_name = empty($data['from_name']) ? '' : $data['from_name'];
|
||||
//邮件内容
|
||||
$content = empty($data['content']) ? '' : $data['content'];
|
||||
//邮箱
|
||||
$memail = empty($data['memail']) ? '' : $data['memail'];
|
||||
//密码
|
||||
$mpassword = empty($data['mpassword']) ? '' : $data['mpassword'];
|
||||
//文章作者
|
||||
$article_author_id = empty($data['article_author_id']) ? 0 : $data['article_author_id'];
|
||||
//关联文章ID
|
||||
$related_article_id = empty($data['related_article_id']) ? 0 : $data['related_article_id'];
|
||||
//期刊ID
|
||||
$journal_id = empty($data['journal_id']) ? '' : $data['journal_id'];
|
||||
//期刊issn
|
||||
$journal_issn = empty($data['journal_issn']) ? '' : $data['journal_issn'];
|
||||
//发送邮件
|
||||
if (!empty($iArticleId) && !empty($article_author_id) && !empty($related_article_id) && !empty($memail) && !empty($mpassword)) {
|
||||
|
||||
//查询是否发送过邮件
|
||||
$oJournalArticle = new JournalArticle;
|
||||
$aLog = json_decode($oJournalArticle::getLog(['article_id' => $iArticleId,'article_author_id' => $article_author_id,'related_article_id' => $related_article_id,'is_success' => 1]),true);
|
||||
$sMsg = '邮件已发送:'.json_encode($aLog['data']);
|
||||
if(empty($aLog['data'])){
|
||||
$aResult = sendEmail($email,$title,$from_name,$content,$memail,$mpassword);
|
||||
$iStatus = empty($aResult['status']) ? 1 : $aResult['status'];
|
||||
$iIsSuccess = 2;
|
||||
$sMsg = empty($aResult['data']) ? '失败' : $aResult['data'];
|
||||
if($iStatus == 1){
|
||||
$iIsSuccess = 1;
|
||||
$sMsg = '成功';
|
||||
}
|
||||
|
||||
//记录邮件发送日志
|
||||
$aEmailLog = ['article_id' => $iArticleId,'article_author_id' => $article_author_id,'related_article_id' => $related_article_id,'email' => $email,'content' => $content,'create_time' => time(),'is_success' => $iIsSuccess,'journal_id' => $journal_id,'journal_issn' => $journal_issn,'msg' => $sMsg];
|
||||
//添加邮件发送日志
|
||||
$iId = JournalArticle::addLog($aEmailLog);
|
||||
}
|
||||
}
|
||||
}
|
||||
$job->delete();
|
||||
|
||||
//更新任务状态
|
||||
$aParam = ['log_id' => $iLogId,'status' => 1,'update_time' => time(),'error' => $sMsg];
|
||||
$oQueueJob->updateLog($aParam);
|
||||
// // 记录日志
|
||||
// \think\Log::info("RelatedArticle延迟任务执行成功: ".json_encode($data));
|
||||
} catch (\Exception $e) {
|
||||
|
||||
//实例化
|
||||
$oQueueJob = new QueueJob;
|
||||
//更新任务状态
|
||||
$sMsg = empty($e->getMessage()) ? '任务出错' : $e->getMessage();
|
||||
$aParam = ['log_id' => $iLogId,'status' => 2,'update_time' => time(),'error' => $sMsg];
|
||||
$oQueueJob->updateLog($aParam);
|
||||
$job->delete();
|
||||
// // 记录错误日志
|
||||
// \think\Log::error("RelatedArticle延迟任务失败: ".$e->getMessage());
|
||||
}finally {
|
||||
gc_collect_cycles(); // 强制垃圾回收
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1192,7 +1192,7 @@ function getArticleType(){
|
||||
['name' => 'CASE SERIES','value' => 'CS'],
|
||||
['name' => 'RETRACTION','value' => 'RT'],
|
||||
['name' => 'MINI REVIEW','value' => 'MR'],
|
||||
['name' => 'PERSPECTIVE','value' => 'PERSP'],
|
||||
// ['name' => 'PERSPECTIVE','value' => 'PERSP'],
|
||||
['name' => 'OTHERS','value' => 'O']
|
||||
],
|
||||
'supplement' => [
|
||||
@@ -1232,6 +1232,7 @@ function getMedicalType(){
|
||||
['label' => 'CASE SERIES','value' => 'Case Series'],
|
||||
['label' => 'RETRACTION','value' => 'Retraction'],
|
||||
['label' => 'MINI REVIEW','value' => 'Mini Review'],
|
||||
['label' => 'PERSPECTIVE','value' => 'Perspective'],
|
||||
['label' => '内经难经','value' => '内经难经'],
|
||||
['label' => '伤寒金匮','value' => '伤寒金匮'],
|
||||
['label' => '神农本草经','value' => '神农本草经'],
|
||||
|
||||
243
application/common/JournalArticle.php
Normal file
243
application/common/JournalArticle.php
Normal file
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
namespace app\common;
|
||||
use think\Db;
|
||||
use think\Env;
|
||||
use think\Queue;
|
||||
class JournalArticle
|
||||
{
|
||||
|
||||
//官网接口地址
|
||||
protected static $sApiUrl = 'http://journalapi.tmrjournals.com/public/index.php/';//'http://zmzm.journal.dev.com/';
|
||||
|
||||
//期刊官网
|
||||
protected static $sJournalUsx = 'https://www.tmrjournals.com/';
|
||||
|
||||
protected static $aEmailTemplate = [
|
||||
|
||||
'email_subject' => 'Recommended Articles from {#email_subject#}',
|
||||
|
||||
'email_content' => 'Dear {#author_name#},<br><br>
|
||||
|
||||
I hope this message finds you well!<br><br>
|
||||
|
||||
We would like to extend our sincere thanks for your recent contribution to {#journal_title#} with your article titled "{#article_title#}".<br><br>
|
||||
|
||||
In light of the themes explored in your paper, we would like to share with you a selection of recently published articles that cover similar or complementary topics. We believe these may be of interest to you:<br><br>
|
||||
{#article_info#}
|
||||
|
||||
We hope these articles prove useful for your research or teaching. Should you have any thoughts or feedback, we would be delighted to hear from you.<br><br>
|
||||
|
||||
Thank you for your continued engagement with {#journal_title#}<br><br>
|
||||
|
||||
Best regards,<br>
|
||||
{#editorinchief#}<br>
|
||||
{#journal_title#}<br>
|
||||
Website:{#journal_usx#}<br>
|
||||
X: @{#journal_sx#}Journals'
|
||||
];
|
||||
|
||||
protected static $sDoiUrl = 'https://doi.org/';
|
||||
|
||||
//必填参数
|
||||
protected static $aField = ['article_id','journal_id','journal_issn','related_article_id','article_author_id','email','content','is_success','msg','create_time'];
|
||||
|
||||
|
||||
/**
|
||||
* 查询文章所关联的文章并发送邮件提醒
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static function get($aParam = []) {
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? '' : $aParam['article_id'];
|
||||
if(empty($iArticleId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select an article'.json_encode($aParam) ));
|
||||
}
|
||||
|
||||
//接口获取信息
|
||||
$sApiUrl = self::$sApiUrl.'wechat/Article/getRelatedArticles';
|
||||
$aResult = object_to_array(json_decode(myPost($sApiUrl, $aParam),true));
|
||||
|
||||
//获取接口状态
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
if($iStatus != 1){
|
||||
return json_encode($aResult);
|
||||
}
|
||||
|
||||
//处理数据
|
||||
$aData = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
|
||||
//文章基本信息
|
||||
$aArticle = empty($aData['article']) ? [] : $aData['article'];
|
||||
if(empty($aArticle)){
|
||||
return json_encode(array('status' => 3,'msg' => 'Article not found' ));
|
||||
}
|
||||
//关联文章基本信息
|
||||
$aRelatedArticle = empty($aData['related_article']) ? [] : array_column($aData['related_article'], null,'article_id');
|
||||
if(empty($aRelatedArticle)){
|
||||
return json_encode(['status' => 4,'msg' => 'No information was found for the associated article']);
|
||||
}
|
||||
$aRelatedArticle += [$iArticleId => $aArticle];
|
||||
|
||||
//期刊数据
|
||||
$aJournal = empty($aData['journal']) ? [] : array_column($aData['journal'], null,'journal_id');
|
||||
if(empty($aJournal)){
|
||||
return json_encode(['status' => 5,'msg' => 'The journal to which the article belongs does not exist']);
|
||||
}
|
||||
//文章作者
|
||||
$aAuthor = empty($aData['author']) ? [] : $aData['author'];
|
||||
if(empty($aAuthor)){
|
||||
return json_encode(['status' => 6,'msg' => 'No author information found for the article']);
|
||||
}
|
||||
|
||||
//查询邮件发送日志
|
||||
$aWhere = ['article_id' => $iArticleId,'is_success' => 1];
|
||||
$aEmailLog = Db::name('email_related_article')->field('related_article_id,article_author_id')->where($aWhere)->select();
|
||||
$aLog = [];
|
||||
if(!empty($aEmailLog)){
|
||||
foreach ($aEmailLog as $key => $value) {
|
||||
$aLog[$value['related_article_id']][] = $value['article_author_id'];
|
||||
}
|
||||
}
|
||||
|
||||
//邮件模版
|
||||
$aEmailInfo =self::$aEmailTemplate;
|
||||
//数据处理
|
||||
$aEmailLog = [];
|
||||
foreach ($aAuthor as $key => $value) {
|
||||
|
||||
//作者邮箱-发送信息
|
||||
$email = empty($value['email']) ? '' : $value['email'];
|
||||
if(empty($email)){
|
||||
continue;
|
||||
}
|
||||
$email = '1172937051@qq.com';//'tmr@tmrjournals.com';
|
||||
//判断是否发送过邮件
|
||||
//邮件日志
|
||||
$aEmailLogInfo = empty($aLog[$value['article_id']]) ? [] : $aLog[$value['article_id']];
|
||||
if(in_array($value['article_author_id'], $aEmailLogInfo)){
|
||||
continue;
|
||||
}
|
||||
|
||||
//关联文章信息
|
||||
$aRelatedArticleInfo = empty($aRelatedArticle[$value['article_id']]) ? [] : $aRelatedArticle[$value['article_id']];
|
||||
if(empty($aRelatedArticleInfo)){
|
||||
continue;
|
||||
}
|
||||
//期刊信息
|
||||
$aJournalInfo = empty($aJournal[$aRelatedArticleInfo['journal_id']]) ? [] : $aJournal[$aRelatedArticleInfo['journal_id']];
|
||||
if(empty($aJournalInfo)){
|
||||
continue;
|
||||
}
|
||||
|
||||
//期刊标题
|
||||
$from_name = empty($aJournalInfo['title']) ? '' : $aJournalInfo['title'];
|
||||
//邮件标题
|
||||
$title = str_replace('{#email_subject#}', $from_name, $aEmailInfo['email_subject']);
|
||||
//邮件内容
|
||||
$aSearch = [
|
||||
'{#author_name#}' => empty($value['author_name']) ? $email : $value['author_name'],
|
||||
'{#article_title#}' => empty($aRelatedArticleInfo['title']) ? '' : strip_tags($aRelatedArticleInfo['title']),//文章标题
|
||||
'{#editorinchief#}' => 'Editorial Office',//empty($aJournalInfo['editorinchief']) ? '' : $aJournalInfo['editorinchief'],//总编辑
|
||||
'{#journal_title#}' => $from_name,//期刊名
|
||||
'{#journal_usx#}' => empty($aJournalInfo['usx']) ? '' : self::$sJournalUsx.$aJournalInfo['usx'],//官网地址
|
||||
'{#journal_sx#}' => empty($aJournalInfo['sx']) ? '' : $aJournalInfo['sx'],//期刊sx
|
||||
];
|
||||
//关联文章说明
|
||||
$sArticleInfo = '';
|
||||
$i = 1;
|
||||
foreach ($aRelatedArticle as $v) {
|
||||
if($v['article_id'] == $value['article_id']){
|
||||
continue;
|
||||
}
|
||||
$sDoi = empty($v['doi']) ? '' : self::$sDoiUrl.$v['doi'];
|
||||
//作者
|
||||
$aAuthorInfo = empty($v['abbr']) ? [] : explode(', ', str_replace([', ',','], ', ', $v['abbr']));
|
||||
if(count($aAuthorInfo) > 3){
|
||||
$sAuthorInfo = implode(', ', array_slice($aAuthorInfo,0,3)).", et al.";
|
||||
}else{
|
||||
$sAuthorInfo = empty($aAuthorInfo) ? '' : implode(', ', $aAuthorInfo).'.';
|
||||
}
|
||||
$sArticleInfo .= $i.'. Article Title: '.$v['title'].'<br>Author(s): '.$sAuthorInfo.'<br>Link or DOI: '.$sDoi.'<br><br>';
|
||||
$i++;
|
||||
}
|
||||
$aSearch['{#article_info#}'] = empty($sArticleInfo) ? '' : $sArticleInfo;
|
||||
|
||||
$content = str_replace(array_keys($aSearch), array_values($aSearch), $aEmailInfo['email_content']);
|
||||
|
||||
//判断标题和内容是否为空
|
||||
if(empty($title) || empty($content)){
|
||||
continue;
|
||||
}
|
||||
$pre = Env::get('emailtemplete.pre');
|
||||
$net = Env::get('emailtemplete.net');
|
||||
$net1 = str_replace("{{email}}",trim($email),$net);
|
||||
$content=$pre.$content.$net1;
|
||||
//发送邮件
|
||||
$memail = empty($aJournalInfo['email']) ? '' : $aJournalInfo['email'];
|
||||
$mpassword = empty($aJournalInfo['epassword']) ? '' : $aJournalInfo['epassword'];
|
||||
$aResult = sendEmail($email,$title,$from_name,$content,$memail,$mpassword);
|
||||
$iStatus = empty($aResult['status']) ? 1 : $aResult['status'];
|
||||
$iIsSuccess = 2;
|
||||
$sMsg = empty($aResult['data']) ? '失败' : $aResult['data'];
|
||||
if($iStatus == 1){
|
||||
$iIsSuccess = 1;
|
||||
$sMsg = '成功';
|
||||
}
|
||||
$aEmaiParam = ['article_id' => $iArticleId,'article_author_id' =>$value['article_author_id'],'related_article_id' => $value['article_id'],'email' => $email,'content' => $content,'create_time' => time(),'journal_id' => $aJournalInfo['journal_id'],'journal_issn' => $aJournalInfo['issn'],'email' => $email,'title' => $title,'from_name' => $from_name,'content' => $content,'memail' => $memail,'mpassword' => $mpassword];
|
||||
//调用邮件发送队列
|
||||
Queue::push('app\api\job\SendRelatedArticleEmail@fire', $aEmaiParam, 'SendRelatedArticleEmail');
|
||||
}
|
||||
|
||||
return json_encode(['status' => 1,'msg' => 'Added to email sending queue']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入日志
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static function addLog($aParam = []) {
|
||||
|
||||
//数据处理
|
||||
$aField = self::$aField;
|
||||
$aInsert = [];
|
||||
foreach ($aField as $key => $value) {
|
||||
if(isset($aParam[$value])){
|
||||
$aInsert[$value] = $aParam[$value];
|
||||
}
|
||||
}
|
||||
$result = 0;
|
||||
if(!empty($aInsert)){
|
||||
$result = DB::name('email_related_article')->insertGetId($aParam);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询邮件日志是否发送
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static function getLog($aParam = []) {
|
||||
|
||||
//查询条件判断
|
||||
if(empty($aParam['article_id']) || empty($aParam['article_author_id']) || empty($aParam['related_article_id'])){
|
||||
return json_encode(['status' => 2,'msg' => 'Missing parameter']);
|
||||
}
|
||||
|
||||
//数据处理
|
||||
$aField = self::$aField;
|
||||
$aWhere = [];
|
||||
foreach ($aField as $key => $value) {
|
||||
if(!empty($aParam[$value])){
|
||||
$aWhere[$value] = is_array($aParam[$value]) ? ['in',$aParam[$value]] : $aParam[$value];
|
||||
}
|
||||
}
|
||||
$aResult = DB::name('email_related_article')->field('article_id,related_article_id,article_author_id,is_success,create_time')->where($aWhere)->find();
|
||||
return json_encode(['status' => 1,'msg' => 'success','data' => $aResult]);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user