From 37ecfb7fc0d5b844c0e2d05310c836794e03ed39 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Fri, 15 Jul 2022 09:53:07 +0800 Subject: [PATCH] 1 --- application/api/controller/Tmrde.php | 117 +++++++++++++++++++ application/master/controller/Journal.php | 23 ++++ application/master/controller/Medicament.php | 11 +- 3 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 application/api/controller/Tmrde.php diff --git a/application/api/controller/Tmrde.php b/application/api/controller/Tmrde.php new file mode 100644 index 0000000..b7e81eb --- /dev/null +++ b/application/api/controller/Tmrde.php @@ -0,0 +1,117 @@ +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, '' . $val . '', $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 = ''; + } + $frag = $frag == '' ? '' . $v['author_name'] . $ca : $frag . ', ' . $v['author_name'] . $ca; + } + return $frag; + } + + + +} \ No newline at end of file diff --git a/application/master/controller/Journal.php b/application/master/controller/Journal.php index 2f6318a..44fba09 100644 --- a/application/master/controller/Journal.php +++ b/application/master/controller/Journal.php @@ -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 获取所有期刊 diff --git a/application/master/controller/Medicament.php b/application/master/controller/Medicament.php index 0638968..a180927 100644 --- a/application/master/controller/Medicament.php +++ b/application/master/controller/Medicament.php @@ -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([]); }