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:
+39
-4
@@ -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
@@ -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
@@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user