1
This commit is contained in:
117
application/api/controller/Tmrde.php
Normal file
117
application/api/controller/Tmrde.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -115,6 +115,29 @@ class Journal extends Controller {
|
||||
$re['stages']=$list;
|
||||
return jsonSuccess($re);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取期刊和分期信息
|
||||
*/
|
||||
public function getJournalsAndStage(){
|
||||
$data = $this->request->post();
|
||||
$journal_list = $this->journal_obj->where('state', 0)->select();
|
||||
$frag = [];
|
||||
foreach ($journal_list as $v) {
|
||||
// $v['journal_stage_id'] = $v['journal_id'];
|
||||
$cache_list = $this->journal_stage_obj->where('journal_id', $v['journal_id'])->where('state', 0)->select();
|
||||
foreach ($cache_list as $k => $vv) {
|
||||
$cache_list[$k]['title'] = $vv['stage_year'] . ' Vol.' . $vv['stage_vol'] . ' issue.' . $vv['stage_no'] . $vv['stage_pagename'] . $vv['stage_page'];
|
||||
}
|
||||
if (count($cache_list) > 0) {
|
||||
$v['children'] = $cache_list;
|
||||
} else {
|
||||
$v['children'] = [];
|
||||
}
|
||||
$frag[] = $v;
|
||||
}
|
||||
return json(['code' => 0, 'msg' => 'success', 'data' => ['joutaglist' => $frag]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取所有期刊
|
||||
|
||||
@@ -85,13 +85,18 @@ class Medicament extends Controller
|
||||
public function delMedicament(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'article_id'=>'require',
|
||||
'med_id'=>'require'
|
||||
'article_id'=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$this->article_to_medicament_obj->where('article_id',$data['article_id'])->where('med_id',$data['med_id'])->update(['med_state'=>1]);
|
||||
$atm_info = $this->article_to_medicament_obj->where('article_id',$data['article_id'])->where('atm_state',0)->find();
|
||||
//确定此关联的药剂话题项目是否有其他关联文章,决定是否删除连带的药剂话题
|
||||
$check = $this->article_to_medicament_obj->where('med_id',$atm_info['med_id'])->where('atm_id','<>',$atm_info['atm_id'])->where('atm_state',0)->find();
|
||||
if($check==null){
|
||||
$this->medicament_obj->where('med_id',$atm_info['med_id'])->update(['med_state'=>1]);
|
||||
}
|
||||
$this->article_to_medicament_obj->where('article_id',$data['article_id'])->where('atm_state',0)->update(['atm_state'=>1]);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user