补齐未接入代码的功能域:参与人 / 评论 / 花销与分摊
数据库里早就建好了 comments、node_members + role_tags、expenses +
expense_splits 三组表,但一直没有代码接入。本次把这三块连上业务,
并新增「节点详情页」作为聚合入口。
新增
- src/Access.php 统一归属校验。此前每个控制器各写各的 family_id
条件,容易漏;现在 activity()/node()/target() 一处收敛,
requireAdmin() 统一管理员判断。
- src/Comments.php 两级平铺:parent_id 只允许指向顶层,写「回复的回复」
时规范化回顶层;删顶层会连同回复一起删。
- src/Members.php 参与人 + 角色标签 + 情绪 + 签到。情绪目录 17 项,
全部选用 Emoji 11.0(2018)及以前的码位,避免旧系统
字体缺字形显示成空白方块。
- src/Expenses.php 花销与分摊。分摊按「分」为单位 intdiv 平均,
余数归最后一人,保证 SUM(share_amount) = total_amount。
- templates/nodes/show.php 节点详情页:基本信息 + 参与人 + 花销 + 讨论 + 附件入口。
- 角色标签管理、评论区、参与人区、花销区各自的模板与控制器。
修复
- 越权:往别人活动的节点上插节点、把别家用户加成参与人,都只校验了
「节点存在」,没校验「用户与节点同家庭」。现统一走 Access。
- 删活动时节点附件文件删不掉:附件在 /uploads/attachments/ 下,却调了
只认 /uploads/covers/ 的删除函数,判定不通过 → 文件永久残留。改为
统一的 deleteUploadFile(),两个目录都认。
- 删有引用记录的用户会 500(activities.created_by / attachments.uploader_id /
comments.author_id / expenses.payer_user_id 这几处没有级联,也没做前置检查)。
其他
- 活动/节点列表补上附件、评论、参与人、花销四个计数(一次 GROUP BY 查完)。
- 首页布局新增一条迁移易踩的规避:新列上的索引必须排在 ALTER TABLE 之后。
- 新增 .gitignore:config.php(含数据库口令)与 uploads/ 下用户上传的
头像封面不入库,只保留 uploads/.htaccess 那条禁止执行脚本的规则。
- 新增 config.example.php 作为新环境的配置模板。
本批不改数据库结构,不需要任何数据迁移。
本地与线上验证
- php -l 全绿(PHP 8.4 本地 / 线上 7.4.30 与 8.1.7 双版本)。
- 模板渲染检查 180 项全通过。
- 线上端到端 153 项全通过:登录、活动增删改查、节点流转、
参与人/角色标签/情绪/签到、评论、花销与分摊、权限、级联清理、
全站页面无 PHP 报错泄漏、跑完基线逐表核对且既有 id 集合逐字未变。
- 顺带写了 trip_sql_column_check.py:拿真实库表结构静态校验全项目 SQL 的
列名引用。本次就是靠它之外的 e2e 抓到 travel_modes 并没有 line_name
(该列属于 trip_nodes),一个列名写错导致节点详情页整页 Fatal。
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* 节点卡片(计划列 / 执行列共用)
|
||||
* 依赖外部变量:$n(节点行)、$cardCategory(plan|reality)、$executedPlanIds
|
||||
*/
|
||||
$cardCategory = $cardCategory ?? 'plan';
|
||||
$executedPlanIds = $executedPlanIds ?? [];
|
||||
|
||||
$statusLabels = [
|
||||
'planned' => '待执行',
|
||||
'ongoing' => '进行中',
|
||||
'completed' => '已完成',
|
||||
'cancelled' => '已取消',
|
||||
];
|
||||
$st = (string)($n['status'] ?? ($cardCategory === 'plan' ? 'planned' : 'completed'));
|
||||
if (!isset($statusLabels[$st])) $st = $cardCategory === 'plan' ? 'planned' : 'completed';
|
||||
|
||||
$isExecuted = $cardCategory === 'plan' && in_array((int)$n['id'], $executedPlanIds, true);
|
||||
|
||||
$sLoc = json_decode_field($n['start_location'] ?? null);
|
||||
$eLoc = json_decode_field($n['end_location'] ?? null);
|
||||
|
||||
$transportParts = [];
|
||||
if (!empty($n['trip_number'])) $transportParts[] = $n['trip_number'];
|
||||
if (!empty($n['line_name'])) $transportParts[] = $n['line_name'];
|
||||
if (!empty($n['carrier'])) $transportParts[] = $n['carrier'];
|
||||
if (!empty($n['seat_info'])) $transportParts[] = $n['seat_info'];
|
||||
if (!empty($n['gate'])) $transportParts[] = $n['gate'];
|
||||
|
||||
// 卡片上的状态快捷切换:计划节点在"待执行 / 已完成"之间来回,取消后可以恢复
|
||||
$quickStatus = null;
|
||||
$quickLabel = '';
|
||||
if ($cardCategory === 'plan') {
|
||||
if ($st === 'planned') { $quickStatus = 'completed'; $quickLabel = '✓ 标记完成'; }
|
||||
elseif ($st === 'completed') { $quickStatus = 'planned'; $quickLabel = '↺ 撤销完成'; }
|
||||
elseif ($st === 'cancelled') { $quickStatus = 'planned'; $quickLabel = '↺ 恢复'; }
|
||||
} elseif ($st === 'cancelled') {
|
||||
$quickStatus = 'completed';
|
||||
$quickLabel = '↺ 恢复';
|
||||
}
|
||||
?>
|
||||
<div class="node-card node-<?= e($cardCategory) ?><?= $st === 'cancelled' ? ' node-cancelled' : '' ?>">
|
||||
<div class="node-head">
|
||||
<span class="node-icon"><?= e($n['node_type_icon']) ?></span>
|
||||
<span class="node-type"><?= e($n['node_type_name']) ?></span>
|
||||
<?php if ($cardCategory === 'reality' && empty($n['original_plan_node_id'])): ?>
|
||||
<span class="tag-temp">临时</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="node-time">
|
||||
<?= date('m-d H:i', strtotime($n['start_time'])) ?> - <?= date('H:i', strtotime($n['end_time'])) ?>
|
||||
</div>
|
||||
<div class="node-title"><?= e($n['title'] ?: '(无标题)') ?></div>
|
||||
|
||||
<?php if (!empty($sLoc['name']) || !empty($eLoc['name'])): ?>
|
||||
<div class="node-loc">
|
||||
<?php if (!empty($sLoc['name'])): ?>
|
||||
<span class="loc-start">📍 <?= e($sLoc['name']) ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($sLoc['name']) && !empty($eLoc['name'])): ?>
|
||||
<span class="loc-arrow"> → </span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($eLoc['name'])): ?>
|
||||
<span class="loc-end">📍 <?= e($eLoc['name']) ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($transportParts)): ?>
|
||||
<div class="node-transport">🚄 <?= e(implode(' · ', $transportParts)) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($st === 'cancelled' && !empty($n['cancel_reason'])): ?>
|
||||
<div class="node-cancel-reason">取消原因:<?= e($n['cancel_reason']) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="node-actions">
|
||||
<span class="status-tag status-<?= e($st) ?>"><?= e($statusLabels[$st]) ?></span>
|
||||
|
||||
<a href="<?= url('nodes/show', ['id' => $n['id']]) ?>" class="node-action-link node-action-strong">详情</a>
|
||||
<a href="<?= url('attachments/node', ['id' => $n['id']]) ?>" class="node-action-link">
|
||||
📎 附件 (<?= (int)($n['attachment_count'] ?? 0) ?>)
|
||||
</a>
|
||||
<?php if ((int)($n['member_count'] ?? 0) > 0): ?>
|
||||
<a href="<?= url('nodes/show', ['id' => $n['id']]) ?>#members" class="node-action-link">
|
||||
👥 <?= (int)$n['member_count'] ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ((int)($n['comment_count'] ?? 0) > 0): ?>
|
||||
<a href="<?= url('nodes/show', ['id' => $n['id']]) ?>#comments" class="node-action-link">
|
||||
💬 <?= (int)$n['comment_count'] ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if ((int)($n['expense_count'] ?? 0) > 0): ?>
|
||||
<a href="<?= url('nodes/show', ['id' => $n['id']]) ?>#expenses" class="node-action-link">
|
||||
💰 <?= (int)$n['expense_count'] ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<a href="<?= url('nodes/edit', ['id' => $n['id']]) ?>" class="node-action-link">编辑</a>
|
||||
|
||||
<?php if ($quickStatus !== null): ?>
|
||||
<form method="post" action="<?= url('nodes/status') ?>" class="node-action-form">
|
||||
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
|
||||
<input type="hidden" name="id" value="<?= (int)$n['id'] ?>">
|
||||
<input type="hidden" name="status" value="<?= e($quickStatus) ?>">
|
||||
<button type="submit" class="node-action-btn"><?= e($quickLabel) ?></button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($cardCategory === 'plan'): ?>
|
||||
<?php if ($isExecuted): ?>
|
||||
<span class="node-action-note">✓ 已成行</span>
|
||||
<?php else: ?>
|
||||
<form method="post" action="<?= url('nodes/fromPlan') ?>" class="node-action-form">
|
||||
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
|
||||
<input type="hidden" name="plan_node_id" value="<?= (int)$n['id'] ?>">
|
||||
<button type="submit" class="node-action-btn">→ 生成执行记录</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="<?= url('nodes/destroy') ?>" class="node-action-form"
|
||||
onsubmit="return confirm('确定删除这个节点?该节点的附件也会一并删除。');">
|
||||
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
|
||||
<input type="hidden" name="id" value="<?= (int)$n['id'] ?>">
|
||||
<button type="submit" class="node-action-btn danger">删除</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user