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'];