From ab2bc31c0451b12a352dbce2c81816a6016492f1 Mon Sep 17 00:00:00 2001 From: xiaodong Date: Wed, 9 Sep 2026 17:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=86=85=E5=AE=B9bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/backend/ContentController.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/app/controller/backend/ContentController.php b/app/controller/backend/ContentController.php index 7dd954d..d07e2ea 100644 --- a/app/controller/backend/ContentController.php +++ b/app/controller/backend/ContentController.php @@ -708,21 +708,31 @@ class ContentController extends BaseController // category_map(源语言栏目ID) → 目标语言栏目ID $categoryMap = array_combine($categoryMapData, array_column($categories,'id')); - // 清理目标语言已有的关联数据,防止重复插入 + // 查找模型 + $Module = new Module(); + $modules = $Module->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id']],'id asc','id,table')['data']; + $SubContent = new SubContent(); + + // 清理目标语言已有的数据,防止重复插入 $existingTargetSubIds = Db::name('sub_content') ->where('lang', $param['to']) ->where('seller_id', $this->admin['seller_id']) ->column('id'); if (!empty($existingTargetSubIds)) { + // 清理关联表 Db::name('category_sub_content')->where('sub_content_id', 'in', $existingTargetSubIds)->delete(); Db::name('tag_sub_content')->where('sub_content_id', 'in', $existingTargetSubIds)->delete(); Db::name('inner_chart_sub_content')->where('sub_content_id', 'in', $existingTargetSubIds)->delete(); + // 清理各模块主表 + foreach($modules as $m){ + Db::name($m['table'])->where([['sub_id','in',$existingTargetSubIds],['lang','=',$param['to']]])->delete(); + } + // 清理副表 + Db::name('sub_content')->where('id', 'in', $existingTargetSubIds)->delete(); } - - // 查找模型 - $Module = new Module(); - $modules = $Module->getAllCustomArrayData(['seller_id'=>$this->admin['seller_id']],'id asc','id,table')['data']; - $SubContent = new SubContent(); + // 清理目标语言导航数据 + Db::name('nav')->where('lang', $param['to'])->where('seller_id', $this->admin['seller_id'])->delete(); + Db::name('nav_cate')->where('lang', $param['to'])->where('seller_id', $this->admin['seller_id'])->delete(); // 源语言sub_content_id → 目标语言sub_content_id 的映射 $subIdMap = []; @@ -739,11 +749,6 @@ class ContentController extends BaseController $contentIds = array_column($content,'id'); // 源语言主表内容 $mainContent = Db::name($module['table'])->where([['sub_id','in',$contentIds]])->select()->toArray(); - // 源语言主表 sub_id → 主表记录 的映射 - $mainContentBySubId = []; - foreach($mainContent as $mc){ - $mainContentBySubId[$mc['sub_id']] = $mc; - } // ========== 逐条插入副表(sub_content),获取实际新ID ========== foreach($content as $item){