request->post(); $iArticleId = empty($aParam['article_id']) ? '' :$aParam['article_id'] ; if(empty($iArticleId)){ return json_encode(array('status' => 2,'msg' => 'Please select an article')); } //查询文章 $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,type')->where($aWhere)->find(); if(empty($aArticle)){ return json_encode(array('status' => 3,'msg' => 'Article not found' )); } //文章内容 $aMain = $this->_main($iArticleId); //查询文章所属期刊信息 $aJournal = $this->_journal($aArticle['journal_id']); //获取文章所属分期信息 $aJournalStage = $this->_journalStage($aArticle['journal_stage_id']); //获取通讯作者 $aAuthor = $this->_author($iArticleId); return json_encode(array('status' => 1,'msg' => 'Successfully obtained AI generated article content','data' => ['article' => $aArticle,'journal' => $aJournal,'journal_stage' => $aJournalStage,'author' => $aAuthor,'main' => $aMain])); } /** * 获取文章的内容 * @param article_id 文章ID */ private function _main($iArticleId = 0){ $aWhere['article_id'] = $iArticleId; $aWhere['content'] =['<>','']; $aWhere['state'] = 0; $aMain = Db::name('article_main')->where($aWhere)->column('content'); return $aMain; } /** * 获取文章的所属期刊信息 * @param article_id 文章ID */ private function _journal($iJournalId = 0){ $aWhere = ['journal_id' => $iJournalId,'state' => 0]; $aJournal = Db::name('journal')->field('journal_id,title as journal_title,icon as journal_icon,usx as journal_usx,abstract as journal_content_english, abstract_chinese as journal_content,jabbr,email as journal_email,issn,publish_author,editor_qrcode,journal_topic,wechat_name,wechat_app_id,wechat_app_secret')->where($aWhere)->find(); return $aJournal; } /** * 获取文章的所属期刊信息 * @param article_id 文章ID */ private function _journalStage($iJournalStageId = 0){ $aWhere = ['journal_stage_id' => $iJournalStageId,'state' => 0]; $aJournalStage = Db::name('journal_stage')->field('stage_year,stage_vol,stage_no,stage_pagename,stage_page,stage_name,stage_icon')->where($aWhere)->find(); return $aJournalStage; } /** * 获取文章的通讯作者 * @param article_id 文章ID */ private function _author($iArticleId = 0){ $aWhere = ['article_id' => $iArticleId,'state' => 0,'is_report' => 1]; $aAuthor = Db::name('article_author')->field('article_author_id,first_name,last_name,author_country,email,article_id')->where($aWhere)->select(); return $aAuthor; // if(empty($aAuthor)){ // return []; // } // //查询文章作者机构 // $aAuthorId = array_column($aAuthor, 'article_author_id'); // $aWhere = ['article_id' => $iArticleId,'state' => 0,'article_author_id' => ['in',$aAuthorId]]; // $aAuthorOrgan = Db::name('article_author_to_organ')->where($aWhere)->column('article_author_id,article_organ_id'); // //查询组织机构名称 // if(!empty($aAuthorOrgan)){ // $aAuthorOrganId = array_values($aAuthorOrgan); // $aWhere = ['article_id' => $iArticleId,'state' => 0,'article_organ_id' => ['in',$aAuthorOrganId]]; // $aOrgan = Db::name('article_organ')->where($aWhere)->column('article_organ_id,organ_name'); // } // //数据整合 // $aAuthorInfo = []; // foreach($aAuthor as $key => $value){ // //作者姓名 // $sAuthorName = $value['last_name'].$value['first_name']; // //所属机构ID // $iOrganId = empty($aAuthorOrgan[$value['article_author_id']]) ? 0 : $aAuthorOrgan[$value['article_author_id']]; // if(empty($iOrganId)){ // $aAuthorInfo[] = ['author_name' => $sAuthorName,'email' => $value['email'],'article_id' => $value['article_id']]; // continue; // } // //获取所属机构名称 // $sOrganName = empty($aOrgan[$iOrganId]) ? '' : $aOrgan[$iOrganId]; // if(empty($sOrganName)){ // $aAuthorInfo[] = ['author_name' => $sAuthorName,'email' => $value['email'],'article_id' => $value['article_id']]; // continue; // } // $sOrganName = empty($sOrganName) ? '' : $sOrganName; // $aAuthorInfo[] = ['company' => $sOrganName,'author_name' => $sAuthorName,'email' => $value['email'],'article_id' => $value['article_id']]; // } // return $aAuthorInfo; } /** * 更新期刊内容 * @param article_id 文章ID */ public function updateJournal(){ //获取参数 $aParam = $this->request->post(); $sIssn = empty($aParam['issn']) ? '' :$aParam['issn'] ; if(empty($sIssn)){ return json_encode(array('status' => 2,'msg' => 'Please select an journal')); } //查询期刊是否存在 $aJournal = Db::name('journal')->where('issn',$sIssn)->find(); if(empty($aJournal)){ return json_encode(array('status' => 4,'msg' => 'The journal does not exist')); } $iJournalId = $aJournal['journal_id']; //更新字段 $aFileds = ['journal_topic','abstract_chinese','publish_author','editor_qrcode','wechat_name','wechat_app_id','wechat_app_secret']; foreach ($aFileds as $key => $value) { if(isset($aParam[$value])){ $aUpdate[$value] = empty($aParam[$value]) ? '' : addslashes(trim(htmlspecialchars($aParam[$value]))); } } if(empty($aUpdate)){ return json_encode(array('status' => 5,'msg' => 'update success')); } $result = Db::name('journal')->where('journal_id',$iJournalId)->limit(1)->update($aUpdate); if($result === false){ return json_encode(array('status' => 6,'msg' => 'Update failed')); } 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]]); } }