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');
$this->article_reviewer_obj = Db::name('article_reviewer');
}
public function YLtest(){
$data = $this->request->post();
return jsonSuccess(['mycode'=>md5($data['mmm'])]);
}
// public function retest(){
// $frag = [];
// $emails = $this->user_obj->where("state",0)->group("email")->having("count(*)>1")->column("email");
// $list = $this->user_obj->where("email","in",$emails)->select();
//
//
// foreach ($list as $v){
// $frag[$v['email']][] = $v;
// }
//
// foreach ($frag as $val){
// $this->aaaaa($val);
// }
// foreach ($list as $v){
// $c1 = $this->article_obj->where('user_id',$v['user_id'])->find();
// $c2 = $this->reviewer_to_journal_obj->where('reviewer_id',$v['user_id'])->where('state',0)->find();
// if($c1==null&&$c2==null){
// $frag[] = $v;
// }
// }
// foreach ($frag as $val){
// $this->user_obj->where('user_id',$val['user_id'])->delete();
// }
// }
// private function aaaaa($arr){
// $a = $arr[0];
// $b = $arr[1];
// $this->article_obj->where('user_id',$b['user_id'])->update(['user_id'=>$a['user_id']]);
// $this->article_reviewer_obj->where('reviewer_id',$b['user_id'])->update(['reviewer_id'=>$a['user_id']]);
// $this->reviewer_to_journal_obj->where("reviewer_id",$b['user_id'])->update(['reviewer_id'=>$a['user_id'],'account'=>$a['account']]);
// $this->user_reviewer_info_obj->where('reviewer_id',$b['user_id'])->delete();
// $this->user_obj->where('user_id',$b['user_id'])->delete();
// }
/**
* 获取编辑人员列表(分页)
*/
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, 6]);
} 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]);
}
/**
* @title 上传reviewer申请
* @description 上传reviewer申请
* @author wangjinlei
* @url /api/Admin/reviewer
* @method POST
*
* @param name:company type:String require:1 desc:单位
* @param name:country type:String require:1 desc:国家
* @param name:email type:String require:1 desc:邮箱
* @param name:field type:String require:1 desc:领域描述
* @param name:gender type:String require:1 desc:1男2女
* @param name:introduction type:String require:1 desc:简介
* @param name:journal type:int require:1 desc:journal_id
* @param name:major type:int require:1 desc:major_id
* @param name:qualifications type:String require:1 desc:cv地址
* @param name:technical type:String require:1 desc:职称
* @param name:username type:String require:1 desc:申请者用户名
*
*/
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();
//组合数据,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,
';
$tt .= 'Please check the new reviewer application.';
$sendUser=[
'title'=>$journal_info['title'], // 邮件标题
'content'=>$tt,//邮件内容
'user_id'=>$editor_info['user_id'], //收件人ID
'email'=>$editor_info['email'],// 收件人邮箱
'journal_id'=>$journal_info['journal_id'], // 期刊ID
'sendEmail'=>$journal_info['email'], // 期刊邮箱
'sendPassword'=>$journal_info['epassword'], // 期刊密码
'from_name'=>$journal_info['title']
];
// Queue::push('app\api\job\domail@fire',$sendUser,'domail');
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();
$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,
';
$tt .= 'Please check the new reviewer application.';
$sendUser=[
'title'=>$journal_info['title'], // 邮件标题
'content'=>$tt,//邮件内容
'user_id'=>$editor_info['user_id'], //收件人ID
'email'=>$editor_info['email'],// 收件人邮箱
'journal_id'=>$journal_info['journal_id'], // 期刊ID
'sendEmail'=>$journal_info['email'], // 期刊邮箱
'sendPassword'=>$journal_info['epassword'], // 期刊密码
'from_name'=>$journal_info['title']
];
// Queue::push('app\api\job\domail@fire',$sendUser,'domail');
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() {
die("server stoped");
//接收信息
$data = $this->request->post();
// $data['journal'] = 5;
// $data['url'] = 'reviewer/import/20210819/beb6de5c69e4878d995fd8de192d17af.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']==''){
continue;
}
//验证数据完整性
if ($v['username'] == '' || $v['email'] == '' || $v['realname'] == '' || $v['major'] == '' || $v['username'] == null || $v['email'] == null || $v['realname'] == null || $v['major'] == null) {
$er_data[] = [
'username' => trim($v['username']),
'realname' => trim($v['realname']),
'email' => $v['email'],
'reason' => 'Missing data'
];
continue;
}
//验证major
$major = self::get_major($v['major']);
if ($major === null) {
$er_data[] = [
'username' => trim($v['username']),
'realname' => trim($v['realname']),
'email' => $v['email'],
'reason' => 'major is error'
];
continue;
}
//验证是否存在此用户并且存在对应关系
$this_reviewer = self::get_username(trim($v['username']));
$mme = self::get_userByEmail(trim($v['email']));
if ($this_reviewer == null && $mme != null) {
$er_data[] = [
'username' => trim($v['username']),
'realname' => trim($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' => trim($v['username']),
'realname' => trim($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'] = trim($v['email']);
$cache_reviewer['realname'] = trim($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'] = trim($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' => trim($v['username']),
'realname' => trim($v['realname']),
'email' => $v['email'],
'reason' => 'success'
];
//发送邮件提醒审稿人
$content = "Thank you for registering as a " . $journal_info['title'] . " reviewer
". "At present, you have passed our examination
";
$content .= 'Submission System
';
$content .= '
username:' . trim($v['username']) . '
'; $content .= 'Original Password: 123456qwe
';//$has_res ? '' : 'password:123456qwe
'; $maidata['email'] = $v['email']; $maidata['title'] = $journal_info['title']; $maidata['content'] = $content; $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)->where('state',0)->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(); } }