490 lines
17 KiB
PHP
490 lines
17 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use think\Controller;
|
|
use think\Db;
|
|
use think\Validate;
|
|
|
|
|
|
class Ucenter extends Controller{
|
|
|
|
protected $user_obj = '';
|
|
protected $user_reviewer_info_obj = '';
|
|
protected $journal_obj = '';
|
|
protected $reviewer_to_journal_obj = '';
|
|
protected $article_reviewer_obj = '';
|
|
protected $article_obj = '';
|
|
protected $chief_to_journal_obj = '';
|
|
protected $board_to_journal_obj = '';
|
|
protected $major_obj = "";
|
|
protected $major_to_journal_obj = '';
|
|
protected $user_cv_obj = '';
|
|
protected $apply_board_obj = '';
|
|
protected $apply_yboard_obj = '';
|
|
|
|
public function __construct(\think\Request $request = null)
|
|
{
|
|
parent::__construct($request);
|
|
$this->user_obj = Db::name('user');
|
|
$this->user_reviewer_info_obj = Db::name("user_reviewer_info");
|
|
$this->journal_obj = Db::name('journal');
|
|
$this->reviewer_to_journal_obj = Db::name('reviewer_to_journal');
|
|
$this->article_reviewer_obj = Db::name('article_reviewer');
|
|
$this->article_obj = Db::name('article');
|
|
$this->chief_to_journal_obj = Db::name('chief_to_journal');
|
|
$this->board_to_journal_obj = Db::name('board_to_journal');
|
|
$this->major_obj = Db::name("major");
|
|
$this->major_to_journal_obj = Db::name('major_to_journal');
|
|
$this->user_cv_obj = Db::name('user_cv');
|
|
$this->apply_board_obj = Db::name('apply_board');
|
|
$this->apply_yboard_obj = Db::name('apply_yboard');
|
|
}
|
|
|
|
|
|
/**
|
|
* Notes:获取个人基本信息
|
|
* User: wangzhaocui
|
|
* Date: 2022/3/11
|
|
* Time: 18:12
|
|
* @return \think\response\Json
|
|
*/
|
|
|
|
public function getUserInfo(){
|
|
//接收参数
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'user_id'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
|
|
// 基本信息
|
|
$baseInfo = $this->user_obj->where(['user_id' => $data['user_id']])->find();
|
|
// $userInfo['baseInfo'] = $baseInfo;
|
|
|
|
//检查用户reviewer的info信息
|
|
$reviewer_info = $this->user_reviewer_info_obj->where('reviewer_id',$data['user_id'])->find();
|
|
if(!$reviewer_info){
|
|
$insert_reviewer['reviewer_id'] = $data['user_id'];
|
|
$this->user_reviewer_info_obj->insert($insert_reviewer);
|
|
}
|
|
|
|
$userInfo['baseInfo']=$this->user_obj
|
|
// ->field("t_user.*,")
|
|
->join('t_user_reviewer_info','t_user.user_id = t_user_reviewer_info.reviewer_id','left')
|
|
->where('t_user.user_id',$data['user_id'])
|
|
->find();
|
|
|
|
//cv信息
|
|
$cvs = $this->user_cv_obj->where('user_id',$data['user_id'])->where('state',0)->select();
|
|
$userInfo['cvs'] = $cvs;
|
|
// 默认为作者(若作者没有发表过文章则不返回)
|
|
$isAuthor = $this->article_obj->where(['user_id'=>$baseInfo['user_id']])->find();
|
|
if($isAuthor){
|
|
$userInfo['asAuthor'] = self::getAsAuthor($baseInfo['user_id']);
|
|
}
|
|
//审稿人
|
|
$isReviewer = $this->reviewer_to_journal_obj->where(['reviewer_id'=>$baseInfo['user_id'],'state'=>0])->find();
|
|
if($isReviewer){
|
|
$userInfo['asReviewer'] = self::getAsReviewer($baseInfo['user_id']);
|
|
}
|
|
//编委信息
|
|
$isBoard = $this->board_to_journal_obj->where('user_id',$baseInfo['user_id'])->where('state',0)->select();
|
|
if($isBoard){
|
|
$userInfo['asBoard'] = self::getAsBoard($baseInfo['user_id']);
|
|
}
|
|
|
|
return jsonSuccess($userInfo);
|
|
}
|
|
|
|
public function getCanApplyJournal(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'user_id'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$journals = $this->apply_board_obj->where('user_id',$data['user_id'])->where('state',0)->column("journal_id");
|
|
$js = $this->board_to_journal_obj->where('user_id',$data['user_id'])->where('state',0)->column('journal_id');
|
|
$list = $this->journal_obj->where('journal_id','not in',$journals)->where('journal_id','not in',$js)->where('state',0)->select();
|
|
$re['journals'] = $list;
|
|
return jsonSuccess($re);
|
|
}
|
|
|
|
public function getCanApplyYjournal(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'user_id'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$ids = $this->reviewer_to_journal_obj->where('reviewer_id',$data['user_id'])->where('state',0)->where('is_yboard',0)->column('journal_id');
|
|
$journals = $this->journal_obj->where('journal_id','in',$ids)->where('state',0)->select();
|
|
$re['journals'] = $journals;
|
|
return jsonSuccess($re);
|
|
}
|
|
|
|
public function applyYboard(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'user_id'=>'require',
|
|
'journal_id'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$check = $this->apply_yboard_obj->where('user_id',$data['user_id'])->where('journal_id',$data['journal_id'])->where('state',0)->find();
|
|
if($check){
|
|
return jsonError("Your application for Editorial Board is processing. Please do not repeat it.");
|
|
}
|
|
$insert['user_id'] = $data['user_id'];
|
|
$insert['journal_id'] = $data['journal_id'];
|
|
$insert['ctime'] = time();
|
|
$this->apply_yboard_obj->insert($insert);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
public function applyBoard(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'user_id'=>'require',
|
|
'journal_id'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$check = $this->apply_board_obj->where('user_id',$data['user_id'])->where('journal_id',$data['journal_id'])->where('state',0)->find();
|
|
if($check){
|
|
return jsonError("");
|
|
}
|
|
$insert['user_id'] = $data['user_id'];
|
|
$insert['journal_id'] = $data['journal_id'];
|
|
$insert['ctime'] = time();
|
|
$this->apply_board_obj->insert($insert);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 增加用户cv
|
|
*/
|
|
public function addUserCv(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'user_id'=>'require',
|
|
'cv'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$insert['user_id'] = $data['user_id'];
|
|
$insert['cv'] = $data['cv'];
|
|
$insert['ctime'] = time();
|
|
$this->user_cv_obj->insert($insert);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* 删除用户简历
|
|
*/
|
|
public function delUserCv(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'user_cv_id'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$this->user_cv_obj->where('user_cv_id',$data['user_cv_id'])->update(['state'=>1]);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
/**
|
|
* Notes: 修改个人基本信息baseInfo
|
|
* User: wangzhaocui
|
|
* Date: 2022/3/14
|
|
* Time: 12:23
|
|
* @return \think\response\Json
|
|
*/
|
|
public function updateUserInfo(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'user_id'=>'require',
|
|
'realname'=>'require',
|
|
'technical'=>'require',
|
|
'country'=>'require',
|
|
'major'=>'require|number',
|
|
'field'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$update['realname'] = trim($data['realname']);
|
|
if(isset($data['phone'])&&$data['phone']!=''){
|
|
$update['phone'] = $data['phone'];
|
|
}
|
|
$this->user_obj->where(['user_id'=>$data['user_id']])->update($update);
|
|
$updata1=[
|
|
'technical'=>$data['technical'],
|
|
'country'=>$data['country'],
|
|
'major'=>$data['major'],
|
|
'field'=>$data['field'],
|
|
'introduction'=>$data['introduction'],
|
|
];
|
|
$this->user_reviewer_info_obj->where(['reviewer_id'=>$data['user_id']])->update($updata1);
|
|
return jsonSuccess([]);
|
|
|
|
}
|
|
|
|
/**
|
|
* Notes: 修改 asReviewe 信息
|
|
* User: wangzhaocui
|
|
* Date: 2022/3/14
|
|
* Time: 17:02
|
|
* @return \think\response\Json
|
|
*/
|
|
// public function updateAsReviewerInfo(){
|
|
// $data = $this->request->post();
|
|
// // 验证规则
|
|
// $rule = new Validate([
|
|
// 'user_id'=>'require|number',
|
|
// 'technical'=>'require',
|
|
// 'country'=>'require',
|
|
// 'major'=>'require|number',
|
|
// 'field'=>'require'
|
|
// ]);
|
|
// if(!$rule->check($data)){
|
|
// return json(['code' => 1,'msg'=>$rule->getError()]);
|
|
// }
|
|
// $updata=[
|
|
// 'technical'=>$data['technical'],
|
|
// 'country'=>$data['country'],
|
|
// 'major'=>$data['major'],
|
|
// 'field'=>$data['field'],
|
|
// 'introduction'=>$data['introduction'],
|
|
// ];
|
|
// $this->user_reviewer_info_obj->where(['reviewer_id'=>$data['user_id']])->update($updata);
|
|
// return jsonSuccess([]);
|
|
// }
|
|
|
|
/**
|
|
* Notes:修改 asEditor 信息
|
|
* User: wangzhaocui
|
|
* Date: 2022/3/16
|
|
* Time: 10:16
|
|
*/
|
|
public function updateAsEditorInfo(){
|
|
$data = $this->request->post();
|
|
// 验证规则
|
|
$rule = new Validate([
|
|
'user_id'=>'require|number',
|
|
'journal_id'=>'require|number',
|
|
'email'=>'require|email',
|
|
'password'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return json(['code' => 1,'msg'=>$rule->getError()]);
|
|
}
|
|
$isExist = $this->journal_obj->where(['journal_id'=>$data['journal_id'],'editor_id'=>$data['user_id']])->find();
|
|
if(empty($isExist)){
|
|
return json(['code' => 1,'msg'=>'not exist']);
|
|
}
|
|
$update=[
|
|
'email'=>$data['email'],
|
|
'epassword'=>$data['password']
|
|
];
|
|
$this->journal_obj->where(['journal_id'=>$data['journal_id'],'editor_id'=>$data['user_id']])->update($update);
|
|
return jsonSuccess([]);
|
|
|
|
}
|
|
|
|
/**
|
|
* Notes:修改个人头像
|
|
* User: wangzhaocui
|
|
* Date: 2022/3/14
|
|
* Time: 10:52
|
|
* @return \think\response\Json
|
|
*/
|
|
public function updateIncon(){
|
|
// 获取表单上传文件
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'user_id'=>'require',
|
|
'icon'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$this->user_obj->where(['user_id'=>$data['user_id']])->update(['icon'=>$data['icon']]);
|
|
return jsonSuccess([]);
|
|
}
|
|
|
|
public function up_userIcon_file()
|
|
{
|
|
$file = request()->file('icon');
|
|
if ($file) {
|
|
$info = $file->move(ROOT_PATH . 'public' . DS . 'usericon');
|
|
if ($info) {
|
|
return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
|
|
} else {
|
|
return json(['code' => 1, 'msg' => $file->getError()]);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* Notes: 作者信息
|
|
* User: wangzhaocui
|
|
* Date: 2022/3/14
|
|
* Time: 14:49
|
|
* @param $userId
|
|
* @return array
|
|
*/
|
|
private function getAsAuthor($userId){
|
|
// 作者发表文章总数
|
|
$manuscriptNum = $this->article_obj->where(['user_id'=>$userId])->count();
|
|
$journal = $this->article_obj->field('t_journal.title,t_journal.abbr')
|
|
->join('t_journal','t_journal.journal_id = t_article.journal_id','RIGHT')
|
|
->where(['user_id'=>$userId])
|
|
->distinct('t_article.journal_id')
|
|
->select();
|
|
// 发表文章通过数
|
|
$accept = $this->article_obj->where(['user_id'=>$userId,'state'=>5])->count();
|
|
$res = [
|
|
'manuscriptNum'=>$manuscriptNum,
|
|
'accept'=>$accept,
|
|
'journal'=>$journal
|
|
];
|
|
return $res;
|
|
}
|
|
|
|
public function getMajor(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'major_id'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$major = $this->major_obj->where('major_id',$data['major_id'])->find();
|
|
$major['children'] = $this->major_obj->where('pid',$major['major_id'])->select();
|
|
$re['major'] = $major;
|
|
return jsonSuccess($re);
|
|
}
|
|
/**
|
|
* Notes:获取审稿人
|
|
* User: admin
|
|
* Date: 2022/3/14
|
|
* Time: 14:45
|
|
* @param $account
|
|
*/
|
|
private function getAsReviewer($userId){
|
|
// 获取审稿人基本信息
|
|
$res = $this->user_reviewer_info_obj->where(['reviewer_id'=>$userId])->find();
|
|
|
|
$res['majors'] = self::getMajorShu($res['major']);
|
|
|
|
|
|
// 获取审稿人期刊
|
|
$journal = $this->reviewer_to_journal_obj->field('t_journal.title,t_journal.abbr')
|
|
->join('t_journal','t_journal.journal_id = t_reviewer_to_journal.journal_id','LEFT')
|
|
->where(['t_reviewer_to_journal.reviewer_id'=>$userId,'t_reviewer_to_journal.state'=>0])
|
|
->select();
|
|
// 审稿人成功审稿次数
|
|
$successReview = $this->article_reviewer_obj->where('reviewer_id',$userId)->where('state','in',[1,2,3])->count();
|
|
|
|
$res['successReview'] = $successReview;
|
|
$res['journal'] = $journal;
|
|
return $res;
|
|
}
|
|
|
|
private function getMajorShu($major){
|
|
$res = $this->major_obj->where('major_id',$major)->find();
|
|
if($res['pid']==1){
|
|
return $res['major_id'];
|
|
}
|
|
|
|
$p = self::getMajorShu($res['pid']);
|
|
return $p.','.$res['major_id'];
|
|
}
|
|
|
|
/**
|
|
* Notes: 编辑的期刊资料
|
|
* User: wangzhaocui
|
|
* Date: 2022/3/15
|
|
* Time: 15:36
|
|
* @param $userId
|
|
*/
|
|
private function getAsEditor($userId){
|
|
$res = $this->journal_obj->field('journal_id,title,abbr,issn,email,epassword')->where(['editor_id'=>$userId])->select();
|
|
foreach ($res as $k =>$v){
|
|
$res[$k]['notApproved'] = $this->article_obj->where(['journal_id'=>$v['journal_id'],'state'=>0])->count();
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
|
|
/**
|
|
* Notes: 主编资料
|
|
* User: wangzhaocui
|
|
* Date: 2022/3/15
|
|
* Time: 14:17
|
|
* @param $userId
|
|
*/
|
|
private function getAsChief($userId){
|
|
$res = $this->chief_to_journal_obj->field('t_chief_to_journal.journal_id,t_journal.title,t_journal.issn,t_journal.abbr,t_user.realname as editorRealname')
|
|
->join('t_journal','t_journal.journal_id = t_chief_to_journal.journal_id','LEFT')
|
|
->join('t_user','t_user.user_id = t_journal.editor_id','LEFT')
|
|
->where(['t_chief_to_journal.user_id'=>$userId])
|
|
->select();
|
|
foreach ( $res as $k=>$v){
|
|
//期刊发表投稿总数
|
|
$res[$k]['totalManuscripts'] = $this->article_obj->where(['journal_id'=>$v['journal_id']])->count();
|
|
//期刊已录用数
|
|
$res[$k]['acceptManuscripts'] = $this->article_obj->where(['journal_id'=>$v['journal_id'],'state'=>5])->count();
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* Notes: 编委信息 asBoard 信息
|
|
* User: wangzhaocui
|
|
* Date: 2022/3/16
|
|
* Time: 16:15
|
|
* @param $data
|
|
* @return array
|
|
*/
|
|
private function getAsBoard($user_id){
|
|
$data = $this->board_to_journal_obj->where('user_id',$user_id)->where('state',0)->select();
|
|
foreach ($data as $k=>$v){
|
|
// 查找期刊title
|
|
// $data[$k]= $this->journal_obj->where('journal_id',$v['journal_id'])->field('journal_id,title,issn,abbr')->find();
|
|
$data[$k]= $this->journal_obj->where('journal_id',$v['journal_id'])->find();
|
|
// 其他编委名字
|
|
// $otherBoards = $this->board_to_journal_obj->field('t_user.realname')
|
|
// ->join('t_user','t_user.user_id = t_board_to_journal.user_id')
|
|
// ->where('t_board_to_journal.journal_id',$v['journal_id'])
|
|
// ->select();
|
|
// $data[$k]['otherBoards'] = array_column($otherBoards, 'realname');
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
|
|
public function up_cv_file()
|
|
{
|
|
$file = request()->file('reviewerCV');
|
|
if ($file) {
|
|
$info = $file->move(ROOT_PATH . 'public' . DS . 'reviewer');
|
|
if ($info) {
|
|
return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
|
|
} else {
|
|
return json(['code' => 1, 'msg' => $file->getError()]);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|