关联文章发送邮件提醒
This commit is contained in:
@@ -37,7 +37,12 @@ class JournalArticle
|
|||||||
|
|
||||||
protected static $sDoiUrl = 'https://doi.org/';
|
protected static $sDoiUrl = 'https://doi.org/';
|
||||||
|
|
||||||
// 记录任务开始
|
|
||||||
|
/**
|
||||||
|
* 查询文章所关联的文章并发送邮件提醒
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
static function get($aParam = []) {
|
static function get($aParam = []) {
|
||||||
|
|
||||||
//文章ID
|
//文章ID
|
||||||
@@ -45,11 +50,6 @@ class JournalArticle
|
|||||||
if(empty($iArticleId)){
|
if(empty($iArticleId)){
|
||||||
return json_encode(array('status' => 2,'msg' => 'Please select an article'.json_encode($aParam) ));
|
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';
|
$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']);
|
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 = [];
|
$aArticleAuthor = [];
|
||||||
foreach ($aAuthor as $key => $value) {
|
foreach ($aAuthor as $key => $value) {
|
||||||
if(empty($value['email'])){
|
if(empty($value['email'])){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//用户信息
|
$aArticleAuthor[$value['article_id']][$value['email']] = $value['author_name'];
|
||||||
$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)){
|
if(empty($aArticleAuthor)){
|
||||||
return json_encode(['status' => 7,'msg' => 'No author information found for the article']);
|
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;
|
$aEmailInfo =self::$aEmailTemplate;
|
||||||
//数据处理
|
//数据处理
|
||||||
|
$aEmailLog = [];
|
||||||
foreach ($aArticleAuthor as $key => $value) {
|
foreach ($aArticleAuthor as $key => $value) {
|
||||||
|
|
||||||
if(empty($value)){
|
if(empty($value)){
|
||||||
@@ -131,8 +131,6 @@ class JournalArticle
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//用户信息
|
|
||||||
$realname = empty($val) ? $realname : $val;
|
|
||||||
//期刊标题
|
//期刊标题
|
||||||
$from_name = empty($aJournalInfo['title']) ? '' : $aJournalInfo['title'];
|
$from_name = empty($aJournalInfo['title']) ? '' : $aJournalInfo['title'];
|
||||||
//邮件标题
|
//邮件标题
|
||||||
@@ -140,7 +138,7 @@ class JournalArticle
|
|||||||
//邮件内容
|
//邮件内容
|
||||||
$aSearch = [
|
$aSearch = [
|
||||||
'{#article_title#}' => empty($aRelatedArticleInfo['title']) ? '' : strip_tags($aRelatedArticleInfo['title']),//文章标题
|
'{#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_title#}' => $from_name,//期刊名
|
||||||
'{#journal_usx#}' => empty($aJournalInfo['usx']) ? '' : self::$sJournalUsx.$aJournalInfo['usx'],//官网地址
|
'{#journal_usx#}' => empty($aJournalInfo['usx']) ? '' : self::$sJournalUsx.$aJournalInfo['usx'],//官网地址
|
||||||
'{#journal_sx#}' => empty($aJournalInfo['sx']) ? '' : $aJournalInfo['sx'],//期刊sx
|
'{#journal_sx#}' => empty($aJournalInfo['sx']) ? '' : $aJournalInfo['sx'],//期刊sx
|
||||||
@@ -154,22 +152,33 @@ class JournalArticle
|
|||||||
}
|
}
|
||||||
$sDoi = empty($v['doi']) ? '' : self::$sDoiUrl.$v['doi'];
|
$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){
|
if(count($aAuthorInfo) > 3){
|
||||||
$sAuthorInfo = implode(',', array_slice($aAuthorInfo,0,3))."等";
|
$sAuthorInfo = implode(', ', array_slice($aAuthorInfo,0,3)).", et al.";
|
||||||
}else{
|
}else{
|
||||||
$sAuthorInfo = empty($aAuthorInfo) ? '' : implode(',', $aAuthorInfo);
|
$sAuthorInfo = empty($aAuthorInfo) ? '' : implode(', ', $aAuthorInfo).'.';
|
||||||
}
|
}
|
||||||
$sArticleInfo .= $i.'. Article Title: '.$v['title'].'<br>Author(s): '.$sAuthorInfo.'<br>Link or DOI: '.$sDoi.'<br><br>';
|
$sArticleInfo .= $i.'. Article Title: '.$v['title'].'<br>Author(s): '.$sAuthorInfo.'<br>Link or DOI: '.$sDoi.'<br><br>';
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$aSearch['{#article_info#}'] = empty($sArticleInfo) ? '' : $sArticleInfo;
|
$aSearch['{#article_info#}'] = empty($sArticleInfo) ? '' : $sArticleInfo;
|
||||||
|
|
||||||
|
//邮件日志
|
||||||
|
$aEmailLogInfo = empty($aLog[$key]) ? [] : $aLog[$key];
|
||||||
|
|
||||||
//作者邮箱-发送信息
|
//作者邮箱-发送信息
|
||||||
foreach ($value as $k => $val) {
|
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;
|
$aSearch['{#author_name#}'] = empty($val) ? $email : $val;
|
||||||
$content = str_replace(array_keys($aSearch), array_values($aSearch), $aEmailInfo['email_content']);
|
$content = str_replace(array_keys($aSearch), array_values($aSearch), $aEmailInfo['email_content']);
|
||||||
|
|
||||||
//判断标题和内容是否为空
|
//判断标题和内容是否为空
|
||||||
if(empty($title) || empty($content)){
|
if(empty($title) || empty($content)){
|
||||||
continue;
|
continue;
|
||||||
@@ -182,6 +191,7 @@ class JournalArticle
|
|||||||
$memail = empty($aJournalInfo['email']) ? '' : $aJournalInfo['email'];
|
$memail = empty($aJournalInfo['email']) ? '' : $aJournalInfo['email'];
|
||||||
$mpassword = empty($aJournalInfo['epassword']) ? '' : $aJournalInfo['epassword'];
|
$mpassword = empty($aJournalInfo['epassword']) ? '' : $aJournalInfo['epassword'];
|
||||||
$aResult = sendEmail($email,$title,$from_name,$content,$memail,$mpassword);
|
$aResult = sendEmail($email,$title,$from_name,$content,$memail,$mpassword);
|
||||||
|
exit;
|
||||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||||
$iIsSuccess = 2;
|
$iIsSuccess = 2;
|
||||||
$sMsg = empty($aResult['data']) ? '失败' : $aResult['data'];
|
$sMsg = empty($aResult['data']) ? '失败' : $aResult['data'];
|
||||||
|
|||||||
Reference in New Issue
Block a user