Files
tougao/application/api/controller/Super.php
wangjinlei 0a6126543b 1
2024-08-12 15:51:30 +08:00

372 lines
14 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
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\Validate;
use think\Db;
class Super extends Controller {
protected $article_obj = '';
protected $user_obj = '';
protected $user_act_obj = '';
protected $journal_obj = '';
protected $user_log_obj = '';
protected $reviewer_major_obj = '';
protected $reviewer_to_journal_obj = '';
protected $article_msg_obj = '';
protected $article_file_obj = '';
protected $article_reviewer_obj = '';
protected $article_author_obj = '';
protected $board_to_journal = '';
protected $article_transfer_obj = '';
protected $staff_obj = '';
protected $staff_level_obj = '';
protected $staff_log_obj = '';
protected $staff_to_journal_obj = '';
public function __construct(\think\Request $request = null) {
parent::__construct($request);
$this->user_obj = Db::name('user');
$this->user_act_obj = Db::name('user_act');
$this->article_obj = Db::name('article');
$this->journal_obj = Db::name('journal');
$this->user_log_obj = Db::name('user_log');
$this->reviewer_major_obj = Db::name('reviewer_major');
$this->reviewer_to_journal_obj = Db::name('reviewer_to_journal');
$this->article_msg_obj = Db::name('article_msg');
$this->article_file_obj = Db::name('article_file');
$this->article_reviewer_obj = Db::name('article_reviewer');
$this->article_author_obj = Db::name('article_author');
$this->board_to_journal = Db::name("board_to_journal");
$this->article_transfer_obj = Db::name('article_transfer');
$this->staff_obj = Db::name('staff');
$this->staff_level_obj = Db::name('staff_level');
$this->staff_log_obj = Db::name('staff_log');
$this->staff_to_journal_obj = Db::name('staff_to_journal');
}
public function main() {
$data = $this->request->post();
$start_time = strtotime($data['start']);
$end_time = strtotime($data['end'].' 23:59:59');
$list = $this->journal_obj->where('state',0)->select();
foreach ($list as $k => $v){
$list[$k]['SGRSL'] = $this->getSGRSL($v['journal_id']);
$list[$k]['LYL'] = $this->getLYL($v['journal_id'],$start_time,$end_time);
$list[$k]['CC'] = $this->getCC($v['journal_id'],$start_time,$end_time);
$list[$k]['WS'] = $this->getWS($v['journal_id'],$start_time,$end_time);
$list[$k]['SJ'] = $this->getSJ($v['journal_id'],$start_time,$end_time);
$list[$k]['JST'] = $this->getJST($v['journal_id'],$start_time,$end_time);
}
return json($list);
}
/**编辑的期刊情况表
* @return void
*/
public function editorJournal(){
$data = $this->request->post();
$rule = new Validate([
"editor_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$start_time = strtotime(date("Y")."-01-01");
$end_time = strtotime(date("Y")."-12-31 23:59:59");
$q_start_time = strtotime((date("Y")-1)."-01-01");
$q_end_time = strtotime((date("Y")-1)."-12-31 23:59:59");
$journal_list = $this->journal_obj->field("journal_id,title,issn,abbr")->where("editor_id",$data['editor_id'])->select();
$gjh_url = "http://journalapi.tmrjournals.com/public/index.php/super/Publish/getGJHByIssn";
foreach ($journal_list as $k => $v){
$journal_list[$k]["board"] = $this->getBoardData($v['journal_id']);
$sj_r = $this->getSJ($v['journal_id'],$start_time,$end_time);
$lyl_r = $this->getLYL($v['journal_id'],$start_time,$end_time);
$year["mq"] = $sj_r['mq'];
$year["zc"] = $sj_r['zc'];
$year["zr"] = $sj_r['zr'];
$year['lyl'] = $lyl_r;
$gjh = object_to_array(json_decode(myPost($gjh_url,["year"=>date("Y"),"issn"=>$v['issn']])));
$year['gjh'] = $gjh['data']['result'];
$journal_list[$k]["year"] = $year;
$sj_rq = $this->getSJ($v['journal_id'],$q_start_time,$q_end_time);
$lyl_rq = $this->getLYL($v['journal_id'],$q_start_time,$q_end_time);
$yearq["mq"] = $sj_rq['mq'];
$yearq["zc"] = $sj_rq['zc'];
$yearq["zr"] = $sj_rq['zr'];
$yearq['lyl'] = $lyl_rq;
$gjhq = object_to_array(json_decode(myPost($gjh_url,["year"=>date("Y")-1,"issn"=>$v['issn']])));
$yearq['gjh'] = $gjhq['data']['result'];
$journal_list[$k]['p_year'] = $yearq;
}
$re['list'] = $journal_list;
return jsonSuccess($re);
}
public function getAllArticle(){
$data = $this->request->post();
$list = $this->journal_obj->where('state',0)->select();
foreach ($list as $k => $v){
$list[$k]['SJ'] = $this->article_obj
->where('journal_id',$v['journal_id'])
->where('ctime','>',$data['start'])
->where('ctime','<=',$data['end'])
->count();
}
return jsonSuccess($list);
}
/**
* 获取查重文章
*/
public function getCCArticles(){
$data = $this->request->post();
$journal_info = $this->journal_obj->where('issn',$data['issn'])->find();
$where['journal_id'] = $journal_info['journal_id'];
$where['ctime'] = [['>', strtotime($data['start'])],['<', strtotime($data['end'].' 23:59:59')]];
$where['state'] = 5;
if($data['type']=='low'){
$where['repetition'] = ['<=',20];
}elseif($data['type']=='low1'){
$where['repetition'] = [['>',20],['<=',30]];
}elseif($data['type']=='mid'){
$where['repetition'] = [['>',30],['<=',50]];
}else{
$where['repetition'] = ['>',50];
}
$list = $this->article_obj->where($where)->select();
$re['articles'] = $list;
return jsonSuccess($re);
}
private function getBoardData($journal_id){
$list = $this->board_to_journal->field("t_board_to_journal.*,t_user_reviewer_info.country")
->join("t_user_reviewer_info","t_user_reviewer_info.reviewer_id = t_board_to_journal.user_id","left")
->where("t_board_to_journal.journal_id",$journal_id)
->where("t_board_to_journal.state",0)
->select();
$flag = [];
$flag['all'] = count($list);
$f = [];
foreach ($list as $v){
if(isset($f[$v['country']])){
$f[$v['country']]++;
}else{
$f[$v['country']] = 1;
}
}
$flag['country'] = $f;
return $flag;
}
/**
* 获取审稿人数量
*/
private function getSGRSL($journal_id){
$res = $this->reviewer_to_journal_obj->where('journal_id',$journal_id)->where('state',0)->select();
return count($res);
}
/**
* 获取录用率
*/
private function getLYL($journalId,$start_time,$end_time){
$res = $this->article_obj
->field('state,count(state) as num')
->where('journal_id',$journalId)
->where('ctime','>',$start_time)
->where('ctime','<',$end_time)
->where('state','in','3,5')
->group('state')
->select();
//获取全部总数
$all = $this->article_obj
->where('journal_id',$journalId)
->where('ctime','>',$start_time)
->where('ctime','<',$end_time)
->count();
$js = 0;
$jj = 0;
foreach ( $res as $v){
if($v['state']==3){
$jj = $v['num'];
} else {
$js = $v['num'];
}
}
return $all==0?0:$js/$all;
}
private function getJST($journal_id,$start_time,$end_time){
$list = $this->article_obj->where("journal_id",$journal_id)
->where('rtime','>',$start_time)
->where('rtime','<=',$end_time)
->select();
$f = 0;
foreach ($list as $v){
$f += ($v['rtime']-$v["ctime"]);
}
$list1 = $this->article_obj->where("journal_id",$journal_id)
->where('rstime','>',$start_time)
->where('rstime','<=',$end_time)
->select();
foreach ($list1 as $v){
$f += ($v['rstime']-$v["ctime"]);
}
$frag = count($list)==0?0:intval(($f/(count($list) + count($list1)))/(24*60*60));
return $frag;
}
/**
* 获取查重异常
*/
private function getCC($journalId,$start_time,$end_time){
$res = $this->article_obj
->where('journal_id',$journalId)
->where('ctime','>=',$start_time)
->where('ctime','<=',$end_time)
->where('state',5)
->select();
$low = 0;
$low1 = 0;
$mid = 0;
$high = 0;
foreach ($res as $v){
if($v['repetition']<=20){
$low++;
}elseif($v['repetition']>20 && $v['repetition']<=30){
$low1++;
}elseif($v['repetition']>30 && $v['repetition']<=50){
$mid++;
}else{
$high++;
}
}
$re['low'] = $low;
$re['low1'] = $low1;
$re['mid'] = $mid;
$re['high'] = $high;
return $re;
}
/**
* 获取外审异常
*/
private function getWS($journalId,$start_time,$end_time){
$res = $this->article_obj
->where('journal_id',$journalId)
->where('state',5)
->where('type','<>','N')
->where('type','<>','T')
->where('ctime','>',$start_time)
->where('ctime','<',$end_time)
->select();
$np =0;
foreach ( $res as $v){
$ca = $this->article_reviewer_obj->where('article_id',$v['article_id'])->count();
if($ca<2){
$np++;
}
}
$re['all'] = count($res);
$re['np'] = $np;
return $re;
}
// public function company(){
// $file = "d://company.xlsx";
// $res = $this->readExcel($file);
// $frag = [];
// foreach($res as $v){
// $ca['title'] = trim($v);
// $ca['ctime'] = time();
// $ca['state'] = 0;
// $frag[] = $ca;
// }
// Db::name('company_top')->insertAll($frag);
// }
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 = 3; $i <= $highestRow; $i++) {
// $aa['username'] = $objPHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();
// $aa['has'] = '未出证';
// if($aa['username']==''){
// continue;
// }
$aa = $objPHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();
$frag[] = $aa;
}
return $frag;
}
/**
* 获取时间异常
*/
private function getSJ($journalId,$start_time,$end_time){
//文章提交至接收超过48小时
$res['t48'] = $this->article_obj
->where('ctime','>',$start_time)
->where('ctime','<',$end_time)
->where('journal_id',$journalId)
->where('state',0)
->count();
//文章接受时间小于15天
$res['j15'] = $this->article_obj
->where('journal_id',$journalId)
->where('ctime','>',$start_time)
->where('ctime','<',$end_time)
->where('state',5)
->where('rtime','>',0)
->where('(rtime-ctime) <'.(3600*24*15))
->count();
//文章接收时间大于120天
$res['j120'] = $this->article_obj
->where('journal_id',$journalId)
->where('state',5)
->where('ctime','>',$start_time)
->where('ctime','<',$end_time)
->where('rtime','>',0)
->where('(rtime-ctime) > '.(3600*24*120))
->count();
//with editor时间超过三天预留
$journal_info = $this->journal_obj->where('journal_id',$journalId)->find();
$zc_num = $this->article_obj->where('accept_sn','like',$journal_info['abbr'].'%')->where('journal_id','<>',$journalId)->where('ctime','>',$start_time)->where('ctime','<',$end_time)->count();
$zr_num = $this->article_obj->where('accept_sn','not like',$journal_info['abbr'].'%')->where('journal_id',$journalId)->where('ctime','>',$start_time)->where('ctime','<',$end_time)->count();
//获取全部总数
$mq_num = $this->article_obj
->where('journal_id',$journalId)
->where('ctime','>',$start_time)
->where('ctime','<',$end_time)
->count();
$res['mq'] = $mq_num;//文章总数
$res['zc'] = $zc_num;//转出文章数
$res['zr'] = $zr_num;//转入文章数
return $res;
}
}