升级
This commit is contained in:
358
application/api/controller/Contribute.php
Normal file
358
application/api/controller/Contribute.php
Normal file
@@ -0,0 +1,358 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\controller;
|
||||||
|
|
||||||
|
use app\api\controller\Base;
|
||||||
|
use think\Db;
|
||||||
|
use PhpOffice\PhpWord\IOFactory;
|
||||||
|
use think\Exception;
|
||||||
|
use \app\common\ArticleParserService;
|
||||||
|
/**
|
||||||
|
* @title 自动投稿控制器
|
||||||
|
* @description 所有的测试方法汇总
|
||||||
|
*/
|
||||||
|
class Contribute extends Base
|
||||||
|
{
|
||||||
|
|
||||||
|
private $phpWord; // PhpWord实例
|
||||||
|
private $sections; // 文档段落集合
|
||||||
|
public function __construct(\think\Request $request = null) {
|
||||||
|
parent::__construct($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动投稿
|
||||||
|
* @param file_url 文件地址
|
||||||
|
*/
|
||||||
|
public function contribute($aParam = []){
|
||||||
|
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//必填值验证
|
||||||
|
$sFileUrl = empty($aParam['file_url']) ? '' : $aParam['file_url'];
|
||||||
|
$sOriginalFileUrl = $sFileUrl;
|
||||||
|
if(empty($sFileUrl)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please upload the submission file']);
|
||||||
|
}
|
||||||
|
// //文章类型
|
||||||
|
// $sType = empty($aParam['type']) ? '' : $aParam['type'];
|
||||||
|
// if(empty($sType)){
|
||||||
|
// return json_encode(['status' => 2,'msg' => 'Please select the article type']);
|
||||||
|
// }
|
||||||
|
// //期刊ID
|
||||||
|
// $iJournalId = empty($aParam['journal_id']) ? '' : $aParam['journal_id'];
|
||||||
|
// if(empty($iJournalId)){
|
||||||
|
// return json_encode(['status' => 2,'msg' => 'Please select the journal to which you belong']);
|
||||||
|
// }
|
||||||
|
//用户ID
|
||||||
|
$iUserId = empty($aParam['user_id']) ? '' : $aParam['user_id'];
|
||||||
|
if(empty($iUserId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select author']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断文件是否执行
|
||||||
|
$sFileUrl = rtrim(ROOT_PATH,'/').'/public/'.ltrim(ltrim($sFileUrl,'/'),'public');
|
||||||
|
if (!file_exists($sFileUrl)) {
|
||||||
|
return json_encode(['status' => 3, 'msg' => 'The uploaded file does not exist']);
|
||||||
|
}
|
||||||
|
if (!is_readable($sFileUrl)) {
|
||||||
|
return json_encode(['status' => 4, 'msg' => 'The uploaded file is unreadable']);
|
||||||
|
}
|
||||||
|
//文章ID
|
||||||
|
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||||
|
$aWhere = [];
|
||||||
|
if(!empty($iArticleId)){//更新文章内容
|
||||||
|
$aWhere['article_id'] = $iArticleId;
|
||||||
|
$aArticle = Db::name('article')->field('state,user_id,manuscirpt_url')->where($aWhere)->find();
|
||||||
|
if(empty($aArticle)){
|
||||||
|
return json_encode(['status' => 7,'msg' => 'The article does not exist']);
|
||||||
|
}
|
||||||
|
if($aArticle['state'] != -1 && $aArticle['state'] != 3){
|
||||||
|
return json_encode(['status' => 8,'msg' => 'Article cannot be edited']);
|
||||||
|
}
|
||||||
|
if($aArticle['user_id'] != $iUserId){
|
||||||
|
return json_encode(['status' => 9,'msg' => 'Not modified by the author themselves']);
|
||||||
|
}
|
||||||
|
if($aArticle['manuscirpt_url'] == trim($sOriginalFileUrl,'/')){
|
||||||
|
return json_encode(['status' => 9,'msg' => 'The content of the article has not changed']);
|
||||||
|
}
|
||||||
|
$aWhere['article_id'] = ['<>',$iArticleId];
|
||||||
|
}
|
||||||
|
//获取数据
|
||||||
|
$aDealData = json_decode(ArticleParserService::uploadAndParse($sFileUrl),true);
|
||||||
|
$iStatus = empty($aDealData['status']) ? 0 : $aDealData['status'];
|
||||||
|
$sMsg = empty($aDealData['msg']) ? 'fail' : $aDealData['msg'];
|
||||||
|
if($iStatus != 1){
|
||||||
|
return json_encode(['status' => 5, 'msg' => $sMsg]);
|
||||||
|
}
|
||||||
|
$aData = empty($aDealData['data']) ? '' : $aDealData['data'];
|
||||||
|
if(empty($aData['title'])){
|
||||||
|
return json_encode(['status' => 6,'msg' => 'The article title is empty']);
|
||||||
|
}
|
||||||
|
//查询标题是否存在
|
||||||
|
$aWhere += ['title' => trim($aData['title']),'state' => ['<>',3]];
|
||||||
|
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||||
|
if(!empty($aArticle)){
|
||||||
|
return json_encode(['code' => 7, 'msg' => 'Warning: you are re-submitting the article!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//数据入库
|
||||||
|
$aData += $aParam;
|
||||||
|
$result = $this->_addData($aData);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组装数据插入相关数据表
|
||||||
|
* @param array $aParam
|
||||||
|
*/
|
||||||
|
private function _addData($aParam = []){
|
||||||
|
if(empty($aParam)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Data is empty']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取文章ID
|
||||||
|
$iUpdateArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||||
|
if(!empty($iUpdateArticleId)){
|
||||||
|
$aWhere = ['article_id' => $iUpdateArticleId];
|
||||||
|
$aArticle = Db::name('article')->field('title,keywords,abstrart,fund,journal_id')->where($aWhere)->find();
|
||||||
|
}
|
||||||
|
//插入基础表 t_article
|
||||||
|
$aInsert = [];
|
||||||
|
//标题
|
||||||
|
if(empty($aArticle['title'])){
|
||||||
|
$sTitile = empty($aParam['title']) ? '' : $aParam['title'];
|
||||||
|
if(!empty($sTitile)){
|
||||||
|
$aInsert['title'] = $sTitile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//关键词
|
||||||
|
if(empty($aArticle['keywords'])){
|
||||||
|
$sKeyWords = empty($aParam['keywords']) ? '' : $aParam['keywords'];
|
||||||
|
if(!empty($sKeyWords)){
|
||||||
|
$aInsert['keywords'] = is_array($sKeyWords) ? implode(',', $sKeyWords) : $sKeyWords;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//摘要
|
||||||
|
if(empty($aArticle['abstrart'])){
|
||||||
|
$sAbstrart = empty($aParam['abstrart']) ? '' : $aParam['abstrart'];
|
||||||
|
if(!empty($sAbstrart)){
|
||||||
|
$aInsert['abstrart'] = $sAbstrart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//基金
|
||||||
|
if(empty($aArticle['fund'])){
|
||||||
|
$sFund = empty($aParam['fund']) ? '' : $aParam['fund'];
|
||||||
|
if(!empty($sAbstrart)){
|
||||||
|
$aInsert['fund'] = $sFund;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//期刊ID
|
||||||
|
$iJournalId = empty($aParam['journal_id']) ? 0 : $aParam['journal_id'];
|
||||||
|
if(!empty($iJournalId)){
|
||||||
|
$aInsert['journal_id'] = $iJournalId;
|
||||||
|
//查询期刊信息
|
||||||
|
$aJournalWhere = ['journal_id' => $iJournalId,'state' => 0];
|
||||||
|
$aJournal = DB::name('journal')->field('editor_id')->where($aJournalWhere)->find();
|
||||||
|
$aInsert['editor_id'] = empty($aJournal['editor_id']) ? 0 : $aJournal['editor_id'];
|
||||||
|
}
|
||||||
|
//类型
|
||||||
|
$sType = empty($aParam['type']) ? '' : $aParam['type'];
|
||||||
|
if(!empty($sType)){
|
||||||
|
$aInsert['type'] = $sType;
|
||||||
|
}
|
||||||
|
//上传文件地址
|
||||||
|
$sFileUrl = empty($aParam['file_url']) ? '' : $aParam['file_url'];
|
||||||
|
if(!empty($sFileUrl)){
|
||||||
|
$aInsert['manuscirpt_url'] = trim(trim($sFileUrl,'/'),'public/');
|
||||||
|
}
|
||||||
|
//用户ID
|
||||||
|
$iUserId = empty($aParam['user_id']) ? 0 : $aParam['user_id'];
|
||||||
|
if(!empty($iUserId)){
|
||||||
|
$aInsert['user_id'] = $iUserId;
|
||||||
|
//查询用户信息
|
||||||
|
$aUser = Db::name('user')->field('account')->where(['user_id' => $iUserId,'state' => 0])->find();
|
||||||
|
}
|
||||||
|
Db::startTrans();
|
||||||
|
//插入article
|
||||||
|
if(empty($aArticle) && !empty($aInsert)){//新插入
|
||||||
|
$aInsert['ctime'] = time();
|
||||||
|
$aInsert['state'] = -1;
|
||||||
|
$aInsert['is_use_ai'] = 3;
|
||||||
|
$aInsert['is_figure_copyright'] = 3;
|
||||||
|
$aInsert['is_transfer'] = 3;
|
||||||
|
$aInsert['is_become_reviewer'] = 3;
|
||||||
|
$iArticleId = Db::name('article')->insertGetId($aInsert);
|
||||||
|
if(empty($iArticleId)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Article added successfully']);
|
||||||
|
}
|
||||||
|
//获取accept_sn并更新
|
||||||
|
$sAcceptSn = $this->getArticleAcceptSn(['article_id' => $iArticleId]);
|
||||||
|
if(!empty($sAcceptSn)){
|
||||||
|
$aWhere = ['article_id' => $iArticleId];
|
||||||
|
$aUpdate = ['accept_sn' => $sAcceptSn];
|
||||||
|
$update_result = Db::name('article')->where($aWhere)->limit(1)->update($aUpdate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!empty($aArticle) && !empty($aInsert)){//更新
|
||||||
|
$aWhere = ['article_id' => $iUpdateArticleId,'state' => ['in',[-1,3]]];
|
||||||
|
$update_result = Db::name('article')->where($aWhere)->limit(1)->update($aInsert);
|
||||||
|
if($update_result === false){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Article update failed']);
|
||||||
|
}
|
||||||
|
//更新作者为逻辑删除
|
||||||
|
$aWhere['state'] = 0;
|
||||||
|
$update_author_result = DB::name('article_author')->where($aWhere)->update(['state' => 1]);
|
||||||
|
if($update_author_result === false){
|
||||||
|
return json_encode(['status' => 4,'msg' => 'Article author update failed']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//作者单位
|
||||||
|
$iArticleId = empty($iArticleId) ? $iUpdateArticleId : $iArticleId;
|
||||||
|
$aCompany = empty($aParam['company']) ? [] : $aParam['company'];
|
||||||
|
if(!empty($aCompany)){
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0];
|
||||||
|
$aOrgan = Db::name('article_organ')->field('organ_id,organ_name,sort')->where($aWhere)->select();
|
||||||
|
$aOrganName = empty($aOrgan) ? [] : array_column($aOrgan, 'organ_name');
|
||||||
|
$iMaxSort = empty($aOrgan) ? 0 : max(array_column($aOrgan, 'sort'));
|
||||||
|
//查询文章
|
||||||
|
$aCompanyInsert = $aSort = [];
|
||||||
|
foreach ($aCompany as $key => $value) {
|
||||||
|
if(empty($value)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$sName = trim(trim(trim($value,'*'),'#'));
|
||||||
|
if(in_array($sName, $aOrganName)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(empty($iMaxSort)){
|
||||||
|
$iSort = $key;
|
||||||
|
$aSort[$key] = $key;
|
||||||
|
}else{
|
||||||
|
$iMaxSort++;
|
||||||
|
$iSort = $iMaxSort;
|
||||||
|
$aSort[$key] = $iMaxSort;
|
||||||
|
}
|
||||||
|
$aCompanyInsert[] = ['article_id' => $iArticleId,'organ_name' =>$sName,'create_time' => time(),'sort' => $iMaxSort];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!empty($aCompanyInsert)){
|
||||||
|
$company_result = Db::name('article_organ')->insertAll($aCompanyInsert);
|
||||||
|
if(empty($company_result)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Article institution insertion failed']);
|
||||||
|
}
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0];
|
||||||
|
$aCompanyData = Db::name('article_organ')->where($aWhere)->column('sort,organ_id');
|
||||||
|
}
|
||||||
|
//处理作者
|
||||||
|
$aAuthorData = $aAuthorOrgn = [];
|
||||||
|
if(!empty($aParam['author'])){
|
||||||
|
$aAuthor = $aParam['author'];
|
||||||
|
//通讯作者
|
||||||
|
$aCorresponding = empty($aParam['corresponding']) ? [] : array_column($aParam['corresponding'], null,'name');
|
||||||
|
//查询文章作者
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0];
|
||||||
|
$aAuthorList = Db::name('article_author')->field('art_aut_id,firstname')->where($aWhere)->select();
|
||||||
|
$aAuthorNameList = empty($aAuthorList) ? [] : array_column($aAuthorList, 'firstname');
|
||||||
|
foreach ($aAuthor as $key => $value) {
|
||||||
|
if(empty($iArticleId)){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//处理作者机构单位关联
|
||||||
|
if(!empty($value['company_id'])){
|
||||||
|
foreach ($value['company_id'] as $k => $v) {
|
||||||
|
$iNewSort = empty($aSort[$v]) ? $v : $aSort[$v];
|
||||||
|
$iOrgnId = empty($aCompanyData[$iNewSort]) ? 0 : $aCompanyData[$iNewSort];
|
||||||
|
if(empty($iOrgnId)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$aAuthorOrgn[] = ['article_id' => $iArticleId,'organ_id' => $iOrgnId,'art_aut_id' => $value['name']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$value['firstname'] = empty($value['name']) ? '' : trim($value['name']);
|
||||||
|
//已添加
|
||||||
|
if(!empty($value['firstname']) && in_array($value['firstname'], $aAuthorList)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$value['email'] = empty($aCorresponding[$value['name']]['email']) ? '' : $aCorresponding[$value['name']]['email'];
|
||||||
|
$value['article_id'] = $iArticleId;
|
||||||
|
unset($value['name'],$value['company_id']);
|
||||||
|
$aAuthorData[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!empty($aAuthorData)){
|
||||||
|
$author_result = DB::name('article_author')->insertAll($aAuthorData);
|
||||||
|
if(empty($author_result)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Adding article author failed']);
|
||||||
|
}
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0];
|
||||||
|
$aAuthorResult = DB::name('article_author')->where($aWhere)->select();
|
||||||
|
}
|
||||||
|
|
||||||
|
//作者所属机构
|
||||||
|
$aAuthorOrgnInsert = [];
|
||||||
|
if(!empty($aAuthorOrgn)){
|
||||||
|
//查询文章作者所属机构
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0];
|
||||||
|
$aAuthorOrganList = Db::name('article_author_organ')->field('art_aut_id,organ_id')->where($aWhere)->select();
|
||||||
|
$aAuthorOrganIdList = [];
|
||||||
|
if(!empty($aAuthorOrganList)){
|
||||||
|
foreach ($aAuthorOrganList as $key => $value) {
|
||||||
|
$aAuthorOrganIdList[$value['art_aut_id']][] = $value['organ_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$aAuthorName = empty($aAuthorResult) ? [] : array_column($aAuthorResult, 'art_aut_id','firstname');
|
||||||
|
foreach ($aAuthorOrgn as $key => $value) {
|
||||||
|
if(empty($value['art_aut_id'])){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$iAuthorId = empty($aAuthorName[$value['art_aut_id']]) ? 0 : $aAuthorName[$value['art_aut_id']];
|
||||||
|
if(empty($iAuthorId)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!empty($aAuthorOrganIdList[$iAuthorId]) && in_array($value['organ_id'], $aAuthorOrganIdList[$iAuthorId])){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$value['art_aut_id'] = $iAuthorId;
|
||||||
|
$aAuthorOrgnInsert[] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!empty($aAuthorOrgnInsert)){
|
||||||
|
$author_orgn_result = DB::name('article_author_organ')->insertAll($aAuthorOrgnInsert);
|
||||||
|
if(empty($author_orgn_result)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Adding article author orgn failed']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// //处理上传文件
|
||||||
|
// if(!empty($sFileUrl) && !empty($iUserId)){
|
||||||
|
// $aInsertFile['article_id'] = $iArticleId;
|
||||||
|
// $aInsertFile['user_id'] = $iUserId;
|
||||||
|
// $aInsertFile['username'] = empty($aUser['account']) ? '' : $aUser['account'];
|
||||||
|
// $aInsertFile['file_url'] = trim($sFileUrl,'/');
|
||||||
|
// $aInsertFile['type_name'] = 'manuscirpt';
|
||||||
|
// $aInsertFile['ctime'] = time();
|
||||||
|
// $iFileId = Db::name('article_file')->insertGetId($aInsertFile);
|
||||||
|
// }
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
$aInsert['article_id'] = $iArticleId;
|
||||||
|
return json_encode(['status' => 1,'msg' => 'Successfully added article','article' => $aInsert]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成文章sn号
|
||||||
|
*/
|
||||||
|
private function getArticleAcceptSn($aParam = [],$sFlag = 'Draft')
|
||||||
|
{
|
||||||
|
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||||
|
if(empty($iArticleId)){
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$sDate = date('Y');
|
||||||
|
$sType = $sDate;
|
||||||
|
return $sFlag.$sType.str_pad($iArticleId,6,'0',STR_PAD_LEFT).rand(100,999);
|
||||||
|
}
|
||||||
|
}
|
||||||
218
application/api/controller/Organ.php
Normal file
218
application/api/controller/Organ.php
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\controller;
|
||||||
|
use app\api\controller\Base;
|
||||||
|
use think\Db;
|
||||||
|
/**
|
||||||
|
* @title 文章机构管理
|
||||||
|
*/
|
||||||
|
class Organ extends Base
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct(\think\Request $request = null) {
|
||||||
|
parent::__construct($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文章机构
|
||||||
|
* @param file_url 文件地址
|
||||||
|
*/
|
||||||
|
public function lists(){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//获取文章ID
|
||||||
|
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||||
|
if(empty($iArticleId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select the article']);
|
||||||
|
}
|
||||||
|
//用户ID
|
||||||
|
$iUserId = empty($aParam['user_id']) ? 0 : $aParam['user_id'];
|
||||||
|
if(empty($iUserId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select author']);
|
||||||
|
}
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'user_id' => $iUserId,'state' => ['in',[-1,3]]];
|
||||||
|
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||||
|
if(empty($aArticle)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'The article does not exist']);
|
||||||
|
}
|
||||||
|
if(empty($aArticle)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'The article does not exist']);
|
||||||
|
}
|
||||||
|
//查询文章机构
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0];
|
||||||
|
$aOragn = Db::name('article_organ')->field('organ_id,article_id,organ_name,sort')->where($aWhere)->select();
|
||||||
|
return json_encode(['status' => 1,'data' => $aOragn]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 添加文章机构
|
||||||
|
* @param file_url 文件地址
|
||||||
|
*/
|
||||||
|
public function add(){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//获取文章ID
|
||||||
|
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||||
|
if(empty($iArticleId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select the article']);
|
||||||
|
}
|
||||||
|
//用户ID
|
||||||
|
$iUserId = empty($aParam['user_id']) ? '' : $aParam['user_id'];
|
||||||
|
if(empty($iUserId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select author']);
|
||||||
|
}
|
||||||
|
//机构名称
|
||||||
|
$sOrganName = empty($aParam['organ_name']) ? '' : $aParam['organ_name'];
|
||||||
|
if(empty($sOrganName)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter the name of the institution']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'user_id' => $iUserId,'state' => ['in',[-1,3]]];
|
||||||
|
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||||
|
if(empty($aArticle)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'The article does not exist']);
|
||||||
|
}
|
||||||
|
//查询文章机构
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0,'organ_name' => trim($sOrganName)];
|
||||||
|
$aOragn = Db::name('article_organ')->field('organ_id,article_id,organ_name,sort')->where($aWhere)->find();
|
||||||
|
if(!empty($aOragn)){
|
||||||
|
return json_encode(['status' => 1,'msg' => 'Article organization already exists','data' => $aOragn]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//插入机构表
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0];
|
||||||
|
$aOragn = Db::name('article_organ')->field('max(sort) as sort')->where($aWhere)->find();
|
||||||
|
$iSort = empty($aOragn['sort']) ? 0 : $aOragn['sort'];
|
||||||
|
$iSort += 1;
|
||||||
|
$aInsert = ['article_id' => $iArticleId,'organ_name' => $sOrganName,'create_time' => time(),'sort' => $iSort];
|
||||||
|
$iId = Db::name('article_organ')->insertGetId($aInsert);
|
||||||
|
if(empty($iId)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Failed to add article organization']);
|
||||||
|
}
|
||||||
|
$aInsert['organ_id'] = $iId;
|
||||||
|
return json_encode(['status' => 1,'msg' => 'success','data' => $aInsert]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 修改文章机构
|
||||||
|
* @param file_url 文件地址
|
||||||
|
*/
|
||||||
|
public function modify(){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//获取文章ID
|
||||||
|
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||||
|
if(empty($iArticleId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select the article']);
|
||||||
|
}
|
||||||
|
//用户ID
|
||||||
|
$iUserId = empty($aParam['user_id']) ? '' : $aParam['user_id'];
|
||||||
|
if(empty($iUserId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select author']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//机构名称
|
||||||
|
$sOrganName = empty($aParam['organ_name']) ? '' : $aParam['organ_name'];
|
||||||
|
if(empty($sOrganName)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter the name of the institution']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取机构ID
|
||||||
|
$iOrganId = empty($aParam['organ_id']) ? 0 : $aParam['organ_id'];
|
||||||
|
if(empty($iOrganId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select the institution to modify']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询文章
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'user_id' => $iUserId,'state' => ['in',[-1,3]]];
|
||||||
|
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||||
|
if(empty($aArticle)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'The article does not exist']);
|
||||||
|
}
|
||||||
|
//查询文章机构
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0,'organ_id' => $iOrganId];
|
||||||
|
$aOragn = Db::name('article_organ')->field('organ_id,article_id,organ_name,sort')->where($aWhere)->find();
|
||||||
|
if(empty($aOragn)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Article organization does not exist','data' => $aOragn]);
|
||||||
|
}
|
||||||
|
//查询是否有重名
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0,'organ_id' => ['<>',$iOrganId],'organ_name' => trim($sOrganName)];
|
||||||
|
$aOragn = Db::name('article_organ')->field('organ_id')->where($aWhere)->find();
|
||||||
|
if(!empty($aOragn)){
|
||||||
|
return json_encode(['status' => 1,'msg' => 'Article organization already exists','data' => $aOragn]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新机构
|
||||||
|
$aWhere = ['organ_id' => $iOrganId];
|
||||||
|
$aUpdate = ['organ_name' => $sOrganName,'update_time' => time()];
|
||||||
|
$result = Db::name('article_organ')->where($aWhere)->limit(1)->update($aUpdate);
|
||||||
|
if($result === false){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Failed to update article organization']);
|
||||||
|
}
|
||||||
|
return json_encode(['status' => 1,'msg' => 'success']);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 删除文章机构
|
||||||
|
* @param file_url 文件地址
|
||||||
|
*/
|
||||||
|
public function remove(){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//获取文章ID
|
||||||
|
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||||
|
if(empty($iArticleId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select the article']);
|
||||||
|
}
|
||||||
|
//用户ID
|
||||||
|
$iUserId = empty($aParam['user_id']) ? '' : $aParam['user_id'];
|
||||||
|
if(empty($iUserId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select author']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取机构ID
|
||||||
|
$iOrganId = empty($aParam['organ_id']) ? 0 : $aParam['organ_id'];
|
||||||
|
if(empty($iOrganId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select the institution to modify']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询文章
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'user_id' => $iUserId,'state' => ['in',[-1,3]]];
|
||||||
|
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||||
|
if(empty($aArticle)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'The article does not exist']);
|
||||||
|
}
|
||||||
|
//查询文章机构
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0,'organ_id' => $iOrganId];
|
||||||
|
$aOragn = Db::name('article_organ')->field('organ_id,article_id,organ_name,sort')->where($aWhere)->find();
|
||||||
|
if(empty($aOragn)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Article organization does not exist','data' => $aOragn]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//作者关联的机构
|
||||||
|
$aWhere = ['organ_id' => $iOrganId,'article_id' => $iArticleId,'state' => 0];
|
||||||
|
$aId = Db::name('article_author_organ')->where($aWhere)->column('id');
|
||||||
|
|
||||||
|
//删除机构
|
||||||
|
Db::startTrans();
|
||||||
|
//更新机构状态
|
||||||
|
$aWhere = ['organ_id' => $iOrganId];
|
||||||
|
$aUpdate = ['state' => 1,'update_time' => time()];
|
||||||
|
$result = Db::name('article_organ')->where($aWhere)->limit(1)->update($aUpdate);
|
||||||
|
if($result === false){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Failed to update article organization']);
|
||||||
|
}
|
||||||
|
//更新作者关联的机构
|
||||||
|
if(!empty($aId)){
|
||||||
|
$aWhere = ['id' => ['in',$aId],'state' => 0];
|
||||||
|
$aUpdate = ['state' => 1,'update_time' => time()];
|
||||||
|
$author_organ_result = Db::name('article_author_organ')->where($aWhere)->limit(count($aId))->update($aUpdate);
|
||||||
|
if($author_organ_result === false){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Failed to unbind the relationship between the institution and the author']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
return json_encode(['status' => 1,'msg' => 'success']);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user