v8:观影落地(MovieLog 整体迁入统一事件原语)+ 三处 UI 撤除

- Schema v8:events / movie_details / event_attendees / event_photos 四张表,
  uk_event_source(family_id, source_ref) 作迁移幂等锚
- Movie 模型:时间线/详情/增删改、同行人整组替换、照片逐张管理、感受英→中映射
- ImageSlot 新增 poster(2:3) / ticket(free) / photo(free) 三槽位;
  free 槽位不裁剪、整图等比缩进框(只缩不放大)
- OssDriver::copyObject:同桶 CopyObject(手写 V1 签名,x-oss-* 头按字典序进签名串)
- 路由:movies 时间线/详情/新增/编辑/删除/补照片/删照片;同行人按家庭过滤;
  访客只读(requireWrite)
- UI 撤除:首页「我的一句话」、家谱页「补充我的亲属关系 / 看整个名册」两个按钮;
  顶栏加「观影」入口
- 修潜伏 bug:ImageSlot::parseRatio 的正则用 / 作分隔符,字符类里的 / 把模式
  提前截断(Unknown modifier ']')—— ratio() 只在上传 POST 里被调到,一直没被观察到
- 线上数据迁移(临时 token 门禁页,用完即删):MovieLog 219 条观影 → events,
  14 位观影人新增进名册(带 MovieLog 头像),431 个 OSS 对象同桶拷贝
  (movielog/uploads/<dir>/x → family/<dir>/x),review/feelings/影院三段/照片全量搬
