0) { try { $st = Database::get()->prepare('SELECT slogan FROM persons WHERE id = ? AND family_id = ?'); $st->execute([$personId, $familyId]); $mine = trim((string)($st->fetchColumn() ?: '')); if ($mine !== '') { return $mine; } } catch (\Throwable $ex) { // 老库还没这一列 / 读不到都不该挡路:往下走家庭那句 } } try { $f = self::find($familyId); $motto = trim((string)($f['motto'] ?? '')); if ($motto !== '') { return $motto; } } catch (\Throwable $ex) { // 同上:读不到就用默认 } return self::DEFAULT_SLOGAN; } public static function find(int $id): ?array { $st = Database::get()->prepare('SELECT * FROM families WHERE id = ?'); $st->execute([$id]); $row = $st->fetch(); return $row ?: null; } public static function create(string $name, string $motto = ''): int { $st = Database::get()->prepare('INSERT INTO families (name, motto) VALUES (?, ?)'); $st->execute([$name, $motto !== '' ? $motto : null]); return (int)Database::get()->lastInsertId(); } public static function update(int $id, string $name, string $motto = ''): void { $st = Database::get()->prepare('UPDATE families SET name = ?, motto = ? WHERE id = ?'); $st->execute([$name, $motto !== '' ? $motto : null, $id]); } public static function countMembers(int $familyId): int { $st = Database::get()->prepare( "SELECT COUNT(*) FROM persons WHERE family_id = ? AND kind = 'member'" ); $st->execute([$familyId]); return (int)$st->fetchColumn(); } }