Merge remote-tracking branch 'origin/master'
This commit is contained in:
358
application/api/controller/Articlemain.php
Normal file
358
application/api/controller/Articlemain.php
Normal file
@@ -0,0 +1,358 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
use app\api\controller\Base;
|
||||
use think\Db;
|
||||
/**
|
||||
* @title 文章正文内容处理
|
||||
*/
|
||||
class Articlemain extends Base
|
||||
{
|
||||
|
||||
|
||||
|
||||
public function __construct(\think\Request $request = null) {
|
||||
parent::__construct($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传表格图片
|
||||
*/
|
||||
public function uploadTableImage(){
|
||||
|
||||
//获取参数
|
||||
$aParam = $this->request->post();
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||
if(empty($iArticleId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select an article' ));
|
||||
}
|
||||
//上传文件域
|
||||
$file = $this->request->file('file_name');
|
||||
if (empty($file)) {
|
||||
return json_encode(array('status' => 2,'msg' => 'No uploaded file was obtained'));
|
||||
}
|
||||
//查询文章信息
|
||||
$aWhere = ['article_id' => $iArticleId];
|
||||
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||
if(empty($aArticle)){
|
||||
return json_encode(array('status' => 3,'msg' => 'The article does not exist' ));
|
||||
}
|
||||
//验证文件(类型/大小)
|
||||
$validate = [
|
||||
'size' => 1024000, // 限制1M以内
|
||||
// 'ext' => 'jpg,jpeg,png,gif' // 允许的后缀
|
||||
];
|
||||
$fileValid = $file->validate($validate);
|
||||
if (!$fileValid) {
|
||||
$errorMsg = $file->getError();
|
||||
return json_encode(['status' => 3, 'msg' => 'Format/size validation failed:' . $errorMsg]);
|
||||
}
|
||||
|
||||
//图片名后缀
|
||||
$ext = $file->getExtension();
|
||||
if (empty($ext)) {
|
||||
// 获取文件真实MIME类型(复制粘贴的图片也能识别)
|
||||
$mime = $file->getMime();
|
||||
// MIME类型与后缀的映射表(覆盖常见图片类型)
|
||||
$mimeExtMap = [
|
||||
// 基础图片格式
|
||||
'image/jpeg' => 'jpg',
|
||||
'image/jpg' => 'jpg', // 兼容简写
|
||||
'image/png' => 'png',
|
||||
'image/gif' => 'gif',
|
||||
'image/bmp' => 'bmp',
|
||||
'image/x-bmp' => 'bmp', // 兼容Windows bmp
|
||||
// 扩展图片格式
|
||||
'image/webp' => 'webp', // 网页常用
|
||||
'image/tiff' => 'tiff',
|
||||
'image/x-tiff' => 'tiff',
|
||||
'image/svg+xml' => 'svg', // 矢量图
|
||||
'image/heic' => 'heic', // 苹果图片格式
|
||||
'image/heif' => 'heif',
|
||||
'image/avif' => 'avif', // 高效压缩图
|
||||
// 特殊图片格式
|
||||
'image/x-icon' => 'ico', // 图标
|
||||
'image/vnd.microsoft.icon' => 'ico',
|
||||
];
|
||||
$ext = $mimeExtMap[$mime] ?? '';
|
||||
}
|
||||
$ext = empty($ext) ? 'png' : $ext;
|
||||
//组装新的图片名
|
||||
$sFileName = md5(uniqid(mt_rand(), true)) . '.' . $ext;
|
||||
|
||||
//保存文件
|
||||
$sImagePath = rtrim(ROOT_PATH,'/') . '/public' . DS . 'articleTableImage' . DS . $iArticleId;
|
||||
if (!is_dir($sImagePath)) {
|
||||
mkdir($sImagePath, 0777, true);
|
||||
}
|
||||
$sImageName = $fileValid->move($sImagePath,$sFileName);
|
||||
if (!$sImageName) {
|
||||
return json_encode(['status' => 4, 'msg' => $fileValid->getError()]);
|
||||
}
|
||||
|
||||
//返回图片路径
|
||||
return json_encode(['status' => 1, 'msg' => 'Upload successful','data' => $iArticleId .DS.$sFileName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取正文内容里删除图片
|
||||
*/
|
||||
public function removeMainImage(){
|
||||
|
||||
//获取参数
|
||||
$aParam = $this->request->post();
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||
if(empty($iArticleId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select an article' ));
|
||||
}
|
||||
//图片ID
|
||||
$iAmiId = empty($aParam['ami_id']) ? 0 : $aParam['ami_id'];
|
||||
if(empty($iAmiId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select the image ID to query'));
|
||||
}
|
||||
//查询文章信息
|
||||
$aWhere = ['article_id' => $iArticleId];
|
||||
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||
if(empty($aArticle)){
|
||||
return json_encode(array('status' => 3,'msg' => 'The article does not exist' ));
|
||||
}
|
||||
//查询图片信息
|
||||
$aWhere = ['ami_id' => $iAmiId,'state' => 0,'article_id' => $iArticleId];
|
||||
$aMainImage = Db::name('article_main_image')->field('ami_id')->where($aWhere)->find();
|
||||
if(empty($aMainImage)){
|
||||
return json_encode(array('status' => 4,'msg' => 'Article image information does not exist' ));
|
||||
}
|
||||
//获取正文内容
|
||||
$aWhere = ['article_id' => $iArticleId,'type' => ['in',[0,1]],'state' => 0,'is_h1' => ['<>',1],'is_h2' => ['<>',1],'is_h3' => ['<>',1]];
|
||||
$aArticleMain = Db::name('article_main')->field('am_id,content,type,ami_id')->where($aWhere)->order('sort asc')->select();
|
||||
|
||||
$iBindImage = 2;
|
||||
if(!empty($aArticleMain)){//验证正文内容是否绑定该图片
|
||||
//数据处理
|
||||
foreach ($aArticleMain as $key => $value) {
|
||||
$sContent = empty($value['content']) ? '' : trim($value['content']);
|
||||
if(empty($sContent)){
|
||||
continue;
|
||||
}
|
||||
if(!empty($iAmiId)){
|
||||
if($value['type'] == 1 && $value['ami_id'] == $iAmiId){
|
||||
$iBindImage = 1;
|
||||
break;
|
||||
}
|
||||
if($value['type'] == 0){
|
||||
$result = $this->hasProcessedTagWithId($value['content'],$iAmiId);
|
||||
if($result == 1){
|
||||
$iBindImage = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($iBindImage == 1){
|
||||
return json_encode(array('status' => 5,'msg' => 'The main content has been bound to this image and cannot be deleted' ));
|
||||
}
|
||||
//删除图片
|
||||
$aWhere = ['ami_id' => $iAmiId];
|
||||
$aUpdate = ['state' => 1];
|
||||
$result = Db::name('article_main_image')->where($aWhere)->limit(1)->update($aUpdate);
|
||||
if($result === false){
|
||||
return json_encode(array('status' => 6,'msg' => 'Image deletion failed' ));
|
||||
}
|
||||
//返回数据
|
||||
return json_encode(array('status' => 1,'msg' => 'Image deleted successfully'));
|
||||
}
|
||||
/**
|
||||
* 获取正文内容里删除表格
|
||||
*/
|
||||
public function removeMainTable(){
|
||||
|
||||
//获取参数
|
||||
$aParam = $this->request->post();
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||
if(empty($iArticleId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select an article' ));
|
||||
}
|
||||
//表格ID
|
||||
$iAmtId = empty($aParam['amt_id']) ? 0 : $aParam['amt_id'];
|
||||
if(empty($iAmtId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select the table ID to query'));
|
||||
}
|
||||
//查询文章信息
|
||||
$aWhere = ['article_id' => $iArticleId];
|
||||
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||
if(empty($aArticle)){
|
||||
return json_encode(array('status' => 3,'msg' => 'The article does not exist' ));
|
||||
}
|
||||
//查询表格信息
|
||||
$aWhere = ['amt_id' => $iAmtId,'state' => 0,'article_id' => $iArticleId];
|
||||
$aMainTable = Db::name('article_main_table')->field('amt_id')->where($aWhere)->find();
|
||||
if(empty($aMainTable)){
|
||||
return json_encode(array('status' => 4,'msg' => 'Article table information does not exist' ));
|
||||
}
|
||||
|
||||
//获取正文内容
|
||||
$aWhere = ['article_id' => $iArticleId,'type' => ['in',[0,2]],'state' => 0,'is_h1' => ['<>',1],'is_h2' => ['<>',1],'is_h3' => ['<>',1]];
|
||||
$aArticleMain = Db::name('article_main')->field('am_id,content,type,amt_id')->where($aWhere)->order('sort asc')->select();
|
||||
//数据处理-验证正文是否绑定表格
|
||||
$iBindTable = 2;
|
||||
if(!empty($aArticleMain)){
|
||||
foreach ($aArticleMain as $key => $value) {
|
||||
$sContent = empty($value['content']) ? '' : trim($value['content']);
|
||||
if(empty($sContent)){
|
||||
continue;
|
||||
}
|
||||
if($value['type'] == 2 && $value['amt_id'] == $iAmtId){
|
||||
$iBindTable = 1;
|
||||
break;
|
||||
}
|
||||
if($value['type'] == 0){
|
||||
$result = $this->hasProcessedTagWithId($value['content'],$iAmtId,'mytable');
|
||||
if($result == 1){
|
||||
$iBindTable = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($iBindTable == 1){
|
||||
return json_encode(array('status' => 5,'msg' => 'The main content is already bound to this table and cannot be deleted' ));
|
||||
}
|
||||
//删除表格
|
||||
$aWhere = ['amt_id' => $iAmtId];
|
||||
$aUpdate = ['state' => 1];
|
||||
$result = Db::name('article_main_table')->where($aWhere)->limit(1)->update($aUpdate);
|
||||
if($result === false){
|
||||
return json_encode(array('status' => 6,'msg' => 'Table deletion failed' ));
|
||||
}
|
||||
//返回数据
|
||||
return json_encode(array('status' => 1,'msg' => 'Table deleted successfully'));
|
||||
}
|
||||
/**
|
||||
* 验证是否存在
|
||||
*/
|
||||
public function hasProcessedTagWithId($content = '', $primaryId = 0, $sLable = 'myfigure') {
|
||||
if(empty($content) || empty($primaryId)){
|
||||
return 2;
|
||||
}
|
||||
$escapedTagName = preg_quote($sLable, '/');
|
||||
$escapedId = preg_quote($primaryId, '/');
|
||||
|
||||
// 优化后的正则表达式
|
||||
$pattern = "/<{$escapedTagName}\s+data-id\s*=\s*['\"]{$escapedId}['\"]\s*>(.*?)<\/{$escapedTagName}>/i";
|
||||
|
||||
// 执行匹配
|
||||
if (!preg_match($pattern, $content, $matches)) {
|
||||
return 3;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/**
|
||||
* 获取文章关联的图片
|
||||
*/
|
||||
public function getArticleMainImage(){
|
||||
//获取参数
|
||||
$aParam = $this->request->post();
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||
if(empty($iArticleId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select an article' ));
|
||||
}
|
||||
//查询文章信息
|
||||
$aWhere = ['article_id' => $iArticleId];
|
||||
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||
if(empty($aArticle)){
|
||||
return json_encode(array('status' => 3,'msg' => 'The article does not exist' ));
|
||||
}
|
||||
//查询图片信息
|
||||
$aWhere = ['state' => 0,'article_id' => $iArticleId];
|
||||
$aMainImage = Db::name('article_main_image')->field('ami_id,title')->where($aWhere)->select();
|
||||
return json_encode(array('status' => 1,'msg' => 'success','data' => $aMainImage));
|
||||
}
|
||||
/**
|
||||
* 获取文章关联的表格
|
||||
*/
|
||||
public function getArticleMainTable(){
|
||||
//获取参数
|
||||
$aParam = $this->request->post();
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||
if(empty($iArticleId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select an article' ));
|
||||
}
|
||||
//查询文章信息
|
||||
$aWhere = ['article_id' => $iArticleId];
|
||||
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||
if(empty($aArticle)){
|
||||
return json_encode(array('status' => 3,'msg' => 'The article does not exist' ));
|
||||
}
|
||||
//查询表格信息
|
||||
$aWhere = ['state' => 0,'article_id' => $iArticleId];
|
||||
$aMainTable = Db::name('article_main_table')->field('amt_id,title')->where($aWhere)->order('amt_id asc')->select();
|
||||
return json_encode(array('status' => 1,'msg' => 'success','data' => $aMainTable));
|
||||
}
|
||||
/**
|
||||
* 获取文章关联图片的详细信息
|
||||
*/
|
||||
public function getMainImageInfo(){
|
||||
//获取参数
|
||||
$aParam = $this->request->post();
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||
if(empty($iArticleId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select an article' ));
|
||||
}
|
||||
//图片ID
|
||||
$iAmiId = empty($aParam['ami_id']) ? 0 : $aParam['ami_id'];
|
||||
if(empty($iAmiId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select the image ID to query'));
|
||||
}
|
||||
//查询文章信息
|
||||
$aWhere = ['article_id' => $iArticleId];
|
||||
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||
if(empty($aArticle)){
|
||||
return json_encode(array('status' => 3,'msg' => 'The article does not exist' ));
|
||||
}
|
||||
//查询图片信息
|
||||
$aWhere = ['state' => 0,'article_id' => $iArticleId,'ami_id' => $iAmiId];
|
||||
$aMainImage = Db::name('article_main_image')->field('ami_id,title,url,note')->where($aWhere)->find();
|
||||
return json_encode(array('status' => 1,'msg' => 'success','data' => $aMainImage));
|
||||
}
|
||||
/**
|
||||
* 获取文章关联表格的详细信息
|
||||
*/
|
||||
public function getMainTableInfo(){
|
||||
//获取参数
|
||||
$aParam = $this->request->post();
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||
if(empty($iArticleId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select an article' ));
|
||||
}
|
||||
//表格ID
|
||||
$iAmtId = empty($aParam['amt_id']) ? 0 : $aParam['amt_id'];
|
||||
if(empty($iAmtId)){
|
||||
return json_encode(array('status' => 2,'msg' => 'Please select the table ID to query'));
|
||||
}
|
||||
//查询文章信息
|
||||
$aWhere = ['article_id' => $iArticleId];
|
||||
$aArticle = Db::name('article')->field('article_id')->where($aWhere)->find();
|
||||
if(empty($aArticle)){
|
||||
return json_encode(array('status' => 3,'msg' => 'The article does not exist' ));
|
||||
}
|
||||
//查询表格信息
|
||||
$aWhere = ['state' => 0,'article_id' => $iArticleId,'amt_id' => $iAmtId];
|
||||
$aMainTable = Db::name('article_main_table')->field('amt_id,type,table_data,url,title,note')->where($aWhere)->find();
|
||||
return json_encode(array('status' => 1,'msg' => 'success','data' => $aMainTable));
|
||||
}
|
||||
}
|
||||
@@ -4196,4 +4196,72 @@ class Production extends Base
|
||||
$sContent .= $sReferences;
|
||||
return ['status' => 1,'msg' => 'success','data' => ['references' => $sContent,'references_list' => $aReferencesLists]];
|
||||
}
|
||||
/**
|
||||
* 生成初稿-处理正文内容表格/图片相关联
|
||||
* @param p_article_id 生产环境文章信息
|
||||
*/
|
||||
public function dealMainFigureOrTable(){
|
||||
|
||||
//获取参数
|
||||
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||
|
||||
//必填值验证
|
||||
$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,'type' => 0,'state' => 0,'is_h1' => ['<>',1],'is_h2' => ['<>',1],'is_h3' => ['<>',1]];
|
||||
$aTextMain = Db::name('article_main')->field('am_id,content')->where($aWhere)->order('sort asc')->select();
|
||||
if(empty($aTextMain)){
|
||||
return json_encode(array('status' => 3,'msg' => 'The content is empty' ));
|
||||
}
|
||||
//查询图片信息
|
||||
$aWhere = ['article_id' => $iArticleId,'type' => 1,'state' => 0];
|
||||
$aImageMain = Db::name('article_main')->where($aWhere)->order('sort asc')->column('ami_id');
|
||||
//查询图片信息
|
||||
$aWhere = ['article_id' => $iArticleId,'type' => 2,'state' => 0];
|
||||
$aTableMain = Db::name('article_main')->where($aWhere)->order('sort asc')->column('amt_id');
|
||||
|
||||
//数据处理
|
||||
$aUpdate = [];
|
||||
$oFigureTagProcessor = new \app\common\FigureTagProcessor;
|
||||
$oTableTagProcessor = new \app\common\TableTagProcessor;
|
||||
foreach ($aTextMain as $key => $value) {
|
||||
$sContent = empty($value['content']) ? '' : trim($value['content']);
|
||||
if(empty($sContent)){
|
||||
continue;
|
||||
}
|
||||
//处理图片
|
||||
$aFigureContent = $oFigureTagProcessor->dealFigureStr($sContent,$aImageMain);
|
||||
$iStatus = empty($aFigureContent['status']) ? 0 : $aFigureContent['status'];
|
||||
$sData = empty($aFigureContent['data']) ? '' : $aFigureContent['data'];
|
||||
// var_dump($aFigureContent);
|
||||
if($iStatus != 1){
|
||||
$sData = $sContent;
|
||||
}else{
|
||||
$aUpdate[$value['am_id']] = ['am_id' => $value['am_id'],'content' => $sData];
|
||||
}
|
||||
//处理表格
|
||||
$aTableContent = $oTableTagProcessor->dealTableStr($sData,$aTableMain);
|
||||
$iStatus = empty($aTableContent['status']) ? 0 : $aTableContent['status'];
|
||||
$sData = empty($aTableContent['data']) ? $sContent : $aTableContent['data'];
|
||||
if($iStatus != 1){
|
||||
continue;
|
||||
}
|
||||
$aUpdate[$value['am_id']] = ['am_id' => $value['am_id'],'content' => $sData];
|
||||
}
|
||||
//批量更新入库
|
||||
if(empty($aUpdate)){
|
||||
return json_encode(array('status' => 3,'msg' => 'No table or image data to be processed was found' ));
|
||||
}
|
||||
|
||||
$oArticleMain = new \app\common\ArticleMain();
|
||||
$result = $oArticleMain->saveAll($aUpdate);
|
||||
if ($result === false) {
|
||||
return json_encode(array('status' => 4,'msg' => 'Operation failed'.json_encode($aUpdate)));
|
||||
}
|
||||
|
||||
return json_encode(array('status' => 1,'msg' => 'success'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,9 +659,6 @@ class Workbench extends Base
|
||||
return json_encode(['status' => 7,'msg' => 'The article is not in the review status']);
|
||||
}
|
||||
|
||||
//查询期刊信息
|
||||
$aWhere = ['journal_id' => $aArticle['article_id'],'state' => 0];
|
||||
$aJournal = Db::name('journal')->field('title as journal_name,website')->find();
|
||||
//查询期刊信息
|
||||
if(empty($aArticle['journal_id'])){
|
||||
return json_encode(array('status' => 8,'msg' => 'The article is not associated with a journal' ));
|
||||
@@ -721,7 +718,8 @@ class Workbench extends Base
|
||||
|
||||
//发邮件
|
||||
//邮箱
|
||||
$email = empty($aUser[$iUserId]['email']) ? '' : $aUser[$iUserId]['email'];
|
||||
// $email = empty($aUser[$iUserId]['email']) ? '' : $aUser[$iUserId]['email'];
|
||||
$email = empty($aJournal['email']) ? '' : $aJournal['email'];
|
||||
if(empty($email)){
|
||||
return json_encode(['status' => 8,'msg' => 'Edit email as empty']);
|
||||
}
|
||||
@@ -793,9 +791,6 @@ class Workbench extends Base
|
||||
return json_encode(['status' => 7,'msg' => 'The article is not in the review status']);
|
||||
}
|
||||
|
||||
//查询期刊信息
|
||||
$aWhere = ['journal_id' => $aArticle['article_id'],'state' => 0];
|
||||
$aJournal = Db::name('journal')->field('title as journal_name,website')->find();
|
||||
//查询期刊信息
|
||||
if(empty($aArticle['journal_id'])){
|
||||
return json_encode(array('status' => 8,'msg' => 'The article is not associated with a journal' ));
|
||||
@@ -807,10 +802,10 @@ class Workbench extends Base
|
||||
}
|
||||
|
||||
//判断编辑的操作权限
|
||||
$iEditorId = empty($aJournal['editor_id']) ? 0 : $aJournal['editor_id'];
|
||||
if($iEditorId != $iUserId){
|
||||
return json_encode(array('status' => 10,'msg' => 'This article is not authorized for operation under the journal you are responsible for' ));
|
||||
}
|
||||
// $iEditorId = empty($aJournal['editor_id']) ? 0 : $aJournal['editor_id'];
|
||||
// if($iEditorId != $iUserId){
|
||||
// return json_encode(array('status' => 10,'msg' => 'This article is not authorized for operation under the journal you are responsible for' ));
|
||||
// }
|
||||
|
||||
//更新文章状态为邀请
|
||||
$aWhere = ['art_rev_id' => $iArtRevId,'state' => 4];
|
||||
|
||||
Reference in New Issue
Block a user