Files
journal/application/super/controller/Publish.php
wangjinlei 5f7f50fe82 20201112
2021-04-08 11:45:18 +08:00

338 lines
12 KiB
PHP

<?php
namespace app\super\controller;
use think\Controller;
use think\Db;
/**
* @title 总监Main接口
* @description 总监Main接口
* @group 总监Main接口
*/
class Publish extends Controller{
// const JURL = 'http://www.tougao.com/api/Article/getArticleForJournal';
const JURL = 'http://api.tmrjournals.com/public/index.php/api/Article/getArticleForJournal';
const TJ_URL = 'http://api.tmrjournals.com/public/index.php/api/Super/main';
const AL_URL = 'http://api.tmrjournals.com/public/index.php/api/Super/getAllArticle';
protected $admin_obj = '';
protected $journal_obj = '';
protected $article_obj = '';
protected $article_author_obj = '';
protected $article_ltai_obj = '';
protected $journal_topic_obj = '';
protected $journal_stage_obj = '';
protected $journal_notices_obj = '';
protected $journal_abs_obj = '';
protected $journal_cfp_obj = '';
protected $journal_line_obj = '';
protected $article_to_topic_obj = '';
protected $article_to_line_obj = '';
protected $journal_paper_obj = '';
protected $journal_paper_art_obj = '';
protected $subscribe_journal_obj = '';
protected $subscribe_topic_obj = '';
protected $super_danger_obj = '';
public function __construct(\think\Request $request = null) {
parent::__construct($request);
$this->admin_obj = Db::name('admin');
$this->journal_obj = Db::name('journal');
$this->article_obj = Db::name('article');
$this->article_author_obj = Db::name('article_author');
$this->article_ltai_obj = Db::name('article_ltai');
$this->journal_topic_obj = Db::name('journal_topic');
$this->journal_stage_obj = Db::name('journal_stage');
$this->journal_notices_obj = Db::name('journal_notices');
$this->journal_abs_obj = Db::name('journal_abstracting');
$this->journal_cfp_obj = Db::name('journal_cfp');
$this->journal_line_obj = Db::name('journal_line');
$this->article_to_topic_obj = Db::name('article_to_topic');
$this->article_to_line_obj = Db::name('article_to_line');
$this->journal_paper_obj = Db::name('journal_paper');
$this->journal_paper_art_obj = Db::name('journal_paper_art');
$this->subscribe_journal_obj = Db::name('subscribe_journal');
$this->subscribe_topic_obj = Db::name('subscribe_topic');
$this->super_danger_obj = Db::name('super_danger');
}
/**
* @title 获取期刊列表
* @description 获取期刊列表
* @author wangjinlei
* @url /super/Publish/getMain
* @method POST
*
* @return journals:期刊信息array#
*/
public function getMain(){
$journals = $this->journal_obj->where('journal_id','<>',17)->where('state',0)->select();
foreach ($journals as $k => $v){
$journals[$k]['mark'] = $this->calMark($v['journal_id']);
$last_stage = $this->journal_stage_obj
->where('journal_id',$v['journal_id'])
->where('is_publish',1)
->where('state',0)
->order('journal_stage_id desc')
->limit(1)
->select();
$stage_now = $last_stage?$last_stage[0]:['issue_date'=>'2020-05-15'];
$ctime = strtotime($stage_now['issue_date']);
$cs = [];
$cs['issn'] = $v['issn'];
$cs['ctime'] = $ctime;
$journals[$k]['last_time'] = $ctime;
$cache_arts = $this->object_to_array(json_decode(myPost(self::JURL,$cs)));
// $journals[$k]['arts'] = $cache_arts['data'];
$count = is_array($cache_arts['data']['articles'])?count($cache_arts['data']['articles']):0;
$journals[$k]['artCount'] = $count;
}
for($i=0;$i<count($journals);$i++){
for($j=$i+1;$j<count($journals);$j++){
if($journals[$i]['mark']['mk']<$journals[$j]['mark']['mk']){
$cac = $journals[$i];
$journals[$i] = $journals[$j];
$journals[$j] = $cac;
}
}
}
$re['journals'] = $journals;
return jsonSuccess($re);
}
/**
* 自动任务存储危险值
*/
public function autoDanger(){
$journals = $this->journal_obj->where('state',0)->select();
foreach ($journals as $k => $v){
$cah_res = $this->calMark($v['journal_id']);
$insert['journal_id'] = $v['journal_id'];
$insert['date'] = date('Ymd');
$insert['danger'] = $cah_res['mk'];
$this->super_danger_obj->insert($insert);
}
}
/**
* @title 获取合规检测
* @description 获取合规检测
* @author wangjinlei
* @url /super/Publish/getTjJournal
* @method POST
*
* @return dates:数据@
* @dates LYL:录用率
* @dates CC:查重
* @dates WS:外审
* @dates SJ:时间
*/
public function getTjJournal(){
$res = myPost(self::TJ_URL);
return $res;
}
/**
* @title 获取质量评估
* @description 获取质量评估
* @author wangjinlei
* @url /super/Publish/getQuality
* @method POST
*
* @return YY:引用数
* @return TGL:投稿量
* @return FWL:发文量
* @return LX:文章类型
* @return GJH:国际化
* @return CK:创刊时间
*/
public function getQuality(){
$journals = $this->journal_obj->where('state',0)->select();
$res = $this->object_to_array(json_decode(myPost(self::AL_URL)));
$r = $res['data'];
$tg = [];
foreach ($r as $val){
$tg[$val['issn']] = $val['SJ'];
}
foreach ($journals as $k => $v){
$journals[$k]['YY'] = $this->article_obj->where('journal_id',$v['journal_id'])->where('state',0)->sum('cited');
$journals[$k]['TGL'] = isset($tg[$v['issn']])?$tg[$v['issn']]:[];
$journals[$k]['FWL'] = $this->getFWL($v['journal_id']);
$journals[$k]['LX'] = $this->getLX($v['journal_id']);
$journals[$k]['GJH'] = $this->getGJH($v['journal_id']);
$journals[$k]['CK'] = $this->getCK($v['journal_id']);
}
return jsonSuccess($journals);
}
/**
* 获取创刊时间
*/
private function getCK($journal_id){
$stage = $this->journal_stage_obj->where('journal_id',$journal_id)->where('state',0)->order('journal_stage_id')->limit(1)->select();
return $stage?$stage[0]['issue_date']:'';
}
/**
* 获取期刊的
*/
private function getFWL($journal_id){
$frag = [];
$frag['all'] = 0;
for($i=2016;$i<= intval(date('Y'));$i++){
$cstages = $this->journal_stage_obj->where('journal_id',$journal_id)->where('stage_year',$i)->where('state',0)->column('journal_stage_id');
$frag[$i] = $this->article_obj->where('journal_stage_id','in',$cstages)->where('state',0)->count();
$frag['all'] += $frag[$i];
}
return $frag;
}
private function getLX($journal_id){
$arts = $this->article_obj->where('journal_id',$journal_id)->where('state',0)->select();
$frag = [];
foreach ($arts as $v){
if(isset($frag[$v['type']])){
$kk = $v['type']==''?'Other':$v['type'];
$frag[$kk]++;
}else{
$kk = $v['type']==''?'Other':$v['type'];
$frag[$kk]=1;
}
}
return $frag;
}
private function getGJH($journal_id){
$arts = $this->article_obj->where('journal_id',$journal_id)->where('state',0)->column('article_id');
$auts = $this->article_author_obj->where('article_id','in',$arts)->where('state',0)->select();
$frag = [];
$frag['list'] = [];
$frag['countrys'] = 0;
foreach($auts as $v){
if(isset($frag['list'][$v['author_country']])){
$frag['list'][$v['author_country']]++;
}else{
$frag['list'][$v['author_country']] = 1;
$frag['countrys']++;
}
}
return $frag;
}
/**
* @title 获取历史危险值
* @description 获取历史危险值
* @author wangjinlei
* @url /super/Publish/getDangerHistory
* @method POST
*
* @return dates:日期数组#
* @return journals:期刊信息array#
*/
public function getDangerHistory(){
$dates = [];
for ($index = 8; $index > 0; $index--) {
$dates[] = date("Ymd",strtotime("-$index week Sunday"));
}
$re['dates'] = $dates;
$journals = $this->journal_obj->where('state',0)->select();
foreach ($journals as $k => $v){
$fr = [];
$cache = $this->super_danger_obj
->where('journal_id',$v['journal_id'])
->where('state',0)
->order('super_danger_id desc')
->limit(8)
->column('danger');
for($in=0;$in<8-count($cache);$in++){
$fr[] = 0;
}
foreach ($cache as $val){
$fr[] = $val;
}
$journals[$k]['ma'] = $fr;
}
$re['journals'] = $journals;
return jsonSuccess($re);
}
public function test(){
echo strtotime('2021-02-24');
}
public function index()
{
echo THINK_VERSION;
}
public function mymy(){
$last_stage = $this->journal_stage_obj
->where('journal_id',22)
->where('is_publish',1)
->where('state',0)
->order('journal_stage_id desc')
->limit(1)
->select();
echo '<pre>';
var_dump($last_stage);
echo '</pre>';
die;
}
/**
* 计算危险指数
*/
private function calMark($journal_id){
$journal_info = $this->journal_obj->where('journal_id',$journal_id)->find();
$stages = $this->journal_stage_obj->where('journal_id',$journal_id)->where('is_publish',0)->where('state',0)->column('journal_stage_id');
$count = $this->article_obj->where('journal_stage_id','in',$stages)
->where('state',0)
->count();
$last_stage = $this->journal_stage_obj
->where('journal_id',$journal_id)
->where('is_publish',1)
->where('state',0)
->order('journal_stage_id desc')
->limit(1)
->select();
$stage_now = $last_stage?$last_stage[0]:['issue_date'=>'2020-05-15'];
$cday = intval((time()-strtotime($stage_now['issue_date']))/(3600*24));
$cycle = $journal_info['cycle']==0?2:$journal_info['cycle'];
$art_num = $journal_info['art_num']==0?5:$journal_info['art_num'];
$frag = [];
$frag['count'] = $count;
$frag['sy'] = $cycle*30 - $cday;
$frag['ntime'] = strtotime($stage_now['issue_date'])+($cycle*30*3600*24);
if($cday>($cycle*30)){
$frag['mk'] = 100;
return $frag;
}
$lart = intval($cday*$art_num/($cycle*30));
if($count>=$lart){
$frag['mk'] = 0;
}else{
$frag['mk'] = intval(($lart - $count)*100/$art_num);
}
return $frag;
}
public function object_to_array($obj){
$_arr=is_object($obj)?get_object_vars($obj):$obj;
$arr = null;
foreach($_arr as $key=>$val){
$val=(is_array($val))||is_object($val)?$this->object_to_array($val):$val;
$arr[$key]=$val;
}
return $arr;
}
}