同步PDF
This commit is contained in:
128
application/api/controller/Syncdata.php
Normal file
128
application/api/controller/Syncdata.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
namespace app\api\controller;
|
||||
use app\api\controller\Base;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Queue;
|
||||
/**
|
||||
* @title 服务器同步数据
|
||||
* @description 服务器同步数据
|
||||
* @group 服务器同步数据
|
||||
*/
|
||||
class Syncdata extends Base
|
||||
{
|
||||
|
||||
protected $sJournalUrl = 'http://journalapi.tmrjournals.com/public/index.php/';//'http://zmzm.journal.dev.com/';//
|
||||
|
||||
public function __construct(\think\Request $request = null) {
|
||||
parent::__construct($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 查询期刊下的子刊
|
||||
* @param journal_id 期刊ID
|
||||
* @param journal_stage_id 子刊ID
|
||||
*/
|
||||
public function getJournalStage(){
|
||||
|
||||
//获取数据
|
||||
$aParam = $this->request->post();
|
||||
|
||||
//期刊ID
|
||||
$iJournalId = empty($aParam['journal_id']) ? 0 : $aParam['journal_id'];
|
||||
if(empty($iJournalId)){
|
||||
return json_encode(['code' => 2, 'msg' => 'Please select a journal']);
|
||||
}
|
||||
//获取期刊下的子刊
|
||||
$sUrl = $this->sJournalUrl."api/Syncdata/getJournalStage";
|
||||
$aResult = object_to_array(json_decode(myPost1($sUrl,$aParam),true));
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
|
||||
$sMsg = empty($aResult['msg']) ? 'Illegal operation-getJournalStage' : $aResult['msg'];
|
||||
if($iStatus != 1){
|
||||
return json_encode(['code' => 3, 'msg' => $sMsg]);
|
||||
}
|
||||
//获取期刊下的子刊
|
||||
$aJournalStage = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
if(empty($aJournalStage)){
|
||||
return json_encode(['code' => 4, 'msg' => 'Journal data is empty']);
|
||||
}
|
||||
|
||||
//数据处理
|
||||
foreach ($aJournalStage as $key => $value) {
|
||||
// $aArticle = json_decode($this->getJournalStageArticle(['journal_stage_id' => $value['journal_stage_id']]),true);
|
||||
// var_dump($aArticle);exit;
|
||||
//写入查询期刊文章队列
|
||||
$sQueue = Queue::push('app\api\job\SyncArticleData@fire', ['journal_stage_id' => $value['journal_stage_id']], 'SyncArticleData');
|
||||
}
|
||||
return json_encode(['code' => 1, 'msg' => 'Synchronization queue addition completed','data' => $sQueue]);
|
||||
}
|
||||
/**
|
||||
* @title 获取期刊下的文章
|
||||
* @param journal_id 期刊ID
|
||||
* @param journal_stage_id 子刊ID
|
||||
*/
|
||||
public function getJournalStageArticle($aParam = []){
|
||||
|
||||
//获取数据
|
||||
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||
|
||||
//期刊ID
|
||||
$iJournalStageId = empty($aParam['journal_stage_id']) ? 0 : $aParam['journal_stage_id'];
|
||||
if(empty($iJournalStageId)){
|
||||
return json_encode(['code' => 2, 'msg' => 'Please select a sub issue under the journal']);
|
||||
}
|
||||
//获取期刊下的子刊
|
||||
$sUrl = $this->sJournalUrl."api/Syncdata/getJournalStageArticle";
|
||||
$aResult = object_to_array(json_decode(myPost1($sUrl,$aParam),true));
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? 'Illegal operation-getJournalStageArticle' : $aResult['msg'];
|
||||
if($iStatus != 1){
|
||||
return json_encode(['code' => 3, 'msg' => $sMsg]);
|
||||
}
|
||||
//获取文章
|
||||
$aArticle = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
if(empty($aArticle)){
|
||||
return json_encode(['code' => 4, 'msg' => 'Article data is empty']);
|
||||
}
|
||||
|
||||
//写入上传文章队列
|
||||
$sQueue = Queue::push('app\api\job\SyncArticleUpload@fire', $aArticle, 'SyncArticleUpload');
|
||||
// $aResult = json_decode($this->uploadArticle($aArticle),true);
|
||||
return json_encode(['code' => 1, 'msg' => 'Joined the upload file queue','data' => $sQueue]);
|
||||
}
|
||||
/**
|
||||
* @title 同步文章数据到服务器
|
||||
* @param file 文章数据
|
||||
* @param journal_stage_id 子刊ID
|
||||
*/
|
||||
public function uploadArticle($aParam = []){
|
||||
|
||||
//获取数据
|
||||
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||
|
||||
//期刊ID
|
||||
$iJournalStageId = empty($aParam['journal_stage_id']) ? 0 : $aParam['journal_stage_id'];
|
||||
if(empty($iJournalStageId)){
|
||||
return json_encode(['code' => 2, 'msg' => 'Please select a sub issue under the journal']);
|
||||
}
|
||||
//文章数据
|
||||
$aArticle = empty($aParam['article']) ? [] : $aParam['article'];
|
||||
if(empty($aArticle)){
|
||||
return json_encode(['code' => 2, 'msg' => 'Article data is empty']);
|
||||
}
|
||||
//获取期刊下的子刊
|
||||
$sUrl = $this->sJournalUrl."api/Syncdata/uploadArticle";
|
||||
$aResult = object_to_array(json_decode(myPost1($sUrl,$aParam),true));
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? 'Illegal operation-uploadArticle' : $aResult['msg'];
|
||||
if($iStatus != 1){
|
||||
return json_encode(['code' => 3, 'msg' => $sMsg]);
|
||||
}
|
||||
$aResult = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
return json_encode(['code' => 1, 'msg' => $sMsg,'data' => $aResult]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user