From bf0208b32a0092cc1a968323a705c85b9a3a6f25 Mon Sep 17 00:00:00 2001 From: chengxl Date: Sun, 18 Jan 2026 17:06:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=AD=A3=E6=96=87=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E8=A1=A8=E6=A0=BC/=E5=9B=BE=E7=89=87=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Production.php | 68 +++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/application/api/controller/Production.php b/application/api/controller/Production.php index 6d5d5b2..4f3b171 100644 --- a/application/api/controller/Production.php +++ b/application/api/controller/Production.php @@ -3803,4 +3803,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')); + } }