mainId ?? 0; $name = $data['name'] ?? ''; if (empty($name)) { util::fail("请输入名称"); } $has = self::getByCondition(['mainId' => $mainId, 'name' => $name]); if ($has) { util::fail("名称已存在"); } $res = self::add($data); //在首店添加,则父级下所有直营和加盟店,同步添加分类 if (isset($masterShop->default) && $masterShop->default == 1) { $sjId = $masterShop->sjId ?? 0; $shopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true); foreach ($shopList as $shop) { $shopId = $shop->id ?? 0; if ($shopId == $masterShop->id) { //前面已经添加过了 continue; } $thisMainId = $shop->mainId ?? 0; $data['shopId'] = $shopId; $data['mainId'] = $thisMainId; $has = self::getByCondition(['mainId' => $thisMainId, 'name' => $name]); if (!empty($has)) { continue; } self::add($data); } } return $res; } }