Files
tougao/application/api/controller/Special.php
wangjinlei 1ee952836d 1
2022-04-15 18:17:29 +08:00

446 lines
17 KiB
PHP

<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use think\Env;
use think\Queue;
use think\Validate;
class Special extends Controller {
protected $user_obj = '';
protected $captcha_obj = '';
protected $user_act_obj = '';
protected $admin_obj = '';
protected $article_obj = '';
protected $user_reviewer_obj = '';
protected $journal_obj = '';
protected $country_obj = '';
protected $article_author_obj = '';
protected $reviewer_major_obj = '';
protected $reviewer_to_journal_obj = '';
protected $user_reviewer_info_obj = '';
protected $user_msg_obj = '';
protected $article_file_obj = '';
protected $user_log_obj = '';
protected $user_black_obj = '';
protected $user_to_special_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->article_obj = Db::name('article');
$this->user_reviewer_obj = Db::name('user_reviewer_apply');
$this->journal_obj = Db::name('journal');
$this->reviewer_major_obj = Db::name('reviewer_major');
$this->reviewer_to_journal_obj = Db::name('reviewer_to_journal');
$this->user_reviewer_info_obj = Db::name('user_reviewer_info');
$this->user_msg_obj = Db::name('user_msg');
$this->country_obj = Db::name('country');
$this->article_author_obj = Db::name('article_author');
$this->article_file_obj = Db::name('article_file');
$this->user_log_obj = Db::name('user_log');
$this->user_black_obj = Db::name('user_black');
$this->user_to_special_obj = Db::name('user_to_special');
}
/**
* 注册功能
*/
public function register() {
$data = $this->request->post();
//检测是否用户名和密码已经占用
$account = $data['username'];
$email = $data['email'];
$res_once = $this->user_obj->where("account='$account' or email = '$email'")->find();
if ($res_once != null) {
return json('existence');
}
//验证验证码
// if (!$this->my_checkcaptcha($data['code'], $data['random_num'])) {
// return json('errcaptcha');
// }
//存入数据
$inser_data['account'] = trim($account);
$inser_data['password'] = md5($data['password']);
$inser_data['email'] = $email;
$inser_data['phone'] = $data['phone'];
$inser_data['realname'] = $data['realname'];
$inser_data['ctime'] = time();
$id = $this->user_obj->insertGetId($inser_data);
//发送注册成功邮件
$tt = "Dear author,You have successfully registered<br><br>";
$content = $tt . '<p>Username:' . $account . '<br>Password:' . $data['password'] . '</p>';
$sendUser=[
'title'=>'Dear ' . $data['realname'], // 邮件标题
'content'=>$content,//邮件内容
'user_id'=>$id, //收件人ID
'email'=>$email,// 收件人邮箱
'journal_id'=>0, // 期刊ID
'sendEmail'=>Env::get('email.send_email'), // 期刊邮箱
'sendPassword'=>Env::get('email.send_email_password'), // 期刊密码
'from_name'=>'TMR'
];
// Queue::push('app\api\job\domail@fire',$sendUser,'domail');
sendEmail($email, 'Dear ' . $data['realname'], 'TMR', $content);
return json($inser_data);
}
/**
* 登录功能
* @return type
*/
public function checkLogin() {
$data = $this->request->post();
//判断是否管理员登录
if ($data['username'] == 'superadmin' || $data['username'] == 'wuxiongzhi2') {
$where_admin['account'] = $data['username'];
$where_admin['password'] = md5($data['password']);
$admin_info = $this->admin_obj->where($where_admin)->find();
if ($admin_info == null) {
return json(['code' => 1]);
} else {
$up_admin['last_login_time'] = time();
$up_admin['last_login_ip'] = $this->request->ip();
$this->admin_obj->where('admin_id = ' . $admin_info['admin_id'])->update($up_admin);
return json(['code' => 0, 'userinfo' => $admin_info]);
}
} else {//用户登录
// $where['account'] = $data['username'];
// $where['password'] = md5($data['password']);
$user_info = $this->user_obj->where('account|email', trim($data['username']))->where('password', md5($data['password']))->find();
if ($user_info == null) {//登陆失败
return json(['code' => 1]);
}
//黑名单验证
$blackCheck = $this->user_black_obj->where('user_id',$user_info['user_id'])->where('black_state',0)->find();
if($blackCheck){
return jsonError("Your account has been blocked. Please contact the publisher for details: publisher@tmrjournals.com.");
}
$up_data['last_login_time'] = time();
$up_data['last_login_ip'] = $this->request->ip();
$this->user_obj->where('user_id = ' . $user_info['user_id'])->update($up_data);
return json(['code' => 0, 'userinfo' => $user_info]);
}
}
/**
* 获取文章
*/
public function getArticles() {
$data = $this->request->post();
$list = $this->article_obj
->where('special_num', $data['special_id'])
->where('user_id', $data['user_id'])
->where('state', 0)->select();
$re['articles'] = $list;
return json(['code' => 0, 'data' => ['articles' => $re]]);
}
/**
* 获取期刊的专刊列表
*/
public function getSpecialByIssn(){
$data = $this->request->post();
$rule = new Validate([
'journal_issn' => 'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$base_url = Env::get('journal.base_url');
$res = object_to_array(json_decode(myPost($base_url."/master/Special/getSpecialByIssn",['journal_issn'=>$data['journal_issn']])));
$specials = $res['data']['specials'];
foreach($specials as $k => $v){
unset($specials[$k]['journal_id']);
}
$re['specials'] = $specials;
return jsonSuccess($re);
}
/**
* 获取客座审稿人文章列表
*/
public function getSpecialArticles(){
$data = $this->request->post();
$rule = new Validate([
'user_id' => 'require',
'pageIndex' => 'require',
'pageSize' =>'require',
'special_id' => 'require',
'state'=>'require'
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
//构造查询条件
$specialIds = $this->user_to_special_obj->where('user_id',$data['user_id'])->where('uts_state',0)->column('special_id');
$where['t_article.special_num'] = ['in',$specialIds];
if($data['special_id']!=0){
$where['special_num'] = $data['special_id'];
}
if($data['state']>-1){
$where['t_article.state'] = $data['state'];
}
if(isset($data['titleKey'])&&$data['titleKey']!=''){
$where['t_article.title'] = ['like','%'.trim($data['titleKey']).'%'];
}
if(isset($data['sn'])&&$data['sn']!=''){
$where['t_article.accept_sn']=$data['sn'];
}
//分页查询数据
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'];
$res = $this->article_obj
->field('t_article.*,t_journal.title journalname,t_user.email,t_user.realname,t_user.phone')
->join('t_journal', 't_journal.journal_id = t_article.journal_id', 'LEFT')
->join('t_user',"t_user.user_id = t_article.user_id",'left')
->where($where)
->order('article_id desc')
->limit($limit_start, $data['pageSize'])->select();
//添加国家信息
foreach($res as $k => $v){
$cache_author_list = $this->article_author_obj->where('article_id',$v['article_id'])->select();
$cache_country = [];
foreach($cache_author_list as $key => $val){
if($val['country']!=''&&!in_array($val['country'],$cache_country)){
$cache_country[] = $val['country'];
}
}
$res[$k]['countrys'] = $cache_country;
}
$count = $this->article_obj->where($where)->count();
$re['articles'] = $res;
$re['count'] = $count;
return jsonSuccess($re);
}
/**
* 添加专刊文章(作者)
*/
public function addArticle() {
//接受参数,查询信息
$data = $this->request->post();
// $data['authorList'] = [
// [
// 'address'=>'111',
// 'company'=>'111',
// 'country'=>'china',
// 'department'=>'',
// 'email'=>'6541654@qq.com',
// 'firstname'=>'2222222',
// 'isReport'=>'true',
// 'isSuper'=>'false',
// 'lastname'=>'2222222',
// 'title'=>'Ph.D.'
// ],
// [
// 'address'=>'',
// 'company'=>'112221',
// 'country'=>'china',
// 'department'=>'',
// 'email'=>'2254@qq.com',
// 'firstname'=>'22212222',
// 'isReport'=>'false',
// 'isSuper'=>'true',
// 'lastname'=>'2222222',
// 'title'=>'Ph.D.'
// ]
// ];
// $data['abstrart'] = '1111';
// $data['coverLetter'] = '';
// $data['fund'] = '';
// $data['journal_issn'] = '2538-015X';
// $data['keyWords'] = '111,1111,1111';
// $data['title'] = "111";
// $data['major'] = '1';
// $data['cmajor'] = '26';
// $data['type'] = 'A';
// $data['approval'] = 'true';
// $data['username'] = "user1";
// $data['coverLetter'] = '';
// $data['picturesAndTables'] = '';
// $data['totalpage'] = '';
// $data['manuscirpt'] = '20210122/e08e82edcabe5dc9d9409d1947fccc82.png';
$user_res = $this->user_obj->where('account', $data['username'])->find();
$journal_info = $this->journal_obj->where('issn', $data['journal_issn'])->find();
Db::startTrans();
//添加文章基础信息
$inset_data['user_id'] = $user_res['user_id'];
$inset_data['journal_id'] = $journal_info['journal_id'];
$inset_data['editor_id'] = $journal_info['editor_id'];
$inset_data['title'] = $data['title'];
$inset_data['keywords'] = $data['keyWords'];
$inset_data['fund'] = $data['fund'];
$inset_data['special_num'] = $data['special_id'];
$inset_data['special_title'] = $data['special_title'];
$inset_data['accept_sn'] = getArticleSN($journal_info['abbr'], $data['type']);
$inset_data['type'] = $data['type'];
$inset_data['major_id'] = $data['major'];
$inset_data['cmajor_id'] = $data['cmajor'];
$inset_data['approval'] = $data['approval'] == 'true' ? 1 : 0;
$inset_data['abstrart'] = $data['abstrart'];
$inset_data['author_act'] = 1;
$inset_data['ctime'] = time();
$res = $this->article_obj->insertGetId($inset_data);
//上传文章作者信息
$authors = [];
foreach ($data['authorList'] as $v) {
if ($v['firstname'] == '') {
continue;
}
$i['article_id'] = $res;
$i['firstname'] = $v['firstname'];
$i['lastname'] = $v['lastname'];
$i['company'] = $v['company'];
$i['department'] = $v['department'];
$i['author_title'] = $v['title'];
$i['country'] = $v['country'];
$i['email'] = $v['email'];
$i['address'] = $v['address'];
$i['is_super'] = $v['isSuper'] == 'true' ? 1 : 0;
$i['is_report'] = $v['isReport'] == 'true' ? 1 : 0;
$authors[] = $i;
}
$res_author = $this->article_author_obj->insertAll($authors);
//增加转投信息
$transr = true;
// if($data['istransfer']=='true'){
// foreach ($data['checkedjours'] as $val){
// $trans_insert['article_id'] = $res;
// $trans_insert['journal_id'] = $val;
// $trans_insert['ctime'] = time();
// $transr = $transr?$this->article_transfer_obj->insert($trans_insert):false;
// }
// }
//增加articlefile表的信息
$res_file1 = self::save_article_file($res, $user_res['user_id'], $user_res['account'], $data['coverLetter'], 'coverLetter');
$res_file2 = self::save_article_file($res, $user_res['user_id'], $user_res['account'], $data['picturesAndTables'], 'picturesAndTables');
$res_file4 = self::save_article_file($res, $user_res['user_id'], $user_res['account'], $data['totalpage'], 'totalpage');
$res_file3 = self::save_article_file($res, $user_res['user_id'], $user_res['account'], $data['manuscirpt'], 'manuscirpt');
//发送邮件到编辑,提醒有待审文章
$editor_info = $this->user_obj->where('user_id', $journal_info['editor_id'])->find();
$tt = 'Dear editor,<br>';
$tt .= 'Please check the new manuscript in the submission system.';
sendEmail($editor_info['email'], $journal_info['title'], $journal_info['title'], $tt, $journal_info['email'], $journal_info['epassword']);
$sendEditor=[
'title'=>$journal_info['title'], // 邮件标题
'content'=>$tt,//邮件内容
'user_id'=>$journal_info['editor_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',$sendEditor,'domail');
//增加用户操作log
$log_data['user_id'] = $user_res['user_id'];
$log_data['type'] = 0;
$log_data['content'] = $user_res['account'] . "(" . $user_res['realname'] . "),上传了一篇文章:" . $data['title'] . ",上传时间是:" . date('Y-m-d H:i:s', time());
$log_data['ctime'] = time();
$res_log = $this->user_log_obj->insert($log_data);
//增加usermsg
$res_msg = add_usermsg($journal_info['editor_id'], 'New manuscript', '/articleDetailEditor?id=' . $res);
if ($res && $res_author && $transr && $res_file1 && $res_file2 && $res_file3 && $res_file4 && $res_log && $res_msg) {
Db::commit();
return json(['code' => 0]);
} else {
Db::rollback();
return json(['code' => 1]);
}
}
/**
* 上传文章的文件
*/
public function up_file($type) {
$file = request()->file($type);
if ($file) {
$info = $file->move(ROOT_PATH . 'public' . DS . $type);
if ($info) {
return json(['code' => 0, 'upurl' => str_replace("\\", "/", $info->getSaveName())]);
} else {
return json(['code' => 1, 'msg' => $file->getError()]);
}
}
}
/**
* 获取领域分类
*/
public function getMajor() {
$majors = $this->reviewer_major_obj->where('pid', 0)->select();
return json(['code' => 0, 'data' => $majors]);
}
/**
* 获取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 getCountrys() {
$res = $this->country_obj->order('en_name')->select();
return json($res);
}
public function test() {
echo strtotime('2021-1-1');
}
/**
* 存储article文件历史信息
*/
private function save_article_file($article_id, $user_id, $username, $url, $type_name) {
//首先确定数据库里面是否存在此数据
$res = $this->article_file_obj->where(['file_url' => $url])->find();
if ($res) {
return true;
} else if ($type_name == 'picturesAndTables' && $url == '') {
return true;
} else if ($type_name == 'coverLetter' && $url == '') {
return true;
} else if ($type_name == 'totalpage' && $url = '') {
return true;
}
$insert_data['article_id'] = $article_id;
$insert_data['user_id'] = $user_id;
$insert_data['username'] = $username;
$insert_data['file_url'] = $url;
$insert_data['type_name'] = $type_name;
$insert_data['ctime'] = time();
return $this->article_file_obj->insert($insert_data);
}
}