Files
tougao/application/api/controller/Board.php
wangjinlei 949fa3f9b3 1
2022-09-29 07:50:12 +08:00

334 lines
12 KiB
PHP

<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use think\Queue;
use think\Validate;
/**
* @title 编委相关接口
* @description 编委相关接口
*/
class Board extends Controller {
protected $article_obj = '';
protected $user_obj = '';
protected $user_act_obj = '';
protected $journal_obj = '';
protected $user_log_obj = '';
protected $reviewer_major_obj = '';
protected $reviewer_to_journal_obj = '';
protected $article_msg_obj = '';
protected $article_file_obj = '';
protected $article_reviewer_obj = '';
protected $article_author_obj = '';
protected $article_transfer_obj = '';
protected $staff_obj = '';
protected $staff_level_obj = '';
protected $staff_log_obj = '';
protected $staff_to_journal_obj = '';
protected $chief_to_journal_obj = '';
protected $board_to_journal_obj = '';
protected $chief_msg_obj = '';
protected $article_to_board_obj = '';
protected $login_auto_obj = '';
protected $user_index_obj = '';
protected $user_email_index_obj = '';
public function __construct(\think\Request $request = null) {
parent::__construct($request);
$this->user_obj = Db::name('user');
$this->user_act_obj = Db::name('user_act');
$this->article_obj = Db::name('article');
$this->journal_obj = Db::name('journal');
$this->user_log_obj = Db::name('user_log');
$this->reviewer_major_obj = Db::name('reviewer_major');
$this->reviewer_to_journal_obj = Db::name('reviewer_to_journal');
$this->article_msg_obj = Db::name('article_msg');
$this->article_file_obj = Db::name('article_file');
$this->article_reviewer_obj = Db::name('article_reviewer');
$this->article_author_obj = Db::name('article_author');
$this->article_transfer_obj = Db::name('article_transfer');
$this->staff_obj = Db::name('staff');
$this->staff_level_obj = Db::name('staff_level');
$this->staff_log_obj = Db::name('staff_log');
$this->staff_to_journal_obj = Db::name('staff_to_journal');
$this->chief_to_journal_obj = Db::name('chief_to_journal');
$this->board_to_journal_obj = Db::name('board_to_journal');
$this->chief_msg_obj = Db::name('chief_msg');
$this->article_to_board_obj = Db::name('article_to_board');
$this->chief_to_journal_obj = Db::name('chief_to_journal');
$this->login_auto_obj = Db::name('login_auto');
$this->user_index_obj = Db::name('user_index');
$this->user_email_index_obj = Db::name('user_email_index');
}
/**
* @title 编委主页--获取进行中的文章
* @description 编委主页--获取进行中的文章
* @author wangjinlei
* @url /api/Board/getBoardPendArticle
* @method POST
*
* @param name:user_id type:int require:1 desc:编委用户id
* @param name:journal_id type:int require:1 desc:期刊id
*
* @return articles:文章列表#
*/
public function getBoardPendArticle() {
$data = $this->request->post();
$list = $this->article_obj
->field('t_article.*,t_journal.title journal_title')
->join('t_journal','t_journal.journal_id = t_article.journal_id','left')
->where('t_article.journal_id', $data['journal_id'])
->where('t_article.state', 6)
->select();
foreach ($list as $k => $v) {
$auts = $this->article_author_obj->where('article_id', $v['article_id'])->where('state', 0)->select();
$au = '';
foreach ($auts as $vv) {
$au .= $vv['firstname'] . ' ' . $vv['lastname'] . ';';
}
$list[$k]['author'] = substr($au, 0, -1);
}
foreach ($list as $k => $v){
if($v['type']){
$list[$k]['type'] = translateType($v['type']);
}
}
//加上文章领域
foreach($list as $k => $v){
$major = $this->reviewer_major_obj->where('major_id',$v['major_id'])->find();
$cmajor = $this->reviewer_major_obj->where('major_id',$v['cmajor_id'])->find();
$list[$k]['major'] = $major['title'];
$list[$k]['cmajor'] = $cmajor['title'];
}
$re['articles'] = $list;
return jsonSuccess($re);
}
/**
* @title 编委主页--获取历史文章
* @description 编委主页--获取历史文章
* @author wangjinlei
* @url /api/Board/getBoardHistArticles
* @method POST
*
* @param name:user_id type:int require:1 desc:编委用户id
* @param name:journal_id type:int require:1 desc:期刊id
*
* @return articles:文章列表#
*/
public function getBoardHistArticles(){
$data = $this->request->post();
$list = $this->article_obj->field('t_article.*,t_journal.title journal_title')
->join('t_journal','t_journal.journal_id = t_article.journal_id','left')
->where('t_article.journal_id',$data['journal_id'])
->where('t_article.state',5)->select();
foreach ($list as $k => $v) {
$auts = $this->article_author_obj->where('article_id', $v['article_id'])->where('state', 0)->select();
$au = '';
foreach ($auts as $vv) {
$au .= $vv['firstname'] . ' ' . $vv['lastname'] . ';';
}
$list[$k]['author'] = substr($au, 0, -1);
}
foreach ($list as $k => $v){
if($v['type']){
$list[$k]['type'] = translateType($v['type']);
}
}
$re['articles'] = $list;
return jsonSuccess($re);
}
/**
* @title 编委主页--获取编委期刊列表
* @description 编委主页--获取编委期刊列表
* @author wangjinlei
* @url /api/Board/getBoardJournals
* @method POST
*
* @param name:user_id type:int require:1 desc:编委用户id
*
* @return journals:期刊列表#
*/
public function getBoardJournals(){
$data = $this->request->post();
$list = $this->board_to_journal_obj->field('t_journal.*,t_board_to_journal.btj_id')
->join('t_journal','t_board_to_journal.journal_id = t_journal.journal_id','left')
->where('t_board_to_journal.user_id',$data['user_id'])
->where('t_board_to_journal.state',0)
->select();
$re['journals'] = $list;
return jsonSuccess($re);
}
/**
* @title 青年编委详情页--获取青年编委期刊列表
* @description 青年编委详情页--获取青年编委期刊列表
* @author wangjinlei
* @url /api/Board/getYboardJournals
* @method POST
*
* @param name:user_id type:int require:1 desc:编委用户id
*
* @return journals:期刊列表#
*/
public function getYboardJournals(){
$data = $this->request->post();
$journals = $this->reviewer_to_journal_obj
->join('t_journal','t_journal.journal_id = t_reviewer_to_journal.journal_id','left')
->where('t_reviewer_to_journal.reviewer_id',$data['user_id'])
->where('t_reviewer_to_journal.is_yboard',1)
->where('t_reviewer_to_journal.state',0)
->select();
$re['journals'] = $journals;
return jsonSuccess($re);
}
/**
* @title 编委导入--获取官网编委
* @description 编委导入--获取官网编委
* @author wangjinlei
* @url /api/Board/getOffwebBoard
* @method POST
*
* @param name:journal_id type:int require:1 desc:期刊id
*
* @return boards:编委list#
*/
public function getOffwebBoard(){
$data = $this->request->post();
$journal_info = $this->journal_obj->where('journal_id',$data['journal_id'])->find();
$cs['issn'] = $journal_info['issn'];
$url = 'http://journalapi.tmrjournals.com/public/index.php/api/Main/getBoards';
$list = object_to_array(json_decode(myPost($url, $cs)));
foreach ($list as $k => $v){
if($v['tuser_id']==0){
continue;
}
$list[$k]['user'] = $this->user_obj->where('user_id',$v['tuser_id'])->find();
}
$re['boards'] = $list;
return jsonSuccess($re);
}
/**
* @title 编委导入--关联用户
* @description 编委导入--关联用户
* @author wangjinlei
* @url /api/Board/relationUser
* @method POST
*
* @param name:user_id type:int require:1 desc:用户id
* @param name:journal_id type:int require:1 desc:期刊id
* @param name:email type:string require:1 desc:邮箱
* @param name:jboard_id type:int require:1 desc:官网boardid
*
* @return boards:编委list#
*/
public function relationUser(){
$data = $this->request->post();
$url = 'http://journalapi.tmrjournals.com/public/index.php/api/Main/bindBoard';
$cs['user_id'] = $data['user_id'];
$cs['board_id'] = $data['jboard_id'];
$cs['email'] = $data['email'];
$list = myPost($url, $cs);
$insert['user_id'] = $data['user_id'];
$insert['journal_id'] = $data['journal_id'];
$this->board_to_journal_obj->insert($insert);
return jsonSuccess([]);
}
/**
* @title 编委导入--获取全部审稿人
* @description 编委导入--获取全部审稿人
* @author wangjinlei
* @url /api/Board/getAllReviewer
* @method POST
*
* @return boards:编委list#
*/
public function getAllReviewer(){
$revs = $this->user_obj->where('is_reviewer',1)->where('state',0)->select();
$re['reviewers'] = $revs;
return jsonSuccess($re);
}
/**
* 编辑/添加H指数
*/
public function editIndex(){
$data = $this->request->post();
$rule = new Validate([
'user_id'=>'require',
'year'=>'require',
'index'=>'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$check = $this->user_index_obj->where('user_id',$data['user_id'])->where('year',$data['year'])->where('state',0)->find();
if($check){
$this->user_index_obj->where('in_id',$check['in_id'])->update(['h_index'=>$data['index']]);
}else{
$insert['user_id'] = $data['user_id'];
$insert['year'] = $data['year'];
$insert['h_index'] = $data['index'];
$this->user_index_obj->insert($insert);
}
return jsonSuccess([]);
}
/**
* @title 编委导入--通过账号搜索用户
* @description 编委导入--通过账号搜索用户
* @author wangjinlei
* @url /api/Board/searchUserByAccount
* @method POST
*
* @param name:account type:string require:1 desc:用户名
*
* @return users:用户#
*/
public function searchUserByAccount(){
$data = $this->request->post();
$users = $this->user_obj->where('state',0)->where('account','like','%'.$data['account'].'%')->select();
$re['users'] = $users;
return jsonSuccess($re);
}
/**
* @title 编委导入--通过邮箱搜索用户
* @description 编委导入--通过邮箱搜索用户
* @author wangjinlei
* @url /api/Board/searchUserByEmail
* @method POST
*
* @param name:email type:string require:1 desc:邮箱
*
* @return user:用户信息#
*/
public function searchUserByEmail(){
$data = $this->request->post();
$user = $this->user_obj->where('state',0)->where('email',$data['email'])->find();
if($user == null){
return jsonError('can not find user!!');
}
$re['user'] = $user;
return jsonSuccess($re);
}
}