补齐未接入代码的功能域:参与人 / 评论 / 花销与分摊
数据库里早就建好了 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,43 @@
|
||||
<?php
|
||||
/**
|
||||
* 评论区(活动详情页 / 节点详情页共用)
|
||||
* 依赖外部变量:$commentTree、$commentTargetType、$commentTargetId
|
||||
*/
|
||||
$tree = $commentTree ?? ['top' => [], 'replies' => [], 'total' => 0];
|
||||
$ctType = (string)($commentTargetType ?? '');
|
||||
$ctId = (int)($commentTargetId ?? 0);
|
||||
?>
|
||||
<section class="panel" id="comments">
|
||||
<h2 class="section-title">💬 讨论 (<?= (int)($tree['total'] ?? 0) ?>)</h2>
|
||||
|
||||
<?php if (empty($tree['top'])): ?>
|
||||
<p class="muted">还没有人发言,来说点什么吧</p>
|
||||
<?php else: ?>
|
||||
<div class="comment-list">
|
||||
<?php foreach ($tree['top'] as $c): ?>
|
||||
<?php $replies = $tree['replies'][(int)$c['id']] ?? []; ?>
|
||||
<div class="comment-thread">
|
||||
<?php require __DIR__ . '/_comment.php'; ?>
|
||||
<?php if (!empty($replies)): ?>
|
||||
<div class="comment-replies">
|
||||
<?php foreach ($replies as $c): ?>
|
||||
<?php require __DIR__ . '/_comment.php'; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" action="<?= url('comments/store') ?>" class="comment-form">
|
||||
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
|
||||
<input type="hidden" name="target_type" value="<?= e($ctType) ?>">
|
||||
<input type="hidden" name="target_id" value="<?= (int)$ctId ?>">
|
||||
<textarea name="content" rows="3" maxlength="2000" required
|
||||
placeholder="写下你的想法、提醒或者吐槽…(最多 2000 字)"></textarea>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn-primary">发表评论</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* 单条评论(顶层 / 回复共用)
|
||||
* 依赖外部变量:$c(评论行)、$ctType、$ctId
|
||||
*/
|
||||
$row = $c;
|
||||
$canDelete = \App\Auth::isAdmin() || (int)$row['author_id'] === (int)\App\Auth::id();
|
||||
$authorName = (string)($row['author_name'] ?? '');
|
||||
if ($authorName === '') $authorName = '已注销用户';
|
||||
?>
|
||||
<div class="comment-item<?= $row['parent_id'] !== null ? ' comment-child' : '' ?>"
|
||||
id="comment-<?= (int)$row['id'] ?>">
|
||||
<div class="comment-head">
|
||||
<?php if (!empty($row['author_avatar'])): ?>
|
||||
<img src="<?= e($row['author_avatar']) ?>" alt="" class="avatar-sm">
|
||||
<?php else: ?>
|
||||
<span class="avatar-sm avatar-placeholder"><?= e(mb_substr($authorName, 0, 1)) ?></span>
|
||||
<?php endif; ?>
|
||||
<span class="comment-author"><?= e($authorName) ?></span>
|
||||
<?php if (($row['author_role'] ?? '') === 'admin'): ?>
|
||||
<span class="role-tag role-admin">管理员</span>
|
||||
<?php endif; ?>
|
||||
<span class="comment-time"><?= date('Y-m-d H:i', strtotime((string)$row['created_at'])) ?></span>
|
||||
|
||||
<?php if ($canDelete): ?>
|
||||
<form method="post" action="<?= url('comments/destroy') ?>" class="comment-del-form"
|
||||
onsubmit="return confirm('确定删除这条评论?它下面的回复也会一起删除。');">
|
||||
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
|
||||
<input type="hidden" name="id" value="<?= (int)$row['id'] ?>">
|
||||
<input type="hidden" name="target_type" value="<?= e($ctType) ?>">
|
||||
<input type="hidden" name="target_id" value="<?= (int)$ctId ?>">
|
||||
<button type="submit" class="comment-del">删除</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="comment-body"><?= nl2br(e($row['content'])) ?></div>
|
||||
|
||||
<details class="comment-reply-box">
|
||||
<summary>回复</summary>
|
||||
<form method="post" action="<?= url('comments/store') ?>" class="comment-form comment-form-inline">
|
||||
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
|
||||
<input type="hidden" name="target_type" value="<?= e($ctType) ?>">
|
||||
<input type="hidden" name="target_id" value="<?= (int)$ctId ?>">
|
||||
<input type="hidden" name="parent_id" value="<?= (int)$row['id'] ?>">
|
||||
<textarea name="content" rows="2" maxlength="2000" required
|
||||
placeholder="回复 <?= e($authorName) ?>…"></textarea>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn-sm btn-primary-sm">发表回复</button>
|
||||
</div>
|
||||
</form>
|
||||
</details>
|
||||
</div>
|
||||
Reference in New Issue
Block a user