diff --git a/app/Anniversary.php b/app/Anniversary.php index 4aa40e8..6058a58 100644 --- a/app/Anniversary.php +++ b/app/Anniversary.php @@ -79,6 +79,13 @@ final class Anniversary } $month = max(1, min(12, (int)($d['month'] ?? 1))); $day = max(1, min(31, (int)($d['day'] ?? 1))); + /* 🔴 v53(用户 2026-10-16 第 1 条):「纪念日需要记录年份,这样才能知道 + **是第几个纪念日**。」 + ⇒ 年份是**可选**的:用户没填(或填了个不合理的)就存 NULL, + 页面只按月日过、不显示"第 N 个" —— 比猜一个年份诚实。 + ⚠️ 合理区间 1900..2100:防手滑输入 0 / 999999 把"第 N 个"算成天文数字。 */ + $year = (int)($d['year'] ?? 0); + $year = ($year >= 1900 && $year <= 2100) ? $year : null; $kind = mb_substr(trim((string)($d['kind'] ?? '')), 0, 40, 'UTF-8'); $note = trim((string)($d['note'] ?? '')); $leap = !empty($d['leap']) ? 1 : 0; @@ -117,18 +124,18 @@ final class Anniversary if ($id > 0) { $db->prepare( - 'UPDATE anniversaries SET title=?, repeat_type=?, month=?, day=?, is_leap=?, + 'UPDATE anniversaries SET title=?, repeat_type=?, year=?, month=?, day=?, is_leap=?, kind=?, note=?, person_id=? WHERE id=? AND family_id=?' - )->execute([$title, $repeat, $month, $day, $leap, $kind !== '' ? $kind : null, + )->execute([$title, $repeat, $year, $month, $day, $leap, $kind !== '' ? $kind : null, $note !== '' ? $note : null, $pid, $id, $familyId]); self::savePeople($id, $pids); return $id; } $db->prepare( - 'INSERT INTO anniversaries (family_id, title, repeat_type, month, day, is_leap, + 'INSERT INTO anniversaries (family_id, title, repeat_type, year, month, day, is_leap, kind, note, person_id) - VALUES (?,?,?,?,?,?,?,?,?)' - )->execute([$familyId, $title, $repeat, $month, $day, $leap, + VALUES (?,?,?,?,?,?,?,?,?,?)' + )->execute([$familyId, $title, $repeat, $year, $month, $day, $leap, $kind !== '' ? $kind : null, $note !== '' ? $note : null, $pid]); $newId = (int)$db->lastInsertId(); self::savePeople($newId, $pids); @@ -448,6 +455,14 @@ final class Anniversary } $date = sprintf('%04d-%02d-%02d', $sol['year'], $sol['month'], $sol['day']); } else { + /* 🔴 v53:`once`(只此一次)**有年份时只在那一年出现**。 + 老行为是"落在公历分支 ⇒ 年年都冒出来",与"只此一次"自相矛盾; + 以前没有年份,没法判"哪一年",只能那样漂着。 + ⚠️ 没有年份的 `once` 仍然保持老行为(不知道是哪一年,不能凭空丢掉)。 */ + $onceYear = (int)($a['year'] ?? 0); + if ($repeat === 'once' && $onceYear > 0 && $onceYear !== $year) { + continue; + } // 公历(含"只此一次"):2/29 落在平年时退到 2/28 $dd = $d; if (!checkdate($m, $dd, $year)) { @@ -459,6 +474,16 @@ final class Anniversary if (($a['source'] ?? '') !== 'custom' && !empty($a['born'])) { $age = Birthday::ageOn((string)$a['born'], $date); } + /* 🔴 v53(用户 2026-10-16 第 1 条):算出**这是第几个纪念日**。 + 规则:`nth = 本次年份 - 起始年份 + 1`(起始那年就是"第 1 个")。 + ⚠️ 只用**用户自己填的** `year`(`birthdays()` 派生的生日条目没有这一项, + 它们走 `age` 那套,别混)。没填年份 ⇒ null ⇒ 页面不显示序号。 + ⚠️ `nth < 1` 不显示(年份填到了未来 ⇒ 这一年的这次还没到"第 1 个")。 */ + $y0 = (int)($a['year'] ?? 0); + // ⚠️ 派生的生日条目没有 year(它们走 age 那套),所以这里判 source + $nth = (($a['source'] ?? 'custom') === 'custom') + ? self::nthFor($y0 > 0 ? $y0 : null, $year) + : null; $out[] = [ 'date' => $date, 'title' => (string)($a['title'] ?? ''), @@ -469,6 +494,8 @@ final class Anniversary 'id' => (int)($a['id'] ?? 0), 'age' => $age, 'repeat' => $repeat, + 'year' => $y0 > 0 ? $y0 : null, // 用户填的起始年(没有则 null) + 'nth' => $nth, // 第几个(没有年份则 null) ]; } return $out; @@ -511,4 +538,26 @@ final class Anniversary { return self::REPEAT[$k] ?? $k; } + + /** + * 🔴 v53(用户 2026-10-16 第 1 条):**这是第几个纪念日**。 + * + * `nth = 年份 - 起始年 + 1`(起始那年就是"第 1 个");没有起始年(或算出来 < 1)返回 null。 + * + * ⚠️ **单点来源**:`occurrences()`(临近区)与 `days/index.php`(我自己添加的那张表) + * 都调它 —— 两处各写一遍 `date('Y') - $year + 1` 是本项目反复踩过的 + * "同一个概念两处计算"型坑(改一处忘一处 ⇒ 两个页面显示的序号能对不上)。 + * ⚠️ 用**今天所在的年**("今年是第几个")而不是"下一次发生的那年"—— + * 否则一个 12 月的纪念日在 1 月看会显示成"第 N+1 个",反直觉。 + */ + public static function nthFor(?int $startYear, ?int $inYear = null): ?int + { + $y0 = (int)($startYear ?? 0); + if ($y0 <= 0) { + return null; + } + $y = $inYear !== null ? (int)$inYear : (int)date('Y'); + $n = $y - $y0 + 1; + return $n >= 1 ? $n : null; + } } \ No newline at end of file diff --git a/app/Schema.php b/app/Schema.php index a9203fc..777d6b7 100644 --- a/app/Schema.php +++ b/app/Schema.php @@ -1837,6 +1837,8 @@ CREATE TABLE IF NOT EXISTS `anniversaries` ( `title` VARCHAR(120) NOT NULL, `repeat_type` ENUM('solar','lunar','once') NOT NULL DEFAULT 'solar' COMMENT '重复方式:solar=每年阳历同月同日 / lunar=每年农历同月同日 / once=只此一次', + `year` SMALLINT UNSIGNED DEFAULT NULL + COMMENT '起始年份(v53:算"第几个纪念日"用;NULL=用户没填,只按月日过)', `month` TINYINT UNSIGNED NOT NULL, `day` TINYINT UNSIGNED NOT NULL, `is_leap` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '农历:该月是否为闰月', @@ -1852,6 +1854,20 @@ CREATE TABLE IF NOT EXISTS `anniversaries` ( COMMENT='纪念日:用户自建(生日不在此表,由 persons 实时派生)' SQL); + // ---- 🔴 v53(用户 2026-10-16 第 1 条):纪念日要有**年份** ---- + // 「纪念日需要记录年份,这样才能知道**是第几个纪念日**。」 + // ⇒ 加 `anniversaries.year`。新库由上面那条 CREATE TABLE 带上; + // **老库**(表已在、但没有这一列)走这里补。 + // ⚠️ 调用点必须**紧跟在这张表的 CREATE TABLE 之后**: + // `addColumn` 是 `ALTER TABLE`,表还不存在就会 + // `1146 Table ... doesn't exist` —— 整段 Schema::ensure 直接抛异常, + // install 变成"安装失败"(本轮实测踩到过:放在 movie_details 那段里, + // 而 anniversaries 的建表在那之后 ⇒ 全新安装直接挂)。 + // ⚠️ 可空、不给默认值:**老数据就是没有年份**,猜一个(比如按创建年)反而会 + // 让页面上算出一个错的"第 N 个"。NULL = 只按月日过、不显示序号 —— 诚实。 + self::addColumn($db, 'anniversaries', 'year', + "ADD COLUMN `year` SMALLINT UNSIGNED DEFAULT NULL COMMENT '起始年份(算第几个纪念日)' AFTER `repeat_type`"); + // ---- 财务 / 账本(版本 13,用户第 15 条)---- // 两层:账本(可共享给人的一本总账)+ 账目(存款/基金/保险/房子/车子…)。 // ⚠️ 金额一律存**分**(BIGINT),不存浮点:钱是最不能容忍 diff --git a/assets/css/app.css b/assets/css/app.css index 4b9d398..5926e46 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -5385,6 +5385,22 @@ h5.md-h, h6.md-h { font-size: 14px; } ⚠️ `> .mv-lb` 而**不是** `.mv-row label`:后者会把同行人那排 checkbox 的 小标签一起卷进来(它们不是"字段标签")。 */ .mv-grid { display: flex; flex-direction: column; gap: 12px; } +/* 🔴🔴 v53(用户 2026-10-16 第 3 条):「点击一个日程,弹出简介,点击编辑, + 新的编辑框,**只有左侧有内容,右侧是空白的,好像分栏了一样**。这个样式不太对。」 + + 真根因:日程编辑页(`templates/calendar/event.php`)里,`.mv-grid`(观影式的**纵向**列表) + 被嵌在**两列**的 `.form-grid` 里: + `
` ← `grid-template-columns: 1fr 1fr` + `
` ← 一个 grid 项,**只占第一列** + 在整页形态下不明显(页面宽,两列各 ~700px 还能看);但**浮层里面板只有 620px** + ⇒ 两列各 286px,而所有字段都挤在左边那一列 286px 里,右边整列空着 —— 就是用户看到的"分栏"。 + (实测:panel 620 / form-grid 588 / cols="286px 286px" / mv-grid w=286。) + + ⇒ 让 `.mv-grid` **跨满整行**(`grid-column: 1 / -1`)。 + 它本身是 `
` 包着**纵向堆叠**的 `.mv-row`,语义上就是"一整块、占满宽度", + 天生不该被塞进半列。这样两种形态(整页 / 浮层)都正确, + 而且不必去改 `event.php` 里"整页保留两列"的结构判断(那条注释说明整页形态是有意保留的)。 */ +.form-grid > .mv-grid { grid-column: 1 / -1; } .mv-row { display: flex; align-items: flex-start; gap: 10px; min-width: 0; } .mv-row > .mv-lb { flex: 0 0 62px; width: 62px; /* 固定宽 = 对齐的基准 */ diff --git a/index.php b/index.php index 2fc2709..b669226 100644 --- a/index.php +++ b/index.php @@ -860,18 +860,26 @@ switch ($r) { $soon = array_values(array_filter($soon, static function (array $e): bool { return (string)($e['kind'] ?? '') !== 'lunar'; })); - // 进行中的任务 + 已经过期的待办(**只有这些才值得占首页**; - // 没截止日期的待办放任务看板里看,堆到首页会变成一张长长的清单) + // 进行中的任务 + 待办(用户 2026-10-16 v53 第 2 条) // // ⚠️ v24 第 14 批 用户第 2 条:**按状态取,不看板取**。 // 原话:「首页上显示的任务,是和任务的状态有关,而不是和它在那个看板有关」。 // 原来调的是 Task::board() —— 它只取**默认看板**,于是建在别的看板上的 // 「进行中」永远上不了首页(用户看到的就是"我明明在做,首页却没有")。 + // + // 🔴🔴 v53(用户 2026-10-16 第 2 条):「首页的近期任务,**把待办也放进来吧, + // 放在进行中的下面**。」 + // ⇒ 原来只收「进行中 + **已逾期**的待办」(当年怕"待办一多首页变成一张长清单")。 + // 现在用户明确要待办也进来,那就**全部**收进来,并按**状态分组**: + // 进行中在前、待办在后 —— "放在进行中的下面"就是这个意思, + // 而不是"混在一起按截止时间排"(那样进行中的会被一堆待办淹掉)。 + // ⚠️ 两组**各自内部**仍按截止时间升序(byStatus 的 ORDER BY 已经排好), + // 所以"马上要做的"在各自那一段里仍然靠前。 + // ⚠️ 逾期仍是**红色整行**(状态语义,见模板),它落在"待办"那一段里 —— + // 与原来"逾期待办会进清单"的行为一致,只是现在**没逾期的待办也在**。 $tasks = Task::byStatus($familyId, $me, 'doing'); foreach (Task::byStatus($familyId, $me, 'todo') as $t) { - if (Task::isOverdue($t['due_at'] ?? null)) { - $tasks[] = $t; - } + $tasks[] = $t; } $memories = home_memories($familyId); @@ -1931,6 +1939,11 @@ switch ($r) { // 工作经历先给一行空白(第 4 条),省得还要点「再加一段」 'jobRows' => [[]], 'myNote' => '', + // 🔴 v53(第 4/5 条):新增页也要能打标签 + 填「我对他的称呼 / 备注」。 + // 标签候选与编辑页同一个来源(我名下用过的全部标签)。 + 'myTags' => [], + 'tagChoices' => array_column(PersonTag::cloud((int)Auth::familyId(), (int)Auth::personId()), 'tag'), + 'myNick' => '', ], 'people'); break; @@ -2004,6 +2017,11 @@ switch ($r) { 'contacts' => $contacts, 'jobRows' => (array)($d['jobs'] ?? []), 'myNote' => trim((string)($_POST['my_note'] ?? '')), + // 🔴 v53:新增页新加的这三样也要**原样回显**,否则一撞名/一报错 + // 用户刚打的标签、刚写的称呼与备注就全没了(重填一遍)。 + 'myTags' => PersonTag::clean((string)($_POST['tags'] ?? '')), + 'tagChoices' => array_column(PersonTag::cloud((int)Auth::familyId(), (int)Auth::personId()), 'tag'), + 'myNick' => trim((string)($_POST['my_nick'] ?? '')), 'confirmHit' => $hit, 'confirmWhy' => (string)($hit['_match'] ?? 'name'), ], 'people'); @@ -2055,6 +2073,9 @@ switch ($r) { // 私备注同理(第 5 条)—— 别让他重填一遍。 'jobRows' => (array)($d['jobs'] ?? []), 'myNote' => trim((string)($_POST['my_note'] ?? '')), + 'myTags' => PersonTag::clean((string)($_POST['tags'] ?? '')), + 'tagChoices' => array_column(PersonTag::cloud($familyId, (int)Auth::personId()), 'tag'), + 'myNick' => trim((string)($_POST['my_nick'] ?? '')), ], 'people'); exit; } @@ -2082,23 +2103,41 @@ switch ($r) { // 私备注同理(第 5 条)—— 别让他重填一遍。 'jobRows' => (array)($d['jobs'] ?? []), 'myNote' => trim((string)($_POST['my_note'] ?? '')), + 'myTags' => PersonTag::clean((string)($_POST['tags'] ?? '')), + 'tagChoices' => array_column(PersonTag::cloud($familyId, (int)Auth::personId()), 'tag'), + 'myNick' => trim((string)($_POST['my_nick'] ?? '')), ], 'people'); exit; } // 我加的人,自动进**我的**名册(名册是每人一份的,v5 起)。 - // 分组:表单里选了就用它(用户第 12 条「增加名册时可选择所属分组」); - // ⚠️ 只认**我自己**的分组列表里的 id —— 表单可以改,不能凭它把人塞进 - // 别人私有的分组、或根本不存在的分组里。 - $gid = (int)($_POST['group_id'] ?? 0); - $okGids = array_map('intval', array_column( - PersonGroup::orderFor($familyId, (int)Auth::personId()), 'id')); - if ($gid > 0 && !in_array($gid, $okGids, true)) { - $gid = 0; - } - PersonRoster::ensure($familyId, (int)Auth::personId(), $id, $gid > 0 ? $gid : null, 'self'); + // 🔴 v53(用户 2026-10-16 第 4 条):「添加成员时**不是选择分组,而是打标签**, + // 现在已经没有分组的概念了,只有标签的概念。」 + // ⇒ 新增表单不再给 group_id 下拉(改成标签输入)。这里硬写 null: + // · 名册里"未分组"本来就合法(拖到哪栏都能再归); + // · 列表页还有「调整分组」那套(拖动归档),需要时再用。 + // ⚠️ 表结构 `person_roster.group_id` **保留不动**(拖动归档还在用它, + // 历史数据也在)—— 只是**新增入口不再要求人选**。 + PersonRoster::ensure($familyId, (int)Auth::personId(), $id, null, 'self'); Person::replaceContacts($id, $contacts); // 工作经历:整组替换(第 4 条)。空的那组会把这段经历清空 —— 与联系人同一口径。 PersonJob::replace($id, (array)($d['jobs'] ?? [])); + // 🔴 v53(用户 2026-10-16 第 5 条):新增页也要能一次填完「我对他的称呼」与 + // 「我对他的备注」,否则用户还得"先添加 → 再回他的名册 → 再填这两样"。 + // ⚠️ 两者都挂在**我**名下(别人写的互不影响): + // · 称呼 → nicknames(viewer=我, target=他); + // · 备注 → person_notes(owner=我, person=他)。 + // ⚠️ 判"表单里有没有这一栏"用 `array_key_exists`(而不是判值是否为空)—— + // 与编辑路径同一个口径:空串是明确的"清空"语义(`Nickname::set('')` 会删行)。 + if (array_key_exists('my_nick', $_POST)) { + Nickname::set($familyId, (int)Auth::personId(), $id, (string)$_POST['my_nick']); + } + if (array_key_exists('my_note', $_POST)) { + PersonNote::set($id, (int)Auth::personId(), (string)$_POST['my_note']); + } + // 标签(v53 第 4 条):与"编辑成员"页同一个入口、同一把尺(owner 永远是"我")。 + if (array_key_exists('tags', $_POST)) { + PersonTag::setFor($familyId, (int)Auth::personId(), $id, (string)$_POST['tags']); + } clear_old(); if ($avatarWarn !== '') { flash('ok', '已把「' . $d['name'] . '」加进名册。头像没有保存:' . $avatarWarn); @@ -2158,6 +2197,9 @@ switch ($r) { (名册页那颗标签按钮也只在 `$canMove` 时出现)。 */ 'myTags' => $isSelf ? [] : PersonTag::of((int)Auth::personId(), $id), 'tagChoices' => $isSelf ? [] : array_column(PersonTag::cloud((int)Auth::familyId(), (int)Auth::personId()), 'tag'), + // 🔴 v53(第 5 条):编辑页也要回显「我对他的称呼」(与新增页同一个字段名), + // 否则在新增页填了称呼、到编辑页却看不见(会以为没存上)。 + 'myNick' => $isSelf ? '' : Nickname::get((int)Auth::personId(), $id), ], 'people'); break; @@ -2292,6 +2334,13 @@ switch ($r) { if ((int)$id !== (int)Auth::personId() && array_key_exists('my_note', $_POST)) { PersonNote::set($id, (int)Auth::personId(), (string)$_POST['my_note']); } + // 🔴 v53(用户 2026-10-16 第 5 条):**我对他的称呼** —— 与上面那条同一把尺, + // 新增页与编辑页都会提交 `my_nick`(同一个字段名,一处处理)。 + // ⚠️ 空串 = **清空**("留空就用他自己的名字"是明确语义,与"没这个字段"不同)—— + // 所以这里用 `array_key_exists` 判"表单里有没有这一栏",而不是判"值是不是空"。 + if ((int)$id !== (int)Auth::personId() && array_key_exists('my_nick', $_POST)) { + Nickname::set($familyId, (int)Auth::personId(), $id, (string)$_POST['my_nick']); + } if ((int)$p['id'] === (int)Auth::personId()) { Auth::refreshAvatar((string)$d['avatar']); // 姓名也可能改了 —— 不同步会话的话顶栏还是旧名字 @@ -4675,6 +4724,9 @@ $want = array_keys($want); 'repeat_type' => (string)($_POST['repeat_type'] ?? 'solar'), 'month' => (int)($_POST['month'] ?? 1), 'day' => (int)($_POST['day'] ?? 1), + // 🔴 v53(用户 2026-10-16 第 1 条):年份 —— 用来算"第几个纪念日"。 + // 留空就是 0/空串 ⇒ Anniversary::save 里落成 NULL(不猜年份)。 + 'year' => (int)($_POST['year'] ?? 0), 'is_leap' => !empty($_POST['is_leap']), 'kind' => (string)($_POST['kind'] ?? ''), 'note' => (string)($_POST['note'] ?? ''), diff --git a/templates/days/form.php b/templates/days/form.php index fe8b197..841bba4 100644 --- a/templates/days/form.php +++ b/templates/days/form.php @@ -147,6 +147,14 @@ $backUrl = url('days'); + ` 是 YYYY-MM-DD), + 但下面那个拆分 JS 以前**只取 mm/dd、把年份丢了** ⇒ 库里没有年份。 + 现在补一个 hidden `year`,由同一条 JS 一起写。 + ⚠️ 留空 = 不记年份(`` 清空时 year 也清空)—— + 页面就不显示"第 N 个",不猜。 */ ?> +
@@ -268,12 +276,16 @@ $backUrl = url('days'); var d = document.getElementById('an-date'); var mo = document.getElementById('an-month'); var dy = document.getElementById('an-day'); + var yr = document.getElementById('an-year'); if (!d || !mo || !dy) { return; } function split() { var m = (d.value || '').match(/^(\d{4})-(\d{2})-(\d{2})$/); if (!m) { return; } // 空值不动(用户清空时保留原值,不至于变成 0) mo.value = String(parseInt(m[2], 10)); dy.value = String(parseInt(m[3], 10)); + /* 🔴 v53(第 1 条):年份一起写进 hidden —— 它就是"第几个纪念日"的依据。 + ⚠️ 以前这里**只取 mm/dd**,年份被丢掉 ⇒ 库里根本没年份,算不出第几个。 */ + if (yr) { yr.value = m[1]; } } d.addEventListener('change', split); split(); // 初始也同步一次(编辑回填) diff --git a/templates/days/index.php b/templates/days/index.php index 20df577..a30523b 100644 --- a/templates/days/index.php +++ b/templates/days/index.php @@ -87,6 +87,23 @@ $renderTable = function (array $rows, bool $editable) use ($canWrite, $kindBadge (闰月) + + + + + 年起 + + 第 个 + + @@ -310,6 +327,13 @@ $renderTable = function (array $rows, bool $editable) use ($canWrite, $kindBadge 岁 + + + 第 个 + diff --git a/templates/home.php b/templates/home.php index 8e0ac8f..97c6c14 100644 --- a/templates/home.php +++ b/templates/home.php @@ -140,20 +140,27 @@ $todayMarks = $todayMarks ?? ['tags' => [], 'line' => '']; 用户刚在看板上拖成「进行中」的那件任务于是**不计入**,数字就显示 0。 两个口径不同源,数字和列表当场对不上。 - ⇒ 现在这个数字与右侧列表**同源**:`doing + 已逾期的 todo` - (也就是 `count($tasks)`,与 index.php 传给本页的那个数组完全一致)。 - 文案也说清是什么:「件在做」,而不是含糊的「件待办」。 + ⇒ 现在这个数字与右侧列表**同源**(与 index.php 传给本页的**同一个数组**)。 + + 🔴 v53(用户 2026-10-16 第 2 条):右侧列表现在**也含待办**了(放在进行中下面) + ⇒ 「件在做」不能再数整个数组(那会把待办也算成"在做")。 + 改成**按状态拆开数**:进行中 →「件在做」,待办 →「件待办」。 + ⚠️ 两个数字相加 = 右侧列表的行数(列表也是这两段拼起来的),仍然同源。 ⚠️ 「已经动手」与「排队等着」是两件事(用户第 6 条要求说清区别): 首页要回答的是"我手头在做什么",所以主数字用「在做」的口径; 排队的那些(todo)另给一个小字,不必让人点进任务页才知道还有多少。 */ ?> + - 件在做 + title="近期任务(进行中)"> + 件在做 - 0): ?> + 0): ?> - 件待办 + 件待办 0): ?> @@ -428,7 +435,7 @@ unset($evRef); 所以每行前面也有复选框,点了就地完成(AJAX,不跳页)。 表单与 JS 在页面末尾各一份(见 home.php 的 taskDoneForm 段)。 */ ?> -

没有进行中的任务。

+

没有进行中的任务,也没有待办。