个人中心

This commit is contained in:
DESKTOP-B7F3Q04\admin
2022-03-17 17:19:14 +08:00
parent b299680e67
commit 6a24c71bca

View File

@@ -0,0 +1,359 @@
<?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 = '';
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');
}
/**
* Notes:获取个人基本信息
* User: wangzhaocui
* Date: 2022/3/11
* Time: 18:12
* @return \think\response\Json
*/
public function getUserInfo(){
//接收参数
$data = $this->request->post();
if(!isset($data['account'])){
return json(['code' => 1,'msg'=>'account not null']);
}
//账号是否存在
$isExist = $this->user_obj->where(['account' => $data['account']])->find();
if(!$isExist){
return json(['code' => 1,'msg'=>'account not exist']);
}
// 基本信息
$baseInfo = $this->user_obj->where(['account' => $data['account']])->field('user_id,account,realname,email,ctime,orcid,icon,type')->find();
$userInfo['baseInfo'] = $baseInfo;
// 默认为作者(若作者没有发表过文章则不返回)
$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']);
}
// 编辑
if($baseInfo['type'] == 2){
$editor = self::getAsEditor($baseInfo['user_id']);
if(!empty($editor)){
$userInfo['asEditor'] = $editor;
}
}
// 主编
$isChief = $this->chief_to_journal_obj->where(['user_id'=>$baseInfo['user_id'],'state'=>0])->find();
if(!empty($isChief)){
$userInfo['asChief'] = self::getAsChief($baseInfo['user_id']);
}
// 编委
// $isBoard = $this->board_to_journal_obj->where(['user_id'=>$baseInfo['user_id'],'state'=>0])->select();
// if(!empty($isBoard)){
// $userInfo['asBoard'] = self::getAsBoard($isBoard);
// }
// 客座编辑 asGuestEditor
// 青年编委 asYBoard
return jsonSuccess($userInfo);
}
/**
* Notes: 修改个人基本信息baseInfo
* User: wangzhaocui
* Date: 2022/3/14
* Time: 12:23
* @return \think\response\Json
*/
public function updateUserInfo(){
$data = $this->request->post();
if(!isset($data['account']) || !isset($data['realname']) || !isset($data['email'])){
return json(['code' => 1,'msg'=>'account not null']);
}
//验证邮箱是否合规
if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$data['email'])){
return json(['code'=>1,'msg'=>'Invalid email']);
}
// 邮箱是否已经被绑定
$res = $this->user_obj->where(['email'=>$data['email']])->find();
if($res){
return json(['code' => 1,'msg'=>'email is exist']);
}
$update=[
'realname'=>$data['realname'],
'email'=>$data['email']
];
$this->user_obj->where(['account'=>$data['account']])->update($update);
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',
// 'introduction'=>'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(){
// 获取表单上传文件
$file = request()->file('icon');
$data = $this->request->post();
if(!$file){
return json(['code'=>1,'msg'=>'icon not null']);
}
if(!isset($data['account']) || empty($data['account'])){
return json(['code'=>1,'msg'=>'account not null']);
}
// 移动到框架应用根目录/public/icon/ 目录下
if($file){
$info = $file->move(ROOT_PATH . 'public' . DS . 'icon');
if($info){
// 输出 icon/20160820/42a79759f284b767dfcb2a0197904287.jpg
$icon = 'icon/'.str_replace("\\", "/", $info->getSaveName());
// 更新数据库
$this->user_obj->where(['account'=>$data['account']])->update(['icon'=>$icon]);
return jsonSuccess(['account'=>$data['account'],'icon'=>$icon]);
}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;
}
/**
* Notes:获取审稿人
* User: admin
* Date: 2022/3/14
* Time: 14:45
* @param $account
*/
private function getAsReviewer($userId){
// 获取审稿人基本信息
$res = $this->user_reviewer_info_obj->field('gender,technical,country,major,field,introduction')->where(['reviewer_id'=>$userId])->find();
// 获取审稿人期刊
$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();
// 审稿人成功审稿次数
$reviewerWhere=[
'reviewer_id'=>$userId,
'state'=>3
];
$successReview = $this->article_reviewer_obj->where($reviewerWhere)->count();
$res['successReview'] = $successReview;
$res['journal'] = $journal;
return $res;
}
/**
* 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($data){
foreach ($data as $k=>$v){
// 查找期刊title
$data[$k]= $this->journal_obj->where('journal_id',$v['journal_id'])->field('journal_id,title,issn,abbr')->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;
}
/**
* Notes: 客座编辑资料(未完成)
* User: wangzhaocui
* Date: 2022/3/16
* Time: 10:22
* @param $userId
*/
private function getAsGuestEditor($userId){
return ;
}
/**
* Notes: 青年编委
* User: wangzhaocui
* Date: 2022/3/17
* Time: 16:01
* @param $userId
*/
private function getAsYBoard($userId){
return ;
}
}