五项家庭化改造:以个人为中心 · 家谱 · 三种角色 · 附件存储可配置 · 独立页样式
1. 独立页(登录/安装/错误)套上 HTML 骨架 —— 修「首页为什么没有样式」: 新增 templates/layout-bare.php,View::render 对独立页也走完整 <head> + CSS。 2. 以个人为中心:Kinship::label() 现算称呼、Auth::homeTitle() 出「X的家书」; 同一批人在不同登录者眼里自动变成公公婆婆 / 岳父岳母(不存一次性称谓)。 3. 附件存储可配置:Storage 门面(local / 阿里云 OSS),库里只存相对键, 云端失败自动回退本地;设置页可选驱动并填 OSS 参数(照 MovieLog 的方案)。 4. 三种角色:admin / member / guest,访客只读、写操作一律 403; accounts.role 枚举扩容,老库靠 Schema::ensure() 自动升级。 5. 家谱:只存相邻两代的边(parent / spouse),其余称呼全部推导 —— 兄弟姐妹不存边(共同父母 + birth_rank 排行推长子/次女、哥哥/妹妹), 认不清的人用虚拟人物 is_placeholder 占位,关系天然双向。 顺带修掉本地 e2e 挖出的 8 个线上级 bug(性别写死、长幼方向反、关系方向静默写反、 birth_rank 不从表单取回、隐式可空参数致响应头失效、无文件字段被误判为上传失败、 layout 变量撞车覆盖 $me、世代 0 显示成「下 0 代」)。 验证:kinship 单测 37/0 · HTTP e2e 81/0 · 老库升级专测 14/0 · 反向验证 11/11(把每个修复改回旧写法,对应断言都会变红)。
This commit is contained in:
@@ -9,6 +9,8 @@ namespace App;
|
||||
|
||||
final class Account
|
||||
{
|
||||
public const ROLES = ['admin', 'member', 'guest'];
|
||||
|
||||
public static function findByPerson(int $personId): ?array
|
||||
{
|
||||
$st = Database::get()->prepare('SELECT * FROM accounts WHERE person_id = ?');
|
||||
@@ -19,6 +21,7 @@ final class Account
|
||||
|
||||
public static function create(int $personId, string $password, string $role = 'member'): int
|
||||
{
|
||||
$role = in_array($role, self::ROLES, true) ? $role : 'member';
|
||||
$st = Database::get()->prepare(
|
||||
'INSERT INTO accounts (person_id, password_hash, role) VALUES (?, ?, ?)'
|
||||
);
|
||||
@@ -34,6 +37,7 @@ final class Account
|
||||
|
||||
public static function setRole(int $accountId, string $role): void
|
||||
{
|
||||
$role = in_array($role, self::ROLES, true) ? $role : 'member';
|
||||
Database::get()->prepare('UPDATE accounts SET role = ? WHERE id = ?')
|
||||
->execute([$role, $accountId]);
|
||||
}
|
||||
@@ -44,6 +48,24 @@ final class Account
|
||||
->execute([$status, $accountId]);
|
||||
}
|
||||
|
||||
/** 各角色各有多少人(设置页显示) */
|
||||
public static function roleCounts(): array
|
||||
{
|
||||
$st = Database::get()->query(
|
||||
"SELECT role, COUNT(*) AS n FROM accounts WHERE status = 'active' GROUP BY role"
|
||||
);
|
||||
$out = ['admin' => 0, 'member' => 0, 'guest' => 0];
|
||||
foreach ($st->fetchAll() as $r) {
|
||||
$out[(string)$r['role']] = (int)$r['n'];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function roleWord(string $role): string
|
||||
{
|
||||
return ['admin' => '管理员', 'member' => '家庭成员', 'guest' => '访客'][$role] ?? '成员';
|
||||
}
|
||||
|
||||
/** 管理员不能被停用/降权 —— 否则全家人都会被锁在系统外面 */
|
||||
public static function adminCount(): int
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user