补齐未接入代码的功能域:参与人 / 评论 / 花销与分摊
数据库里早就建好了 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,66 @@
|
||||
<?php $isEdit = $type !== null; ?>
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1><?= $isEdit ? '编辑节点类型' : '新增节点类型' ?></h1>
|
||||
<?php if ($isEdit && (int)$type['is_system'] === 1): ?>
|
||||
<p class="muted">这是系统内置类型,可以修改显示名称和图标,但不可删除</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<a href="<?= url('node_types/index') ?>" class="btn">返回列表</a>
|
||||
</div>
|
||||
|
||||
<form method="post" action="<?= url($isEdit ? 'node_types/update' : 'node_types/store') ?>" class="form">
|
||||
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
|
||||
<?php if ($isEdit): ?>
|
||||
<input type="hidden" name="id" value="<?= (int)$type['id'] ?>">
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="form-row">
|
||||
<label>名称 *</label>
|
||||
<input type="text" name="name" required maxlength="30"
|
||||
value="<?= e($type['name'] ?? '') ?>" placeholder="例如:游玩、用餐、赶路">
|
||||
<p class="muted" style="font-size:12px; margin-top:6px;">最多 30 个字符</p>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label>图标(emoji)</label>
|
||||
<input type="text" name="icon" maxlength="8"
|
||||
value="<?= e($type['icon'] ?? '') ?>" placeholder="例如:🎡 🍽️ 🚗"
|
||||
id="icon-input">
|
||||
<div class="emoji-picker" id="emoji-picker">
|
||||
<?php
|
||||
$emojiSuggestions = [
|
||||
'🚗','🚌','🚇','🚄','✈️','🚕','🚲','🚶','⛴️','🛵',
|
||||
'🎡','🎢','🎭','🎬','🎨','🏞️','🏖️','⛰️','🏛️','🎪',
|
||||
'🍽️','🍜','🍕','🍔','☕','🍰','🍺','🍣','🥘','🍱',
|
||||
'😴','🛌','💤','🧘','🚿','🏨',
|
||||
'⚠️','❗','🆘','🔥','💡',
|
||||
'🛍️','🛒','🎁','💰','🏠','🏥','📸','🎉','👨👩👧','🌟',
|
||||
];
|
||||
foreach ($emojiSuggestions as $e):
|
||||
?>
|
||||
<button type="button" class="emoji-btn" data-emoji="<?= $e ?>"><?= $e ?></button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<p class="muted" style="font-size:12px; margin-top:6px;">点击下方表情快速填入</p>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="<?= url('node_types/index') ?>" class="btn">取消</a>
|
||||
<button type="submit" class="btn-primary">保存</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
var iconInput = document.getElementById('icon-input');
|
||||
var picker = document.getElementById('emoji-picker');
|
||||
if (!picker || !iconInput) return;
|
||||
picker.addEventListener('click', function (e) {
|
||||
var btn = e.target.closest('.emoji-btn');
|
||||
if (!btn) return;
|
||||
iconInput.value = btn.getAttribute('data-emoji');
|
||||
iconInput.focus();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
@@ -0,0 +1,54 @@
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1>节点类型管理</h1>
|
||||
<p class="muted">自定义活动的节点类型,如游玩、用餐、赶路等</p>
|
||||
</div>
|
||||
<a href="<?= url('node_types/create') ?>" class="btn-primary">+ 新增类型</a>
|
||||
</div>
|
||||
|
||||
<?php if (empty($types)): ?>
|
||||
<div class="empty"><p>暂无节点类型</p></div>
|
||||
<?php else: ?>
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:70px;">ID</th>
|
||||
<th style="width:70px;">图标</th>
|
||||
<th>名称</th>
|
||||
<th style="width:100px;">来源</th>
|
||||
<th style="width:100px;">使用次数</th>
|
||||
<th style="width:160px;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($types as $t): ?>
|
||||
<tr>
|
||||
<td><?= (int)$t['id'] ?></td>
|
||||
<td style="font-size:22px;"><?= e($t['icon'] ?: '·') ?></td>
|
||||
<td><?= e($t['name']) ?></td>
|
||||
<td>
|
||||
<?php if ((int)$t['is_system'] === 1): ?>
|
||||
<span class="role-tag role-admin">系统内置</span>
|
||||
<?php else: ?>
|
||||
<span class="role-tag role-user">自定义</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="muted"><?= (int)$t['node_count'] ?> 个节点</td>
|
||||
<td>
|
||||
<a href="<?= url('node_types/edit', ['id' => $t['id']]) ?>" class="btn-sm">编辑</a>
|
||||
<?php if ((int)$t['is_system'] === 0): ?>
|
||||
<form method="post" action="<?= url('node_types/destroy') ?>" style="display:inline"
|
||||
onsubmit="return confirm('确定删除类型「<?= e($t['name']) ?>」?');">
|
||||
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
|
||||
<input type="hidden" name="id" value="<?= (int)$t['id'] ?>">
|
||||
<button type="submit" class="btn-sm btn-danger">删除</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<span class="muted" style="font-size:12px;">不可删除</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
Reference in New Issue
Block a user