Files
journal/application/api/controller/Article.php
wangjinlei c981ce89b2 20201112
2020-12-17 11:48:04 +08:00

228 lines
9.4 KiB
PHP

<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
/**
* @title 文章web接口
* @description 文章web相关操作
* @group 文章web相关
*/
class Article extends Controller{
//put your code here
protected $admin_obj = '';
protected $journal_obj = '';
protected $article_obj = '';
protected $article_author_obj = '';
protected $article_organ_obj = '';
protected $article_author_to_organ_obj = '';
protected $journal_topic_obj = '';
protected $journal_stage_obj = '';
protected $journal_notices_obj = '';
protected $journal_abs_obj = '';
protected $article_to_topic_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_organ_obj = Db::name('article_organ');
$this->article_author_to_organ_obj = Db::name('article_author_to_organ');
$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->article_to_topic_obj = Db::name('article_to_topic');
}
/**
* @title 获取文章详情
* @description 获取文章详情
* @author wangjinlei
* @url /api/Article/getArticleDetail
* @method POST
*
* @param name:article_id type:int require:1 desc:文章id
*
* @return articleInfo:文章信息#
* @return journalInfo:期刊信息#
* @return stageInfo:分期信息#
* @return author:作者信息#
* @return cite:引用#
*
*/
public function getArticleDetail(){
$data = $this->request->post();
$article_info = $this->article_obj->where('article_id',$data['article_id'])->find();
$journal_info = $this->journal_obj->where('journal_id',$article_info['journal_id'])->find();
$stage_info = $this->journal_stage_obj->where('journal_stage_id',$article_info['journal_stage_id'])->find();
//获取文章作者相关
$authors = $this->article_author_obj->where('article_id',$article_info['article_id'])->where('state',0)->select();
$organs = $this->article_organ_obj->where('article_id',$article_info['article_id'])->where('state',0)->select();
$atto = $this->article_author_to_organ_obj->where('article_id',$article_info['article_id'])->where('state',0)->select();
$author = $this->sys_author($authors,$organs,$atto);
//组合cite信息
$no = $stage_info['stage_no']==0?':':'('.$stage_info['stage_no'].'):';
$cite = $article_info['abbr'].'. '.$article_info['title'].' <i>'.$journal_info['jabbr'].'</i>. '.$stage_info['stage_year'].';'.$stage_info['stage_vol'].$no.$article_info['npp'].'. doi:'.$article_info['doi'];
//修改keywords
$article_info['keywords'] = str_replace(',','&nbsp;&nbsp;&nbsp;&nbsp;', $article_info['keywords']);
//返回数据
$re['articleInfo'] = $article_info;
$re['journalInfo'] = $journal_info;
$re['stageInfo'] = $stage_info;
$re['author'] = $author;
$re['cite'] = $cite;
return jsonSuccess($re);
}
private function sys_author($authors,$organs,$atto){
$cache = [];
foreach ($organs as $k => $v){
$cache[$v['article_organ_id']] = $k+1;
$organs[$k]['alias'] = $k+1;
}
foreach ($authors as $key => $val){
$authors[$key]['ors'] = '';
foreach ($atto as $vv){
if($vv['article_author_id']==$val['article_author_id']){
$authors[$key]['ors'] = $authors[$key]['ors']==''?''.$cache[$vv['article_organ_id']]:$authors[$key]['ors'].', '.$cache[$vv['article_organ_id']];
}
}
}
return ['authors'=>$authors,'organs'=>$organs];
}
/**
* @title 获取话题文章列表
* @description 获取话题文章列表
* @author wangjinlei
* @url /api/Article/getTopicArticles
* @method POST
*
* @param name:topic_id type:int require:1 desc:文章id
*
* @return topicInfo:话题信息#
* @return articleList:文章信息#
*
*/
public function getTopicArticles(){
$data = $this->request->post();
$topic_info = $this->journal_topic_obj->where('journal_topic_id',$data['topic_id'])->find();
$list = $this->article_to_topic_obj->field('j_article.*,j_journal_stage.*')
->join(array(['j_article','j_article_to_topic.article_id = j_article.article_id','LEFT'],['j_journal_stage','j_article.journal_stage_id = j_journal_stage.journal_stage_id','LEFT']))
->where('j_article_to_topic.topic_id',$data['topic_id'])
->where('j_article_to_topic.state',0)
->select();
//获取作者
foreach($list as $k=>$v){
$list[$k]['authortitle'] = $this->getAuthor($v);
}
$re['topicInfo'] = $topic_info;
$re['articleList'] = $list;
return jsonSuccess($re);
}
private function getAuthor($article){
$where['article_id'] = $article['article_id'];
$where['state'] = 0;
$list = $this->article_author_obj->where($where)->select();
$frag = '';
foreach ($list as $k=>$v){
$frag = $frag==''?''.$v['author_name']:$frag.', '.$v['author_name'];
}
return $frag;
}
// private function getAuthor($article){
// $where['article_id'] = $article['article_id'];
// $where['state'] = 0;
// $list = $this->article_author_obj->where($where)->select();
// $frag = '';
// foreach ($list as $k=>$v){
// $frag .= $v['author_name'].',';
// }
// return substr($frag,0, -1);
// }
/**
* @title 获取stage文章列表
* @description 获取stage文章列表
* @author wangjinlei
* @url /api/Article/getStageArticles
* @method POST
*
* @param name:stage_id type:int require:1 desc:分期id
*
* @return stageInfo:分期#
* @return articleList:文章信息#
*
*/
public function getStageArticles(){
$data = $this->request->post();
$stage_info = $this->journal_stage_obj->where('journal_stage_id',$data['stage_id'])->find();
$list = $this->article_obj->field('j_article.*,j_journal_stage.*')->join('j_journal_stage','j_article.journal_stage_id = j_journal_stage.journal_stage_id','LEFT')->where('j_article.journal_stage_id',$data['stage_id'])->where('j_article.state',0)->select();
// $topic_info = $this->journal_topic_obj->where('journal_topic_id',$data['topic_id'])->find();
// $list = $this->article_to_topic_obj->field('j_article.*,j_journal_stage.*')
// ->join(array(['j_article','j_article_to_topic.article_id = j_article.article_id','LEFT'],['j_journal_stage','j_article.journal_stage_id = j_journal_stage.journal_stage_id','LEFT']))
// ->where('j_article_to_topic.topic_id',$data['topic_id'])
// ->where('j_article_to_topic.state',0)
// ->select();
//获取作者
foreach($list as $k=>$v){
$list[$k]['authortitle'] = $this->getAuthor($v);
}
$re['stageInfo'] = $stage_info;
$re['articleList'] = $list;
return jsonSuccess($re);
}
/**
* @title 获取top文章列表
* @description 获取top文章列表
* @author wangjinlei
* @url /api/Article/getTopArt
* @method POST
*
* @param name:journal_id type:int require:1 desc:期刊id
* @param name:type type:string require:1 desc:类型(cited/read/download)
*
* @return articleList:文章信息#
*
*/
public function getTopArt(){
$data = $this->request->post();
$list = [];
if($data['type']=='cited'){
$list = $this->article_obj->field('j_article.*,j_journal_stage.*')
->join('j_journal_stage','j_article.journal_stage_id = j_journal_stage.journal_stage_id','LEFT')
->where('j_article.journal_id',$data['journal_id'])
->where('j_article.state',0)
->order('j_article.cited desc')
->select();
}else if($data['type']=='read'){
$list = $this->article_obj->field('j_article.*,j_journal_stage.*')
->join('j_journal_stage','j_article.journal_stage_id = j_journal_stage.journal_stage_id','LEFT')
->where('j_article.journal_id',$data['journal_id'])
->where('j_article.state',0)
->order('j_article.abs_num desc')
->select();
}else{
$list = $this->article_obj->field('j_article.*,j_journal_stage.*')
->join('j_journal_stage','j_article.journal_stage_id = j_journal_stage.journal_stage_id','LEFT')
->where('j_article.journal_id',$data['journal_id'])
->where('j_article.state',0)
->orderRaw('j_article.html_num+j_article.pdf_num desc')
->select();
}
$re['articleList'] = $list;
return jsonSuccess($re);
}
}