From 4ef64ebb251fabf87e26983bed19f65fbf551bf6 Mon Sep 17 00:00:00 2001 From: chengxl Date: Thu, 5 Jun 2025 13:48:54 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=85=AC=E5=85=B1=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/common.php b/application/common.php index c9eeaff..f6b4b95 100644 --- a/application/common.php +++ b/application/common.php @@ -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' => '神农本草经'], From a819a46b40e360da370bc18408efd48f264896be Mon Sep 17 00:00:00 2001 From: chengxl Date: Thu, 5 Jun 2025 13:49:32 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=85=B3=E8=81=94=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=82=AE=E4=BB=B6=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/JournalArticle.php | 207 ++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 application/common/JournalArticle.php diff --git a/application/common/JournalArticle.php b/application/common/JournalArticle.php new file mode 100644 index 0000000..a6d8421 --- /dev/null +++ b/application/common/JournalArticle.php @@ -0,0 +1,207 @@ + 'Recommended Articles from {#email_subject#}', + + 'email_content' => 'Dear {#author_name#},

+ + I hope this message finds you well!

+ + We would like to extend our sincere thanks for your recent contribution to {#journal_title#} with your article titled "{#article_title#}".

+ + 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:

+ {#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.

+ + Thank you for your continued engagement with {#journal_title#}

+ + Best regards,
+ {#editorinchief#}
+ {#journal_title#}
+ Website:{#journal_usx#}
+ X: @{#journal_sx#}Journals' + ]; + + protected static $sDoiUrl = 'https://doi.org/'; + + // 记录任务开始 + 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) )); + } + //关联文章ID + $iRelatedArticleId = empty($aParam['related_article_id']) ? '' :$aParam['related_article_id'] ; + if(empty($iRelatedArticleId)){ + return json_encode(array('status' => 2,'msg' => 'Please select an associated article')); + } + + //接口获取信息 + $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']); + } + + //查询发送人信息 + $aEmail = array_unique(array_column($aAuthor, 'email')); + $aWhere = ['email' => ['in',$aEmail]]; + $aUser = Db::name('user')->where($aWhere)->column('email,realname,localname'); + + //数据处理-获取文章作者 + $aArticleAuthor = []; + foreach ($aAuthor as $key => $value) { + if(empty($value['email'])){ + continue; + } + //用户信息 + $aUserInfo = empty($aUser[$value['email']]) ? [] : $aUser[$value['email']]; + $realname = empty($aUserInfo['realname']) ? '' : $aUserInfo['realname']; + $localname = empty($aUserInfo['localname']) ? '' : $aUserInfo['localname']; + $realname = empty($realname) ? $localname : $realname; + $realname = empty($value['author_name']) ? $realname : $value['author_name']; + $aArticleAuthor[$value['article_id']][$value['email']] = $realname; + } + if(empty($aArticleAuthor)){ + return json_encode(['status' => 7,'msg' => 'No author information found for the article']); + } + + + //邮件模版 + $aEmailInfo =self::$aEmailTemplate; + //数据处理 + foreach ($aArticleAuthor as $key => $value) { + + if(empty($value)){ + continue; + } + + //关联文章信息 + $aRelatedArticleInfo = empty($aRelatedArticle[$key]) ? [] : $aRelatedArticle[$key]; + if(empty($aRelatedArticleInfo)){ + continue; + } + //期刊信息 + $aJournalInfo = empty($aJournal[$aRelatedArticleInfo['journal_id']]) ? [] : $aJournal[$aRelatedArticleInfo['journal_id']]; + if(empty($aJournalInfo)){ + continue; + } + + //用户信息 + $realname = empty($val) ? $realname : $val; + //期刊标题 + $from_name = empty($aJournalInfo['title']) ? '' : $aJournalInfo['title']; + //邮件标题 + $title = str_replace('{#email_subject#}', $from_name, $aEmailInfo['email_subject']); + //邮件内容 + $aSearch = [ + '{#article_title#}' => empty($aRelatedArticleInfo['title']) ? '' : strip_tags($aRelatedArticleInfo['title']),//文章标题 + '{#editorinchief#}' => 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'] == $key){ + continue; + } + $sDoi = empty($v['doi']) ? '' : self::$sDoiUrl.$v['doi']; + //作者 + $aAuthorInfo = empty($aArticleAuthor[$v['article_id']]) ? [] : array_values($aArticleAuthor[$v['article_id']]); + if(count($aAuthorInfo) > 3){ + $sAuthorInfo = implode(',', array_slice($aAuthorInfo,0,3))."等"; + }else{ + $sAuthorInfo = empty($aAuthorInfo) ? '' : implode(',', $aAuthorInfo); + } + $sArticleInfo .= $i.'. Article Title: '.$v['title'].'
Author(s): '.$sAuthorInfo.'
Link or DOI: '.$sDoi.'

'; + $i++; + } + $aSearch['{#article_info#}'] = empty($sArticleInfo) ? '' : $sArticleInfo; + //作者邮箱-发送信息 + foreach ($value as $k => $val) { + + $email = '1172937051@qq.com';//$k; + $aSearch['{#author_name#}'] = empty($val) ? $email : $val; + $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']) ? 0 : $aResult['status']; + $iIsSuccess = 2; + $sMsg = empty($aResult['data']) ? '失败' : $aResult['data']; + if($iStatus == 1){ + $iIsSuccess = 1; + $sMsg = '成功'; + } + $aEmailLog[] = ['article_id' => $iArticleId,'related_article_id' => $key,'email' => $email,'content' => $content,'create_time' => time(),'is_success' => $iIsSuccess,'journal_id' => $aJournalInfo['journal_id'],'journal_issn' => $aJournalInfo['issn'],'msg' => $sMsg]; + } + + } + //插入日志记录 + if(!empty($aEmailLog)){ + $result = Db::name('email_related_article')->insertAll($aEmailLog); + if($result === false){ + return json_encode(['status' => 8,'msg' => 'Email sending log insertion failed:'.json_encode($aEmailLog)]); + } + } + return json_encode(['status' => 1,'msg' => 'Email sent successfully']); + } + +} +?> \ No newline at end of file From f83f7e11b46e84ae2a8a4d238f9b296ad04c827d Mon Sep 17 00:00:00 2001 From: chengxl Date: Thu, 5 Jun 2025 15:53:22 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=85=B3=E8=81=94=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=82=AE=E4=BB=B6=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/JournalArticle.php | 60 ++++++++++++++++----------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/application/common/JournalArticle.php b/application/common/JournalArticle.php index a6d8421..08091a7 100644 --- a/application/common/JournalArticle.php +++ b/application/common/JournalArticle.php @@ -37,7 +37,12 @@ class JournalArticle protected static $sDoiUrl = 'https://doi.org/'; - // 记录任务开始 + + /** + * 查询文章所关联的文章并发送邮件提醒 + * + * @return void + */ static function get($aParam = []) { //文章ID @@ -45,11 +50,6 @@ class JournalArticle if(empty($iArticleId)){ return json_encode(array('status' => 2,'msg' => 'Please select an article'.json_encode($aParam) )); } - //关联文章ID - $iRelatedArticleId = empty($aParam['related_article_id']) ? '' :$aParam['related_article_id'] ; - if(empty($iRelatedArticleId)){ - return json_encode(array('status' => 2,'msg' => 'Please select an associated article')); - } //接口获取信息 $sApiUrl = self::$sApiUrl.'wechat/Article/getRelatedArticles'; @@ -87,33 +87,33 @@ class JournalArticle return json_encode(['status' => 6,'msg' => 'No author information found for the article']); } - //查询发送人信息 - $aEmail = array_unique(array_column($aAuthor, 'email')); - $aWhere = ['email' => ['in',$aEmail]]; - $aUser = Db::name('user')->where($aWhere)->column('email,realname,localname'); - //数据处理-获取文章作者 $aArticleAuthor = []; foreach ($aAuthor as $key => $value) { if(empty($value['email'])){ continue; } - //用户信息 - $aUserInfo = empty($aUser[$value['email']]) ? [] : $aUser[$value['email']]; - $realname = empty($aUserInfo['realname']) ? '' : $aUserInfo['realname']; - $localname = empty($aUserInfo['localname']) ? '' : $aUserInfo['localname']; - $realname = empty($realname) ? $localname : $realname; - $realname = empty($value['author_name']) ? $realname : $value['author_name']; - $aArticleAuthor[$value['article_id']][$value['email']] = $realname; + $aArticleAuthor[$value['article_id']][$value['email']] = $value['author_name']; } + if(empty($aArticleAuthor)){ return json_encode(['status' => 7,'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,email')->where($aWhere)->select(); + $aLog = []; + if(!empty($aEmailLog)){ + foreach ($aEmailLog as $key => $value) { + $aLog[$value['related_article_id']][] = $value['email']; + } + } //邮件模版 $aEmailInfo =self::$aEmailTemplate; //数据处理 + $aEmailLog = []; foreach ($aArticleAuthor as $key => $value) { if(empty($value)){ @@ -131,8 +131,6 @@ class JournalArticle continue; } - //用户信息 - $realname = empty($val) ? $realname : $val; //期刊标题 $from_name = empty($aJournalInfo['title']) ? '' : $aJournalInfo['title']; //邮件标题 @@ -140,7 +138,7 @@ class JournalArticle //邮件内容 $aSearch = [ '{#article_title#}' => empty($aRelatedArticleInfo['title']) ? '' : strip_tags($aRelatedArticleInfo['title']),//文章标题 - '{#editorinchief#}' => empty($aJournalInfo['editorinchief']) ? '' : $aJournalInfo['editorinchief'],//总编辑 + '{#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 @@ -154,22 +152,33 @@ class JournalArticle } $sDoi = empty($v['doi']) ? '' : self::$sDoiUrl.$v['doi']; //作者 - $aAuthorInfo = empty($aArticleAuthor[$v['article_id']]) ? [] : array_values($aArticleAuthor[$v['article_id']]); + $aAuthorInfo = empty($v['abbr']) ? [] : explode(', ', str_replace([', ',','], ', ', $v['abbr'])); if(count($aAuthorInfo) > 3){ - $sAuthorInfo = implode(',', array_slice($aAuthorInfo,0,3))."等"; + $sAuthorInfo = implode(', ', array_slice($aAuthorInfo,0,3)).", et al."; }else{ - $sAuthorInfo = empty($aAuthorInfo) ? '' : implode(',', $aAuthorInfo); + $sAuthorInfo = empty($aAuthorInfo) ? '' : implode(', ', $aAuthorInfo).'.'; } $sArticleInfo .= $i.'. Article Title: '.$v['title'].'
Author(s): '.$sAuthorInfo.'
Link or DOI: '.$sDoi.'

'; $i++; } $aSearch['{#article_info#}'] = empty($sArticleInfo) ? '' : $sArticleInfo; + + //邮件日志 + $aEmailLogInfo = empty($aLog[$key]) ? [] : $aLog[$key]; + //作者邮箱-发送信息 foreach ($value as $k => $val) { - $email = '1172937051@qq.com';//$k; + $email = 'tmr@tmrjournals.com';//$k; + + //判断是否发送过邮件 + if(in_array($email, $aEmailLogInfo)){ + continue; + } + $aSearch['{#author_name#}'] = empty($val) ? $email : $val; $content = str_replace(array_keys($aSearch), array_values($aSearch), $aEmailInfo['email_content']); + //判断标题和内容是否为空 if(empty($title) || empty($content)){ continue; @@ -182,6 +191,7 @@ class JournalArticle $memail = empty($aJournalInfo['email']) ? '' : $aJournalInfo['email']; $mpassword = empty($aJournalInfo['epassword']) ? '' : $aJournalInfo['epassword']; $aResult = sendEmail($email,$title,$from_name,$content,$memail,$mpassword); + exit; $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; $iIsSuccess = 2; $sMsg = empty($aResult['data']) ? '失败' : $aResult['data']; From 91803b6a8d11267125e837c9dd7a7d6fd411470a Mon Sep 17 00:00:00 2001 From: chengxl Date: Thu, 5 Jun 2025 17:37:47 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=98=9F=E5=88=97=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/job/RelatedArticle.php | 61 ++++++++++++ .../api/job/SendRelatedArticleEmail.php | 92 +++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 application/api/job/RelatedArticle.php create mode 100644 application/api/job/SendRelatedArticleEmail.php diff --git a/application/api/job/RelatedArticle.php b/application/api/job/RelatedArticle.php new file mode 100644 index 0000000..7f16614 --- /dev/null +++ b/application/api/job/RelatedArticle.php @@ -0,0 +1,61 @@ +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(); // 强制垃圾回收 + } + } + +} \ No newline at end of file diff --git a/application/api/job/SendRelatedArticleEmail.php b/application/api/job/SendRelatedArticleEmail.php new file mode 100644 index 0000000..50babc7 --- /dev/null +++ b/application/api/job/SendRelatedArticleEmail.php @@ -0,0 +1,92 @@ +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($email) && !empty($memail) && !empty($mpassword)) { + // $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]; + //添加邮件发送日志 + $oJournalArticle = new JournalArticle; + $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(); // 强制垃圾回收 + } + } + +} \ No newline at end of file From 2ca099a25c80c73eb9f75604edd1c1028d1a93c2 Mon Sep 17 00:00:00 2001 From: chengxl Date: Thu, 5 Jun 2025 17:38:22 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=98=9F=E5=88=97=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/JournalArticle.php | 128 +++++++++++++------------- 1 file changed, 65 insertions(+), 63 deletions(-) diff --git a/application/common/JournalArticle.php b/application/common/JournalArticle.php index 08091a7..9f4d49f 100644 --- a/application/common/JournalArticle.php +++ b/application/common/JournalArticle.php @@ -2,6 +2,7 @@ namespace app\common; use think\Db; use think\Env; +use think\Queue; class JournalArticle { @@ -37,6 +38,9 @@ class JournalArticle 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']; + /** * 查询文章所关联的文章并发送邮件提醒 @@ -87,26 +91,13 @@ class JournalArticle return json_encode(['status' => 6,'msg' => 'No author information found for the article']); } - //数据处理-获取文章作者 - $aArticleAuthor = []; - foreach ($aAuthor as $key => $value) { - if(empty($value['email'])){ - continue; - } - $aArticleAuthor[$value['article_id']][$value['email']] = $value['author_name']; - } - - if(empty($aArticleAuthor)){ - return json_encode(['status' => 7,'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,email')->where($aWhere)->select(); + $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['email']; + $aLog[$value['related_article_id']][] = $value['article_author_id']; } } @@ -114,14 +105,23 @@ class JournalArticle $aEmailInfo =self::$aEmailTemplate; //数据处理 $aEmailLog = []; - foreach ($aArticleAuthor as $key => $value) { + foreach ($aAuthor as $key => $value) { - if(empty($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[$key]) ? [] : $aRelatedArticle[$key]; + $aRelatedArticleInfo = empty($aRelatedArticle[$value['article_id']]) ? [] : $aRelatedArticle[$value['article_id']]; if(empty($aRelatedArticleInfo)){ continue; } @@ -137,6 +137,7 @@ class JournalArticle $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,//期刊名 @@ -147,7 +148,7 @@ class JournalArticle $sArticleInfo = ''; $i = 1; foreach ($aRelatedArticle as $v) { - if($v['article_id'] == $key){ + if($v['article_id'] == $value['article_id']){ continue; } $sDoi = empty($v['doi']) ? '' : self::$sDoiUrl.$v['doi']; @@ -163,54 +164,55 @@ class JournalArticle } $aSearch['{#article_info#}'] = empty($sArticleInfo) ? '' : $sArticleInfo; - //邮件日志 - $aEmailLogInfo = empty($aLog[$key]) ? [] : $aLog[$key]; + $content = str_replace(array_keys($aSearch), array_values($aSearch), $aEmailInfo['email_content']); - //作者邮箱-发送信息 - foreach ($value as $k => $val) { - - $email = 'tmr@tmrjournals.com';//$k; - - //判断是否发送过邮件 - if(in_array($email, $aEmailLogInfo)){ - continue; - } - - $aSearch['{#author_name#}'] = empty($val) ? $email : $val; - $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); - exit; - $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; - $iIsSuccess = 2; - $sMsg = empty($aResult['data']) ? '失败' : $aResult['data']; - if($iStatus == 1){ - $iIsSuccess = 1; - $sMsg = '成功'; - } - $aEmailLog[] = ['article_id' => $iArticleId,'related_article_id' => $key,'email' => $email,'content' => $content,'create_time' => time(),'is_success' => $iIsSuccess,'journal_id' => $aJournalInfo['journal_id'],'journal_issn' => $aJournalInfo['issn'],'msg' => $sMsg]; + //判断标题和内容是否为空 + if(empty($title) || empty($content)){ + continue; } - - } - //插入日志记录 - if(!empty($aEmailLog)){ - $result = Db::name('email_related_article')->insertAll($aEmailLog); - if($result === false){ - return json_encode(['status' => 8,'msg' => 'Email sending log insertion failed:'.json_encode($aEmailLog)]); + $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' => 'Email sent successfully']); + + 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; } } From f4880d1846f8ee8e6daa6b8b960d907857e9f3da Mon Sep 17 00:00:00 2001 From: chengxl Date: Fri, 6 Jun 2025 10:10:47 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E5=8F=91=E9=80=81=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/job/SendRelatedArticleEmail.php | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/application/api/job/SendRelatedArticleEmail.php b/application/api/job/SendRelatedArticleEmail.php index 50babc7..b6a7cf5 100644 --- a/application/api/job/SendRelatedArticleEmail.php +++ b/application/api/job/SendRelatedArticleEmail.php @@ -49,21 +49,27 @@ class SendRelatedArticleEmail //期刊issn $journal_issn = empty($data['journal_issn']) ? '' : $data['journal_issn']; //发送邮件 - if (!empty($iArticleId) && !empty($email) && !empty($memail) && !empty($mpassword)) { - // $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]; - //添加邮件发送日志 + if (!empty($iArticleId) && !empty($article_author_id) && !empty($related_article_id) && !empty($memail) && !empty($mpassword)) { + + //查询是否发送过邮件 $oJournalArticle = new JournalArticle; - $iId = JournalArticle::addLog($aEmailLog); + $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(); From b0835c7ad1cd14b90d371dfaca5f4df59eba5955 Mon Sep 17 00:00:00 2001 From: chengxl Date: Fri, 6 Jun 2025 10:11:12 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=8F=91=E9=80=81=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/JournalArticle.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/application/common/JournalArticle.php b/application/common/JournalArticle.php index 9f4d49f..ec17403 100644 --- a/application/common/JournalArticle.php +++ b/application/common/JournalArticle.php @@ -7,7 +7,7 @@ class JournalArticle { //官网接口地址 - protected static $sApiUrl = 'http://zmzm.journal.dev.com/'; + protected static $sApiUrl = 'http://journalapi.tmrjournals.com/public/index.php/';//'http://zmzm.journal.dev.com/'; //期刊官网 protected static $sJournalUsx = 'https://www.tmrjournals.com/'; @@ -215,5 +215,29 @@ class JournalArticle 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]); + } + } ?> \ No newline at end of file From 39e3d247f0cb17aa0a29c9d6b6e30c7f8eec3aad Mon Sep 17 00:00:00 2001 From: chengxl Date: Tue, 10 Jun 2025 10:10:27 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=8F=91=E9=80=81=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E7=BB=99=E5=85=B3=E8=81=94=E6=96=87=E7=AB=A0=E7=9A=84=E4=BD=9C?= =?UTF-8?q?=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Production.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/application/api/controller/Production.php b/application/api/controller/Production.php index 9f30e64..bc31528 100644 --- a/application/api/controller/Production.php +++ b/application/api/controller/Production.php @@ -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']);