Files
tougao/application/api/controller/Admin.php
wangjinlei 936978d35c 20201112
2021-06-15 10:33:18 +08:00

636 lines
26 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use think\Queue;
class Admin extends Controller {
protected $user_obj = '';
protected $captcha_obj = '';
protected $journal_obj = '';
protected $user_act_obj = '';
protected $reviewer_major_obj = '';
protected $article_obj = '';
protected $article_msg_obj = '';
protected $article_author_obj = '';
protected $admin_obj = '';
protected $country_obj = '';
protected $reviewer_to_journal_obj = '';
protected $user_reviewer_info_obj = '';
protected $user_reviewer_obj = '';
protected $user_msg_obj = '';
public function __construct(\think\Request $request = null) {
parent::__construct($request);
$this->user_obj = Db::name('user');
$this->captcha_obj = Db::name('captcha');
$this->user_act_obj = Db::name('user_act');
$this->admin_obj = Db::name('admin');
$this->reviewer_major_obj = Db::name('reviewer_major');
$this->journal_obj = Db::name('journal');
$this->user_reviewer_obj = Db::name('user_reviewer_apply');
$this->user_reviewer_info_obj = Db::name('user_reviewer_info');
$this->reviewer_to_journal_obj = Db::name('reviewer_to_journal');
$this->article_obj = Db::name('article');
$this->user_msg_obj = Db::name('user_msg');
$this->article_msg_obj = Db::name('article_msg');
$this->article_author_obj = Db::name('article_author');
$this->country_obj = Db::name('country');
}
/**
* 获取编辑人员列表(分页)
*/
public function getEditor() {
$data = $this->request->post();
$where['type'] = 2;
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'];
$res = $this->user_obj->where($where)->limit($limit_start, $data['pageSize'])->select();
$count = $this->user_obj->where($where)->count();
return json(['total' => $count, 'data' => $res]);
}
/**
* 获取所有编辑
*/
public function getEditorList() {
$where['type'] = 2;
$res = $this->user_obj->where($where)->select();
return $res == null ? json(['code' => 1, 'msg' => 'Acquisition failed']) : json(['code' => 0, 'data' => $res]);
}
/**
* 添加编辑
*/
public function addEditor() {
$data = $this->request->post();
$checkres = $this->user_obj->where(['account' => $data['username']])->whereOr(['email' => $data['email']])->find();
if ($checkres != null) {
return json(['code' => 1, 'msg' => 'username or email has registered']);
}
$insert_data['account'] = $data['username'];
$insert_data['password'] = md5($data['password']);
$insert_data['email'] = $data['email'];
$insert_data['phone'] = $data['phone'];
$insert_data['realname'] = $data['realname'];
$insert_data['type'] = 2;
$insert_data['ctime'] = time();
$this->user_obj->insert($insert_data);
return json(['code' => 0]);
}
/**
* 获取文章admin
*/
public function getArticle() {
//接收参数
$data = $this->request->post();
// $data['journal'] = 0;
// $data['pageIndex'] = 1;
// $data['pageSize'] = 10;
//构造查询条件
$where = [];
if ($data['journal'] != 0) {
$where['t_article.journal_id'] = $data['journal'];
}
if ($data['state'] >= 0) {
$where['t_article.state'] = $data['state'];
} else {
if ($data['act'] == 1) {
$where['t_article.state'] = array('in', [0, 1, 2, 4]);
} else if ($data['act'] == 2) {
$where['t_article.state'] = array('in', [3, 5]);
}
}
//分页查询数据
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'];
$res = $this->article_obj->field('t_article.*,t_journal.title journalname,t_journal.abbr abbr,t_user.account username,t_user.realname realname')
->join('t_journal', 't_journal.journal_id = t_article.journal_id', 'LEFT')
->join('t_user', 't_journal.editor_id = t_user.user_id', 'LEFT')
->where($where)
->order('article_id desc')
->limit($limit_start, $data['pageSize'])->select();
$count = $this->article_obj->where($where)->count();
//收集文章的国家
foreach ($res as $k => $v) {
$c_res = $this->article_author_obj->where('article_id', $v['article_id'])->select();
$c_frag = [];
foreach ($c_res as $vv) {
if ($vv['country'] == "") {
continue;
}
if (!in_array($vv['country'], $c_frag)) {
$c_frag[] = $vv['country'];
}
}
$res[$k]['country'] = implode(',', $c_frag);
}
//返回数据
return json(['total' => $count, 'data' => $res]);
}
/**
* 获取文章详情
*/
public function getArticleDetail() {
//接受参数
$data = $this->request->post();
//查询文章基础数据
$where['t_article.article_id'] = $data['articleId'];
$article_res = $this->article_obj->field('t_article.*,t_journal.title journalname,t_user.account')->join(array(['t_journal', 't_journal.journal_id = t_article.journal_id', 'LEFT'], ['t_user', 't_user.user_id = t_article.user_id', 'LEFT']))->where($where)->find();
//查询文章状态跟踪信息
$article_msg = $this->article_msg_obj->where(['article_id' => $data['articleId']])->select();
$suggest = '';
//如果是退修状态,显示退休信息
if ($article_res['state'] == 4) {
$lastbean = end($article_msg);
$suggest = $lastbean['content'];
}
//查询major信息
$major_data = [];
if($article_res['major_id']!=0){
$major_data['major'] = $this->reviewer_major_obj->where('major_id',$article_res['major_id'])->find();
}else{
$major_data['major'] = null;
}
if($article_res['cmajor_id']!=0){
$major_data['cmajor'] = $this->reviewer_major_obj->where('major_id',$article_res['cmajor_id'])->find();
}else{
$major_data['cmajor'] = null;
}
//查询文章作者信息
$author_res = $this->article_author_obj->where('article_id', $data['articleId'])->where('state', 0)->select();
return json(['article' => $article_res, 'msg' => $article_msg, 'authors' => $author_res, 'suggest' => $suggest,'major'=>$major_data]);
}
/**
* 获取期刊列表
*/
public function getJournals() {
$data = $this->request->post();
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'] ;
$res = $this->journal_obj->field('t_journal.*,t_user.account editor')->join('t_user', 't_user.user_id=t_journal.editor_id', 'left')->order('t_journal.journal_id')->limit($limit_start, $data['pageSize'])->select();
$count = $this->journal_obj->count();
return json(['total' => $count, 'data' => $res]);
}
/**
* 添加期刊
*/
public function journalAdd() {
$data = $this->request->post();
$checkres = $this->journal_obj->where(['title' => $data['title']])->whereOr(['issn' => $data['issn']])->find();
if ($checkres != null) {
return json(['code' => 1, 'msg' => 'title or issn already exists']);
}
$insert_data['title'] = $data['title'];
$insert_data['issn'] = $data['issn'];
$insert_data['alias'] = $data['alias'];
$this->journal_obj->insert($insert_data);
return json(['code' => 0]);
}
/**
* 更改期刊编辑
*/
public function journalEditorChange() {
$data = $this->request->post();
$update['editor_id'] = $data['editorId'];
$where['journal_id'] = $data['journalId'];
$res = $this->journal_obj->where($where)->update($update);
return json(['code' => $res == null ? 1 : 0]);
}
/**
* 上传reviewer申请
*/
public function reviewer() {
//接受参数
$data = $this->request->post();
$journal_info = $this->journal_obj->where('journal_id', $data['journal'])->find();
$editor_info = $this->user_obj->where('user_id', $journal_info['editor_id'])->find();
// $data['company'] = 'dsadsa';
// $data['country'] = 'china';
// $data['email'] = "dsadsad@126.com";
// $data['field'] = 'dsadsada';
// $data['gender'] = 1;
// $data['introduction'] = 'dsadsads';
// $data['journal'] = 1;
// $data['major'] = 6;
// $data['qualifications'] = "reviewer/20200729/8355df2ee29d8313cf39e1c3b0b6ebd8.rar";
// $data['technical'] = 'Ph.D.';
// $data['username'] = '"wangjinlei11"';
// return json($data);
//组合数据insert
$insert_data['journal_id'] = $data['journal'];
$insert_data['name'] = $data['username'];
$insert_data['introduction'] = $data['introduction'];
$insert_data['email'] = $data['email'];
$insert_data['company'] = $data['company'];
$insert_data['country'] = $data['country'];
$insert_data['major'] = $data['major'];
$insert_data['technical'] = $data['technical'];
$insert_data['field'] = $data['field'];
$insert_data['gender'] = $data['gender'];
$insert_data['qualifications'] = $data['qualifications'];
$insert_data['ctime'] = time();
$res = $this->user_reviewer_obj->insertGetId($insert_data);
if ($res > 0) {
//发送email-》编辑
$tt = 'Dear editor,<br>';
$tt .= 'Please check the new reviewer application.';
sendEmail($editor_info['email'], $journal_info['title'], $journal_info['title'], $tt, $journal_info['email'], $journal_info['epassword']);
//发送消息信息--编辑
$journal_res = $this->journal_obj->where('journal_id', $data['journal'])->find();
add_usermsg($journal_res['editor_id'], '新增审稿人申请,申请人(' . $data['username'] . ')', '/reviewerApplyDetail?id=' . $res);
return json(['code' => 0]);
} else {
return json(['code' => 1, 'msg' => 'reviewer submit error']);
}
}
/**
* 作者申请成为审稿人
*/
public function becameReviewer() {
//接受参数,查询参数
$data = $this->request->post();
//
// return json($data);
// $data['company'] = 'sssssssssssssssssssss';
// $data['country'] = 'China';
// $data['field'] = 'asdsadsa';
// $data['gender'] = 1;
// $data['introduction'] = 'dsds';
// $data['journal'] = 1;
// $data['major'] = 6;
// $data['qualifications'] = "reviewer/20200821/8e291c09e53fbbe12541563d59790464.rar";
// $data['technical'] = 'Ph.D.';
// $data['username'] = 'wangjinlei';
$user_info = $this->user_obj->where('account', $data['username'])->find();
$journal_info = $this->journal_obj->where('journal_id', $data['journal'])->find();
$editor_info = $this->user_obj->where('user_id', $journal_info['editor_id'])->find();
//存储数据
$insert['journal_id'] = $data['journal'];
$insert['name'] = $data['username'];
$insert['gender'] = $data['gender'];
$insert['technical'] = $data['technical'];
$insert['country'] = $data['country'];
$insert['introduction'] = $data['introduction'];
$insert['email'] = $user_info['email'];
$insert['company'] = $data['company'];
$insert['major'] = $data['major'];
$insert['field'] = $data['field'];
$insert['qualifications'] = $data['qualifications'];
$insert['ctime'] = time();
$res = $this->user_reviewer_obj->insertGetId($insert);
//发送email-》编辑
$tt = 'Dear editor,<br>';
$tt .= 'Please check the new reviewer application.';
sendEmail($editor_info['email'], $journal_info['title'], $journal_info['title'], $tt, $journal_info['email'], $journal_info['epassword']);
//发送消息信息--编辑
$journal_res = $this->journal_obj->where('journal_id', $data['journal'])->find();
add_usermsg($journal_res['editor_id'], 'New reviewer apply' . $data['username'] . ')', '/reviewerApplyDetail?id=' . $res);
return json(['code' => 0]);
}
/**
* 获取城市
*/
public function getCountrys() {
$res = $this->country_obj->order('en_name')->select();
return json($res);
}
/**
* 导入reviewer
*/
public function reviewerImport() {
//接收信息
$data = $this->request->post();
// $data['journal'] = 7;
// $data['url'] = 'reviewer/import/20200826/a8c03d7f9ac899c0a590ff26663402f2.xlsx';
$journal = $data['journal'];
$journal_info = $this->journal_obj->where('journal_id', $journal)->find();
//读取excel
$path = ROOT_PATH . 'public' . DS . $data['url'];
$frag = self::readExcel($path);
//check数据分开存储
$su_data = [];
$er_data = [];
foreach ($frag as $v) {
//验证数据完整性
if ($v['username'] == '' || $v['email'] == '' || $v['realname'] == '' || $v['major'] == '' || $v['username'] == null || $v['email'] == null || $v['realname'] == null || $v['major'] == null) {
$er_data[] = [
'username' => $v['username'],
'realname' => $v['realname'],
'email' => $v['email'],
'reason' => 'Missing data'
];
continue;
}
//验证major
$major = self::get_major($v['major']);
if ($major === null) {
$er_data[] = [
'username' => $v['username'],
'realname' => $v['realname'],
'email' => $v['email'],
'reason' => 'major is error'
];
continue;
}
//验证是否存在此用户并且存在对应关系
$this_reviewer = self::get_username($v['username']);
$mme = self::get_userByEmail($v['email']);
if ($this_reviewer == null && $mme != null) {
$er_data[] = [
'username' => $v['username'],
'realname' => $v['realname'],
'email' => $v['email'],
'reason' => 'Email occupied,and username is:'.$mme['account']
];
continue;
}
if ($this_reviewer != null && $this_reviewer['type'] == 2) {
$er_data[] = [
'username' => $v['username'],
'realname' => $v['realname'],
'email' => $v['email'],
'reason' => "Editor can't become reviewer"
];
continue;
}
if ($this_reviewer != null && self::get_retojo($this_reviewer['user_id'], $journal) != null) {
$su_data[] = [
'username' => $v['username'],
'realname' => $v['realname'],
'email' => $v['email'],
'reason' => 'success(has register)'
];
continue;
}
//执行存储,按实际逻辑存储
$cache_id = 0;
if ($this_reviewer == null) {
//添加user主体基本信息
$cache_reviewer['account'] = trim($v['username']);
$cache_reviewer['password'] = md5('123456qwe');
$cache_reviewer['email'] = $v['email'];
$cache_reviewer['realname'] = $v['realname'];
$cache_reviewer['is_reviewer'] = 1;
$cache_reviewer['ctime'] = time();
$cache_id = $this->user_obj->insertGetId($cache_reviewer);
//添加reviewer_info信息
$cache_insert_info['reviewer_id'] = $cache_id;
$cache_insert_info['gender'] = $v['gender'] == '女' ? 2 : 1;
$cache_insert_info['technical'] = $v['technical'] == null ? '' : $v['technical'];
$cache_insert_info['country'] = $v['country'] == null ? '' : $v['country'];
$cache_insert_info['introduction'] = $v['introduction'] == null ? '' : $v['introduction'];
$cache_insert_info['company'] = $v['company'] == null ? '' : $v['company'];
$cache_insert_info['major'] = $major['major_id'];
$cache_insert_info['field'] = $v['field'] == null ? '' : $v['field'];
$this->user_reviewer_info_obj->insert($cache_insert_info);
} else if ($this_reviewer != null && $this_reviewer['is_reviewer'] == 0) {
$this->user_obj->where('user_id', $this_reviewer['user_id'])->update(['is_reviewer' => 1]);
//添加reviewer_info信息
$cache_insert_info['reviewer_id'] = $this_reviewer['user_id'];
$cache_insert_info['gender'] = $v['gender'] == '女' ? 2 : 1;
$cache_insert_info['technical'] = $v['technical'] == null ? '' : $v['technical'];
$cache_insert_info['country'] = $v['country'] == null ? '' : $v['country'];
$cache_insert_info['introduction'] = $v['introduction'] == null ? '' : $v['introduction'];
$cache_insert_info['company'] = $v['company'] == null ? '' : $v['company'];
$cache_insert_info['major'] = $major['major_id'];
$cache_insert_info['field'] = $v['field'] == null ? '' : $v['field'];
$this->user_reviewer_info_obj->insert($cache_insert_info);
}
//存储关系表信息
$cache_insert_rtj['reviewer_id'] = $this_reviewer == null ? $cache_id : $this_reviewer['user_id'];
$cache_insert_rtj['journal_id'] = $journal;
$cache_insert_rtj['account'] = $v['username'];
$cache_insert_rtj['journal_title'] = $journal_info['title'];
$cache_insert_rtj['ctime'] = time();
$this->reviewer_to_journal_obj->insert($cache_insert_rtj);
//增加成功信息
$su_data[] = [
'username' => $v['username'],
'realname' => $v['realname'],
'email' => $v['email'],
'reason' => 'success'
];
//发送邮件提醒审稿人
$tt = 'Dear Reviewer,<br>';
$tt .= 'In order to provide a better online experience for both authors and readers, the submission system was changed to new.<br>';
$tt .= 'Website was closed between 18:00 Aug. 2, 2020 to 24:00 Aug. 2, 2020 Beijing time.<br>';
$tt .= 'You could log in with your account in submission.tmrjournals.com .<br>';
$tt .= 'Your username:'.$v['username'].'<br>';
$tt .= 'Your password: 123456qwe (you could change your password in the system by yourself later.)<br>';
$tt .= 'Thank you so much for your kindly support.<br><br>';
$tt .= $journal_info['title'].'<br>';
$tt .= date('Y-m-d');
$maidata['email'] = $v['email'];
$maidata['title'] = $journal_info['title'];
$maidata['content'] = $tt;
$maidata['tmail'] = $journal_info['email'];
$maidata['tpassword'] = $journal_info['epassword'];
Queue::push( 'app\api\job\mail@fire' , $maidata , "tmail" );
}
return json(['sudata' => $su_data, 'erdata' => $er_data]);
}
/**
* 获取领域分类
*/
public function getMajor(){
$majors = $this->reviewer_major_obj->where('pid',0)->select();
return json(['code'=>0,'data'=>$majors]);
}
public function getMajors(){
$rid = $this->request->post('rid');
$reviewer_info = $this->user_reviewer_info_obj->where('reviewer_id',$rid)->find();
$majors = $this->reviewer_major_obj->where('pid',0)->select();
$cmajors = $this->reviewer_major_obj->where('pid',$reviewer_info['major'])->select();
return json(['code'=>0,'data'=>$majors,'cmajors'=>$cmajors]);
}
/**
* 获取major子项目
*/
public function majorChild(){
$majorid = $this->request->post('majorid');
$ds = $this->reviewer_major_obj->where('pid',$majorid)->select();
return json(['code'=>0,'data'=>$ds]);
}
/**
* 获取期刊除了已申请过的期刊
*/
public function getJournalchu() {
$data = $this->request->post();
$journals = $this->reviewer_to_journal_obj->where('account', $data['username'])->column('journal_id');
$res = $this->journal_obj->where('journal_id', 'not in', $journals)->select();
return json($res);
}
/**
* 获取excel数据
*/
public function getExcelData() {
//接收数据
$data = $this->request->post();
$path = ROOT_PATH . 'public' . DS . $data['url'];
$frag = self::readExcel($path);
return json($frag);
}
/**
* 验证用户名是否存在
*/
private function get_username($username) {
return $this->user_obj->where('account', $username)->find();
}
/**
* 验证major是否合法
*/
private function get_major($major) {
return $this->reviewer_major_obj->where('title', $major)->find();
}
/**
* 获取对应关系
*/
private function get_retojo($reviewer_id, $journal_id) {
return $this->reviewer_to_journal_obj->where('reviewer_id', $reviewer_id)->where('journal_id', $journal_id)->find();
}
/**
* 获取此邮箱注册用户
*/
private function get_userByEmail($email) {
return $this->user_obj->where('email', $email)->find();
}
/**
* 读取excel数据
*/
private function readExcel($path) {
$extension = substr($path, strrpos($path, '.') + 1);
vendor("PHPExcel.PHPExcel");
if ($extension == 'xlsx') {
$objReader = new \PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load($path);
} else if ($extension == 'xls') {
$objReader = new \PHPExcel_Reader_Excel5();
$objPHPExcel = $objReader->load($path);
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$frag = [];
for ($i = 2; $i <= $highestRow; $i++) {
$aa['username'] = $objPHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();
$aa['realname'] = $objPHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();
$aa['gender'] = $objPHPExcel->getActiveSheet()->getCell("C" . $i)->getValue();
$aa['email'] = $objPHPExcel->getActiveSheet()->getCell("D" . $i)->getValue();
$aa['technical'] = $objPHPExcel->getActiveSheet()->getCell("E" . $i)->getValue();
$aa['country'] = $objPHPExcel->getActiveSheet()->getCell("F" . $i)->getValue();
$aa['company'] = $objPHPExcel->getActiveSheet()->getCell("G" . $i)->getValue();
$aa['major'] = $objPHPExcel->getActiveSheet()->getCell("H" . $i)->getValue();
$aa['field'] = $objPHPExcel->getActiveSheet()->getCell("I" . $i)->getValue();
$aa['introduction'] = $objPHPExcel->getActiveSheet()->getCell("J" . $i)->getValue();
$aa['qualifications'] = $objPHPExcel->getActiveSheet()->getCell("K" . $i)->getValue();
$frag[] = $aa;
}
return $frag;
}
/**
* 接收文件
*/
public function up_file() {
$file = request()->file('qualifications');
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()]);
}
}
}
/**
* 接收导入文件
* @return type
*/
public function up_import() {
$file = request()->file('importExcel');
if ($file) {
$info = $file->move(ROOT_PATH . 'public' . DS . 'reviewer' . DS . 'import');
if ($info) {
return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
} else {
return json(['code' => 1, 'msg' => $file->getError()]);
}
}
}
public function info(){
phpinfo();
}
public function testmail() {
$jobHandlerClassName = 'app\api\job\mail@fire';
$jobQueueName = "mail";
$data = [];
// $data['email'] = '751475802@qq.com';
$data['email'] = '13662001490@126.com';
$data['title'] = 'ttttssdsadsadsadasdss';
$tt = 'Dear Reviewer,<br>';
$tt .= 'In order to provide a better online experience for both authors and readers, the submission system was changed to new.<br>';
$tt .= 'Website was closed between 18:00 Aug. 2, 2020 to 24:00 Aug. 2, 2020 Beijing time.<br>';
$tt .= 'You could log in with your account in submission.tmrjournals.com .<br>';
$tt .= 'Your username:aaasssss<br>';
$tt .= 'Your password: 123456qwe (you could change your password in the system by yourself later.)<br>';
$tt .= 'Thank you so much for your kindly support.<br><br>';
$tt .= 'tmr<br>';
$tt .= date('Y-m-d');
$data['content'] = $tt;
$data['tmail'] = 'ghr@tmrjournals.com';
$data['tpassword'] = 'Wu999999gh';
$isPushed = Queue::push( $jobHandlerClassName , $data , $jobQueueName );
echo '<pre>';
var_dump($isPushed);
echo '</pre>';
die;
// sendEmail($v['email'], $journal_info['title'], $journal_info['title'], $tt, $journal_info['email'], $journal_info['epassword']);
}
}