diff --git a/app/Anniversary.php b/app/Anniversary.php index bc36857..d089ea2 100644 --- a/app/Anniversary.php +++ b/app/Anniversary.php @@ -591,7 +591,24 @@ final class Anniversary public static function occurrences(int $familyId, int $viewerId, int $year): array { $out = []; - foreach (self::all($familyId, $viewerId) as $a) { + $all = self::all($familyId, $viewerId); + + /* 🔴🔴 #91d(用户 2026-11-05):「你去查一下这个领证纪念日到底关联了几个人, + 数据库里。」 + + 查库结果:`anniversaries #2` 的**老列** `person_id = 1`(只能存一个), + 但 `anniversary_people` 里有 **2 人**(杨永全 + 洪博为)。 + 端上编辑框只读老列 ⇒ 只带出 1 个人,另一个被静默丢掉。 + + ⇒ 在这里一次性把多对多关系查出来。 + ⚠️ **一次查全表**而不是逐条查:`peopleMap()` 正是为此写的 + (`split()` 早就这么用了;这里漏了)。 + ⚠️ 不能直接用老列兜底就完事 —— 老列是升级前的遗留字段, + 两边不一致时**以多对多表为准**(用户在新版界面上改的是那张表)。 + ⚠️ 多对多表里没有行时才退回老列(升级过渡期还没回填的条目)。 */ + $pmap = self::peopleMap(array_column($all, 'id')); + + foreach ($all as $a) { $repeat = (string)($a['repeat_type'] ?? 'solar'); $m = (int)($a['month'] ?? 0); $d = (int)($a['day'] ?? 0); @@ -649,6 +666,16 @@ final class Anniversary 在这里一次性算好,别让每个渲染点各自去查一遍配置。 */ 'icon' => self::iconOf($familyId, (string)($a['kind'] ?? '')), 'person_id' => (int)($a['person_id'] ?? 0), + /* #91d:**完整关联人列表**(多对多表为准,空则退回老列)。 + 端上编辑纪念日要带出全部关联人、只读卡要显示"关联了谁"。 */ + 'person_ids' => (function () use ($pmap, $a): array { + $aid = (int)($a['id'] ?? 0); + if ($aid > 0 && !empty($pmap[$aid])) { + return array_map('intval', $pmap[$aid]); + } + $one = (int)($a['person_id'] ?? 0); + return $one > 0 ? [$one] : []; + })(), /* 🔴 #87(用户 2026-11-05):「如果这个纪念日来自生日… 点击之后,显示这个人的头像、姓名,以及生日的『日』和日期就可以了。」