826 lines
38 KiB
PHP
826 lines
38 KiB
PHP
<?php
|
||
namespace app\common;
|
||
use think\Db;
|
||
use think\Queue;
|
||
use think\Env;
|
||
//审稿人相关公共方法
|
||
class Reviewer
|
||
{
|
||
|
||
//14天秒数
|
||
protected $iSeconds = 14 * 86400;
|
||
|
||
protected $aEmailConfig = [
|
||
|
||
'reviewer' => [
|
||
'email_subject' => 'Invitation to review a manuscript for {journal_title}-[{accept_sn}]',
|
||
'email_content' => '
|
||
Dear Dr. {realname},<br><br>
|
||
The manuscript entitled "{article_title}" has been submitted to the journal {journal_title}.The Editor-in-Chief would be most grateful if you could offer an opinion regarding its suitability for publication in the journal {journal_title}. <br><br>
|
||
<b style="font-size: 14px;">Abstract of the Manuscript:</b><br>
|
||
<b style="font-size: 12px;">{abstrart}</b><br><br>
|
||
Please let us know if there are any potential conflicts of interest. If you agree to review this manuscript, we kindly request that you complete and submit your review through the submission system within 14 days of receiving the manuscript.<br>
|
||
<a href="{creatLoginUrlForreviewer}">Click here to accept the invitation to review</a><br>
|
||
<a href="{creatRejectUrlForReviewer}">Click here to decline the invitation to review</a><br>
|
||
Your username: {account}<br>
|
||
Your original password:123456qwe, if you have reset the password, please login with the new one or click the "<a href="https://submission.tmrjournals.com/retrieve">forgot password</a>".<br>
|
||
Thank you for your continued support of our journal.<br><br>
|
||
Sincerely,<br>Editorial Office<br>
|
||
<a href="https://www.tmrjournals.com/draw_up.html?issn={journal_issn}">Subscribe to this journal</a><br>{journal_title}<br>
|
||
Email: {journal_email}<br>
|
||
Website: {website}'
|
||
],
|
||
'editor' => [
|
||
'email_subject' => 'Reminder: Request to Assign New Reviewers!',
|
||
'email_content' => '
|
||
Dear Editor,<br><br>
|
||
I hope this message finds you well.<br>
|
||
During the automatic reviewer assignment process, we were unable to find suitable reviewers for the manuscript. Please kindly add new reviewers as soon as possible.<br><br>
|
||
Sincerely,<br>
|
||
Editorial Office<br>
|
||
<a href="https://www.tmrjournals.com/draw_up.html?issn={journal_issn}">Subscribe to this journal</a><br>
|
||
{journal_title}<br>
|
||
Email: {journal_email}<br>
|
||
Website: {website}'
|
||
],
|
||
'revision' => [
|
||
'email_subject' => 'Termination of Review Assignment for {journal_title}-[{accept_sn}]',
|
||
'email_content' => '
|
||
Dear Dr. {realname},<br><br>
|
||
I hope this message finds you well.<br>
|
||
We truly appreciate your kind acceptance to review the manuscript titled "{article_title}" ({accept_sn}). <br>
|
||
However, due to recent updates in our editorial workflow, we would like to request the termination of this review task. <br>
|
||
We sincerely apologize for any inconvenience caused and are grateful for your ongoing support of our journal. We hope to have the opportunity to invite you for future reviews. <br>
|
||
Thank you for your understanding. <br><br>
|
||
Sincerely,<br>
|
||
Editorial Office<br>
|
||
<a href="https://www.tmrjournals.com/draw_up.html?issn={journal_issn}">Subscribe to this journal</a><br>
|
||
{journal_title}<br>
|
||
Email: {journal_email}<br>
|
||
Website: {website}'
|
||
]
|
||
|
||
];
|
||
|
||
//必填参数
|
||
protected $aField = ['article_id','type','art_rev_id','reviewer_id','email','content','is_success','msg','create_time'];
|
||
|
||
//推荐审稿人的数量
|
||
protected $iReviewerNum = 5;
|
||
|
||
//1人同意审稿推荐审稿人的数量
|
||
protected $iReviewerLimitNum = 3;
|
||
|
||
/**
|
||
* @title 审稿人评分
|
||
*
|
||
*/
|
||
public function score($aParam = []){
|
||
|
||
//文章ID
|
||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||
if(empty($iArticleId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select the article to query']);
|
||
}
|
||
//审稿人ID
|
||
$iReviewerId = empty($aParam['reviewer_id']) ? 0 : $aParam['reviewer_id'];
|
||
if(empty($iReviewerId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select a reviewer']);
|
||
}
|
||
//主键ID
|
||
$iArtRevId = empty($aParam['art_rev_id']) ? 0 : $aParam['art_rev_id'];
|
||
if(empty($iReviewerId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select a reviewer']);
|
||
}
|
||
|
||
//查询文章状态-待审核
|
||
$aWhere = [
|
||
'article_id' => $iArticleId,
|
||
'state' => 2
|
||
];
|
||
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||
if(empty($aArticle)){
|
||
return json_encode(['status' => 3,'msg' => 'No articles found that meet the criteria']);
|
||
}
|
||
|
||
//查询审稿人的记录
|
||
$aWhere = [
|
||
'art_rev_id' => $iArtRevId,
|
||
'article_id' => $iArticleId,
|
||
'reviewer_id' => $iReviewerId,
|
||
'state' => ['between',[1,3]]
|
||
];
|
||
$aReviewer = Db::name('article_reviewer')->field('reviewer_id,agree_review_time,ctime,state')->where($aWhere)->find();
|
||
if(empty($aReviewer)){
|
||
return json_encode(['status' => 4,'msg' => 'No reviewer records found that meet the criteria']);
|
||
}
|
||
|
||
//查询用户信息
|
||
$aWhere = ['user_id' => $aReviewer['reviewer_id'],'state' => 0];
|
||
$aUser = Db::name('user')->field('user_id,review_score')->where($aWhere)->find();
|
||
if(empty($aUser)){
|
||
return json_encode(['status' => 5,'msg' => 'No basic information of the reviewer was found']);
|
||
}
|
||
|
||
//数据处理
|
||
//获取当前时间
|
||
$iNow = time();
|
||
//14天秒数
|
||
$iSeconds = $this->iSeconds;
|
||
//同意审稿时间
|
||
$ctime = empty($aReviewer['ctime']) ? 0 : $aReviewer['ctime'];
|
||
$agree_review_time = empty($aReviewer['agree_review_time']) ? $ctime : $aReviewer['agree_review_time'];
|
||
//审稿状态
|
||
$iState = empty($aReviewer['state']) ? '-1' : $aReviewer['state'];
|
||
//根据状态进行评分
|
||
$iScore = empty($aUser['review_score']) ? 0 : $aUser['review_score'];
|
||
$iDiff = abs($iNow - $agree_review_time);
|
||
if ($iDiff > $iSeconds) { //大于14天
|
||
$iScore += 2;
|
||
}
|
||
if($iDiff <= $iSeconds) { //小于等于14天
|
||
$iScore += 6; //同意后≤14天完成
|
||
}
|
||
//更新分数
|
||
$result = Db::name('user')->where('user_id',$aUser['user_id'])->limit(1)->update(['review_score' => $iScore]);
|
||
if ($result === false) {
|
||
return json_encode(['status' => 7,'msg' => 'Reviewer rating failed:'.Db::getLastSql()."\n"]);
|
||
}
|
||
return json_encode(['status' => 1,'msg' => "Reviewer's rating successful"]);
|
||
}
|
||
|
||
/**
|
||
* @title 筛选审稿人
|
||
*
|
||
*/
|
||
|
||
public function get($aParam = []){
|
||
//文章ID
|
||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||
if(empty($iArticleId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select the article to query']);
|
||
}
|
||
|
||
//查询送审中的文章
|
||
$aWhere = ['state' => 2,'article_id' => $iArticleId];
|
||
$aArticle = Db::name('article')->field('article_id,user_id,journal_id')->where($aWhere)->find();
|
||
if(empty($aArticle)){
|
||
return json_encode(array('status' => 3,'msg' => 'No articles requiring review were found' ));
|
||
}
|
||
//期刊ID
|
||
$iJournalId = empty($aArticle['journal_id']) ? 0 : $aArticle['journal_id'];
|
||
if(empty($iJournalId)){
|
||
return json_encode(array('status' => 3,'msg' => 'The article is not associated with a journal' ));
|
||
}
|
||
|
||
//查询文章所属领域
|
||
$aWhere['state'] = 0;
|
||
$aMajor = json_decode($this->getArticleMajor($aWhere),true);
|
||
|
||
$aMajorId = empty($aMajor['data']) ? [] : $aMajor['data'];
|
||
if(empty($aMajorId)){
|
||
return json_encode(array('status' => 1,'msg' => 'No field found for the article','data' => []));
|
||
}
|
||
//查询作者所属机构
|
||
$aAuthor = json_decode($this->getAuthor($aArticle),true);
|
||
$sCompany = empty($aAuthor['data']) ? '' : $aAuthor['data'];
|
||
//获取劣迹审稿人
|
||
$aBlack = json_decode($this->getBlackReviewer(),true);
|
||
$aBlack = empty($aBlack['data']) ? [] : $aBlack['data'];
|
||
|
||
//获取审稿人信息
|
||
// 获取时间点
|
||
$iSixMonth = strtotime(date('Y-m-d 00:00:00',strtotime('-6 months')));
|
||
// 计算10天之前的时间戳
|
||
$iTeenDaysLater = strtotime('-10 days');
|
||
|
||
// 先查询符合专业条件的审稿人ID
|
||
$aWhere = ['state' => 0, 'major_id' => ['in', $aMajorId]];
|
||
$sMajorQuery = Db::name('major_to_user')->field('user_id')->where($aWhere)->buildSql();
|
||
|
||
// 查询符合公司条件的审稿人ID,确保去重
|
||
$aWhere = ['state' => 0, 'company' => ['<>', $sCompany]];
|
||
if(!empty($aBlack) && !empty($aParam['not_choose_id'])){
|
||
$aBlack = array_unique(array_merge($aBlack, $aParam['not_choose_id']));
|
||
$aWhere['reviewer_id'] = ['not in',$aBlack];
|
||
}
|
||
if(!empty($aBlack) && empty($aParam['not_choose_id'])){
|
||
$aWhere['reviewer_id'] = ['not in',$aBlack];
|
||
}
|
||
if(empty($aBlack) && !empty($aParam['not_choose_id'])){
|
||
$aBlack = $aParam['not_choose_id'];
|
||
$aWhere['reviewer_id'] = ['not in',$aBlack];
|
||
}
|
||
|
||
if(!empty($aParam['field'])){//根据领域搜索
|
||
$aWhere['field'] = ['like',"%" . $aParam["field"] . "%"];
|
||
}
|
||
$sCompanyQuery = Db::name('user_reviewer_info')->field('reviewer_id,technical,country,introduction,company,field,last_invite_time')
|
||
->where($aWhere)->where(function($query) use ($iTeenDaysLater) {
|
||
$query->where('last_invite_time', '<', $iTeenDaysLater)
|
||
->whereOr('last_invite_time', '=', 0);
|
||
})->buildSql();
|
||
// 主查询条件
|
||
$iSize = empty($aParam['size']) ? $this->iReviewerNum : $aParam['size'];//每页显示条数
|
||
$iPage = empty($aParam['page']) ? 1 : $aParam['page'];// 当前页码
|
||
$aWhere = [
|
||
't_reviewer_to_journal.state' => 0,
|
||
't_reviewer_to_journal.journal_id' => $iJournalId,
|
||
't_user.state' => 0,
|
||
't_user.user_id' => ['<>', $aArticle['user_id']]
|
||
];
|
||
//根据邮箱检索
|
||
if(!empty($aParam['email'])){
|
||
$aWhere['t_user.email'] = ['like',"%" . $aParam["email"] . "%"];
|
||
}
|
||
|
||
//分组字段
|
||
$sGroup = 'major.user_id';
|
||
|
||
//获取数量
|
||
$iCount = Db::name('reviewer_to_journal')
|
||
->join('t_user', 't_user.user_id = t_reviewer_to_journal.reviewer_id')
|
||
->join(Db::raw("({$sMajorQuery}) major"),'major.user_id = t_reviewer_to_journal.reviewer_id')
|
||
->join(Db::raw("({$sCompanyQuery}) company"),'company.reviewer_id = t_reviewer_to_journal.reviewer_id')->where($aWhere)->group($sGroup)->count();
|
||
|
||
if(empty($iCount)){
|
||
return json_encode(['status' => 1,'msg' => 'No reviewer data found that meets the criteria','data' => ['total' => 0,'lists' => [],'size' => $iSize]]);
|
||
}
|
||
//判断页数是否超过最大分页限制
|
||
$iPageNum = ceil($iCount/$iSize);
|
||
if($iPage > $iPageNum){
|
||
return json_encode(['status' => 1,'msg' => 'The number of pages has exceeded the limit, maximum page number:'.$iPageNum,'data' => ['total' => $iCount,'lists' => [],'size' => 0]]);
|
||
}
|
||
//查询字段
|
||
$sSelect = empty($aParam['select']) ? 't_reviewer_to_journal.reviewer_id, t_reviewer_to_journal.is_yboard, t_user.review_num, t_user.review_invite_num, t_user.right_rate, t_user.review_score' : $aParam['select'];
|
||
$sOrder = empty($aParam['order']) ? 'new_level asc, t_user.review_num asc, t_user.review_invite_num desc, t_user.right_rate desc, t_user.review_score desc' : $aParam['order'];
|
||
// 主查询SQL
|
||
$aUser = Db::name('reviewer_to_journal')
|
||
->join('t_user', 't_user.user_id = t_reviewer_to_journal.reviewer_id')
|
||
// 使用LEFT JOIN并确保子查询结果唯一
|
||
->join(Db::raw("({$sMajorQuery}) major"),'major.user_id = t_reviewer_to_journal.reviewer_id')
|
||
->join(Db::raw("({$sCompanyQuery}) company"),'company.reviewer_id = t_reviewer_to_journal.reviewer_id')
|
||
->field($sSelect)
|
||
->fieldRaw("
|
||
CASE
|
||
WHEN t_reviewer_to_journal.is_yboard = 1 AND t_reviewer_to_journal.ctime < {$iSixMonth} THEN 1
|
||
ELSE 2
|
||
END AS new_level
|
||
")
|
||
->where($aWhere)
|
||
->group($sGroup)
|
||
->order($sOrder)
|
||
->page($iPage, $iSize)
|
||
->select();
|
||
return json_encode(['status' => 1,'msg' => 'success','data' => ['total' => $iCount,'lists' => $aUser,'size' => $iSize]]);
|
||
}
|
||
|
||
/**
|
||
* @title 自动推荐审稿人
|
||
*
|
||
*/
|
||
public function recommend($aParam = []){
|
||
|
||
//文章ID
|
||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||
if(empty($iArticleId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select the article to query']);
|
||
}
|
||
|
||
//查询文章的审稿记录
|
||
$aRecommend = json_decode($this->getRecommend($aParam),true);
|
||
$iStatus = empty($aRecommend['status']) ? 0 : $aRecommend['status'];
|
||
if($iStatus != 1){
|
||
return json_encode($aRecommend);
|
||
}
|
||
$aRecommend = empty($aRecommend['data']) ? [] : $aRecommend['data'];
|
||
|
||
//获取文章审稿人的信息
|
||
$aReviewer = empty($aRecommend['reviewer']) ? [] : $aRecommend['reviewer'];
|
||
$iSize = $this->iReviewerNum;
|
||
if(empty($aReviewer)){//第一次推荐
|
||
return $this->get(['article_id' => $iArticleId,'page' => 1,'size' => $iSize]);
|
||
}
|
||
//获取文章同意审稿人的次数
|
||
$iAgreeNum = empty($aRecommend['agree_num']) ? 0 : $aRecommend['agree_num'];
|
||
if($iAgreeNum > 1){//两个以上人同意无需再邀请审稿人
|
||
return json_encode(['status' => 5,'msg' => 'If more than two reviewers have already agreed to the article, there is no need to invite reviewers again']);
|
||
}
|
||
//同意审稿人数
|
||
if($iAgreeNum == 1){
|
||
$iSize = $this->iReviewerLimitNum;
|
||
}
|
||
return $this->get(['article_id' => $iArticleId,'page' => 1,'size' => $iSize,'not_choose_id' => $aReviewer]);
|
||
|
||
}
|
||
/**
|
||
* @title 查询文章领域
|
||
*
|
||
*/
|
||
public function getArticleMajor($aParam = []){
|
||
//文章ID
|
||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||
if(empty($iArticleId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select the article to query']);
|
||
}
|
||
//查询数据库
|
||
$aWhere = ['article_id' => $iArticleId,'state' => 0];
|
||
$aMajor = Db::name('major_to_article')->where($aWhere)->column('major_id');
|
||
return json_encode(['status' => 1,'msg' => 'success','data' => $aMajor]);
|
||
}
|
||
|
||
/**
|
||
* @title 查询劣迹审稿人
|
||
*
|
||
*/
|
||
public function getBlackReviewer(){
|
||
//查询审稿人是否为劣迹审稿人
|
||
$aBlack = Db::name('user_reviewer_black')->where('state',1)->column('reviewer_id');
|
||
return json_encode(['state' => 1,'msg' => 'success','data' => $aBlack]);
|
||
}
|
||
|
||
/**
|
||
* @title 查询作者所属机构,排出同机构的审稿人
|
||
*
|
||
*/
|
||
public function getAuthor($aParam = []){
|
||
|
||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||
if(empty($iArticleId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select the article to query']);
|
||
}
|
||
//用户ID
|
||
$iUserId = empty($aParam['user_id']) ? 0 : $aParam['user_id'];
|
||
if(empty($iUserId)){
|
||
return json_encode(['status' => 2,'msg' => 'User ID cannot be empty']);
|
||
}
|
||
|
||
//查询文章作者详情 作者和审稿人的机构不一致
|
||
$aUserInfo = Db::name('user')->field('email')->where('user_id',$iUserId)->find();
|
||
$sEmail = empty($aUserInfo['email']) ? '' : $aUserInfo['email'];
|
||
if(empty($sEmail)){
|
||
return json_encode(['status' => 3,'msg' => 'No user information found']);
|
||
}
|
||
//查询和作者同机构的审稿人
|
||
$aAuthor = Db::name('article_author')->field('company')->where(['article_id'=>$iArticleId,'email' => $sEmail,'state' => 0])->find();
|
||
return json_encode(['status' => 1,'msg' => 'success','data' => empty($aAuthor['company']) ? '' : $aAuthor['company']]);
|
||
}
|
||
|
||
/**
|
||
* @title 添加审稿人
|
||
*
|
||
*/
|
||
|
||
public function add($aParam = []){
|
||
|
||
//文章ID
|
||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||
if(empty($iArticleId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select the article to query']);
|
||
}
|
||
//用户ID
|
||
$aReviewerId = empty($aParam['reviewer_id']) ? [] : $aParam['reviewer_id'];
|
||
if(empty($aReviewerId)){
|
||
return json_encode(['status' => 2,'msg' => 'Reviewers who meet the criteria of the article were not selected']);
|
||
}
|
||
|
||
//查询文章审稿人是否存在
|
||
$aWhere = ['reviewer_id' => is_array($aReviewerId) ? ['in',$aReviewerId] : $aReviewerId,'article_id' => $iArticleId];
|
||
$aReviewer = Db::name('article_reviewer')->where($aWhere)->column('reviewer_id');
|
||
|
||
//数据处理
|
||
$aInsert = [];
|
||
$iNowTime = time();
|
||
foreach ($aReviewerId as $value) {
|
||
if(in_array($value, $aReviewer)){
|
||
continue;
|
||
}
|
||
$aInsert[] = ['reviewer_id' => $value,'article_id' => $iArticleId,'editor_act' => 1,'ctime' => time(),'state' => 5,'invited_time' => $iNowTime];
|
||
}
|
||
if(empty($aInsert)){
|
||
return json_encode(['status' => 3,'msg' => 'Reviewers have been invited to review, please do not repeat the process']);
|
||
}
|
||
//插入审稿人数据
|
||
Db::startTrans();
|
||
$result = Db::name('article_reviewer')->insertAll($aInsert);
|
||
if($result === false){
|
||
return json_encode(['status' => 4,'msg' => 'Reviewer data insertion failed:'.json_encode($aInsert)]);
|
||
}
|
||
//更新审稿人最后一次审稿时间
|
||
$aReviewerId = array_column($aInsert, 'reviewer_id');
|
||
$aUpdate = ['last_invite_time'=>$iNowTime];
|
||
$aWhere = ['reviewer_id' => ['in',$aReviewerId]];
|
||
$updateResult = Db::name('user_reviewer_info')->where($aWhere)->limit(count($aReviewerId))->update($aUpdate);
|
||
if($updateResult === false){
|
||
return json_encode(['status' => 5,'msg' => 'Invitation time update failed:'.json_encode($aReviewerId)]);
|
||
}
|
||
Db::commit();
|
||
return json_encode(['status' => 1,'msg' => 'Reviewer data insertion successful, execute email queue']);
|
||
}
|
||
|
||
/**
|
||
* @title 给审稿人发送邮件
|
||
*
|
||
*/
|
||
public function email($aParam = []){
|
||
|
||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||
if(empty($iArticleId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select the article to query']);
|
||
}
|
||
//用户ID
|
||
$aReviewerId = empty($aParam['reviewer_id']) ? [] : $aParam['reviewer_id'];
|
||
if(empty($aReviewerId)){
|
||
return json_encode(['status' => 2,'msg' => 'Reviewers who meet the criteria of the article were not selected']);
|
||
}
|
||
|
||
//查询送审中的文章
|
||
$aWhere = ['state' => 2,'article_id' => $iArticleId];
|
||
$aArticle = Db::name('article')->field('article_id,user_id,journal_id,accept_sn,title,abstrart')->where($aWhere)->find();
|
||
if(empty($aArticle)){
|
||
return json_encode(array('status' => 3,'msg' => 'No articles requiring review were found' ));
|
||
}
|
||
|
||
//查询期刊信息
|
||
if(empty($aArticle['journal_id'])){
|
||
return json_encode(array('status' => 4,'msg' => 'The article is not associated with a journal' ));
|
||
}
|
||
$aWhere = ['state' => 0,'journal_id' => $aArticle['journal_id']];
|
||
$aJournal = Db::name('journal')->where($aWhere)->find();
|
||
if(empty($aJournal)){
|
||
return json_encode(array('status' => 5,'msg' => 'No journal information found' ));
|
||
}
|
||
|
||
//查询文章邀请的审稿人
|
||
$aWhere = ['reviewer_id' => is_array($aReviewerId) ? ['in',$aReviewerId] : $aReviewerId,'article_id' => $iArticleId,'state' => 5];
|
||
$aReviewer = Db::name('article_reviewer')->where($aWhere)->column('reviewer_id,art_rev_id');
|
||
if(empty($aReviewer)){
|
||
return json_encode(['status' => 6,'msg' => 'No qualified reviewers were found']);
|
||
}
|
||
|
||
//查询用户邮箱
|
||
$aUserId = array_keys($aReviewer);
|
||
$aWhere = ['user_id' => ['in',$aUserId],'state' => 0,'email' => ['<>','']];
|
||
$aUser = Db::name('user')->field('user_id,email,realname,account')->where($aWhere)->select();
|
||
if(empty($aUser)){
|
||
return json_encode(['status' => 7,'msg' => "Reviewer's email information not found"]);
|
||
}
|
||
|
||
//处理发邮件
|
||
//获取邮件模版
|
||
$aEmailConfig= empty($this->aEmailConfig['reviewer']) ? [] : $this->aEmailConfig['reviewer'];
|
||
//邮件内容
|
||
$aSearch = [
|
||
'{accept_sn}' => empty($aArticle['accept_sn']) ? '' : $aArticle['accept_sn'],//accept_sn
|
||
'{article_title}' => empty($aArticle['title']) ? '' : $aArticle['title'],//文章标题
|
||
'{abstrart}' => empty($aArticle['abstrart']) ? '' : $aArticle['abstrart'],//文章摘要
|
||
'{journal_title}' => empty($aJournal['title']) ? '' : $aJournal['title'],//期刊名
|
||
'{journal_issn}' => empty($aJournal['issn']) ? '' : $aJournal['issn'],
|
||
'{journal_email}' => empty($aJournal['email']) ? '' : $aJournal['email'],
|
||
'{website}' => empty($aJournal['website']) ? '' : $aJournal['website'],
|
||
];
|
||
|
||
//发邮件
|
||
$oArticle = new \app\api\controller\Article;
|
||
$sMsg = '';
|
||
foreach ($aUser as $key => $value) {
|
||
|
||
$email = empty($value['email']) ? '' : $value['email'];
|
||
if(empty($email) || empty($aReviewer[$value['user_id']])){
|
||
continue;
|
||
}
|
||
|
||
//用户名
|
||
$realname = empty($value['account']) ? '' : $value['account'];
|
||
$realname = empty($value['realname']) ? $realname : $value['realname'];
|
||
$aSearch['{realname}'] = $realname;
|
||
//用户账号
|
||
$aSearch['{account}'] = empty($value['account']) ? '' : $value['account'];
|
||
//审稿链接
|
||
$aSearch['{creatLoginUrlForreviewer}'] = $oArticle->creatLoginUrlForreviewer(['user_id' => $value['user_id']],$aReviewer[$value['user_id']]);
|
||
|
||
$aSearch['{creatRejectUrlForReviewer}'] = $oArticle->creatRejectUrlForReviewer(['user_id' => $value['user_id']],$aReviewer[$value['user_id']]);
|
||
|
||
//邮件标题
|
||
$title = str_replace(array_keys($aSearch), array_values($aSearch),$aEmailConfig['email_subject']);
|
||
//邮件内容变量替换
|
||
$content = str_replace(array_keys($aSearch), array_values($aSearch), $aEmailConfig['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($aJournal['email']) ? '' : $aJournal['email'];
|
||
$mpassword = empty($aJournal['epassword']) ? '' : $aJournal['epassword'];
|
||
//期刊标题
|
||
$from_name = empty($aJournal['title']) ? '' : $aJournal['title'];
|
||
|
||
//邮件队列组装参数
|
||
$aEmailParam = ['email' => $email,'title' =>$title,'from_name' => $from_name,'content' => $content,'memail' => $memail,'mpassword' => $mpassword,'article_id' => $iArticleId,'art_rev_id' => $aReviewer[$value['user_id']],'reviewer_id' => $value['user_id'],'type' => 1];
|
||
$isPushed = Queue::push('app\api\job\SendReviewEmail@fire',$aEmailParam, 'SendReviewEmail');
|
||
if($isPushed === false){
|
||
$sMsg .= 'Email queue entry failed:'.json_encode($aEmailParam)."\n";
|
||
continue;
|
||
}
|
||
}
|
||
if(!empty($sMsg)){
|
||
return json_encode(['status' => 8,'msg' => $sMsg]);
|
||
}
|
||
return json_encode(['status' => 1,'msg' => 'The queue for sending review emails has been added']);
|
||
}
|
||
|
||
/**
|
||
* 获取文章审稿人记录
|
||
*
|
||
* @return void
|
||
*/
|
||
public function getRecommend($aParam = []) {
|
||
|
||
//查询条件判断
|
||
if(empty($aParam['article_id'])){
|
||
return json_encode(['status' => 2,'msg' => 'Missing parameter']);
|
||
}
|
||
|
||
//查询文章的审稿记录
|
||
$aWhere = ['article_id' => $aParam['article_id']];
|
||
$iReviewerNum = DB::name('article_reviewer')->where($aWhere)->count();
|
||
if(empty($iReviewerNum)){
|
||
return json_encode(['status' => 1,'msg' => 'The article has not yet invited reviewers for review']);
|
||
}
|
||
|
||
//判断文章最新邀请审稿时间判断是否超过七日
|
||
$iDay = 7;
|
||
$sDate = strtotime('-'.$iDay.' day');
|
||
$iMaxTime = DB::name('article_reviewer')->where($aWhere)->max('invited_time');
|
||
$iMaxTime = empty($iMaxTime) ? 0 : $iMaxTime;
|
||
if($iMaxTime > $sDate){
|
||
return json_encode(['status' => 4,'msg' => 'The last invitation for reviewers did not exceed '.$iDay.' days']);
|
||
}
|
||
|
||
//分别统计文章审稿状态 = 3[同意]
|
||
$aWhere['state'] = ['between',[0,3]];
|
||
$iAgreeNum = DB::name('article_reviewer')->where($aWhere)->count();
|
||
if($iAgreeNum > 1){
|
||
return json_encode(['status' => 5,'msg' => 'If more than two reviewers have already agreed to the article, there is no need to invite reviewers again']);
|
||
}
|
||
//查询文章的审稿人
|
||
unset($aWhere['state']);
|
||
$aReviewer = Db::name('article_reviewer')->where($aWhere)->column('reviewer_id');
|
||
return json_encode(['status' => 1,'msg' => 'success','data' => ['reviewer' => $aReviewer,'agree_num' => $iAgreeNum]]);
|
||
}
|
||
|
||
/**
|
||
* 插入日志
|
||
*
|
||
* @return void
|
||
*/
|
||
public function addLog($aParam = []) {
|
||
|
||
//数据处理
|
||
$aField = $this->aField;
|
||
$aInsert = [];
|
||
foreach ($aField as $key => $value) {
|
||
if(isset($aParam[$value])){
|
||
$aInsert[$value] = $aParam[$value];
|
||
}
|
||
}
|
||
$result = 0;
|
||
if(!empty($aInsert)){
|
||
$result = DB::name('email_reviewer')->insertGetId($aParam);
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 查询邮件日志是否发送
|
||
*
|
||
* @return void
|
||
*/
|
||
public function getLog($aParam = []) {
|
||
|
||
//查询条件判断
|
||
if(empty($aParam['article_id']) || empty($aParam['art_rev_id'])){
|
||
return json_encode(['status' => 2,'msg' => 'Missing parameter']);
|
||
}
|
||
|
||
//数据处理
|
||
$aField = $this->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_reviewer')->where($aWhere)->find();
|
||
return json_encode(['status' => 1,'msg' => 'success','data' => $aResult]);
|
||
}
|
||
|
||
/**
|
||
* @title 给编辑发送邮件
|
||
*
|
||
*/
|
||
public function emailForEditor($aParam = []){
|
||
|
||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||
if(empty($iArticleId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select the article to query']);
|
||
}
|
||
|
||
//查询送审中的文章
|
||
$aWhere = ['state' => 2,'article_id' => $iArticleId];
|
||
$aArticle = Db::name('article')->field('article_id,journal_id')->where($aWhere)->find();
|
||
if(empty($aArticle)){
|
||
return json_encode(array('status' => 3,'msg' => 'No articles requiring review were found' ));
|
||
}
|
||
|
||
//查询期刊信息
|
||
if(empty($aArticle['journal_id'])){
|
||
return json_encode(array('status' => 4,'msg' => 'The article is not associated with a journal' ));
|
||
}
|
||
$aWhere = ['state' => 0,'journal_id' => $aArticle['journal_id']];
|
||
$aJournal = Db::name('journal')->where($aWhere)->find();
|
||
if(empty($aJournal)){
|
||
return json_encode(array('status' => 5,'msg' => 'No journal information found' ));
|
||
}
|
||
//处理发邮件
|
||
//获取邮件模版
|
||
$aEmailConfig= empty($this->aEmailConfig['editor']) ? [] : $this->aEmailConfig['editor'];
|
||
//邮件内容
|
||
$aSearch = [
|
||
'{journal_title}' => empty($aJournal['title']) ? '' : $aJournal['title'],//期刊名
|
||
'{journal_issn}' => empty($aJournal['issn']) ? '' : $aJournal['issn'],
|
||
'{journal_email}' => empty($aJournal['email']) ? '' : $aJournal['email'],
|
||
'{website}' => empty($aJournal['website']) ? '' : $aJournal['website'],
|
||
];
|
||
|
||
//发邮件
|
||
$oArticle = new \app\api\controller\Article;
|
||
$email = empty($aJournal['email']) ? '' : $aJournal['email'];
|
||
if(empty($email)){
|
||
return json_encode(['status' => 6,'msg' => 'Journal email not set up']);
|
||
}
|
||
|
||
//邮件标题
|
||
$title = empty($aEmailConfig['email_subject']) ? '' : $aEmailConfig['email_subject'];
|
||
//邮件内容变量替换
|
||
$content = str_replace(array_keys($aSearch), array_values($aSearch), $aEmailConfig['email_content']);
|
||
|
||
//判断标题和内容是否为空
|
||
if(empty($title) || empty($content)){
|
||
return json_encode(['status' => 7,'msg' => 'The email subject or content cannot be empty']);
|
||
}
|
||
$pre = Env::get('emailtemplete.pre');
|
||
$net = Env::get('emailtemplete.net');
|
||
$net1 = str_replace("{{email}}",trim($email),$net);
|
||
$content=$pre.$content.$net1;
|
||
|
||
//发送邮件
|
||
$memail = empty($aJournal['email']) ? '' : $aJournal['email'];
|
||
$mpassword = empty($aJournal['epassword']) ? '' : $aJournal['epassword'];
|
||
//期刊标题
|
||
$from_name = empty($aJournal['title']) ? '' : $aJournal['title'];
|
||
|
||
//邮件队列组装参数
|
||
$aEmailParam = ['email' => $email,'title' =>$title,'from_name' => $from_name,'content' => $content,'memail' => $memail,'mpassword' => $mpassword,'article_id' => $iArticleId,'art_rev_id' => 0,'reviewer_id' => 0,'type' => 3];
|
||
$isPushed = Queue::push('app\api\job\SendReviewEmail@fire',$aEmailParam, 'SendReviewEmail');
|
||
if($isPushed === false){
|
||
return json_encode(['status' => 8,'msg' => 'Email queue entry failed:'.json_encode($aEmailParam)."\n"]);
|
||
}
|
||
return json_encode(['status' => 1,'msg' => 'The queue for sending review emails has been added']);
|
||
}
|
||
|
||
/**
|
||
* @title 文章退修给审稿人发送邮件且扣减分数[-6]
|
||
*
|
||
*/
|
||
public function revisionForReviewer($aParam = []){
|
||
|
||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||
if(empty($iArticleId)){
|
||
return json_encode(['status' => 2,'msg' => 'Please select the article to query']);
|
||
}
|
||
|
||
//查询退休状态的文章
|
||
$aWhere = ['state' => 4,'article_id' => $iArticleId];
|
||
$aArticle = Db::name('article')->field('article_id,user_id,journal_id,accept_sn,title')->where($aWhere)->find();
|
||
if(empty($aArticle)){
|
||
return json_encode(array('status' => 3,'msg' => 'No articles requiring review were found' ));
|
||
}
|
||
|
||
//查询期刊信息
|
||
if(empty($aArticle['journal_id'])){
|
||
return json_encode(array('status' => 4,'msg' => 'The article is not associated with a journal' ));
|
||
}
|
||
$aWhere = ['state' => 0,'journal_id' => $aArticle['journal_id']];
|
||
$aJournal = Db::name('journal')->where($aWhere)->find();
|
||
if(empty($aJournal)){
|
||
return json_encode(array('status' => 5,'msg' => 'No journal information found' ));
|
||
}
|
||
|
||
//查询同意审稿的审稿人
|
||
$aWhere = ['article_id' => $iArticleId,'state' => 0];
|
||
$aReviewer = Db::name('article_reviewer')->where($aWhere)->column('reviewer_id,art_rev_id');
|
||
if(empty($aReviewer)){
|
||
return json_encode(['status' => 6,'msg' => 'No qualified reviewers were found']);
|
||
}
|
||
//查询是否发过邮件
|
||
$aArtRevId = array_values($aReviewer);
|
||
$aWhere = ['art_rev_id' => ['in',$aArtRevId],'article_id' => $iArticleId,'type' => 4];
|
||
$aEmail = Db::name('email_reviewer')->where($aWhere)->column('art_rev_id');
|
||
|
||
//查询用户邮箱
|
||
$aUserId = array_keys($aReviewer);
|
||
$aWhere = ['user_id' => ['in',$aUserId],'state' => 0,'email' => ['<>','']];
|
||
$aUser = Db::name('user')->field('user_id,email,realname,account')->where($aWhere)->select();
|
||
if(empty($aUser)){
|
||
return json_encode(['status' => 7,'msg' => "Reviewer's email information not found"]);
|
||
}
|
||
|
||
//处理发邮件
|
||
//获取邮件模版
|
||
$aEmailConfig= empty($this->aEmailConfig['revision']) ? [] : $this->aEmailConfig['revision'];
|
||
//邮件内容
|
||
$aSearch = [
|
||
'{accept_sn}' => empty($aArticle['accept_sn']) ? '' : $aArticle['accept_sn'],//accept_sn
|
||
'{article_title}' => empty($aArticle['title']) ? '' : $aArticle['title'],//文章标题
|
||
'{journal_title}' => empty($aJournal['title']) ? '' : $aJournal['title'],//期刊名
|
||
'{journal_issn}' => empty($aJournal['issn']) ? '' : $aJournal['issn'],
|
||
'{journal_email}' => empty($aJournal['email']) ? '' : $aJournal['email'],
|
||
'{website}' => empty($aJournal['website']) ? '' : $aJournal['website'],
|
||
];
|
||
|
||
//发邮件
|
||
$oArticle = new \app\api\controller\Article;
|
||
$sMsg = '';
|
||
$aUserId = [];
|
||
foreach ($aUser as $key => $value) {
|
||
|
||
//审稿人信息
|
||
$art_rev_id = empty($aReviewer[$value['user_id']]) ? 0 : $aReviewer[$value['user_id']];
|
||
$email = empty($value['email']) ? '' : $value['email'];
|
||
if(empty($email) || empty($art_rev_id)){
|
||
continue;
|
||
}
|
||
if(in_array($art_rev_id, $aEmail)){//已发过邮件代表已经扣减分数
|
||
continue;
|
||
}
|
||
|
||
//用户名
|
||
$realname = empty($value['account']) ? '' : $value['account'];
|
||
$realname = empty($value['realname']) ? $realname : $value['realname'];
|
||
$aSearch['{realname}'] = $realname;
|
||
//用户账号
|
||
$aSearch['{account}'] = empty($value['account']) ? '' : $value['account'];
|
||
|
||
//邮件标题
|
||
$title = str_replace(array_keys($aSearch), array_values($aSearch),$aEmailConfig['email_subject']);
|
||
//邮件内容变量替换
|
||
$content = str_replace(array_keys($aSearch), array_values($aSearch), $aEmailConfig['email_content']);
|
||
|
||
//判断标题和内容是否为空
|
||
if(empty($title) || empty($content)){
|
||
continue;
|
||
}
|
||
//发送邮件
|
||
$memail = empty($aJournal['email']) ? '' : $aJournal['email'];
|
||
$mpassword = empty($aJournal['epassword']) ? '' : $aJournal['epassword'];
|
||
//期刊标题
|
||
$from_name = empty($aJournal['title']) ? '' : $aJournal['title'];
|
||
|
||
//邮件队列组装参数
|
||
$aEmailParam = ['email' => $email,'title' =>$title,'from_name' => $from_name,'content' => $content,'memail' => $memail,'mpassword' => $mpassword,'article_id' => $iArticleId,'art_rev_id' => $aReviewer[$value['user_id']],'reviewer_id' => $value['user_id'],'type' => 4];
|
||
$isPushed = Queue::push('app\api\job\SendReviewEmail@fire',$aEmailParam, 'SendReviewEmail');
|
||
if($isPushed === false){
|
||
$sMsg .= 'Email queue entry failed:'.json_encode($aEmailParam)."\n";
|
||
continue;
|
||
}
|
||
|
||
//扣减分数用户ID
|
||
$aUserId[] = $value['user_id'];
|
||
|
||
}
|
||
if(!empty($sMsg)){
|
||
return json_encode(['status' => 8,'msg' => $sMsg]);
|
||
}
|
||
|
||
//扣减分数
|
||
$iScore = 6;
|
||
if(empty($aUser)){
|
||
return json_encode(['status' => 1,'msg' => 'There are currently no reviewers who require deduction of scores']);
|
||
}
|
||
$aWhere = ['user_id' => ['in',$aUserId]];
|
||
$result = Db::name('user')->where($aWhere)->limit(count($aUserId))->setDec('review_score',$iScore);;
|
||
$sMsg = 'The queue for sending review emails has been added';
|
||
if($result === false){
|
||
$sMsg = 'Deduction of reviewer score failed'.json_encode($aUserId);
|
||
}
|
||
return json_encode(['status' => 1,'msg' => $sMsg]);
|
||
}
|
||
}
|
||
?>
|