Files
journal/application/api/controller/Special.php
wangjinlei 18e00ce354 20201112
2021-01-11 17:56:08 +08:00

182 lines
7.3 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'] = intval($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/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.*')
->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.*')
->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);
}
}