diff --git a/application/wechat/controller/Article.php b/application/wechat/controller/Article.php index b92c6cb..9578061 100644 --- a/application/wechat/controller/Article.php +++ b/application/wechat/controller/Article.php @@ -33,7 +33,7 @@ class Article extends Controller //查询文章 $aWhere = ['article_id' => $iArticleId,'state' => 0]; - $aArticle = Db::name('article')->field('article_id,title,abstract,journal_id,journal_stage_id,abbr,npp,doi,icon as article_icon,related')->where($aWhere)->find(); + $aArticle = Db::name('article')->field('article_id,title,abstract,journal_id,journal_stage_id,abbr,npp,doi,icon as article_icon,related,type')->where($aWhere)->find(); if(empty($aArticle)){ return json_encode(array('status' => 3,'msg' => 'Article not found' )); } @@ -175,4 +175,62 @@ class Article extends Controller return json_encode(array('status' => 1,'msg' => 'update success')); } + /** + * @title 获取文章信息 + * @param article_id 文章ID + */ + public function getRelatedArticles(){ + + //获取参数 + $aParam = $this->request->post(); + + //文章ID + $iArticleId = empty($aParam['article_id']) ? '' :$aParam['article_id'] ; + if(empty($iArticleId)){ + return json_encode(array('status' => 2,'msg' => 'Please select an article')); + } + // //关联文章ID + // $iRelatedArticleId = empty($aParam['related_article_id']) ? '' :$aParam['related_article_id'] ; + // if(empty($iRelatedArticleId)){ + // return json_encode(array('status' => 2,'msg' => 'Please select an associated article')); + // } + + //查询文章 + $aWhere = ['article_id' => $iArticleId,'state' => 0]; + $aArticle = Db::name('article')->field('article_id,title,journal_id,doi,related,abbr')->where($aWhere)->find(); + if(empty($aArticle)){ + return json_encode(array('status' => 3,'msg' => 'Article not found' )); + } + + //获取关联文章ID + $aRelatedId = empty($aArticle['related']) ? [] : json_decode($aArticle['related'],true); + if(empty($aRelatedId)){ + return json_encode(array('status' => 4,'msg' => 'This article is not associated with any other articles')); + } + // if(!in_array($iRelatedArticleId, $aRelatedId)){ + // return json_encode(['status' => 5,'msg' => 'The selected associated article is not associated with this article']); + // } + //获取关联文章信息 + $aWhere = ['article_id' => ['in',$aRelatedId],'state' => 0]; + $aRelatedArticle = Db::name('article')->field('article_id,title,journal_id,doi,abbr')->where($aWhere)->select(); + if(empty($aRelatedArticle)){ + return json_encode(['status' => 6,'msg' => 'No information was found for the associated article']); + } + + //获取文章的作者 + array_push($aRelatedId, $iArticleId); + $aWhere = ['article_id' => ['in',$aRelatedId],'state' => 0]; + $aAuthor = Db::name('article_author')->field('article_id,author_name,article_author_id,first_name,last_name,email')->where($aWhere)->order('article_id asc')->select(); + + //获取期刊信息 + //期刊ID + $aJournalId = array_column($aRelatedArticle, 'journal_id'); + array_push($aJournalId, $aArticle['journal_id']); + $aWhere = ['journal_id' => ['in',array_unique($aJournalId)],'state' => 0]; + $aJournal = Db::name('journal')->where($aWhere)->select(); + + return json_encode(['status' => 1,'msg' => 'success','data' => ['article' => $aArticle,'related_article' => $aRelatedArticle,'author' => $aAuthor,'journal' => $aJournal]]); + + } + }