118 lines
4.0 KiB
PHP
118 lines
4.0 KiB
PHP
<?php
|
|
namespace app\api\controller;
|
|
|
|
use think\Controller;
|
|
use think\Db;
|
|
use think\Validate;
|
|
|
|
class Tmrde extends Controller{
|
|
|
|
protected $article_obj = '';
|
|
protected $journal_obj = '';
|
|
protected $medicament_obj = '';
|
|
protected $article_to_medicament_obj = '';
|
|
protected $article_ltai_obj = '';
|
|
protected $journal_stage_obj = '';
|
|
protected $article_to_topic_obj = '';
|
|
|
|
protected $article_author_obj = '';
|
|
|
|
public function __construct(\think\Request $request = null)
|
|
{
|
|
parent::__construct($request);
|
|
$this->article_obj = Db::name('article');
|
|
$this->journal_obj = Db::name('journal');
|
|
$this->medicament_obj = Db::name('medicament');
|
|
$this->article_to_medicament_obj = Db::name('ArticleToMedicament');
|
|
$this->article_ltai_obj = Db::name('article_ltai');
|
|
$this->journal_stage_obj = Db::name('journal_stage');
|
|
$this->article_to_topic_obj = Db::name('article_to_topic');
|
|
$this->article_author_obj = Db::name('article_author');
|
|
}
|
|
|
|
/**
|
|
* 获取所有的药剂话题
|
|
*/
|
|
public function getAllMeds(){
|
|
$list = $this->medicament_obj
|
|
->where('med_state',0)
|
|
->order('med_ename')
|
|
->select();
|
|
$re['meds'] = $list;
|
|
return jsonSuccess($re);
|
|
}
|
|
|
|
/**
|
|
* 检索药剂话题
|
|
*/
|
|
public function searchMeds(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'keyword'=>'require'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$list = $this->medicament_obj->where('med_title|med_ename','like',"%".trim($data['keyword'])."%")->where('med_state',0)->select();
|
|
$re['meds'] = $list;
|
|
return jsonSuccess($re);
|
|
}
|
|
|
|
/**
|
|
* 获取文章通过药剂话题
|
|
*/
|
|
public function getArticleByMed(){
|
|
$data = $this->request->post();
|
|
$rule = new Validate([
|
|
'med_id'=>'require|number'
|
|
]);
|
|
if(!$rule->check($data)){
|
|
return jsonError($rule->getError());
|
|
}
|
|
$med_info = $this->medicament_obj->where('med_id',$data['med_id'])->find();
|
|
$article_ids = $this->article_to_medicament_obj->where('med_id',$data['med_id'])->where('atm_state',0)->column('article_id');
|
|
$list = $this->article_obj
|
|
->field('j_article.*,j_journal_stage.*,j_journal.title journal_title,j_journal.jabbr journal_short,j_journal.usx usx')
|
|
->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.article_id','in',$article_ids)
|
|
->where('j_article.state',0)
|
|
->select();
|
|
//标题斜体
|
|
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['medicament'] = $med_info;
|
|
$re['articles'] = $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) {
|
|
$ca = '';
|
|
if ($v['orcid'] != '') {
|
|
$ca = '<a href="https://orcid.org/' . $v['orcid'] . '" target="_blank"><img src="img/or_id.png" alt="" style="width: 13px;margin-left: 3px;"></a>';
|
|
}
|
|
$frag = $frag == '' ? '' . $v['author_name'] . $ca : $frag . ', ' . $v['author_name'] . $ca;
|
|
}
|
|
return $frag;
|
|
}
|
|
|
|
|
|
|
|
} |