From a34439b183ed0521d92cfe66404730056102509e Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Fri, 25 Jun 2021 15:25:42 +0800 Subject: [PATCH] 20201112 --- application/api/controller/Article.php | 10 + application/api/controller/Journal.php | 137 ++++++-- application/api/controller/Main.php | 1 + application/common.php | 390 ++++++++++++---------- application/master/controller/Article.php | 121 ++++++- 5 files changed, 445 insertions(+), 214 deletions(-) diff --git a/application/api/controller/Article.php b/application/api/controller/Article.php index 4caca95..b079b21 100644 --- a/application/api/controller/Article.php +++ b/application/api/controller/Article.php @@ -160,6 +160,9 @@ class Article extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); } @@ -227,6 +230,9 @@ class Article extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); } @@ -258,6 +264,7 @@ class Article extends Controller { */ public function addArticleNum(){ $data = $this->request->post(); + $this->article_obj->where('article_id',$data['article_id'])->setInc($data['type'].'_num'); $article_info = $this->article_obj->where('article_id',$data['article_id'])->find(); @@ -330,6 +337,9 @@ class Article extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); } diff --git a/application/api/controller/Journal.php b/application/api/controller/Journal.php index cd2ed65..9fdb6b7 100644 --- a/application/api/controller/Journal.php +++ b/application/api/controller/Journal.php @@ -233,6 +233,9 @@ class Journal extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); } @@ -287,8 +290,9 @@ class Journal extends Controller { } else { $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; } + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); -// $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); } @@ -355,6 +359,9 @@ class Journal extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); } @@ -392,6 +399,9 @@ class Journal extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); } @@ -448,6 +458,9 @@ class Journal extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); } @@ -531,6 +544,9 @@ class Journal extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); } @@ -703,7 +719,7 @@ class Journal extends Controller { */ public function getTopicForSubscribe() { $data = $this->request->post(); - $list = $this->journal_topic_obj->where('journal_id', $data['journal_id'])->where('state', 0)->where('level', 2)->select(); + $list = $this->journal_topic_obj->where('journal_id', $data['journal_id'])->where('state', 0)->where('is_final', 1)->select(); $re['topics'] = $list; return jsonSuccess($re); @@ -751,6 +767,57 @@ class Journal extends Controller { return jsonSuccess([]); } + /** + * @title 添加期刊话题订阅(批量) + * @description 添加期刊话题订阅(批量) + * @author wangjinlei + * @url /api/Journal/addSubscribeTopics + * @method POST + * + * @param name:topic_ids type:string require:1 desc:期刊话题id(1,2,3,4) + * @param name:email type:string require:1 desc:邮箱地址 + */ + public function addSubscribeTopics() { + $data = $this->request->post(); +// $topics = explode(',', $data['topic_ids']); + $topics = $data['topic_ids']; + $str = ''; + foreach ($topics as $k => $v) { + //去重 + $repeat = $this->subscribe_topic_obj + ->where('topic_id', $v) + ->where('email', $data['email']) + ->where('state', 0) + ->find(); + if ($repeat) { + continue; + } + $insert['topic_id'] = $v; + $insert['email'] = $data['email']; + $id = $this->subscribe_topic_obj->insertGetId($insert); + $cache_info = $this->journal_topic_obj->where('journal_topic_id',$v)->find(); + $str .= 'Unsubscribe topic->'.$cache_info['title'].'
'; + } + if($str==''){ + return jsonError('repeat subscribe!'); + } + //发送邮件感谢 + $tt = 'Dear Researcher,

