469 lines
20 KiB
PHP
469 lines
20 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use think\Controller;
|
||
use think\Db;
|
||
|
||
/**
|
||
* @title 前段web接口
|
||
* @description 前段web接口
|
||
* @group 前段web接口
|
||
*/
|
||
class Main extends Controller {
|
||
|
||
//put your code here
|
||
protected $admin_obj = '';
|
||
protected $journal_obj = '';
|
||
protected $article_obj = '';
|
||
protected $article_author_obj = '';
|
||
protected $journal_topic_obj = '';
|
||
protected $journal_stage_obj = '';
|
||
protected $journal_notices_obj = '';
|
||
protected $journal_abs_obj = '';
|
||
protected $article_to_topic_obj = '';
|
||
protected $sys_scient_obj = '';
|
||
protected $sys_book_obj = '';
|
||
protected $sys_not_obj = '';
|
||
protected $article_ltai_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->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');
|
||
$this->sys_scient_obj = Db::name('system_scient');
|
||
$this->sys_book_obj = Db::name('system_books');
|
||
$this->sys_not_obj = Db::name('system_notices');
|
||
$this->article_ltai_obj = Db::name('article_ltai');
|
||
}
|
||
|
||
/**
|
||
* @title 获取scients
|
||
* @description 获取scients
|
||
* @author wangjinlei
|
||
* @url /api/Main/getScients
|
||
* @method POST
|
||
*
|
||
* @return scients:array#
|
||
*/
|
||
public function getScients() {
|
||
$list = $this->sys_scient_obj->where('state', 0)->select();
|
||
$re['scients'] = $list;
|
||
return jsonSuccess($re);
|
||
}
|
||
|
||
/**
|
||
* @title 获取scients详情
|
||
* @description 获取scients详情
|
||
* @author wangjinlei
|
||
* @url /api/Main/getScientDetail
|
||
* @method POST
|
||
*
|
||
* @param name:system_scient_id type:int require:1 desc:主键id
|
||
*
|
||
* @return scient:array#
|
||
*/
|
||
public function getScientDetail() {
|
||
$data = $this->request->post();
|
||
$info = $this->sys_scient_obj->where('system_scient_id', $data['system_scient_id'])->find();
|
||
|
||
$re['scient'] = $info;
|
||
return jsonSuccess($re);
|
||
}
|
||
|
||
/**
|
||
* @title 获取books
|
||
* @description 获取books
|
||
* @author wangjinlei
|
||
* @url /api/Main/getBooks
|
||
* @method POST
|
||
*
|
||
* @return books:array#
|
||
*/
|
||
public function getBooks() {
|
||
$list = $this->sys_book_obj->where('state', 0)->select();
|
||
$re['books'] = $list;
|
||
return jsonSuccess($re);
|
||
}
|
||
|
||
/**
|
||
* @title 获取book详情
|
||
* @description 获取book详情
|
||
* @author wangjinlei
|
||
* @url /api/Main/getBookDetail
|
||
* @method POST
|
||
*
|
||
* @param name:system_book_id type:int require:1 desc:主键id
|
||
*
|
||
* @return book:array#
|
||
*/
|
||
public function getBookDetail() {
|
||
$data = $this->request->post();
|
||
$info = $this->sys_book_obj->where('system_book_id', $data['system_book_id'])->find();
|
||
|
||
$re['book'] = $info;
|
||
return jsonSuccess($re);
|
||
}
|
||
|
||
/**
|
||
* @title 获取首页文章列表
|
||
* @description 获取首页文章列表
|
||
* @author wangjinlei
|
||
* @url /api/Main/getMainArticles
|
||
* @method POST
|
||
*
|
||
* @return articles:文章信息array#
|
||
*/
|
||
public function getMainArticles(){
|
||
$list_tmr = $this->article_obj->field('j_article.*,j_journal_stage.*,j_journal.title journal_title,j_journal.jabbr journal_short')->join(array(['j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT'],['j_journal','j_article.journal_id = j_journal.journal_id','LEFT']))->where('j_article.journal_id',1)->where('j_journal_stage.is_publish',1)->where('j_article.state',0)->order('j_article.article_id desc')->limit(3)->select();
|
||
$list_zh = $this->article_obj->field('j_article.*,j_journal_stage.*,j_journal.title journal_title,j_journal.jabbr journal_short')->join(array(['j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT'],['j_journal','j_article.journal_id = j_journal.journal_id','LEFT']))->where('j_article.journal_id',17)->where('j_journal_stage.is_publish',1)->where('j_article.state',0)->order('j_article.article_id desc')->limit(1)->select();
|
||
$list_life = $this->article_obj->field('j_article.*,j_journal_stage.*,j_journal.title journal_title,j_journal.jabbr journal_short')->join(array(['j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT'],['j_journal','j_article.journal_id = j_journal.journal_id','LEFT']))->where('j_article.journal_id',14)->where('j_journal_stage.is_publish',1)->where('j_article.state',0)->order('j_article.article_id desc')->limit(1)->select();
|
||
$list_fyw = $this->article_obj->field('j_article.*,j_journal_stage.*,j_journal.title journal_title,j_journal.jabbr journal_short')->join(array(['j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT'],['j_journal','j_article.journal_id = j_journal.journal_id','LEFT']))->where('j_article.journal_id',20)->where('j_journal_stage.is_publish',1)->where('j_article.state',0)->order('j_article.article_id desc')->limit(1)->select();
|
||
$list_ywlh = $this->article_obj->field('j_article.*,j_journal_stage.*,j_journal.title journal_title,j_journal.jabbr journal_short')->join(array(['j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT'],['j_journal','j_article.journal_id = j_journal.journal_id','LEFT']))->where('j_article.journal_id',6)->where('j_journal_stage.is_publish',1)->where('j_article.state',0)->order('j_article.article_id desc')->limit(1)->select();
|
||
$list_zy = $this->article_obj->field('j_article.*,j_journal_stage.*,j_journal.title journal_title,j_journal.jabbr journal_short')->join(array(['j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT'],['j_journal','j_article.journal_id = j_journal.journal_id','LEFT']))->where('j_article.journal_id',18)->where('j_journal_stage.is_publish',1)->where('j_article.state',0)->order('j_article.article_id desc')->limit(1)->select();
|
||
$list = $list_tmr;
|
||
$list[] = $list_zh[0];
|
||
$list[] = $list_life[0];
|
||
$list[] = $list_fyw[0];
|
||
$list[] = $list_ywlh[0];
|
||
$list[] = $list_zy[0];
|
||
foreach ($list as $k => $v) {
|
||
$list[$k]['authortitle'] = $this->getAuthor($v);
|
||
}
|
||
$re['articles'] = $list;
|
||
return jsonSuccess($re);
|
||
}
|
||
|
||
/**
|
||
* @title 获取文章more列表
|
||
* @description 获取文章more列表
|
||
* @author wangjinlei
|
||
* @url /api/Main/getMoreArticles
|
||
* @method POST
|
||
*
|
||
* @return articles:文章信息array#
|
||
*/
|
||
public function getMoreArticles(){
|
||
$sql = "select a.* from (select MAX(article_id) aid from j_article WHERE state = 0 GROUP BY journal_id) c left join j_article a on a.article_id = c.aid";
|
||
$list = Db::query($sql);
|
||
|
||
//获取作者
|
||
foreach ($list as $k => $v) {
|
||
$stage_info = $this->journal_stage_obj->where('journal_stage_id', $v['journal_stage_id'])->find();
|
||
$journal_info = $this->journal_obj->where('journal_id', $v['journal_id'])->find();
|
||
//组合cite信息
|
||
$no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):';
|
||
$cite = $v['abbr'] . '. ' . $v['title'] . '. <i>' . $journal_info['jabbr'] . '</i>. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi'];
|
||
$list[$k]['cite'] = $cite;
|
||
$list[$k]['authortitle'] = $this->getAuthor($v);
|
||
$list[$k] = array_merge($list[$k],$stage_info);
|
||
$list[$k]['journal_title'] = $journal_info['title'];
|
||
$list[$k]['journal_short'] = $journal_info['jabbr'];
|
||
}
|
||
|
||
//标题斜体
|
||
foreach ($list as $k => $v) {
|
||
$caches = $this->article_ltai_obj->where('article_id', $v['article_id'])->where('state', 0)->column('content');
|
||
$cache_title = $v['title'];
|
||
foreach ($caches as $val) {
|
||
$cache_title = str_replace($val, '<i>' . $val . '</i>', $cache_title);
|
||
}
|
||
$list[$k]['title'] = $cache_title;
|
||
}
|
||
// foreach ($list as $k => $v) {
|
||
// $list[$k]['authortitle'] = $this->getAuthor($v);
|
||
// }
|
||
$re['articles'] = $list;
|
||
return jsonSuccess($re);
|
||
}
|
||
|
||
/**
|
||
* @title 获取onlinefirst文章列表
|
||
* @description 获取onlinefirst文章列表
|
||
* @author wangjinlei
|
||
* @url /api/Main/getOnlineFirstArticles
|
||
* @method POST
|
||
*
|
||
* @param name:pageIndex type:int require:1 desc:当前页码数
|
||
* @param name:pageSize type:int require:1 desc:单页数据条数
|
||
*
|
||
* @return articles:文章信息array#
|
||
* @return count:总数
|
||
*/
|
||
public function getOnlineFirstArticles(){
|
||
$data = $this->request->post();
|
||
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'];
|
||
$list = $this->article_obj
|
||
->field('j_article.*,j_journal_stage.*,j_journal.title journal_title,j_journal.jabbr journal_short')
|
||
->join(array(['j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT'],['j_journal','j_article.journal_id = j_journal.journal_id','LEFT']))
|
||
->where('j_article.state',0)
|
||
->where('j_journal_stage.is_publish',0)
|
||
->where('j_article.journal_id','in','1,10,6,14,11,15,17,20,21,22')
|
||
->order('j_article.article_id desc')
|
||
->limit($limit_start,$data['pageSize'])
|
||
->select();
|
||
$count = $this->article_obj
|
||
->join(array(['j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT'],['j_journal','j_article.journal_id = j_journal.journal_id','LEFT']))
|
||
->where('j_article.state',0)
|
||
->where('j_journal_stage.is_publish',0)
|
||
->where('j_article.journal_id','in','1,10,6,14,11,15,17,20,21,22')
|
||
->count();
|
||
foreach ($list as $k => $v) {
|
||
$list[$k]['authortitle'] = $this->getAuthor($v);
|
||
}
|
||
$re['articles'] = $list;
|
||
$re['count'] = $count;
|
||
return jsonSuccess($re);
|
||
}
|
||
|
||
/**
|
||
* @title 获取news/commons文章列表
|
||
* @description 获取news/commons文章列表
|
||
* @author wangjinlei
|
||
* @url /api/Main/getNewsArticles
|
||
* @method POST
|
||
*
|
||
* @param name:type require:1 type:string desc:(News/Comment)
|
||
*
|
||
* @return articles:文章信息array#
|
||
*/
|
||
public function getNewsArticles(){
|
||
$data = $this->request->post();
|
||
if($data['type']=='News'){
|
||
$type = 'News';
|
||
}else{
|
||
$type = 'Comment';
|
||
}
|
||
$list = $this->article_obj
|
||
->field('j_article.*,j_journal_stage.*,j_journal.title journal_title,j_journal.jabbr journal_short')
|
||
->join(array(['j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT'],['j_journal','j_article.journal_id = j_journal.journal_id','LEFT']))
|
||
->where('j_article.state',0)
|
||
->where('j_journal_stage.is_publish',1)
|
||
->where('j_article.journal_id','in','1,10,6,14,11,15,17,20,21,22')
|
||
->where('j_article.type', $type)
|
||
->order('j_article.article_id desc')
|
||
->select();
|
||
//获取作者
|
||
foreach ($list as $k => $v) {
|
||
$stage_info = $this->journal_stage_obj->where('journal_stage_id', $v['journal_stage_id'])->find();
|
||
$journal_info = $this->journal_obj->where('journal_id', $v['journal_id'])->find();
|
||
//组合cite信息
|
||
$no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):';
|
||
$cite = $v['abbr'] . '. ' . $v['title'] . '. <i>' . $journal_info['jabbr'] . '</i>. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi'];
|
||
$list[$k]['cite'] = $cite;
|
||
$list[$k]['authortitle'] = $this->getAuthor($v);
|
||
}
|
||
|
||
//标题斜体
|
||
foreach ($list as $k => $v) {
|
||
$caches = $this->article_ltai_obj->where('article_id', $v['article_id'])->where('state', 0)->column('content');
|
||
$cache_title = $v['title'];
|
||
foreach ($caches as $val) {
|
||
$cache_title = str_replace($val, '<i>' . $val . '</i>', $cache_title);
|
||
}
|
||
$list[$k]['title'] = $cache_title;
|
||
}
|
||
$re['articles'] = $list;
|
||
return jsonSuccess($re);
|
||
}
|
||
|
||
/**
|
||
* @title 获取3top文章列表
|
||
* @description 获取3top文章列表
|
||
* @author wangjinlei
|
||
* @url /api/Main/getThireTopArticles
|
||
* @method POST
|
||
*
|
||
* @param name:type require:1 type:string desc:类型(cite/read/download)
|
||
*
|
||
* @return articles:文章信息array#
|
||
*/
|
||
public function getThireTopArticles(){
|
||
$data = $this->request->post();
|
||
if($data['type'] == 'cite'){
|
||
$order = 'j_article.cited desc';
|
||
}else if($data['type'] == 'read'){
|
||
$order = 'j_article.abs_num desc';
|
||
}else if($data['type'] == 'download'){
|
||
$order = 'j_article.pdf_num desc';
|
||
}else{
|
||
return jsonError('Please make sure type in "cite/read/download"');
|
||
}
|
||
$list = $this->article_obj->field('j_article.*,j_journal_stage.*,j_journal.title journal_title,j_journal.jabbr journal_short')
|
||
->join(array(['j_journal_stage', 'j_article.journal_stage_id = j_journal_stage.journal_stage_id', 'LEFT'],['j_journal','j_article.journal_id = j_journal.journal_id','LEFT']))
|
||
->where('j_article.state', 0)
|
||
->where('j_journal_stage.is_publish',1)
|
||
// ->orderRaw('j_article.cited+j_article.abs_num+j_article.pdf_num desc')
|
||
->order($order)
|
||
->limit(20)
|
||
->select();
|
||
|
||
//获取作者
|
||
foreach ($list as $k => $v) {
|
||
$stage_info = $this->journal_stage_obj->where('journal_stage_id', $v['journal_stage_id'])->find();
|
||
$journal_info = $this->journal_obj->where('journal_id', $v['journal_id'])->find();
|
||
//组合cite信息
|
||
$no = $stage_info['stage_no'] == 0 ? ':' : '(' . $stage_info['stage_no'] . '):';
|
||
$cite = $v['abbr'] . '. ' . $v['title'] . '. <i>' . $journal_info['jabbr'] . '</i>. ' . $stage_info['stage_year'] . ';' . $stage_info['stage_vol'] . $no . $v['npp'] . '. doi:' . $v['doi'];
|
||
$list[$k]['cite'] = $cite;
|
||
$list[$k]['authortitle'] = $this->getAuthor($v);
|
||
}
|
||
|
||
//标题斜体
|
||
foreach ($list as $k => $v) {
|
||
$caches = $this->article_ltai_obj->where('article_id', $v['article_id'])->where('state', 0)->column('content');
|
||
$cache_title = $v['title'];
|
||
foreach ($caches as $val) {
|
||
$cache_title = str_replace($val, '<i>' . $val . '</i>', $cache_title);
|
||
}
|
||
$list[$k]['title'] = $cache_title;
|
||
}
|
||
return jsonSuccess(['articles' => $list]);
|
||
|
||
}
|
||
|
||
/**
|
||
* @title 获取首页Highlights
|
||
* @description 获取首页Highlights
|
||
* @author wangjinlei
|
||
* @url /api/Main/getMainhl
|
||
* @method POST
|
||
*
|
||
* @param name:journal_id type:int require:1 desc:期刊id
|
||
*
|
||
* @return Highlights:array#
|
||
*/
|
||
public function getMainhl() {
|
||
$data = $this->request->post();
|
||
$topic_info = $this->journal_topic_obj->where('journal_id', $data['journal_id'])->where('position', 'highlights')->where('state', 0)->find();
|
||
if ($topic_info) {
|
||
$list = $this->article_to_topic_obj->field('j_article.*,j_journal_stage.*')
|
||
->join(array(['j_article', 'j_article.article_id = j_article_to_topic.article_id', 'LEFT'], ['j_journal_stage', 'j_journal_stage.journal_stage_id = j_article.journal_stage_id', 'LEFT']))
|
||
->where('j_article_to_topic.topic_id', $topic_info['journal_topic_id'])
|
||
->where('j_article_to_topic.state', 0)
|
||
->select();
|
||
return jsonSuccess(['topic_info' => $topic_info, 'articlelist' => $list]);
|
||
} else {
|
||
return jsonError('no highlights');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @title 获取notices列表
|
||
* @description 获取notices列表
|
||
* @author wangjinlei
|
||
* @url /api/Main/getAllNotices
|
||
* @method POST
|
||
*
|
||
* @return notices:array#
|
||
*/
|
||
public function getAllNotices(){
|
||
$list = $this->sys_not_obj->where('state',0)->order('system_notices_id desc')->select();
|
||
$re['notices'] = $list;
|
||
return jsonSuccess($re);
|
||
}
|
||
|
||
/**
|
||
* @title 获取期刊列表
|
||
* @description 获取期刊列表
|
||
* @author wangjinlei
|
||
* @url /api/Main/getJournals
|
||
* @method POST
|
||
*
|
||
* @return journals:array#
|
||
*/
|
||
public function getJournals() {
|
||
$list = $this->journal_obj->where('state', 0)->select();
|
||
|
||
$re['journals'] = $list;
|
||
return jsonSuccess($re);
|
||
}
|
||
|
||
/**
|
||
* @title 获取查找文章列表
|
||
* @description 获取查找文章列表
|
||
* @author wangjinlei
|
||
* @url /api/Main/getSearchArt
|
||
* @method POST
|
||
*
|
||
* @param name:journals type:string require:1 desc:期刊id(demo:1,2,3)
|
||
* @param name:condition1 type:string require:1 desc:条件1(title/keywords/abstract)
|
||
* @param name:condition1_text type:string require:1 desc:条件1字段
|
||
* @param name:relation type:string require:2 desc:两条件的链接条件('and/or')
|
||
* @param name:condition2 type:string require:2 desc:条件2(title/keywords/abstract)
|
||
* @param name:condition2_text type:string require:2 desc:条件2字段
|
||
* @param name:pageIndex type:int require:1 desc:当前页码数
|
||
* @param name:pageSize type:int require:1 desc:单页数据条数
|
||
*
|
||
* @return count:总数
|
||
* @return journals:array#
|
||
*/
|
||
public function getSearchArt() {
|
||
$data = $this->request->post();
|
||
$where = "j_article.journal_id in (" . $data['journals'] . ")";
|
||
if ($data['condition2_text'] != '') {
|
||
if ($data['relation'] == 'and') {
|
||
$where .= ' and j_article.' . $data['condition1'] . ' like "%' . $data['condition1_text'] . '%" and j_article.' . $data['condition2'] . ' like "%' . $data['condition2_text'] . '%"';
|
||
} else {
|
||
$where .= ' and (j_article.' . $data['condition1'] . ' like "%' . $data['condition1_text'] . '%" or j_article.' . $data['condition2'] . ' like "%' . $data['condition2_text'] . '%")';
|
||
}
|
||
} else {
|
||
$where .= 'and j_article.' . $data['condition1'] . ' like "%' . $data['condition1_text'] . '%"';
|
||
}
|
||
$limit_start = ($data['pageIndex'] - 1) * $data['pageSize'];
|
||
$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($where)
|
||
->order('j_article.article_id')
|
||
->limit($limit_start, $data['pageSize'])
|
||
->select();
|
||
|
||
foreach ($list as $k => $v) {
|
||
$list[$k]['authortitle'] = $this->getAuthor($v);
|
||
}
|
||
$count = $this->article_obj->where($where)->count();
|
||
$re['count'] = $count;
|
||
$re['journals'] = $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;
|
||
}
|
||
|
||
public function test() {
|
||
echo md5('123456');
|
||
}
|
||
|
||
public function rewrite($type){
|
||
$frag = '';
|
||
switch($type){
|
||
case 'tmr':
|
||
$frag = 'https://www.tmrjournals.com/stages.html?J_num=1';
|
||
break;
|
||
case 'lr':
|
||
$frag = 'https://www.tmrjournals.com/stages.html?J_num=14';
|
||
break;
|
||
default :
|
||
$frag = 'https://www.tmrjournals.com/stages.html?J_num=1';
|
||
break;
|
||
}
|
||
echo "<script>location.href='$frag'</script>";
|
||
}
|
||
|
||
}
|