Files
journal/application/api/controller/Special.php
wangjinlei 110fe0f086 20201112
2021-01-27 17:07:48 +08:00

296 lines
13 KiB
PHP

<?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 = '';
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');
}
/**
* @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'];
$special_insert['ctime'] = time();
$special_id = $this->journal_special_obj->insertGetId($special_insert);
//处理客座编辑
$editor_insert['journal_id'] = $data['journal_id'];
$editor_insert['email'] = $data['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'];
$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([]);
}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
*
*/
public function addEditor(){
$data = $this->request->post();
$insert_editor['journal_id'] = $data['journal_id'];
$insert_editor['email'] = $data['email'];
$insert_editor['first_name'] = $data['first_name'];
$insert_editor['last_name'] = $data['last_name'];
$insert_editor['address'] = $data['address'];
$insert_editor['interests'] = $data['interests'];
$insert_editor['website'] = $data['website'];
$insert_editor['orcid'] = $data['orcid'];
$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();
//获取作者
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'];
}
$list[$k]['editor'] = $frag;
}
$re['specials'] = $list;
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')
->limit($limit_start,$data['pageSize'])
->select();
//获取作者
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'];
}
$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>' . $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);
}
$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) {
$frag = $frag == '' ? '' . $v['author_name'] : $frag . ', ' . $v['author_name'];
}
return $frag;
}
}