From bd59c206981b6a240a32b6220c7c52bf7687c1d9 Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Thu, 7 Aug 2025 17:07:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20admapi=20-=20=E4=BA=A7=E5=93=81=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E5=90=8C=E6=AD=A5=E5=88=86=E7=B1=BB=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/ReceiveProductSync.php | 24 +++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/admin/controller/ReceiveProductSync.php b/app/admin/controller/ReceiveProductSync.php index 4aa670fb..04ddf5d8 100644 --- a/app/admin/controller/ReceiveProductSync.php +++ b/app/admin/controller/ReceiveProductSync.php @@ -99,18 +99,20 @@ class ReceiveProductSync } $category = ProductCategoryModel::language($lang_id)->tcoId($tco_category['id'])->find(); - $tco_parent = ProductTcoCategoryModel::language($lang_id)->tcoId($tco_category['tco_pid'])->find(); - if (!empty($tco_parent)) { - $parent = ProductCategoryModel::language($lang_id)->tcoId($tco_parent['id'])->find(); - if ($parent->isEmpty()) { - throw new \Exception('产品分类父级不存在'); + if (!empty($category)) { + $tco_parent = ProductTcoCategoryModel::language($lang_id)->tcoId($tco_category['tco_pid'])->find(); + if (!empty($tco_parent)) { + $parent = ProductCategoryModel::language($lang_id)->tcoId($tco_parent['id'])->find(); + if ($parent->isEmpty()) { + throw new \Exception('产品分类父级不存在'); + } + $category['pid'] = $parent['id']; + $category['path'] = $parent['path'] . $parent['pid']; + $category['level'] = $parent['level'] + 1; + } + if (!$category->save()) { + throw new \Exception('产品分类更新失败'); } - $category['pid'] = $parent['id']; - $category['path'] = $parent['path'] . $parent['pid']; - $category['level'] = $parent['level'] + 1; - } - if (!$category->save($category)) { - throw new \Exception('产品分类更新失败'); } }