This commit is contained in:
2026-09-30 20:22:46 +08:00
parent 809443d429
commit ff353b1eee
13 changed files with 1112 additions and 43 deletions
+39 -4
View File
@@ -41,7 +41,34 @@ final class ImageSlot
'dir' => 'avatars',
'hint' => '正方形。页面上显示成圆形或圆角方形,所以按 1:1 裁。',
],
// 题图按 16:9 —— 宽屏横幅。现在还没有位置用它,需要时把它启用即可:
// v8 观影三槽位。海报是竖版的(豆瓣海报约 2:3)→ 裁剪;
// 票根/现场照片是随手拍、比例五花八门 → ratio='free':**不裁剪**,
// 等比缩到框内(w×h 是「最长边」而不是固定输出尺寸),服务端保证不变形。
'poster' => [
'label' => '海报',
'ratio' => '2:3',
'w' => 600,
'h' => 900,
'dir' => 'posters',
'hint' => '竖版海报,按 2:3 裁。没裁就按整图居中取。',
],
'ticket' => [
'label' => '票根',
'ratio' => 'free',
'w' => 1400,
'h' => 1400,
'dir' => 'tickets',
'hint' => '票根不裁剪,等比缩到最长边 1400。',
],
'photo' => [
'label' => '照片',
'ratio' => 'free',
'w' => 1600,
'h' => 1600,
'dir' => 'photos',
'hint' => '现场照片不裁剪,等比缩到最长边 1600。',
],
// 题图按 16:9 —— 宽屏横幅。需要时把它启用即可:
// 'cover' => ['label' => '题图', 'ratio' => '16:9', 'w' => 1920, 'h' => 1080,
// 'dir' => 'covers', 'hint' => '宽屏横幅,显示在详情页顶部。'],
];
@@ -57,16 +84,22 @@ final class ImageSlot
return self::SLOTS[$key] ?? null;
}
/** 宽高比(宽 / 高)。'1:1' → 1.0,'16:9' → 1.777… */
/** 宽高比(宽 / 高)。'1:1' → 1.0,'16:9' → 1.777…,'free' → 0.0(不锁比例、不裁剪) */
public static function ratio(array $slot): float
{
if (($slot['ratio'] ?? '') === 'free') {
return 0.0;
}
[$a, $b] = self::parseRatio((string)($slot['ratio'] ?? '1:1'));
return $b > 0 ? $a / $b : 1.0;
}
/** 给前端用的 CSS aspect-ratio 写法:'1 / 1'、'16 / 9' */
/** 给前端用的 CSS aspect-ratio 写法:'1 / 1'、'16 / 9';free 槽位返回空串(前端不进裁剪器) */
public static function ratioCss(array $slot): string
{
if (($slot['ratio'] ?? '') === 'free') {
return '';
}
[$a, $b] = self::parseRatio((string)($slot['ratio'] ?? '1:1'));
return $a . ' / ' . $b;
}
@@ -74,7 +107,9 @@ final class ImageSlot
/** @return array{0:int,1:int} */
private static function parseRatio(string $ratio): array
{
if (preg_match('/^\s*(\d+)\s*[:/]\s*(\d+)\s*$/', $ratio, $m)) {
// ⚠️ 分隔符别用 /:'[:/]' 里的斜杠会把模式提前截断("Unknown modifier ']'"),
// 这个潜伏 bug 一直没炸是因为 ratio() 只在上传 POST 里被调到(302 正文没人扫)。
if (preg_match('#^\s*(\d+)\s*[:/]\s*(\d+)\s*$#', $ratio, $m)) {
$a = max(1, (int)$m[1]);
$b = max(1, (int)$m[2]);
return [$a, $b];
+281
View File
@@ -0,0 +1,281 @@
<?php
/**
* 观影记录(统一事件原语的第一个落地种类)。
*
* 归一模型(见 familybook.md 的核心设计):
* events = 一切记录的共同骨架(标题 / 日期 / 地点 / 来源引用)
* movie_details = 观影特有的卫星表(海报 / 票根 / 评分 / 影评 / 影院三段)
* attendees = 同行观影的人(persons.id)
* photos = 现场照片(可多张)
*
* 图片一律存**相对键**(如 posters/xxx.jpg),地址由 media.php 代理 ——
* 本地与 OSS 的差别被 Storage 吃掉,这里永远不碰完整 URL。
*
* source_ref 是迁移幂等的锚点:MovieLog 整体迁入时写成 'movielog:movie:<id>',
* 重跑迁移按它先删后插,不会出现一半新一半旧的中间态。
*/
declare(strict_types=1);
namespace App;
final class Movie
{
/** 观后感受标签(MovieLog 迁移时把英文键映射成中文,这里就是唯一清单) */
public const FEELINGS = ['温暖', '激动', '欢乐', '深思', '伤感', '震撼', '治愈', '无聊'];
/** MovieLog 的英文感受键 → 中文标签(没见过的键原样保留) */
public const FEELING_MAP = [
'warm' => '温暖',
'excited' => '激动',
'thoughtful' => '深思',
'sad' => '伤感',
'funny' => '欢乐',
'happy' => '欢乐',
'boring' => '无聊',
'moved' => '治愈',
'shocked' => '震撼',
];
/** @return array<int,array> 按年份倒序的全部观影记录(时间线用) */
public static function all(int $familyId): array
{
$st = Database::get()->prepare(
'SELECT e.id, e.title, e.starts_at, e.location, e.note,
d.poster_key, d.ticket_key, d.rating, d.cinema_name, d.cinema_place,
(SELECT COUNT(*) FROM event_attendees a WHERE a.event_id = e.id) AS attendee_count,
(SELECT GROUP_CONCAT(p.name ORDER BY a.position, p.id SEPARATOR "、")
FROM event_attendees a JOIN persons p ON p.id = a.person_id
WHERE a.event_id = e.id) AS attendee_names
FROM events e
LEFT JOIN movie_details d ON d.event_id = e.id
WHERE e.family_id = ? AND e.kind = "movie"
ORDER BY e.starts_at DESC, e.id DESC'
);
$st->execute([$familyId]);
return $st->fetchAll();
}
/** 一条完整记录(详情/编辑页用):事件 + 卫星 + 同行人 + 照片 */
public static function find(int $familyId, int $id): ?array
{
$st = Database::get()->prepare(
'SELECT e.*, d.info, d.poster_key, d.ticket_key, d.rating, d.review, d.feelings,
d.cinema_place, d.cinema_name, d.cinema_address
FROM events e
LEFT JOIN movie_details d ON d.event_id = e.id
WHERE e.family_id = ? AND e.id = ? AND e.kind = "movie"'
);
$st->execute([$familyId, $id]);
$row = $st->fetch();
if (!$row) {
return null;
}
$row['attendees'] = self::attendees($id);
$row['photos'] = self::photos($id);
return $row;
}
/** @return array<int,array{id:int,name:string,avatar:?string}> 同行的人 */
public static function attendees(int $eventId): array
{
$st = Database::get()->prepare(
'SELECT p.id, p.name, p.avatar
FROM event_attendees a JOIN persons p ON p.id = a.person_id
WHERE a.event_id = ?
ORDER BY a.position, p.id'
);
$st->execute([$eventId]);
return $st->fetchAll();
}
public static function photos(int $eventId): array
{
$st = Database::get()->prepare(
'SELECT id, `key` FROM event_photos WHERE event_id = ? ORDER BY position, id'
);
$st->execute([$eventId]);
return $st->fetchAll();
}
/**
* 新建一条观影记录,返回事件 id。
* $d 字段:title, starts_at(Y-m-d), location, note, info, rating, review,
* feelings(array), cinema_place, cinema_name, cinema_address,
* poster_key, ticket_key, attendees(int[]), photos(string[])
*/
public static function create(int $familyId, ?int $creatorId, array $d): int
{
$db = Database::get();
$db->prepare(
'INSERT INTO events (family_id, creator_id, kind, title, starts_at, location, note, source_ref)
VALUES (?, ?, "movie", ?, ?, ?, ?, ?)'
)->execute([
$familyId, $creatorId, (string)$d['title'], self::dateOrNull($d['starts_at'] ?? ''),
self::locOrNull($d['location'] ?? ''), self::textOrNull($d['note'] ?? ''),
$d['source_ref'] ?? null,
]);
$id = (int)$db->lastInsertId();
self::saveDetails($id, $d);
self::saveAttendees($id, $d['attendees'] ?? []);
self::savePhotos($id, $d['photos'] ?? []);
return $id;
}
public static function update(int $familyId, int $id, array $d): void
{
$db = Database::get();
$db->prepare(
'UPDATE events SET title = ?, starts_at = ?, location = ?, note = ? WHERE id = ? AND family_id = ?'
)->execute([
(string)$d['title'], self::dateOrNull($d['starts_at'] ?? ''),
self::locOrNull($d['location'] ?? ''), self::textOrNull($d['note'] ?? ''),
$id, $familyId,
]);
self::saveDetails($id, $d);
self::saveAttendees($id, $d['attendees'] ?? []);
// photos 由单独的「删除某张」路由维护,编辑保存不整组替换
}
/** 卫星表 upsert(编辑时可能还没建过这行) */
private static function saveDetails(int $eventId, array $d): void
{
$db = Database::get();
$feel = array_values(array_filter(array_map(
static fn($f) => mb_substr(trim((string)$f), 0, 20, 'UTF-8'),
(array)($d['feelings'] ?? [])
), static fn($f) => $f !== ''));
$row = [
self::textOrNull($d['info'] ?? ''),
self::keyOrNull($d['poster_key'] ?? ''),
self::keyOrNull($d['ticket_key'] ?? ''),
isset($d['rating']) && $d['rating'] !== '' ? max(0, min(10, (int)$d['rating'])) : null,
self::textOrNull($d['review'] ?? ''),
$feel ? json_encode($feel, JSON_UNESCAPED_UNICODE) : null,
self::locOrNull($d['cinema_place'] ?? ''),
self::locOrNull($d['cinema_name'] ?? ''),
self::textOrNull($d['cinema_address'] ?? ''),
];
$has = $db->prepare('SELECT COUNT(*) FROM movie_details WHERE event_id = ?');
$has->execute([$eventId]);
if ((int)$has->fetchColumn() > 0) {
$db->prepare(
'UPDATE movie_details SET info=?, poster_key=?, ticket_key=?, rating=?, review=?,
feelings=?, cinema_place=?, cinema_name=?, cinema_address=? WHERE event_id=?'
)->execute([...$row, $eventId]);
} else {
$db->prepare(
'INSERT INTO movie_details (info, poster_key, ticket_key, rating, review,
feelings, cinema_place, cinema_name, cinema_address, event_id)
VALUES (?,?,?,?,?,?,?,?,?,?)'
)->execute([...$row, $eventId]);
}
}
/** 整组替换同行人(与 Person::replaceContacts 同一思路:一行不剩、一行不多) */
public static function saveAttendees(int $eventId, array $personIds): void
{
$db = Database::get();
$db->prepare('DELETE FROM event_attendees WHERE event_id = ?')->execute([$eventId]);
$ins = $db->prepare(
'INSERT IGNORE INTO event_attendees (event_id, person_id, position) VALUES (?, ?, ?)'
);
$pos = 0;
foreach ($personIds as $pid) {
$pid = (int)$pid;
if ($pid <= 0) {
continue;
}
$pos += 10;
$ins->execute([$eventId, $pid, $pos]);
}
}
/** 整组替换现场照片(导入用;表单的「删一张」走 deletePhoto) */
public static function savePhotos(int $eventId, array $keys): void
{
$db = Database::get();
$db->prepare('DELETE FROM event_photos WHERE event_id = ?')->execute([$eventId]);
$ins = $db->prepare('INSERT INTO event_photos (event_id, `key`, position) VALUES (?, ?, ?)');
$pos = 0;
foreach ($keys as $k) {
$k = trim((string)$k);
if ($k === '') {
continue;
}
$pos += 10;
$ins->execute([$eventId, $k, $pos]);
}
}
/** 删一张现场照片(连带删存储对象) */
public static function deletePhoto(int $familyId, int $eventId, int $photoId): void
{
$st = Database::get()->prepare('SELECT `key` FROM event_photos WHERE id = ? AND event_id = ?');
$st->execute([$photoId, $eventId]);
$key = (string)($st->fetchColumn() ?: '');
Database::get()->prepare('DELETE FROM event_photos WHERE id = ? AND event_id = ?')
->execute([$photoId, $eventId]);
if ($key !== '') {
Storage\Storage::delete($familyId, $key);
}
}
/** 删除整条观影记录(events 级联带走卫星/同行人/照片行;存储对象手动清) */
public static function destroy(int $familyId, int $id): void
{
$keys = [];
foreach (self::photos($id) as $p) {
$keys[] = (string)$p['key'];
}
$st = Database::get()->prepare(
'SELECT poster_key, ticket_key FROM movie_details WHERE event_id = ?'
);
$st->execute([$id]);
if ($row = $st->fetch()) {
foreach ([$row['poster_key'], $row['ticket_key']] as $k) {
if ($k) {
$keys[] = (string)$k;
}
}
}
Database::get()->prepare('DELETE FROM events WHERE id = ? AND family_id = ? AND kind = "movie"')
->execute([$id, $familyId]);
foreach ($keys as $k) {
Storage\Storage::delete($familyId, $k);
}
}
// ---------------- 小工具 ----------------
private static function dateOrNull(string $v): ?string
{
$v = trim($v);
if ($v === '' || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $v)) {
return null;
}
return $v;
}
private static function locOrNull(string $v): ?string
{
$v = mb_substr(trim($v), 0, 200, 'UTF-8');
return $v !== '' ? $v : null;
}
private static function textOrNull(string $v): ?string
{
$v = trim($v);
return $v !== '' ? $v : null;
}
/** 存储键只留安全字符(相对键,不带路径穿越),空串回 NULL */
private static function keyOrNull(string $v): ?string
{
$v = ltrim(trim($v), '/');
if ($v === '' || strpos($v, '..') !== false || strpos($v, "\0") !== false) {
return null;
}
return $v;
}
}
+67 -1
View File
@@ -37,8 +37,13 @@ final class Schema
* 升级时按已有关系回填。起因:家谱/首页按关系推导可见,名册按分享推导
* —— 同一个人三处口径打架(配偶能在家谱看到孩子、名册里却没有)。
* 用户拍板:树上的人三处都可见,没上树的都不可见。
* 8 → **归一事件原语落地(观影先行)**:events(统一事件:标题/日期/地点/
* 来源引用 source_ref)+ movie_details(卫星表:海报/票根/评分/影评/
* 影院三段)+ event_attendees(参与人)+ event_photos(现场照片)。
* MovieLog 的 219 部观影记录整体迁入(source_ref='movielog:movie:<id>',
* 幂等重跑的锚点)。日历本/CalDAV 是后续阶段,events 先不带 calendar_id。
*/
public const VERSION = '7';
public const VERSION = '8';
/** @return string[] */
public static function statements(): array
@@ -193,6 +198,67 @@ CREATE TABLE IF NOT EXISTS `person_contacts` (
KEY `idx_pc_person` (`person_id`, `kind`, `position`),
CONSTRAINT `fk_pc_person` FOREIGN KEY (`person_id`) REFERENCES `persons` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='成员的联系方式(可多条):电话 / 邮箱 / 地址 / 网址,对齐 vCard'
SQL,
<<<'SQL'
CREATE TABLE IF NOT EXISTS `events` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`family_id` INT UNSIGNED NOT NULL,
`creator_id` INT UNSIGNED DEFAULT NULL COMMENT '谁记的(persons.id);系统迁移可为 NULL',
`kind` ENUM('movie') NOT NULL COMMENT '事件类型:movie=观影(trip/任务等是后续阶段的卫星表)',
`title` VARCHAR(200) NOT NULL COMMENT '事件标题(观影=片名)',
`starts_at` DATE DEFAULT NULL COMMENT '发生日期(观影=观影日期;精确到时刻的需求等日历阶段再升 DATETIME)',
`location` VARCHAR(200) DEFAULT NULL COMMENT '地点(观影=影院名)',
`note` TEXT DEFAULT NULL COMMENT '备注',
`source_ref` VARCHAR(64) DEFAULT NULL COMMENT '外部来源引用(如 movielog:movie:123)——迁移幂等重跑的锚点',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_event_source` (`family_id`, `source_ref`),
KEY `idx_event_family_kind` (`family_id`, `kind`, `starts_at`),
CONSTRAINT `fk_event_family` FOREIGN KEY (`family_id`) REFERENCES `families` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_event_creator` FOREIGN KEY (`creator_id`) REFERENCES `persons` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='统一事件:观影/旅行/任务…共同点是都有时间、有人参与、要上日历'
SQL,
<<<'SQL'
CREATE TABLE IF NOT EXISTS `movie_details` (
`event_id` INT UNSIGNED NOT NULL,
`info` TEXT DEFAULT NULL COMMENT '简介(豆瓣抓取的剧情简介等)',
`poster_key` VARCHAR(255) DEFAULT NULL COMMENT '海报(存储相对键,如 posters/xxx.jpg)',
`ticket_key` VARCHAR(255) DEFAULT NULL COMMENT '票根照片(存储相对键)',
`rating` TINYINT DEFAULT NULL COMMENT '评分 0-10(.MovieLog 10 分制原样保留)',
`review` TEXT DEFAULT NULL COMMENT '影评正文',
`feelings` VARCHAR(255) DEFAULT NULL COMMENT '观后感受标签,JSON 数组(如 ["温暖","激动"])',
`cinema_place` VARCHAR(100) DEFAULT NULL COMMENT '影院所在商圈/位置',
`cinema_name` VARCHAR(100) DEFAULT NULL COMMENT '影院名(与 events.location 冗余存一份,详情页直接用)',
`cinema_address` VARCHAR(200) DEFAULT NULL COMMENT '影院地址',
PRIMARY KEY (`event_id`),
CONSTRAINT `fk_mdet_event` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='观影事件的特有数据(一对一卫星表)'
SQL,
<<<'SQL'
CREATE TABLE IF NOT EXISTS `event_attendees` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`event_id` INT UNSIGNED NOT NULL,
`person_id` INT UNSIGNED NOT NULL COMMENT '同行的人(persons.id)',
`position` INT NOT NULL DEFAULT 100 COMMENT '展示先后',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_att_event_person` (`event_id`, `person_id`),
KEY `idx_att_person` (`person_id`),
CONSTRAINT `fk_att_event` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE,
CONSTRAINT `fk_att_person` FOREIGN KEY (`person_id`) REFERENCES `persons` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='事件的参与人(观影=同行观影的人)'
SQL,
<<<'SQL'
CREATE TABLE IF NOT EXISTS `event_photos` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`event_id` INT UNSIGNED NOT NULL,
`key` VARCHAR(255) NOT NULL COMMENT '照片(存储相对键)',
`position` INT NOT NULL DEFAULT 100 COMMENT '展示先后',
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_ep_event` (`event_id`, `position`),
CONSTRAINT `fk_ep_event` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='事件的现场照片(可多张)'
SQL,
];
}
+48
View File
@@ -262,6 +262,54 @@ final class OssDriver implements StorageDriver
return ['ok' => true, 'error' => ''];
}
/**
* 服务端拷贝(CopyObject)—— v8 迁移用:同一个桶里把 movielog/ 前缀的对象
* 复制成 family/ 前缀,不走流量、不用下载重传。
*
* @param string $srcObjectKey 源对象**完整键**(含前缀,如 movielog/uploads/posters/x.jpg)
* @param string $destRelKey 目标**相对键**(不含本站前缀,如 posters/x.jpg)
*
* ⚠️ 签名注意:所有随请求发送的 x-oss-* 头都必须按字典序拼进签名串
* (copy-source 在 security-token 之前),漏一个就是 SignatureDoesNotMatch。
* CopyObject 不需要 Content-Type(拷贝沿用源对象的元数据),签名串里留空。
*/
public function copyObject(string $srcObjectKey, string $destRelKey): array
{
if ($err = $this->validateConfig()) {
return ['ok' => false, 'error' => $err];
}
$cred = $this->credentials();
if (empty($cred['ok'])) {
return ['ok' => false, 'error' => $cred['error']];
}
$bucket = trim((string)$this->cfg['bucket']);
$srcKey = ltrim($srcObjectKey, '/');
$destKey = $this->objectKey($destRelKey);
$date = gmdate('D, d M Y H:i:s \G\M\T');
$copySource = '/' . $bucket . '/' . Http::encodeKey($srcKey);
$canonical = "x-oss-copy-source:{$copySource}\n";
if ((string)($cred['token'] ?? '') !== '') {
$canonical .= "x-oss-security-token:{$cred['token']}\n";
}
$stringToSign = "PUT\n\n\n{$date}\n{$canonical}/{$bucket}/{$destKey}";
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $cred['secret'], true));
$h = [
'Date: ' . $date,
'x-oss-copy-source: ' . $copySource,
'Authorization: OSS ' . $cred['id'] . ':' . $signature,
];
if ((string)($cred['token'] ?? '') !== '') {
$h[] = 'x-oss-security-token: ' . $cred['token'];
}
$res = Http::send('PUT', $this->objectUrl($destKey), $h, null, 60);
if (!$res['ok']) {
return ['ok' => false, 'error' => 'OSS CopyObject 失败:' . Http::shortError($res)];
}
return ['ok' => true, 'error' => ''];
}
public function delete(string $key): array
{
$cred = $this->credentials();
+26 -12
View File
@@ -102,20 +102,34 @@ final class Upload
$w = imagesx($src);
$h = imagesy($src);
// 先按目标比例、在「用户挑的区域」里定位 —— 区域非法时退回整图居中
$region = self::readCrop($cropRaw, $w, $h);
[$sx, $sy, $sw, $sh] = self::fitRegion($region ?? [0.0, 0.0, 1.0, 1.0], $w, $h, ImageSlot::ratio($slot));
// 「框小到没有意义」要明确拒绝(放大之后就是一坨马赛克)。
// ⚠️ 只在**用户真的给了裁剪框**时判:源图本身很小(比如 8×8 的老头像、
// 或者是张一像素级的测试图)时,居中裁出来的区域自然也小 ——
// 那种情况必须照常接受,否则一张本来能用的图会被"太小"挡在外面。
if ($region !== null && ($sw < 16 || $sh < 16)) {
imagedestroy($src);
return ['ok' => false, 'error' => '裁剪区域太小了,请把框放大一点'];
$free = ImageSlot::ratio($slot) === 0.0; // free 槽位(票根/照片):不裁剪,整图等比缩
if ($free) {
// 用户挑的裁剪框对 free 槽位没有意义 —— 忽略,用整张图。
// (票根是随手拍,比例五花八门,硬裁只会把票面裁掉一角。)
$sx = 0; $sy = 0; $sw = $w; $sh = $h;
} else {
// 先按目标比例、在「用户挑的区域」里定位 —— 区域非法时退回整图居中
$region = self::readCrop($cropRaw, $w, $h);
[$sx, $sy, $sw, $sh] = self::fitRegion($region ?? [0.0, 0.0, 1.0, 1.0], $w, $h, ImageSlot::ratio($slot));
// 「框小到没有意义」要明确拒绝(放大之后就是一坨马赛克)。
// ⚠️ 只在**用户真的给了裁剪框**时判:源图本身很小(比如 8×8 的老头像、
// 或者是张一像素级的测试图)时,居中裁出来的区域自然也小 ——
// 那种情况必须照常接受,否则一张本来能用的图会被"太小"挡在外面。
if ($region !== null && ($sw < 16 || $sh < 16)) {
imagedestroy($src);
return ['ok' => false, 'error' => '裁剪区域太小了,请把框放大一点'];
}
}
$outW = (int)$slot['w'];
$outH = (int)$slot['h'];
if ($free) {
// 等比缩到槽位的 w×h **框内**(只缩不放大),保持原始比例
$scale = min((int)$slot['w'] / $sw, (int)$slot['h'] / $sh, 1.0);
$outW = max(1, (int)round($sw * $scale));
$outH = max(1, (int)round($sh * $scale));
} else {
$outW = (int)$slot['w'];
$outH = (int)$slot['h'];
}
$canvas = imagecreatetruecolor($outW, $outH);
// PNG/GIF 的透明区转成纸白,不然头像会是黑底
$bg = imagecolorallocate($canvas, 253, 251, 245);
+71
View File
@@ -758,3 +758,74 @@ textarea.input { min-height: 76px; resize: vertical; }
.ct-row { flex-direction: column; gap: 6px; }
.ct-row .ct-label { flex: none; }
}
/* ===== 观影(v8,MovieLog 迁入) ===== */
.movie-list { display: flex; flex-direction: column; gap: 10px; }
.movie-card {
display: flex; gap: 14px; align-items: center;
padding: 10px; background: var(--card-bg, #fff);
border: 1px solid var(--line); border-radius: 12px;
text-decoration: none; color: var(--ink);
}
.movie-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-l); text-decoration: none; }
.m-poster {
flex: 0 0 64px; width: 64px; height: 96px; object-fit: cover;
border-radius: 8px; background: var(--line-2); display: block;
}
.m-poster-empty {
display: flex; align-items: center; justify-content: center;
color: var(--faint, #B9AE9F); font-size: 20px; font-weight: 600;
}
.m-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.m-title { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rating {
background: var(--brand); color: #fff; border-radius: 999px;
padding: 1px 8px; font-size: 12px; font-weight: 600;
font-variant-numeric: tabular-nums;
}
.rating-lg { font-size: 14px; padding: 2px 10px; }
.m-meta { color: var(--muted); font-size: 13px; }
.m-who { color: var(--muted); font-size: 12px; }
.movie-detail { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
.m-poster-col { display: flex; flex-direction: column; gap: 12px; }
.m-poster-lg {
width: 100%; aspect-ratio: 2 / 3; object-fit: cover;
border-radius: 12px; background: var(--line-2); display: flex;
align-items: center; justify-content: center;
color: var(--faint, #B9AE9F); font-size: 40px; font-weight: 600;
}
a .m-poster-lg { display: block; }
.m-ticket { width: 100%; border-radius: 10px; border: 1px solid var(--line); display: block; }
.m-info .m-score { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.badge-feel { background: #F6E3D7; color: var(--brand-ink); }
.m-block { margin-top: 16px; }
.m-block h3 { font-size: 14px; margin: 0 0 6px; color: var(--muted); font-weight: 500; }
.m-block p { margin: 0; font-size: 14px; line-height: 1.7; white-space: normal; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.photo-cell { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.photo-cell img { width: 100%; height: 160px; object-fit: cover; display: block; }
.photo-del {
position: absolute; top: 6px; right: 6px;
width: 24px; height: 24px; border-radius: 50%; border: 0;
background: rgba(0,0,0,.55); color: #fff; font-size: 16px; line-height: 1;
cursor: pointer; padding: 0;
}
.photo-del:hover { background: var(--red, #C0533F); }
.photo-add label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.photo-add-row { display: flex; gap: 10px; align-items: center; }
.photo-add-row .input { flex: 1; }
.feel-grid { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.feel-item { display: flex; align-items: center; gap: 5px; font-size: 14px; cursor: pointer; }
.feel-item input { accent-color: var(--brand); }
@media (max-width: 720px) {
.movie-detail { grid-template-columns: 1fr; }
.m-poster-col { flex-direction: row; }
.m-poster-col .m-poster-lg, .m-poster-col a:first-child { flex: 0 0 140px; width: 140px; }
.m-ticket { width: auto; max-width: 55%; }
.photo-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.photo-cell img { height: 120px; }
}
+223
View File
@@ -17,6 +17,7 @@ use App\Crypto;
use App\Database;
use App\Family;
use App\Kinship;
use App\Movie;
use App\Nickname;
use App\Person;
use App\PersonGroup;
@@ -1329,6 +1330,228 @@ switch ($r) {
redirect('settings');
break;
// ==================== 观影(v8) ====================
//
// MovieLog 整体迁入后的新家。数据落在统一事件原语上:
// events(骨架)+ movie_details(卫星)+ event_attendees + event_photos,
// 见 App\Movie。可见性与名册同一口径:能登录就能看,能写才能改;
// 迁进来的历史记录 source_ref = 'movielog:movie:<id>'(重跑迁移的幂等锚点)。
/** 观影时间线 —— 按年分组倒序。 */
case 'movies':
$familyId = (int)Auth::familyId();
$rows = Movie::all($familyId);
$years = [];
foreach ($rows as $r) {
$y = $r['starts_at'] !== null ? (int)substr((string)$r['starts_at'], 0, 4) : 0;
$years[$y][] = $r;
}
unset($r);
krsort($years);
View::render('movies/index', [
'title' => '观影记录',
'years' => $years,
'total' => count($rows),
], 'movies');
break;
case 'movies/show':
$familyId = (int)Auth::familyId();
$m = Movie::find($familyId, (int)($_GET['id'] ?? 0));
if (!$m) {
flash('err', '找不到这条观影记录。');
redirect('movies');
}
View::render('movies/show', [
'title' => (string)$m['title'],
'm' => $m,
], 'movies');
break;
case 'movies/new':
Auth::requireWrite();
View::render('movies/form', [
'title' => '记一场电影',
'm' => null,
'people' => Person::roster((int)Auth::familyId(), (int)Auth::personId(), 'member', ''),
'errors' => [],
], 'movies');
break;
case 'movies/edit':
Auth::requireWrite();
$familyId = (int)Auth::familyId();
$m = Movie::find($familyId, (int)($_GET['id'] ?? 0));
if (!$m) {
flash('err', '找不到这条观影记录。');
redirect('movies');
}
View::render('movies/form', [
'title' => '编辑观影记录',
'm' => $m,
'people' => Person::roster($familyId, (int)Auth::personId(), 'member', ''),
'errors' => [],
], 'movies');
break;
/** 收集表单里和观影有关的字段(create / update 共用一份)。 */
case 'movies/create':
case 'movies/update':
$familyId = (int)Auth::familyId();
$me = (int)Auth::personId();
Auth::requireWrite();
csrf_check();
$isEdit = $r === 'movies/update';
$id = $isEdit ? (int)($_POST['id'] ?? 0) : 0;
$m = $isEdit ? Movie::find($familyId, $id) : null;
if ($isEdit && !$m) {
flash('err', '找不到这条观影记录。');
redirect('movies');
}
$d = [
'title' => trim((string)($_POST['title'] ?? '')),
'starts_at' => trim((string)($_POST['starts_at'] ?? '')),
'location' => trim((string)($_POST['location'] ?? '')),
'note' => trim((string)($_POST['note'] ?? '')),
'info' => trim((string)($_POST['info'] ?? '')),
'rating' => trim((string)($_POST['rating'] ?? '')),
'review' => trim((string)($_POST['review'] ?? '')),
'feelings' => array_values((array)($_POST['feelings'] ?? [])),
'cinema_place' => trim((string)($_POST['cinema_place'] ?? '')),
'cinema_name' => trim((string)($_POST['cinema_name'] ?? '')),
'cinema_address' => trim((string)($_POST['cinema_address'] ?? '')),
// 同行的人:只认「确实存在且属于这个家」的 id —— 表单可以改,
// 不能凭它把别人家的成员挂进自己家的观影记录里(会顺着详情页漏人名)。
'attendees' => array_map('intval', (array)($_POST['attendees'] ?? [])),
];
$_familyPeople = Person::map($familyId);
$d['attendees'] = array_values(array_filter($d['attendees'],
static fn($pid) => isset($_familyPeople[$pid])));
$errors = $d['title'] === '' ? ['title' => '片名不能为空'] : [];
// ⚠️ 图片上传失败**不挡保存**(与头像同一思路:一条记录因为一张 5MB 原图
// 存不进去,看起来像功能坏了)。现在是先存记录,图片的事单独提示。
// 海报 / 票根:free 槽位,不需要裁剪框;编辑时换新图就顺带删掉旧对象。
$warns = [];
foreach (['poster', 'ticket'] as $slot) {
$up = Upload::image($familyId, $_FILES[$slot] ?? [], $slot);
if ($up['ok']) {
$oldKey = $isEdit ? (string)($m[$slot === 'poster' ? 'poster_key' : 'ticket_key'] ?? '') : '';
$d[$slot === 'poster' ? 'poster_key' : 'ticket_key'] = (string)$up['file'];
if ($oldKey !== '' && $oldKey !== (string)$up['file']) {
\App\Storage\Storage::delete($familyId, $oldKey);
}
} elseif ((string)($up['error'] ?? '') !== '') {
$warns[] = ($slot === 'poster' ? '海报' : '票根') . '没有保存:' . $up['error'];
} elseif ($isEdit) {
// 没传新图 → 保留库里的旧值
$d[$slot === 'poster' ? 'poster_key' : 'ticket_key'] = (string)($m[$slot === 'poster' ? 'poster_key' : 'ticket_key'] ?? '');
}
}
// 现场照片(多选,仅新增表单提供;编辑页在详情页里逐张补/删)
if (!$isEdit) {
$photoFiles = [];
if (!empty($_FILES['photo']) && is_array($_FILES['photo']['name'])) {
foreach ($_FILES['photo']['name'] as $i => $_n) {
$photoFiles[] = [
'name' => $_FILES['photo']['name'][$i],
'type' => $_FILES['photo']['type'][$i],
'tmp_name' => $_FILES['photo']['tmp_name'][$i],
'error' => $_FILES['photo']['error'][$i],
'size' => $_FILES['photo']['size'][$i],
];
}
}
$photoKeys = [];
foreach ($photoFiles as $f) {
$up = Upload::image($familyId, $f, 'photo');
if ($up['ok']) {
$photoKeys[] = (string)$up['file'];
} elseif ((string)($up['error'] ?? '') !== '') {
$warns[] = '有一张照片没有保存:' . $up['error'];
}
}
$d['photos'] = $photoKeys;
}
if ($errors) {
set_old($_POST);
View::render('movies/form', [
'title' => $isEdit ? '编辑观影记录' : '记一场电影',
'm' => $m,
'people' => Person::roster($familyId, $me, 'member', ''),
'errors' => $errors,
], 'movies');
exit;
}
if ($isEdit) {
Movie::update($familyId, $id, $d);
clear_old();
flash('ok', '已保存。' . ($warns ? '(' . implode(';', $warns) . ')' : ''));
redirect('movies/show', ['id' => $id]);
} else {
$newId = Movie::create($familyId, $me, $d);
clear_old();
flash('ok', '已记下这场电影。' . ($warns ? '(' . implode(';', $warns) . ')' : ''));
redirect('movies/show', ['id' => $newId]);
}
break;
/** 编辑页补传一张现场照片(详情页里的小表单,一次一张)。 */
case 'movies/photo_add':
$familyId = (int)Auth::familyId();
Auth::requireWrite();
csrf_check();
$id = (int)($_POST['id'] ?? 0);
if (!Movie::find($familyId, $id)) {
flash('err', '找不到这条观影记录。');
redirect('movies');
}
$up = Upload::image($familyId, $_FILES['photo'] ?? [], 'photo');
if ($up['ok']) {
// savePhotos 是整组替换 —— 现有键取出来再追加一张,位置接着排
$keys = array_map('strval', array_column(Movie::photos($id), 'key'));
$keys[] = (string)$up['file'];
Movie::savePhotos($id, $keys);
flash('ok', '照片已加上。');
} else {
flash('err', '照片没有保存:' . (string)($up['error'] ?: '没选文件'));
}
redirect('movies/show', ['id' => $id]);
break;
case 'movies/photo_del':
$familyId = (int)Auth::familyId();
Auth::requireWrite();
csrf_check();
$id = (int)($_POST['id'] ?? 0);
$pid = (int)($_POST['photo_id'] ?? 0);
if (!Movie::find($familyId, $id)) {
flash('err', '找不到这条观影记录。');
redirect('movies');
}
Movie::deletePhoto($familyId, $id, $pid);
flash('ok', '照片已删除。');
redirect('movies/show', ['id' => $id]);
break;
case 'movies/destroy':
$familyId = (int)Auth::familyId();
Auth::requireWrite();
csrf_check();
$id = (int)($_POST['id'] ?? 0);
if (!Movie::find($familyId, $id)) {
flash('err', '找不到这条观影记录。');
redirect('movies');
}
Movie::destroy($familyId, $id);
flash('ok', '这条观影记录已删除。');
redirect('movies');
break;
default:
http_response_code(404);
View::render('error', [
+2 -20
View File
@@ -6,10 +6,8 @@
* 爱人登进来看到的是同一批人,称呼却变成「公公/婆婆」。
* 称呼全部由 Kinship 现算、由 Nickname 决定"我叫他什么",库里不存任何一次性称谓。
*
* 标题下面那一行小字的取法(这处被明确纠正过):
* 先看**我自己**有没有写 slogan → 没写才回落到家庭统一的那句。
* 所以同一页不同人登进来看到的是不同的话,而不是全家共用一个口号。
* 家庭名称本身不再展示 —— 标题已经是「某某某的家书」,再挂一个家庭名只会打架。
* ⚠️ 标题下的那句个人口号已按用户要求撤掉(v8):
* hero 区只留标题与三个统计,不再读 slogan / motto。
*/
$kinCount = count($kin);
$hasRel = $relCount > 0;
@@ -30,16 +28,6 @@ if (!$list) {
}
}
// 标题下的一行小字:我的一句话 → 家庭统一那句 → 兜底
$motto = trim((string)$mySlogan);
$mottoIsMine = $motto !== '';
if (!$mottoIsMine) {
$motto = trim((string)($family['motto'] ?? ''));
}
if ($motto === '') {
$motto = '一本用岁月写成的家谱';
}
// 生日事件上用简称,卡片才不会一行塞不下;长名字在详情页里出
$shortKind = ['id' => '身份证生日', 'solar' => '阳历生日', 'lunar' => '农历生日'];
?>
@@ -47,12 +35,6 @@ $shortKind = ['id' => '身份证生日', 'solar' => '阳历生日', 'lunar' => '
<img class="hero-logo" src="<?= e(asset('/assets/icons/icon-192.png')) ?>" alt="">
<div class="hero-main">
<h1><?= e(\App\Auth::homeTitle()) ?></h1>
<p class="motto">
<?= e($motto) ?>
<?php if ($mottoIsMine): ?>
<span class="motto-from">我的一句话</span>
<?php endif; ?>
</p>
</div>
<div class="hero-stats">
<div class="stat"><b><?= (int)$kinCount ?></b><span>与我有关</span></div>
-5
View File
@@ -61,9 +61,4 @@ $genWord = function (int $level): string {
<?php endforeach; ?>
</div>
<div class="btn-row">
<a class="btn btn-ghost" href="<?= e(url('people/show', ['id' => $meId])) ?>">补充我的亲属关系</a>
<a class="btn btn-ghost" href="<?= e(url('people')) ?>">看整个名册</a>
</div>
<?php endif; ?>
+3 -1
View File
@@ -1,10 +1,12 @@
<?php
// ⚠️ 「系统设置」**不在**顶栏里(用户明确要求):它已经收进右上角头像下拉菜单里了,
// 顶栏只留「首页 / 家谱 / 名册」三个日常入口,别再把管理入口顶出来。
// 顶栏留「首页 / 家谱 / 名册 / 观影」四个日常入口,别再把管理入口顶出来。
// (v8 起加了「观影」—— MovieLog 整体迁入后的日常入口。)
$navItems = [
'home' => ['首页', 'home'],
'kin' => ['家谱', 'kin'],
'people' => ['名册', 'people'],
'movies' => ['观影', 'movies'],
];
// ⚠️ 变量名不要叫 $me:layout 是在 extract($data) **之后**被 require 的,
// 这里再赋值会把页面传进来的 $me(当前登录者的完整记录)覆盖掉。
+157
View File
@@ -0,0 +1,157 @@
<?php
/**
* 观影表单(新增 / 编辑,一张表单两用 —— 与 people/form 同一思路)。
*
* 字段分三块:看什么(片名/日期/评分/感受)、跟谁(同行的人)、在哪看(影院三段),
* 再加自由文本(简介/观后感/备注)。海报与票根是 free 槽位(v8):
* 不进裁剪器、整图等比缩进框内,所以这里不放裁剪框,只放普通文件控件。
*
* 现场照片只在**新增**时提供多选;编辑时在详情页里逐张补/删 ——
* 一次改一处的表单,比一个巨型表单不容易出错。
*/
$isEdit = !empty($m['id']);
// 回填:校验失败重画时用用户刚提交的值(old()),否则用库里的值
$curAttendees = array_map('intval', array_column($m['attendees'] ?? [], 'id'));
$curFeelings = [];
if (!empty($m['feelings'])) {
$curFeelings = json_decode((string)$m['feelings'], true) ?: [];
}
$selAttendees = array_map('intval', (array)old('attendees', $curAttendees));
$selFeelings = (array)old('feelings', $curFeelings);
$rtVal = old('rating', $m['rating'] ?? '');
?>
<div class="page-head">
<h1><?= $isEdit ? '编辑观影记录' : '记一场电影' ?></h1>
<span class="sub"><?= $isEdit ? e($m['title']) : '片名必填,其他都可以以后再补' ?></span>
</div>
<form method="post" enctype="multipart/form-data"
action="<?= e(url($isEdit ? 'movies/update' : 'movies/create')) ?>">
<?= csrf_field() ?>
<?php if ($isEdit): ?>
<input type="hidden" name="id" value="<?= (int)$m['id'] ?>">
<?php endif; ?>
<div class="card card-pad">
<div class="form-grid">
<div class="field full">
<label for="title">片名 *</label>
<input class="input" id="title" name="title" value="<?= e(old('title', $m['title'] ?? '')) ?>" required>
<?php if (!empty($errors['title'])): ?><span class="err"><?= e($errors['title']) ?></span><?php endif; ?>
</div>
<div class="field">
<label for="starts_at">观影日期</label>
<input class="input" id="starts_at" name="starts_at" type="date"
value="<?= e(old('starts_at', $m['starts_at'] ?? '')) ?>">
</div>
<div class="field">
<label for="rating">评分(1-10)</label>
<select class="select" id="rating" name="rating">
<option value="">不评</option>
<?php for ($i = 10; $i >= 1; $i--): ?>
<option value="<?= $i ?>" <?= (string)$rtVal === (string)$i ? 'selected' : '' ?>><?= $i ?></option>
<?php endfor; ?>
</select>
</div>
<div class="field full">
<label>观后感受</label>
<div class="feel-grid">
<?php foreach (\App\Movie::FEELINGS as $f): ?>
<label class="feel-item">
<input type="checkbox" name="feelings[]" value="<?= e($f) ?>"
<?= in_array($f, $selFeelings, true) ? 'checked' : '' ?>>
<span><?= e($f) ?></span>
</label>
<?php endforeach; ?>
</div>
<span class="tip">MovieLog 里记的英文标签(warm / excited…)搬过来时已经翻成中文。</span>
</div>
<div class="field full">
<label>同行的人</label>
<?php if ($people): ?>
<div class="feel-grid">
<?php foreach ($people as $p): ?>
<label class="feel-item">
<input type="checkbox" name="attendees[]" value="<?= (int)$p['id'] ?>"
<?= in_array((int)$p['id'], $selAttendees, true) ? 'checked' : '' ?>>
<span><?= e($p['shown'] ?? $p['name']) ?></span>
</label>
<?php endforeach; ?>
</div>
<?php else: ?>
<span class="tip">名册里还没有人,先把家人加进名册再来记。</span>
<?php endif; ?>
</div>
<div class="field">
<label for="cinema_place">影院 · 城市/商圈</label>
<input class="input" id="cinema_place" name="cinema_place"
value="<?= e(old('cinema_place', $m['cinema_place'] ?? '')) ?>" placeholder="如:青岛 · 崂山区">
</div>
<div class="field">
<label for="cinema_name">影院 · 名字</label>
<input class="input" id="cinema_name" name="cinema_name"
value="<?= e(old('cinema_name', $m['cinema_name'] ?? '')) ?>" placeholder="如:万达影城 CBD 店">
</div>
<div class="field full">
<label for="cinema_address">影院 · 地址</label>
<input class="input" id="cinema_address" name="cinema_address"
value="<?= e(old('cinema_address', $m['cinema_address'] ?? '')) ?>">
</div>
<div class="field full">
<label for="info">简介</label>
<textarea class="input" id="info" name="info" rows="3"
placeholder="剧情简介(可选)"><?= e(old('info', $m['info'] ?? '')) ?></textarea>
</div>
<div class="field full">
<label for="review">观后感</label>
<textarea class="input" id="review" name="review" rows="4"
placeholder="看完想记下来的话"><?= e(old('review', $m['review'] ?? '')) ?></textarea>
</div>
<div class="field full">
<label for="note">备注</label>
<textarea class="input" id="note" name="note" rows="2"><?= e(old('note', $m['note'] ?? '')) ?></textarea>
</div>
<div class="field">
<label for="poster">海报</label>
<input class="input" id="poster" name="poster" type="file" accept="image/*">
<?php if ($isEdit && !empty($m['poster_key'])): ?>
<span class="tip">已有海报,不选新图就保留原图。</span>
<?php endif; ?>
</div>
<div class="field">
<label for="ticket">票根</label>
<input class="input" id="ticket" name="ticket" type="file" accept="image/*">
<?php if ($isEdit && !empty($m['ticket_key'])): ?>
<span class="tip">已有票根,不选新图就保留原图。</span>
<?php endif; ?>
</div>
<?php if (!$isEdit): ?>
<div class="field full">
<label for="photo">现场照片(可多选)</label>
<input class="input" id="photo" name="photo[]" type="file" accept="image/*" multiple>
<span class="tip">之后也可以在详情页里逐张补传。</span>
</div>
<?php endif; ?>
</div>
<div class="btn-row">
<button type="submit" class="btn"><?= $isEdit ? '保存' : '记下这场电影' ?></button>
<a class="btn btn-ghost"
href="<?= e($isEdit ? url('movies/show', ['id' => (int)$m['id']]) : url('movies')) ?>">取消</a>
</div>
</div>
</form>
+61
View File
@@ -0,0 +1,61 @@
<?php
/**
* 观影时间线 —— 按年分组倒序(v8,MovieLog 迁入后的新家)。
*
* 没填日期的记录落在键 0,沉到最底下单独一组「日期待补」,
* 不让它混进任何一个年份里(跟名册「未分类」栏是同一个思路)。
*/
$canWrite = \App\Auth::canWrite();
?>
<div class="page-head">
<h1>观影记录</h1>
<span class="sub">一共 <?= (int)$total ?> 场</span>
<div class="actions">
<?php if ($canWrite): ?>
<a class="btn" href="<?= e(url('movies/new')) ?>">记一场电影</a>
<?php endif; ?>
</div>
</div>
<?php if ($total === 0): ?>
<div class="card card-pad empty">
<b>还没有观影记录</b>
一家人一起看过的电影,都会按年份排在这里。
</div>
<?php else: ?>
<?php foreach ($years as $y => $list): ?>
<section class="section">
<h2 class="section-title"><?= $y > 0 ? (int)$y : '日期待补' ?> <span class="hint"><?= count($list) ?> 场</span></h2>
<div class="movie-list">
<?php foreach ($list as $mv): ?>
<?php
// 评分统一一位小数内显示:9 → "9",8.5 → "8.5"(库里是 0-10 整数,这里只做展示兜底)
$rtTxt = $mv['rating'] !== null
? rtrim(rtrim(number_format((float)$mv['rating'], 1, '.', ''), '0'), '.')
: '';
?>
<a class="movie-card" href="<?= e(url('movies/show', ['id' => (int)$mv['id']])) ?>">
<?php if (!empty($mv['poster_key'])): ?>
<img class="m-poster" src="<?= e(media_url($mv['poster_key'])) ?>" alt="" loading="lazy">
<?php else: ?>
<span class="m-poster m-poster-empty" aria-hidden="true">影</span>
<?php endif; ?>
<span class="m-main">
<span class="m-title">
<?= e($mv['title']) ?>
<?php if ($rtTxt !== ''): ?><span class="rating"><?= e($rtTxt) ?></span><?php endif; ?>
</span>
<span class="m-meta">
<?= e((string)($mv['starts_at'] ?? '日期待补')) ?>
<?php if (!empty($mv['cinema_name'])): ?> · <?= e($mv['cinema_name']) ?><?php endif; ?>
</span>
<?php if (!empty($mv['attendee_names'])): ?>
<span class="m-who">和 <?= e($mv['attendee_names']) ?></span>
<?php endif; ?>
</span>
</a>
<?php endforeach; ?>
</div>
</section>
<?php endforeach; ?>
<?php endif; ?>
+134
View File
@@ -0,0 +1,134 @@
<?php
/**
* 观影详情页。
*
* 海报 / 票根 / 照片一律走 media_url() 代理(全站唯一出口,见 helpers.php);
* 感受标签是迁移时已翻成中文的 JSON 数组,这里只展示不加工。
* 访客(只读)看不到编辑/删除/传照片那些表单 —— 与名册同一口径。
*/
$canWrite = \App\Auth::canWrite();
$feel = [];
if (!empty($m['feelings'])) {
$feel = json_decode((string)$m['feelings'], true);
if (!is_array($feel)) {
$feel = [];
}
}
$hasPoster = !empty($m['poster_key']);
$hasTicket = !empty($m['ticket_key']);
?>
<div class="page-head">
<h1><?= e($m['title']) ?></h1>
<span class="sub"><?= e((string)($m['starts_at'] ?? '日期待补')) ?></span>
<div class="actions">
<?php if ($canWrite): ?>
<a class="btn btn-ghost btn-sm" href="<?= e(url('movies/edit', ['id' => (int)$m['id']])) ?>">编辑</a>
<form method="post" action="<?= e(url('movies/destroy')) ?>"
onsubmit="return confirm('删除这条观影记录?海报、票根、照片也会一并删除,不可恢复。')">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$m['id'] ?>">
<button type="submit" class="btn btn-danger btn-sm">删除</button>
</form>
<?php endif; ?>
<a class="btn btn-ghost btn-sm" href="<?= e(url('movies')) ?>">返回</a>
</div>
</div>
<div class="movie-detail">
<div class="m-poster-col">
<?php if ($hasPoster): ?>
<a href="<?= e(media_url($m['poster_key'])) ?>" target="_blank" rel="noopener">
<img class="m-poster-lg" src="<?= e(media_url($m['poster_key'])) ?>" alt="海报">
</a>
<?php else: ?>
<span class="m-poster-lg m-poster-empty" aria-hidden="true">影</span>
<?php endif; ?>
<?php if ($hasTicket): ?>
<a href="<?= e(media_url($m['ticket_key'])) ?>" target="_blank" rel="noopener">
<img class="m-ticket" src="<?= e(media_url($m['ticket_key'])) ?>" alt="票根" loading="lazy">
</a>
<?php endif; ?>
</div>
<div class="card card-pad m-info">
<?php if ($m['rating'] !== null || $feel): ?>
<div class="m-score">
<?php if ($m['rating'] !== null): ?>
<span class="rating rating-lg"><?= e(rtrim(rtrim(number_format((float)$m['rating'], 1, '.', ''), '0'), '.')) ?></span>
<?php endif; ?>
<?php foreach ($feel as $f): ?>
<span class="badge badge-feel"><?= e($f) ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<dl class="kv">
<div class="kv-row"><dt>观影日期</dt><dd><?= e((string)($m['starts_at'] ?? '日期待补')) ?></dd></div>
<?php if (!empty($m['cinema_place']) || !empty($m['cinema_name']) || !empty($m['cinema_address'])): ?>
<div class="kv-row"><dt>影院</dt><dd>
<?= e(trim(implode(' ', array_filter([
(string)($m['cinema_place'] ?? ''),
(string)($m['cinema_name'] ?? ''),
(string)($m['cinema_address'] ?? ''),
], static fn($s) => $s !== '')))) ?>
</dd></div>
<?php endif; ?>
<?php if (!empty($m['location'])): ?>
<div class="kv-row"><dt>地点</dt><dd><?= e($m['location']) ?></dd></div>
<?php endif; ?>
<div class="kv-row"><dt>同行的人</dt><dd>
<?php if ($m['attendees']): ?>
<?php foreach ($m['attendees'] as $i => $a): ?><?= $i > 0 ? '、' : '' ?><a href="<?= e(url('people/show', ['id' => (int)$a['id']])) ?>"><?= e($a['name']) ?></a><?php endforeach; ?>
<?php else: ?>一个人看的<?php endif; ?>
</dd></div>
</dl>
<?php if (!empty($m['info'])): ?>
<div class="m-block"><h3>简介</h3><p><?= nl2br(e($m['info'])) ?></p></div>
<?php endif; ?>
<?php if (!empty($m['review'])): ?>
<div class="m-block"><h3>观后感</h3><p><?= nl2br(e($m['review'])) ?></p></div>
<?php endif; ?>
<?php if (!empty($m['note'])): ?>
<div class="m-block"><h3>备注</h3><p><?= nl2br(e($m['note'])) ?></p></div>
<?php endif; ?>
</div>
</div>
<?php if ($m['photos']): ?>
<section class="section">
<h2 class="section-title">现场照片 <span class="hint"><?= count($m['photos']) ?> 张</span></h2>
<div class="photo-grid">
<?php foreach ($m['photos'] as $ph): ?>
<div class="photo-cell">
<a href="<?= e(media_url($ph['key'])) ?>" target="_blank" rel="noopener">
<img src="<?= e(media_url($ph['key'])) ?>" alt="" loading="lazy">
</a>
<?php if ($canWrite): ?>
<form method="post" action="<?= e(url('movies/photo_del')) ?>"
onsubmit="return confirm('删除这张照片?')">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$m['id'] ?>">
<input type="hidden" name="photo_id" value="<?= (int)$ph['id'] ?>">
<button type="submit" class="photo-del" title="删除这张照片">×</button>
</form>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<?php if ($canWrite): ?>
<section class="section">
<form method="post" enctype="multipart/form-data" action="<?= e(url('movies/photo_add')) ?>" class="card card-pad photo-add">
<?= csrf_field() ?>
<input type="hidden" name="id" value="<?= (int)$m['id'] ?>">
<label for="photo">补一张现场照片</label>
<div class="photo-add-row">
<input class="input" id="photo" name="photo" type="file" accept="image/*" required>
<button type="submit" class="btn btn-ghost btn-sm">上传</button>
</div>
</form>
</section>
<?php endif; ?>