接口提供
This commit is contained in:
139
application/wechat/controller/Article.php
Normal file
139
application/wechat/controller/Article.php
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
<?php
|
||||||
|
namespace app\wechat\controller;
|
||||||
|
|
||||||
|
use think\Controller;
|
||||||
|
use think\Db;
|
||||||
|
use app\common\QrCodeImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title 文章接口
|
||||||
|
* @description 文章接口
|
||||||
|
* @group 文章接口
|
||||||
|
*/
|
||||||
|
class Article extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct(\think\Request $request = null) {
|
||||||
|
|
||||||
|
parent::__construct($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title 获取文章信息
|
||||||
|
* @param article_id 文章ID
|
||||||
|
*/
|
||||||
|
public function getArticle(){
|
||||||
|
|
||||||
|
//获取参数
|
||||||
|
$aParam = $this->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')->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,jabbr,email as journal_email,issn')->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();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user