2026-09-30 00:49:53 +08:00
|
|
|
|
<?php
|
2026-09-30 08:13:07 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 首页 —— 以「我」为中心。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 同一份数据,爸爸登进来看到的是「我的父亲/我的儿子」,
|
|
|
|
|
|
* 爱人登进来看到的是同一批人,称呼却变成「公公/婆婆」。
|
2026-09-30 09:44:55 +08:00
|
|
|
|
* 称呼全部由 Kinship 现算、由 Nickname 决定"我叫他什么",库里不存任何一次性称谓。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 标题下面那一行小字的取法(这处被明确纠正过):
|
|
|
|
|
|
* 先看**我自己**有没有写 slogan → 没写才回落到家庭统一的那句。
|
|
|
|
|
|
* 所以同一页不同人登进来看到的是不同的话,而不是全家共用一个口号。
|
|
|
|
|
|
* 家庭名称本身不再展示 —— 标题已经是「某某某的家书」,再挂一个家庭名只会打架。
|
2026-09-30 08:13:07 +08:00
|
|
|
|
*/
|
|
|
|
|
|
$kinCount = count($kin);
|
|
|
|
|
|
$hasRel = $relCount > 0;
|
2026-09-30 09:44:55 +08:00
|
|
|
|
// 显示名一律走「我怎么称呼他」:同一个孩子,爸爸看到"儿子"、妈妈看到"小宝"。
|
|
|
|
|
|
// ⚠️ 用**已经取好的那张表**(target_id => 我叫他什么)做本地查表,
|
|
|
|
|
|
// 不要再对每个人调一次 Nickname::display() —— 那是每人一条 SQL。
|
|
|
|
|
|
// 没有称呼的人回落到姓名,所以永远不会出现空白名字。
|
|
|
|
|
|
$shownOf = function (array $row) use ($myNicknames): string {
|
|
|
|
|
|
$nk = (string)($myNicknames[(int)($row['id'] ?? 0)] ?? '');
|
|
|
|
|
|
return $nk !== '' ? $nk : (string)($row['name'] ?? '');
|
|
|
|
|
|
};
|
2026-09-30 08:13:07 +08:00
|
|
|
|
// 有亲属关系 → 只显示家人;还没建 → 退回显示全名册,别让首页空着
|
|
|
|
|
|
$list = $hasRel ? $kin : [];
|
|
|
|
|
|
if (!$list) {
|
2026-09-30 09:44:55 +08:00
|
|
|
|
foreach (\App\Person::all((int)\App\Auth::familyId(), '', 'member', (int)$meId) as $p) {
|
|
|
|
|
|
$p['label'] = '';
|
|
|
|
|
|
$list[(int)$p['id']] = $p;
|
2026-09-30 08:13:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-09-30 09:44:55 +08:00
|
|
|
|
|
|
|
|
|
|
// 标题下的一行小字:我的一句话 → 家庭统一那句 → 兜底
|
|
|
|
|
|
$motto = trim((string)$mySlogan);
|
|
|
|
|
|
$mottoIsMine = $motto !== '';
|
|
|
|
|
|
if (!$mottoIsMine) {
|
|
|
|
|
|
$motto = trim((string)($family['motto'] ?? ''));
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($motto === '') {
|
|
|
|
|
|
$motto = '一本用岁月写成的家谱';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 生日事件上用简称,卡片才不会一行塞不下;长名字在详情页里出
|
|
|
|
|
|
$shortKind = ['id' => '身份证生日', 'solar' => '阳历生日', 'lunar' => '农历生日'];
|
2026-09-30 00:49:53 +08:00
|
|
|
|
?>
|
|
|
|
|
|
<section class="hero">
|
|
|
|
|
|
<img class="hero-logo" src="<?= e(asset('/assets/icons/icon-192.png')) ?>" alt="">
|
2026-09-30 09:44:55 +08:00
|
|
|
|
<div class="hero-main">
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<h1><?= e(\App\Auth::homeTitle()) ?></h1>
|
|
|
|
|
|
<p class="motto">
|
2026-09-30 09:44:55 +08:00
|
|
|
|
<?= e($motto) ?>
|
|
|
|
|
|
<?php if ($mottoIsMine): ?>
|
|
|
|
|
|
<span class="motto-from">我的一句话</span>
|
|
|
|
|
|
<?php endif; ?>
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<?php if ($me): ?>
|
2026-09-30 11:06:22 +08:00
|
|
|
|
<a class="motto-edit" href="<?= e(url('settings/me')) ?>#me-profile"><?= $mottoIsMine ? '改' : '写一句我自己的' ?></a>
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</p>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="hero-stats">
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<div class="stat"><b><?= (int)$kinCount ?></b><span>与我有关</span></div>
|
|
|
|
|
|
<div class="stat"><b><?= (int)$allCount ?></b><span>名册总数</span></div>
|
|
|
|
|
|
<div class="stat"><b><?= (int)$relCount ?></b><span>亲属连线</span></div>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
<?php if ($birthdays): ?>
|
|
|
|
|
|
<section class="section">
|
|
|
|
|
|
<h2 class="section-title">接下来的日子 <span class="hint">两个月内</span></h2>
|
|
|
|
|
|
<div class="bdays">
|
|
|
|
|
|
<?php foreach ($birthdays as $b): ?>
|
2026-09-30 09:44:55 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
// 同一个人可能出两条(农历与阳历不在同一天);落在同一天时后端已经并成一条,
|
|
|
|
|
|
// kinds 里会有多项 —— 这里照着列出来,用户才知道"今天过的是哪个生日"。
|
|
|
|
|
|
$bkinds = (array)($b['kinds'] ?? []);
|
|
|
|
|
|
$bwords = [];
|
|
|
|
|
|
foreach ($bkinds as $k) {
|
|
|
|
|
|
$bwords[] = $shortKind[$k] ?? (string)$k;
|
|
|
|
|
|
}
|
|
|
|
|
|
$bshown = (string)($b['shown'] ?? $b['name'] ?? '');
|
|
|
|
|
|
?>
|
|
|
|
|
|
<a class="bday" href="<?= e(url('people/show', ['id' => (int)$b['id']])) ?>">
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<img src="<?= e(avatar_url($b['avatar'])) ?>" alt="">
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<div>
|
2026-09-30 09:44:55 +08:00
|
|
|
|
<b><?= e($bshown) ?></b>
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<?php if (!empty($b['label']) && $b['label'] !== '我'): ?>
|
|
|
|
|
|
<span class="badge"><?= e($b['label']) ?></span>
|
|
|
|
|
|
<?php endif; ?>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<div class="d">
|
2026-09-30 09:44:55 +08:00
|
|
|
|
<?php if ((int)$b['days_left'] === 0): ?>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
就是今天,生日快乐
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
还有 <?= (int)$b['days_left'] ?> 天过生日
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
2026-09-30 09:44:55 +08:00
|
|
|
|
<div class="bday-meta">
|
|
|
|
|
|
<span class="bday-date"><?= e((string)$b['date']) ?></span>
|
|
|
|
|
|
<?php foreach ($bwords as $w): ?>
|
|
|
|
|
|
<span class="bd-kind"><?= e($w) ?></span>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
<?php if (!empty($b['lunar_label'])): ?>
|
|
|
|
|
|
<span class="muted small">农历<?= e((string)$b['lunar_label']) ?></span>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
</div>
|
2026-09-30 09:44:55 +08:00
|
|
|
|
</a>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</section>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
<section class="section">
|
|
|
|
|
|
<div class="page-head" style="margin-bottom:12px">
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<h1 style="font-size:15px"><?= $hasRel ? '我的家人' : '家庭成员' ?></h1>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<div class="actions">
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<a class="btn btn-ghost btn-sm" href="<?= e(url('kin')) ?>">我的家谱</a>
|
|
|
|
|
|
<?php if ($me): ?>
|
|
|
|
|
|
<a class="btn btn-ghost btn-sm" href="<?= e(url('people/show', ['id' => (int)$me['id']])) ?>">补充亲属关系</a>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<?php if (!$hasRel): ?>
|
|
|
|
|
|
<div class="empty">
|
|
|
|
|
|
<b>先把家人连起来</b>
|
|
|
|
|
|
目前还没有任何亲属关系,所以下面显示的是整个名册。<br>
|
|
|
|
|
|
到自己的资料页填上「谁是我的父母、配偶、子女」,之后这一页就只显示跟你有关的人,
|
|
|
|
|
|
每个人的称呼也会按你的视角来算。
|
|
|
|
|
|
<?php if ($me): ?>
|
|
|
|
|
|
<div class="btn-row" style="justify-content:center">
|
|
|
|
|
|
<a class="btn" href="<?= e(url('people/show', ['id' => (int)$me['id']])) ?>">开始连关系</a>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
<?php if (!$list): ?>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<div class="empty">
|
|
|
|
|
|
<b>名册还是空的</b>
|
|
|
|
|
|
先把家里人加进来,之后他们就能出现在每一条记录里。
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<div class="btn-row" style="justify-content:center">
|
|
|
|
|
|
<a class="btn" href="<?= e(url('people/new')) ?>">添加成员</a>
|
|
|
|
|
|
</div>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
<div class="people-grid">
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<?php foreach ($list as $p): ?>
|
2026-09-30 09:44:55 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
// ⚠️ 这里必须用「我给他起的称呼」,不能直接用姓名:
|
|
|
|
|
|
// 同一个「杨父」,儿媳妇看到的是"公公大人"、儿子看到的是"爸"。
|
|
|
|
|
|
$pshow = $shownOf($p);
|
|
|
|
|
|
$pIsMe = (int)$p['id'] === (int)$meId;
|
|
|
|
|
|
?>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<a class="person" href="<?= e(url('people/show', ['id' => (int)$p['id']])) ?>">
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<div class="ph"><img src="<?= e(avatar_url($p['avatar'] ?? '')) ?>" alt=""></div>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<div class="pb">
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<div class="pname">
|
2026-09-30 09:44:55 +08:00
|
|
|
|
<?= e($pshow) ?>
|
|
|
|
|
|
<?php if ($pIsMe): ?><span class="badge badge-me">我</span><?php endif; ?>
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<?php if (!empty($p['is_placeholder'])): ?><span class="badge">待确认</span><?php endif; ?>
|
|
|
|
|
|
</div>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<div class="pmeta">
|
2026-09-30 08:13:07 +08:00
|
|
|
|
<?php if (!empty($p['label'])): ?>
|
|
|
|
|
|
<span class="rel-label"><?= e($p['label']) ?></span>
|
2026-09-30 00:49:53 +08:00
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<?php
|
2026-09-30 08:13:07 +08:00
|
|
|
|
$role = $p['account_role'] ?? '';
|
|
|
|
|
|
if ($role === 'admin' && ($p['account_status'] ?? '') === 'active') {
|
|
|
|
|
|
echo '<span class="badge badge-admin">管理员</span>';
|
|
|
|
|
|
} elseif ($role === 'guest') {
|
|
|
|
|
|
echo '<span class="badge">访客</span>';
|
|
|
|
|
|
} elseif (!empty($p['account_id'])) {
|
|
|
|
|
|
echo '<span class="badge badge-open">已开通</span>';
|
|
|
|
|
|
}
|
2026-09-30 09:44:55 +08:00
|
|
|
|
$age = age_from(\App\Birthday::solarOf($p));
|
2026-09-30 00:49:53 +08:00
|
|
|
|
if ($age !== null) { echo ' · ' . (int)$age . ' 岁'; }
|
|
|
|
|
|
?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</a>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endif; ?>
|
2026-09-30 09:44:55 +08:00
|
|
|
|
</section>
|