'; + $tt .= 'Welcome you to the email alert for the latest research and more. Thank you for your interest in our publications and topics.
'; + $tt .= $str; + $tt .= 'This service is provided by TMR Publishing Group | New Zealand
'; + $tt .= 'Telephone: +64 02108293806'; + $tt .= 'Email: publisher@tmrjournals.com'; + $tt .= 'www.tmrjournals.com'; + $maidata['email'] = $data['email']; + $maidata['title'] = 'Thank you for subscribing.'; + $maidata['content'] = $tt; + $maidata['tmail'] = 'publicrelations@tmrjournals.com'; + $maidata['tpassword'] = 'pRWU999999'; + Queue::push('app\api\job\mail@fire', $maidata, "mail"); + return jsonSuccess([]); + } + /** * @title 添加期刊话题订阅 * @description 添加期刊话题订阅 @@ -863,6 +930,9 @@ class Journal extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); @@ -922,6 +992,9 @@ class Journal extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); //斜体变红 @@ -978,7 +1051,7 @@ class Journal extends Controller { } //组装作者 $arts = []; - if(isset($data['author']) && $data['author'] != ''){ + if (isset($data['author']) && $data['author'] != '') { $arts = $this->article_author_obj->where('state', 0)->where('author_name', 'like', '%' . trim($data['author']) . '%')->column('article_id'); if (count($arts) == 0) { $re['articles'] = []; @@ -986,7 +1059,7 @@ class Journal extends Controller { return jsonSuccess($re); } } - + //构造查询语句 $where_str = ''; if (isset($data['term']) && $data['term'] != '') { @@ -1002,7 +1075,7 @@ class Journal extends Controller { $c_str = '(' . implode(',', $stages) . ')'; $where_str = $where_str == '' ? 'journal_stage_id in ' . $c_str : 'journal_stage_id in ' . $c_str . ' and ' . $where_str; } - + if (count($arts) > 0) { $a_str = '(' . implode(',', $arts) . ')'; $where_str = $where_str == '' ? 'article_id in ' . $a_str : 'article_id in ' . $a_str . ' and ' . $where_str; @@ -1043,7 +1116,7 @@ class Journal extends Controller { $re['count'] = $count; return jsonSuccess($re); } - + /** * @title 查找文章精确查找(新) * @description 查找文章精确查找(新) @@ -1063,54 +1136,54 @@ class Journal extends Controller { * @return articles:文章信息# * @return count:总数 */ - public function searchArticleMenu(){ + public function searchArticleMenu() { $data = $this->request->post(); $limit_start = ($data['pageIndex'] - 1) * $data['pageSize']; - + //组合where语句 $where_str = ''; - - if($data['key1'] == 'author'){ + + if ($data['key1'] == 'author') { $arts = $this->article_author_obj->where('state', 0)->where('author_name', 'like', '%' . trim($data['val1']) . '%')->column('article_id'); $a_str = '(' . implode(',', $arts) . ')'; - $where_str = '(article_id in '. $a_str; - }else{ - $where_str = '('.$data['key1'].' like "%'.$data['val1'].'%"'; + $where_str = '(article_id in ' . $a_str; + } else { + $where_str = '(' . $data['key1'] . ' like "%' . $data['val1'] . '%"'; } - if(isset($data['key2'])&&$data['key2']!=''){ - if($data['oper'] == 'and'){ + if (isset($data['key2']) && $data['key2'] != '') { + if ($data['oper'] == 'and') { $where_str = $where_str . ' and '; - }else{ + } else { $where_str = $where_str . ' or '; } - if($data['key2'] == 'author'){ + if ($data['key2'] == 'author') { $arts = $this->article_author_obj->where('state', 0)->where('author_name', 'like', '%' . trim($data['val2']) . '%')->column('article_id'); $a_str = '(' . implode(',', $arts) . ')'; - $where_str = $where_str.' article_id in '. $a_str; - }else{ - $where_str = $where_str.' '.$data['key2'].' like "%'.$data['val2'].'%"'; + $where_str = $where_str . ' article_id in ' . $a_str; + } else { + $where_str = $where_str . ' ' . $data['key2'] . ' like "%' . $data['val2'] . '%"'; } } //处理journal_id - $where_str = $where_str . ') and journal_id in ('.trim($data['journal_id']).') and state = 0 '; + $where_str = $where_str . ') and journal_id in (' . trim($data['journal_id']) . ') and state = 0 '; //处理order $order_str = ''; - if($data['key1']=='title'&&(isset($data['key2'])&&$data['key2']=='title')){ + if ($data['key1'] == 'title' && (isset($data['key2']) && $data['key2'] == 'title')) { $order_str = "((CASE WHEN title LIKE '%" . trim($data['val1']) . "%' THEN 1 ELSE 0 END) + (CASE WHEN title LIKE '%" . trim($data['val2']) . "%' THEN 1 ELSE 0 END)) desc"; - }elseif($data['key1']=='title'||(isset($data['key2'])&&$data['key2']=='title')){ - if($data['key1']=='title'){ + } elseif ($data['key1'] == 'title' || (isset($data['key2']) && $data['key2'] == 'title')) { + if ($data['key1'] == 'title') { $order_str = "(CASE WHEN title LIKE '%" . trim($data['val1']) . "%' THEN 1 ELSE 0 END) desc"; - }else{ + } else { $order_str = "(CASE WHEN title LIKE '%" . trim($data['val2']) . "%' THEN 1 ELSE 0 END) desc"; } - }else{ + } else { $order_str = "article_id desc"; } - + $list = $this->article_obj ->where($where_str) ->orderRaw($order_str) - ->limit($limit_start,$data['pageSize']) + ->limit($limit_start, $data['pageSize']) ->select(); $count = $this->article_obj ->where($where_str) @@ -1124,6 +1197,9 @@ class Journal extends Controller { //组合cite信息 $no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):'; $cite = $v['abbr'] . '. ' . $v['title'] . '. ' . $journal_info['jabbr'] . '. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi']; + $cache_topic = $this->article_to_topic_obj->field('j_journal_topic.*')->join('j_journal_topic','j_journal_topic.journal_topic_id = j_article_to_topic.topic_id','left')->where('j_article_to_topic.article_id',$v['article_id'])->where('j_article_to_topic.state',0)->select(); + + $list[$k]['topic'] = $cache_topic; $list[$k]['cite'] = $cite; $list[$k]['authortitle'] = $this->getAuthor($v); //斜体变红 @@ -1132,10 +1208,10 @@ class Journal extends Controller { foreach ($caches as $val) { $cache_title = str_replace($val, '' . $val . '', $cache_title); } - if ($data['key1']=='title') { + if ($data['key1'] == 'title') { $cache_title = str_replace(trim($data['val1']), '' . $data['val1'] . '', $cache_title); } - if (isset($data['key2'])&&$data['key2']=='title') { + if (isset($data['key2']) && $data['key2'] == 'title') { $cache_title = str_replace(trim($data['val2']), '' . $data['val2'] . '', $cache_title); } $list[$k]['title'] = $cache_title; @@ -1144,7 +1220,6 @@ class Journal extends Controller { $re['articles'] = $list; $re['count'] = $count; return jsonSuccess($re); - } } diff --git a/application/api/controller/Main.php b/application/api/controller/Main.php index 742f4df..ea0ac5f 100644 --- a/application/api/controller/Main.php +++ b/application/api/controller/Main.php @@ -578,5 +578,6 @@ class Main extends Controller { // echo ''; // die; // } + } diff --git a/application/common.php b/application/common.php index 23c1fa1..bd7ae6d 100644 --- a/application/common.php +++ b/application/common.php @@ -1,177 +1,213 @@ - -// +---------------------------------------------------------------------- -// 应用公共文件 -function authcode($str) { - $key = substr(md5('ThinkPHP.CN'), 5, 8); - $str1 = substr(md5($str), 8, 10); - return md5($key . $str1); -} - -/** - * @function sendEmail - * @intro 发送邮件(带附件) - * @param $email 接收邮箱 - * @param $title 邮件标题 - * @param $from_name 发件人 - * @param $content 邮件内容 - * @param $memail 邮件内容 - * @param $mpassword 邮件内容 - * @param $attachmentFile 附件 (string | array) - * @return array - */ -function sendEmail($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '') { - date_default_timezone_set('PRC'); - //Create a new PHPMailer instance - $mail = new PHPMailer; - //Tell PHPMailer to use SMTP - $mail->isSMTP(); - //Enable SMTP debugging - // 0 = off (for production use) - // 1 = client messages - // 2 = client and server messages - $mail->SMTPDebug = 0; - //Ask for HTML-friendly debug output - $mail->Debugoutput = 'html'; - //charset - $mail->CharSet = 'UTF-8'; - //Set the hostname of the mail server - $mail->Host = "smtp.qiye.aliyun.com"; //请填写你的邮箱服务器 - //Set the SMTP port number - likely to be 25, 465 or 587 - $mail->Port = 25; //端口号 - //Whether to use SMTP authentication - $mail->SMTPAuth = true; - //Username to use for SMTP authentication - $mail->Username = $memail == '' ? "tmrweb@tmrjournals.com" : $memail; //发件邮箱用户名 - //Password to use for SMTP authentication - $mail->Password = $mpassword == '' ? "Wu999999tmrwe" : $mpassword; //发件邮箱密码 - //Set who the message is to be sent from - $mail->setFrom($memail == '' ? "tmrweb@tmrjournals.com" : $memail, $from_name); - //Set an alternative reply-to address(用户直接回复邮件的地址) - $mail->addReplyTo($memail == '' ? "tmrweb@tmrjournals.com" : $memail, $from_name); - //Set who the message is to be sent to - $mail->addAddress($email); - //Set the subject line - $mail->Subject = $title; - //Read an HTML message body from an external file, convert referenced images to embedded, - //convert HTML into a basic plain-text alternative body - $mail->msgHTML($content); - //Replace the plain text body with one created manually - $mail->AltBody = ''; - if (is_array($attachmentFile)) { - for ($i = 0; $i < count($attachmentFile); $i++) { - $mail->addAttachment($attachmentFile[$i], 'thanks.pdf' . $i); //这里可以是多维数组,然后循环附件的文件和名称 - } - } else { - if ($attachmentFile != '') { - //Attach an image file - $mail->addAttachment($attachmentFile, 'thanks.pdf'); - } - } - //send the message, check for errors - if (!$mail->send()) { - $status = 0; - $data = "邮件发送失败" . $mail->ErrorInfo; - ; - } else { - $status = 1; - $data = "邮件发送成功"; - } - return ['status' => $status, 'data' => $data]; //返回值(可选) -} - -/** - * 生成文章sn号 - * @return type - */ -function getArticleSN($abbr,$type) { - $str = $abbr; - $str .= date('Y', time()).$type.date('md', time()); - $where['accept_sn'] = ['like', "$str%"]; - $nowres = Db::name('article')->where($where)->select(); - $last_num = 1; - if ($nowres) { - foreach ($nowres as $v) { - $now_num = intval(substr($v['accept_sn'], -3)); - $last_num = $now_num > $last_num ? $now_num : $last_num; - } - $last_num += 1; - } - $last_str = sprintf("%03d", $last_num); - $str .= $last_str; - return $str; -} - -/** - * 增加usermsg - */ -function add_usermsg($userid, $content, $url) { - $msg_obj = Db::name('user_msg'); - $msg_info = $msg_obj->where('user_id', $userid) - ->where('url', $url) - ->where('state', 0) - ->find(); - if ($msg_info) { - return true; - } - $msgdata['user_id'] = $userid; - $msgdata['content'] = $content; - $msgdata['url'] = $url; - $msgdata['ctime'] = time(); - return $msg_obj->insert($msgdata); -} - -function jsonSuccess($data){ - return json(['code'=>0,'msg'=>'success','data'=>$data]); -} - -function jsonError($msg){ - return json(['code'=>1,'msg'=>$msg]); -} - -function myPost($url, $param=array()){ - - if(!is_array($param)){ - - throw new Exception("参数必须为array"); - - } - - $httph =curl_init($url); - -// curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0); - -// curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1); - - curl_setopt($httph,CURLOPT_RETURNTRANSFER,1); - - curl_setopt($httph, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); - - curl_setopt($httph, CURLOPT_POST, 1);//设置为POST方式 - - curl_setopt($httph, CURLOPT_POSTFIELDS, $param); - -// curl_setopt($httph, CURLOPT_RETURNTRANSFER,0); - -// curl_setopt($httph, CURLOPT_HEADER,1); - - $rst=curl_exec($httph); - - curl_close($httph); - - return $rst; - - } - + +// +---------------------------------------------------------------------- +// 应用公共文件 +function authcode($str) { + $key = substr(md5('ThinkPHP.CN'), 5, 8); + $str1 = substr(md5($str), 8, 10); + return md5($key . $str1); +} + +/** + * @function sendEmail + * @intro 发送邮件(带附件) + * @param $email 接收邮箱 + * @param $title 邮件标题 + * @param $from_name 发件人 + * @param $content 邮件内容 + * @param $memail 邮件内容 + * @param $mpassword 邮件内容 + * @param $attachmentFile 附件 (string | array) + * @return array + */ +function sendEmail($email = '', $title = '', $from_name = '', $content = '', $memail = '', $mpassword = '', $attachmentFile = '') { + date_default_timezone_set('PRC'); + //Create a new PHPMailer instance + $mail = new PHPMailer; + //Tell PHPMailer to use SMTP + $mail->isSMTP(); + //Enable SMTP debugging + // 0 = off (for production use) + // 1 = client messages + // 2 = client and server messages + $mail->SMTPDebug = 0; + //Ask for HTML-friendly debug output + $mail->Debugoutput = 'html'; + //charset + $mail->CharSet = 'UTF-8'; + //Set the hostname of the mail server + $mail->Host = "smtp.qiye.aliyun.com"; //请填写你的邮箱服务器 + //Set the SMTP port number - likely to be 25, 465 or 587 + $mail->Port = 25; //端口号 + //Whether to use SMTP authentication + $mail->SMTPAuth = true; + //Username to use for SMTP authentication + $mail->Username = $memail == '' ? "tmrweb@tmrjournals.com" : $memail; //发件邮箱用户名 + //Password to use for SMTP authentication + $mail->Password = $mpassword == '' ? "Wu999999tmrwe" : $mpassword; //发件邮箱密码 + //Set who the message is to be sent from + $mail->setFrom($memail == '' ? "tmrweb@tmrjournals.com" : $memail, $from_name); + //Set an alternative reply-to address(用户直接回复邮件的地址) + $mail->addReplyTo($memail == '' ? "tmrweb@tmrjournals.com" : $memail, $from_name); + //Set who the message is to be sent to + $mail->addAddress($email); + //Set the subject line + $mail->Subject = $title; + //Read an HTML message body from an external file, convert referenced images to embedded, + //convert HTML into a basic plain-text alternative body + $mail->msgHTML($content); + //Replace the plain text body with one created manually + $mail->AltBody = ''; + if (is_array($attachmentFile)) { + for ($i = 0; $i < count($attachmentFile); $i++) { + $mail->addAttachment($attachmentFile[$i], 'thanks.pdf' . $i); //这里可以是多维数组,然后循环附件的文件和名称 + } + } else { + if ($attachmentFile != '') { + //Attach an image file + $mail->addAttachment($attachmentFile, 'thanks.pdf'); + } + } + //send the message, check for errors + if (!$mail->send()) { + $status = 0; + $data = "邮件发送失败" . $mail->ErrorInfo; + ; + } else { + $status = 1; + $data = "邮件发送成功"; + } + return ['status' => $status, 'data' => $data]; //返回值(可选) +} + +/** + * 生成文章sn号 + * @return type + */ +function getArticleSN($abbr,$type) { + $str = $abbr; + $str .= date('Y', time()).$type.date('md', time()); + $where['accept_sn'] = ['like', "$str%"]; + $nowres = Db::name('article')->where($where)->select(); + $last_num = 1; + if ($nowres) { + foreach ($nowres as $v) { + $now_num = intval(substr($v['accept_sn'], -3)); + $last_num = $now_num > $last_num ? $now_num : $last_num; + } + $last_num += 1; + } + $last_str = sprintf("%03d", $last_num); + $str .= $last_str; + return $str; +} + +/** + * 增加usermsg + */ +function add_usermsg($userid, $content, $url) { + $msg_obj = Db::name('user_msg'); + $msg_info = $msg_obj->where('user_id', $userid) + ->where('url', $url) + ->where('state', 0) + ->find(); + if ($msg_info) { + return true; + } + $msgdata['user_id'] = $userid; + $msgdata['content'] = $content; + $msgdata['url'] = $url; + $msgdata['ctime'] = time(); + return $msg_obj->insert($msgdata); +} + +function jsonSuccess($data){ + return json(['code'=>0,'msg'=>'success','data'=>$data]); +} + +function jsonError($msg){ + return json(['code'=>1,'msg'=>$msg]); +} + +function myPost($url, $param=array()){ + + if(!is_array($param)){ + + throw new Exception("参数必须为array"); + + } + + $httph =curl_init($url); + +// curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, 0); + +// curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1); + + curl_setopt($httph,CURLOPT_RETURNTRANSFER,1); + + curl_setopt($httph, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); + + curl_setopt($httph, CURLOPT_POST, 1);//设置为POST方式 + + curl_setopt($httph, CURLOPT_POSTFIELDS, $param); + +// curl_setopt($httph, CURLOPT_RETURNTRANSFER,0); + +// curl_setopt($httph, CURLOPT_HEADER,1); + + $rst=curl_exec($httph); + + curl_close($httph); + + return $rst; + + } + + function ORCIDPost($url, $param=array()){ + + if(!is_array($param)){ + + throw new Exception("参数必须为array"); + + } + $headerArray = ['Content-Type: application/x-www-form-urlencoded']; + $httph =curl_init($url); + + curl_setopt($httph, CURLOPT_SSL_VERIFYPEER, false); + +// curl_setopt($httph, CURLOPT_SSL_VERIFYHOST, 1); + + curl_setopt($httph,CURLOPT_RETURNTRANSFER,1); + + curl_setopt($httph, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); + + curl_setopt($httph, CURLOPT_POST, 1);//设置为POST方式 + + curl_setopt($httph, CURLOPT_POSTFIELDS, $param); + + curl_setopt($httph, CURLOPT_HTTPHEADER,$headerArray); + +// curl_setopt($httph, CURLOPT_RETURNTRANSFER,0); + +// curl_setopt($httph, CURLOPT_HEADER,1); + + $rst=curl_exec($httph); + + curl_close($httph); + + return $rst; + + } + diff --git a/application/master/controller/Article.php b/application/master/controller/Article.php index a740d93..c141467 100644 --- a/application/master/controller/Article.php +++ b/application/master/controller/Article.php @@ -434,9 +434,6 @@ class Article extends Controller { * @param name:doi type:string require:1 desc:doi * @param name:abstract type:string require:1 desc:简介 * @param name:keywords type:string require:1 desc:关键字 - * @param name:abs_num type:int require:1 desc:简介数量 - * @param name:pdf_num type:int require:1 desc:pdf数量 - * @param name:html_num type:int require:1 desc:html数量 * @param name:ltai type:string require:0 desc:标题斜体(demo1,demo2) * @param name:npp type:strng require:1 desc:文章页码 * @param name:type type:string require:1 desc:类型 @@ -462,9 +459,9 @@ class Article extends Controller { $updata['doi'] = $data['doi']; $updata['abstract'] = $data['abstract']; $updata['keywords'] = $data['keywords']; - $updata['abs_num'] = $data['abs_num']; - $updata['pdf_num'] = $data['pdf_num']; - $updata['html_num'] = $data['html_num']; +// $updata['abs_num'] = $data['abs_num']; +// $updata['pdf_num'] = $data['pdf_num']; +// $updata['html_num'] = $data['html_num']; $updata['npp'] = $data['npp']; $updata['type'] = $data['type']; $updata['cited'] = $data['cited']; @@ -1018,4 +1015,116 @@ class Article extends Controller { $re['cites'] = $list; return jsonSuccess($re); } + + /** + * @title 注册doi + * @description 注册doi + * @author wangjinlei + * @url /master/Article/agentDOI + * @method POST + * + * @param name:doi type:string require:1 desc:doi号 + * @param name:article_id type:int require:1 desc:文章id + */ + public function agentDOI(){ + $data = $this->request->post(); + $data['doi'] = '10.12032/TMR20210301222'; + $data['article_id'] = 1333; + + + $xml = ''; + //create xml 头 + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.date('Ymd').''.PHP_EOL; + $xml .= ''.date('YmdHis').''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= 'TMR2015@163.com'.PHP_EOL; + $xml .= 'TMR2015@163.com'.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= '传统医学研究(英文版)'.PHP_EOL; + $xml .= ''.PHP_EOL; + + //组装主体信息部分 + $article_info = $this->article_obj->where('article_id',$data['article_id'])->find(); + $journal_info = $this->journal_obj->where('journal_id',$article_info['journal_id'])->find(); + $stage_info = $this->journal_stage_obj->where('journal_stage_id',$article_info['journal_stage_id'])->find(); + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.$journal_info['usx'].''.PHP_EOL; + $xml .= ''.$journal_info['title'].''.PHP_EOL; + $xml .= ''.$journal_info['issn'].''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.$stage_info['stage_year'].''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.$stage_info['stage_vol'].''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.$stage_info['stage_no'].''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.$article_info['title'].''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $authors = $this->article_author_obj->where('article_id',$data['article_id'])->where('state',0)->select(); + $address = ''; + $author = ''; + foreach ($authors as $v){ + if($v['is_first']==1){ + $ca = $this->author_to_organ_obj->where('article_author_id',$v['article_author_id'])->where('article_id',$data['article_id'])->find(); + $ca_organ = $this->article_organ_obj->where('article_organ_id',$ca['article_organ_id'])->find(); + $address = $ca_organ['organ_name']; + } + $author .= $v['author_name'].','; + } + $xml .= ''.substr($author,-1).''.PHP_EOL; + $xml .= ''.$address.''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''. str_replace(',', ' ', $article_info['keywords']).''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.str_replace('Abstract','',strip_tags(str_replace(" ","",htmlspecialchars_decode($article_info['abstract'])))).''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.$article_info['doi'].''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $start = ''; + $end = ''; + if(stripos($article_info['npp'],'-')>0){ + $ca_list = explode('-', $article_info['npp']); + $start = $ca_list[0]; + $end = $ca_list[1]; + }else{ + $start = $article_info['npp']; + } + $xml .= ''.$start.''.PHP_EOL; + $xml .= ''.$end.''.PHP_EOL; + $xml .= ''.PHP_EOL; + $xml .= ''.PHP_EOL; + $txt = ROOT_PATH . 'public' . DS . 'xml'.DS.$article_info['article_id'].'.xml'; + file_put_contents($txt, $xml); + + } + + public function upXML(){ + vendor("chinadoi.UPXML2"); + $up_obj = new \UpXml; + $xmlfile = ROOT_PATH . 'public' . DS . 'xml'.DS.'1333.xml'; + $result = $up_obj->upload($xmlfile); + echo '
';
+        var_dump($result);
+        echo '
'; + die; + } }