diff --git a/app/service/CategoryService.php b/app/service/CategoryService.php index fec021f..9af0270 100644 --- a/app/service/CategoryService.php +++ b/app/service/CategoryService.php @@ -328,6 +328,7 @@ class CategoryService $Category = new Category(); $prefix = env('database.prefix'); $cateTable = $prefix . 'category'; + $res = Db::query("SHOW TABLE STATUS WHERE NAME = '$cateTable'"); $maxId = $res[0]['Auto_increment']; $targetIds = range($maxId, $maxId + $cateCount - 1); @@ -339,16 +340,22 @@ class CategoryService unset($val['update_time']); $val['website_id'] = $site; $val['category_map'] = $val['id']; - $val['lang_map'] = $map[$val['lang']]; + $val['lang_map'] = $val['lang']; $val['lang'] = $lang; if ($val['parent_id'] != 0) { $pathArr = explode('-', $val['path']); $tmpPath = ''; array_pop($pathArr); foreach ($pathArr as $path) { + if (!isset($map[$path])) { + throw new \Exception("栏目路径映射失败: 找不到源ID {$path} 的映射"); + } $tmpPath .= $map[$path] . '-'; } $val['path'] = $tmpPath; + if (!isset($map[$val['parent_id']])) { + throw new \Exception("栏目父级映射失败: 找不到源ID {$val['parent_id']} 的映射"); + } $val['parent_id'] = $map[$val['parent_id']]; } // 美化url