where('key', 'system')->where('enterprise_id', 0)->find(); if (!$row || empty($row['value'])) { return null; } $raw = $row['value']; $arr = is_string($raw) ? json_decode($raw, true) : $raw; if (!is_array($arr) || !isset($arr['defaultEnterpriseId']) || $arr['defaultEnterpriseId'] === '' || $arr['defaultEnterpriseId'] === null) { return null; } $de = (int) $arr['defaultEnterpriseId']; if ($de <= 0) { return null; } if (!EnterpriseModel::where('id', $de)->find()) { return null; } return $de; } catch (\Throwable $e) { return null; } } }