Files
journal/application/api/controller/Special.php
2026-08-03 11:08:03 +08:00

644 lines
27 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
/**
* @title 前段web客座期刊
* @description 前段web客座期刊
* @group 前段web客座期刊
*/
class Special extends Controller {
//put your code here
protected $admin_obj = '';
protected $journal_obj = '';
protected $article_obj = '';
protected $article_author_obj = '';
protected $journal_topic_obj = '';
protected $journal_stage_obj = '';
protected $journal_notices_obj = '';
protected $journal_abs_obj = '';
protected $journal_special_obj = '';
protected $journal_special_editor_obj = '';
protected $journal_special_to_editor_obj = '';
protected $article_to_topic_obj = '';
protected $sys_scient_obj = '';
protected $sys_book_obj = '';
protected $journal_special_alert_obj = '';
protected $article_cite_obj = '';
public function __construct(\think\Request $request = null) {
parent::__construct($request);
$this->admin_obj = Db::name('admin');
$this->journal_obj = Db::name('journal');
$this->article_obj = Db::name('article');
$this->article_author_obj = Db::name('article_author');
$this->journal_topic_obj = Db::name('journal_topic');
$this->journal_stage_obj = Db::name('journal_stage');
$this->journal_notices_obj = Db::name('journal_notices');
$this->journal_abs_obj = Db::name('journal_abstracting');
$this->journal_special_obj = Db::name('journal_special');
$this->journal_special_editor_obj = Db::name('journal_special_editor');
$this->journal_special_to_editor_obj = Db::name('journal_special_to_editor');
$this->article_to_topic_obj = Db::name('article_to_topic');
$this->sys_scient_obj = Db::name('system_scient');
$this->sys_book_obj = Db::name('system_books');
$this->journal_special_alert_obj = Db::name('journal_special_alert');
$this->article_cite_obj = Db::name('article_cite');
}
/**
* @title 客座期刊(用户添加)
* @description 客座期刊(用户添加)
* @author wangjinlei
* @url /api/Special/addSpecial
* @method POST
*
* @param name:journal_id type:int require:1 desc:期刊id
* @param name:email type:string require:1 desc:邮箱
* @param name:first_name type:string require:1 desc:名字
* @param name:last_name type:string require:1 desc:名字
* @param name:address type:string require:1 desc:地址
* @param name:interests type:string require:0 desc:兴趣
* @param name:website type:string require:0 desc:编辑主页
* @param name:orcid type:string require:0 desc:orcid
* @param name:title type:string require:1 desc:标题
* @param name:intro type:string require:1 desc:简介
* @param name:abstract type:string require:1 desc:描述
* @param name:keywords type:string require:1 desc:关键字
* @param name:deadline type:int require:1 desc:截止日期
*
*/
public function addSpecial(){
$data = $this->request->post();
Db::startTrans();
//处理客座编辑主题信息
$special_insert['journal_id'] = $data['journal_id'];
$special_insert['title'] = $data['title'];
$special_insert['abstract'] = $data['abstract'];
$special_insert['intro'] = $data['intro'];
$special_insert['keywords'] = $data['keywords'];
$special_insert['deadline'] = $data['deadline'];
if(isset($data['specialIcon']))$special_insert['icon'] = $data['specialIcon'];
// 记录是否有客座编辑(入库 + 流程控制)
$hasEditor = (isset($data['hasEditor']) && intval($data['hasEditor']) === 1) ? 1 : 0;
$special_insert['hasEditor'] = $hasEditor;
$special_insert['ctime'] = time();
$special_id = $this->journal_special_obj->insertGetId($special_insert);
if (!$special_id) {
Db::rollback();
return jsonError('system error');
}
// hasEditor 非 1只创建专刊不保存客座编辑信息
if (!$hasEditor) {
Db::commit();
return jsonSuccess(['journal_special_id' => intval($special_id), 'hasEditor' => 0]);
}
//处理客座编辑:同期刊下相同邮箱已存在则复用,否则新建
$email = trim($data['email']);
$existEditor = $this->journal_special_editor_obj
->where('journal_id', $data['journal_id'])
->where('email', $email)
->where('state', 0)
->find();
if ($existEditor) {
$editor_id = $existEditor['journal_special_editor_id'];
} else {
$editor_insert['journal_id'] = $data['journal_id'];
$editor_insert['email'] = $email;
$editor_insert['first_name'] = $data['first_name'];
$editor_insert['last_name'] = $data['last_name'];
$editor_insert['address'] = $data['address'];
$editor_insert['interests'] = $data['interests'];
$editor_insert['website'] = $data['website'];
$editor_insert['orcid'] = $data['orcid'];
if (isset($data['icon'])) {
$editor_insert['icon'] = $data['icon'];
}
$editor_id = $this->journal_special_editor_obj->insertGetId($editor_insert);
}
//处理客座编辑关系信息
$to_insert['journal_special_editor_id'] = $editor_id;
$to_insert['journal_special_id'] = $special_id;
$to_insert['journal_id'] = $data['journal_id'];
$res = $this->journal_special_to_editor_obj->insert($to_insert);
if($special_id&&$editor_id&&$res){
Db::commit();
return jsonSuccess(['journal_special_id' => intval($special_id), 'hasEditor' => 1]);
}else{
Db::rollback();
return jsonError('system error');
}
}
/**
* @title 客座期刊特邀编辑(添加)
* @description 客座期刊特邀编辑(添加)
* @author wangjinlei
* @url /api/Special/addEditor
* @method POST
*
* @param name:journal_id type:int require:1 desc:期刊id
* @param name:journal_special_id type:int require:1 desc:客座期刊id
* @param name:email type:string require:1 desc:邮箱
* @param name:first_name type:string require:1 desc:名字
* @param name:last_name type:string require:1 desc:名字
* @param name:address type:string require:1 desc:地址
* @param name:interests type:string require:0 desc:兴趣
* @param name:website type:string require:0 desc:编辑主页
* @param name:orcid type:string require:0 desc:orcid
* @param name:specialIcon type:string require:1 desc:客座编辑头像
*
*/
public function addEditor(){
$data = $this->request->post();
$insert_editor['journal_id'] = $data['journal_id'];
$insert_editor['email'] = trim($data['email']);
$insert_editor['first_name'] = trim($data['first_name']);
$insert_editor['last_name'] = trim($data['last_name']);
$insert_editor['address'] = trim($data['address']);
$insert_editor['interests'] = trim($data['interests']);
$insert_editor['website'] = trim($data['website']);
$insert_editor['orcid'] = trim($data['orcid']);
$insert_editor['icon'] = trim($data['specialIcon']);
$uid = $this->journal_special_editor_obj->insertGetId($insert_editor);
$insert_to['journal_special_editor_id'] = $uid;
$insert_to['journal_special_id'] = $data['journal_special_id'];
$insert_to['journal_id'] = $data['journal_id'];
$insert_to['state'] = 2;
$this->journal_special_to_editor_obj->insert($insert_to);
return jsonSuccess([]);
}
/**
* @title 获取客座期刊
* @description 获取客座期刊
* @author wangjinlei
* @url /api/Special/getSpecials
* @method POST
*
* @param name:journal_id type:int require:1 desc:期刊id
*
* @return specials:客座期刊列表array#
*/
public function getSpecials(){
$data = $this->request->post();
$list = $this->journal_special_obj->where('journal_id',$data['journal_id'])->where('state',2)->order('journal_special_id desc')->limit(4)->select();
$f = [];
//获取作者
foreach ($list as $k => $v){
if(strtotime($v['deadline'])<= time()){
continue;
}
$frag = '';
$caches = $this->journal_special_to_editor_obj
->field('j_journal_special_editor.*')
->join('j_journal_special_editor','j_journal_special_editor.journal_special_editor_id = j_journal_special_to_editor.journal_special_editor_id','LEFT')
->where('j_journal_special_to_editor.journal_special_id',$v['journal_special_id'])
->where('j_journal_special_to_editor.state',0)
->select();
foreach ($caches as $val){
$frag .= $frag == ''?$val['first_name'].' '.$val['last_name']:', '.$val['first_name'].' '.$val['last_name'];
}
$v['editor'] = $frag;
$f[] = $v;
}
$re['is_show'] = count($list)>0?'true':'false';
$re['specials'] = $f;
return jsonSuccess($re);
}
/**
* @title 获取客座期刊-新
* @description 获取客座期刊
* @author wangjinlei
* @url /api/Special/getSpecials
* @method POST
*
* @param name:journal_id type:int require:1 desc:期刊id
*
* @return specials:客座期刊列表array#
*/
public function getSpecialsNew(){
//获取参数
$data = $this->request->post();
//期刊ID
$iJournalId = empty($data['journal_id']) ? 0 : $data['journal_id'];
//定义返回数组
$re = ['is_show' => 'false','specials' => [],'count' => 0];
if(empty($iJournalId)){
return jsonSuccess($re);
}
//参数组装
$aWhere = ['state' => 2,'journal_id' => $iJournalId];
//查询数量
$iCount = $this->journal_special_obj->where($aWhere)->count();
if(empty($iCount)){
return jsonSuccess($re);
}
$re['count'] = $iCount;
//查询期刊详情
$list = $this->journal_special_obj->where($aWhere)->order('journal_special_id desc')->select();
$f = [];
//获取作者
foreach ($list as $k => $v){
$frag = '';
$caches = $this->journal_special_to_editor_obj
->field('j_journal_special_editor.*')
->join('j_journal_special_editor','j_journal_special_editor.journal_special_editor_id = j_journal_special_to_editor.journal_special_editor_id','LEFT')
->where('j_journal_special_to_editor.journal_special_id',$v['journal_special_id'])
->where('j_journal_special_to_editor.state',0)
->select();
foreach ($caches as $val){
$frag .= $frag == ''?$val['first_name'].' '.$val['last_name']:', '.$val['first_name'].' '.$val['last_name'];
}
$v['editor'] = $frag;
$f[] = $v;
}
$re['is_show'] = 'true';
$re['specials'] = $f;
return jsonSuccess($re);
}
/**
* @title 获取全部客座期刊
* @description 获取全部客座期刊
* @author wangjinlei
* @url /api/Special/getAllSpecials
* @method POST
*
* @return specials:客座期刊列表array#
*/
public function getAllSpecials(){
$list1 = $this->journal_special_obj
->field("j_journal.usx,j_journal.icon,j_journal.title journaltitle,j_journal_special.*")
->join("j_journal","j_journal.journal_id = j_journal_special.journal_id","left")
->where('j_journal_special.state',2)
->where("j_journal_special.journal_id",1)
->order('j_journal_special.journal_special_id desc')
->limit(1)
->select();
$list2 = $this->journal_special_obj
->field("j_journal.usx,j_journal.icon,j_journal.title journaltitle,j_journal_special.*")
->join("j_journal","j_journal.journal_id = j_journal_special.journal_id","left")
->where('j_journal_special.state',2)
->where("j_journal_special.journal_id",'<>',22)
->where("j_journal_special.journal_special_id","<>",$list1[0]['journal_special_id'])
->order('j_journal_special.journal_special_id desc')
->select();
$list = array_merge($list1,$list2);
$f = [];
//获取作者
foreach ($list as $k => $v){
if(strtotime($v['deadline'])< time()){
continue;
}
$frag = '';
$caches = $this->journal_special_to_editor_obj
->field('j_journal_special_editor.*')
->join('j_journal_special_editor','j_journal_special_editor.journal_special_editor_id = j_journal_special_to_editor.journal_special_editor_id','LEFT')
->where('j_journal_special_to_editor.journal_special_id',$v['journal_special_id'])
->where('j_journal_special_to_editor.state',0)
->select();
foreach ($caches as $val){
$frag .= $frag == ''?$val['first_name'].' '.$val['last_name']:', '.$val['first_name'].' '.$val['last_name'];
}
$v['editor'] = $frag;
$f[] = $v;
}
$re['specials'] = $f;
return jsonSuccess($re);
}
/**
* @title 客座期刊(获取列表)
* @description 客座期刊(获取列表)
* @author wangjinlei
* @url /api/Special/getSpecialList
* @method POST
*
* @param name:journal_id type:int require:1 desc:期刊id
* @param name:pageIndex type:int require:1 desc:当前页码数
* @param name:pageSize type:int require:1 desc:单页数据条数
*
* @return count:总数
* @return specials:客座期刊列表array#
*/
public function getSpecialList(){
$data = $this->request->post();
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'];
$list = $this->journal_special_obj
->where('journal_id',$data['journal_id'])
->where('state',2)
// ->order('journal_special_id desc')
->order('deadline desc')
->limit($limit_start,$data['pageSize'])
->select();
//获取作者
foreach ($list as $k => $v){
if(strtotime($v['deadline'])<= time()){
$cou = $this->article_obj->where('journal_special_id',$v['journal_special_id'])->where('state',0)->count();
// if($cou<3){
// continue;
// }
}
$frag = '';
$caches = $this->journal_special_to_editor_obj
->field('j_journal_special_editor.*')
->join('j_journal_special_editor','j_journal_special_editor.journal_special_editor_id = j_journal_special_to_editor.journal_special_editor_id','LEFT')
->where('j_journal_special_to_editor.journal_special_id',$v['journal_special_id'])
->where('j_journal_special_to_editor.state',0)
->select();
foreach ($caches as $val){
$frag .= $frag == ''?$val['first_name'].' '.$val['last_name']:', '.$val['first_name'].' '.$val['last_name'];
}
$list[$k]['editor'] = $frag;
}
$count = $this->journal_special_obj->where('journal_id',$data['journal_id'])->where('state',2)->count();
$re['count'] = $count;
$re['specials'] = $list;
return jsonSuccess($re);
}
/**
* @title 客座期刊(获取客座期刊详情)
* @description 客座期刊(获取客座期刊详情)
* @author wangjinlei
* @url /api/Special/getSpecialDetail
* @method POST
*
* @param name:journal_special_id type:int require:1 desc:客座期刊id
*
* @return keywords:关键字#
* @return journal:期刊信息#
* @return special:客座期刊信息#
* @return editors:编辑array#
*/
public function getSpecialDetail(){
$data = $this->request->post();
$info = $this->journal_special_obj->where('journal_special_id',$data['journal_special_id'])->find();
$journal_info = $this->journal_obj->where('journal_id',$info['journal_id'])->find();
$editors = $this->journal_special_to_editor_obj->field('j_journal_special_editor.*')
->join('j_journal_special_editor','j_journal_special_to_editor.journal_special_editor_id = j_journal_special_editor.journal_special_editor_id','LEFT')
->where('j_journal_special_to_editor.journal_special_id',$data['journal_special_id'])
->where('j_journal_special_to_editor.state',0)
->select();
$re['keywords'] = explode(';', $info['keywords']);
$re['journal'] = $journal_info;
$re['special'] = $info;
$re['editors'] = $editors;
return jsonSuccess($re);
}
/**
* @title 客座期刊(获取客座期刊文章)
* @description 客座期刊(获取客座期刊文章)
* @author wangjinlei
* @url /api/Special/getSpecialArticles
* @method POST
*
* @param name:journal_special_id type:int require:1 desc:客座期刊id
*
* @return articles:文章列表array#
*/
public function getSpecialArticles(){
$data = $this->request->post();
$special_info = $this->journal_special_obj->where('journal_special_id',$data['journal_special_id'])->find();
$journal_info = $this->journal_obj->where('journal_id',$special_info['journal_id'])->find();
$list = $this->article_obj
->field('j_article.*,j_journal_stage.*')
->join('j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT')
->where('j_article.journal_special_id',$data['journal_special_id'])
->where('j_article.state',0)
->select();
//获取作者
foreach ($list as $k => $v) {
$stage_info = $this->journal_stage_obj->where('journal_stage_id',$v['journal_stage_id'])->find();
//组合cite信息
$no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):';
$cite = $v['abbr'] . '. ' . $v['title'] . '. <i>' . choiseJabbr($v['article_id'],$journal_info['jabbr']) . '</i>. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi'];
$list[$k]['cite'] = $cite;
$list[$k]['authortitle'] = $this->getAuthor($v);
$list[$k]['mains'] = getArticleMains($v['article_id']);
//文章被引用次数和话题 chengxiaoling 20250926 start
$list[$k]["cite_num"] = Db::name("article_cite")->where("article_id",$v['article_id'])->where("state",1)->where("is_wos",1)->count();
$cache_topic = Db::name("article_to_topic")->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;
//文章被引用次数 chengxiaoling 20250926 end
}
$re['articles'] = $list;
return jsonSuccess($re);
}
private function getAuthor($article) {
$where['article_id'] = $article['article_id'];
$where['state'] = 0;
$list = $this->article_author_obj->where($where)->select();
$frag = '';
foreach ($list as $k => $v) {
$ca = '';
if($v['orcid']!=''){
$ca = '<a href="https://orcid.org/'.$v['orcid'].'" target="_blank"><img src="img/or_id.png" alt="" style="width: 13px;margin-left: 3px;"></a>';
}
$frag = $frag == '' ? '' . $v['author_name'].$ca : $frag . ', ' . $v['author_name'].$ca;
// $frag = $frag == '' ? '' . $v['author_name'] : $frag . ', ' . $v['author_name'];
}
return $frag;
}
/**
* @title 客座期刊提示语(获取)
* @description 客座期刊提示语(获取)
* @author wangjinlei
* @url /api/Special/getSpecialAlert
* @method POST
*
* @param name:journal_id type:int require:1 desc:客座期刊id
*
* @return alertInfo:客座期刊提示语#
*/
public function getSpecialAlert(){
$data = $this->request->post();
$info = $this->journal_special_alert_obj->where('journal_id',$data['journal_id'])->find();
$re['alertInfo'] = $info;
return jsonSuccess($re);
}
/**
* 读取引用文件
*/
public function readCiteExcel(){
$path = ROOT_PATH.'public'.DS.'system'.DS;
$res = $this->readExcel($path.'savedrecs.xls');
foreach ($res as $k => $v){
if($k<6||$v['C']<1){
continue;
}
$doi = explode('/', $v['B']);
$article = '';
if(isset($doi[1])){
$article = $this->article_obj->where('doi','like','%'.$doi[1].'%')->find();
}else{
$article = $this->article_obj->where('title',$v['A'])->find();
}
$cache = $this->readExcel1($path.($k+1).'.xls');
foreach ($cache as $key => $val){
if($key == 0){
continue;
}
$insert['article_id'] = $article['article_id'];
$insert['journal_id'] = $article['journal_id'];
$insert['journal_name'] = $val['journal'];
$insert['article_name'] = $val['title'];
$day = $val['day']==''?'':$val['day'].' ';
$insert['date'] = $day.$val['year'];
$insert['ctime'] = time();
$this->article_cite_obj->insert($insert);
}
}
}
/**
* 读取excel数据
*/
private function readExcel1($path) {
$extension = substr($path, strrpos($path, '.') + 1);
vendor("PHPExcel.PHPExcel");
if ($extension == 'xlsx') {
$objReader = new \PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load($path);
} else if ($extension == 'xls') {
$objReader = new \PHPExcel_Reader_Excel5();
$objPHPExcel = $objReader->load($path);
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$frag = [];
for ($i = 1; $i <= $highestRow; $i++) {
$cache['title'] = $objPHPExcel->getActiveSheet()->getCell("I".$i)->getValue();
$cache['journal'] = $objPHPExcel->getActiveSheet()->getCell("J".$i)->getValue();
$cache['year'] = $objPHPExcel->getActiveSheet()->getCell("AS".$i)->getValue();
$cache['day'] = $objPHPExcel->getActiveSheet()->getCell("AR".$i)->getValue();
$frag[] = $cache;
}
return $frag;
}
/**
* 读取excel数据
*/
private function readExcel($path) {
$extension = substr($path, strrpos($path, '.') + 1);
vendor("PHPExcel.PHPExcel");
if ($extension == 'xlsx') {
$objReader = new \PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load($path);
} else if ($extension == 'xls') {
$objReader = new \PHPExcel_Reader_Excel5();
$objPHPExcel = $objReader->load($path);
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$frag = [];
for ($i = 1; $i <= $highestRow; $i++) {
$cache['A'] = $objPHPExcel->getActiveSheet()->getCell("A".$i)->getValue();
$cache['B'] = $objPHPExcel->getActiveSheet()->getCell("B".$i)->getValue();
$cache['C'] = $objPHPExcel->getActiveSheet()->getCell("C".$i)->getValue();
$frag[] = $cache;
}
return $frag;
}
/**
* @title 通过期刊+标题+截止日期查询专刊ID
* @description 供外部系统在 addSpecial 成功但未返回ID时反查
* @url /api/Special/getSpecialIdByUnique
* @method POST
*
* @param name:journal_id type:int require:1 desc:期刊id
* @param name:title type:string require:1 desc:专刊标题
* @param name:deadline type:string require:1 desc:截止日期
*/
public function getSpecialIdByUnique() {
$data = $this->request->post();
$journalId = intval(isset($data['journal_id']) ? $data['journal_id'] : 0);
$title = trim(isset($data['title']) ? $data['title'] : '');
$deadline = trim(isset($data['deadline']) ? $data['deadline'] : '');
if ($journalId <= 0 || $title === '' || $deadline === '') {
return json(['code' => 1, 'msg' => 'journal_id/title/deadline required']);
}
// 优先精确匹配包含非1状态避免“刚创建未发布”查不到
$special = $this->journal_special_obj
->where('journal_id', $journalId)
->where('title', $title)
->where('deadline', $deadline)
->where('state', '<>', 1)
->order('journal_special_id desc')
->find();
if (!$special) {
// 次优:同标题最新一条(仍排除删除态)
$special = $this->journal_special_obj
->where('journal_id', $journalId)
->where('title', $title)
->where('state', '<>', 1)
->order('journal_special_id desc')
->find();
}
if (!$special) {
return json(['code' => 1, 'msg' => 'special not found']);
}
return json([
'code' => 0,
'msg' => 'success',
'data' => [
'journal_special_id' => intval($special['journal_special_id']),
'title' => isset($special['title']) ? $special['title'] : '',
'deadline' => isset($special['deadline']) ? $special['deadline'] : '',
'state' => intval(isset($special['state']) ? $special['state'] : 0),
],
]);
}
/**
* @title 头像图片上传
* @description 头像图片上传
* @author wangjinlei
* @url /api/Special/up_icon_file
* @method POST
*
* @param name:name type:string require:1 default:specialIcon desc:文件域名称
*
* @return upurl:图片地址
*/
public function up_icon_file() {
$file = request()->file('specialIcon');
if ($file) {
$info = $file->move(ROOT_PATH . 'public' . DS . 'specialIcon');
if ($info) {
return json(['code' => 0, 'msg' => 'success', 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
} else {
return json(['code' => 1, 'msg' => $file->getError()]);
}
}
}
}