2026-09-22 22:03:08 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 节点花销面板
|
|
|
|
|
|
* 依赖外部变量:$node、$expenses、$expenseSummary、$familyUsers、
|
|
|
|
|
|
* $categories、$currencies(code=>中文名)、$expenseSymbols(code=>符号)、$currentUserId
|
2026-09-23 14:59:02 +08:00
|
|
|
|
*
|
|
|
|
|
|
* 用户明确反馈「预算没有意义」:只记真实花销,上面一笔一笔列出来,下面给个总计。
|
|
|
|
|
|
* (expenses.is_budget 列仍在库里,但 UI 与查询都不再使用 —— 见 Expenses 类注释。)
|
2026-09-22 22:03:08 +08:00
|
|
|
|
*/
|
|
|
|
|
|
$expenses = $expenses ?? [];
|
|
|
|
|
|
$familyUsers = $familyUsers ?? [];
|
|
|
|
|
|
$categories = $categories ?? [];
|
|
|
|
|
|
$currencies = $currencies ?? [];
|
|
|
|
|
|
$expenseSymbols = $expenseSymbols ?? [];
|
2026-09-23 14:59:02 +08:00
|
|
|
|
$expenseSummary = $expenseSummary ?? ['total' => 0.0, 'count' => 0];
|
2026-09-22 22:03:08 +08:00
|
|
|
|
|
2026-09-23 14:59:02 +08:00
|
|
|
|
$total = (float)$expenseSummary['total'];
|
2026-09-22 22:03:08 +08:00
|
|
|
|
$money = static function (float $v): string {
|
|
|
|
|
|
return number_format($v, 2);
|
|
|
|
|
|
};
|
|
|
|
|
|
?>
|
|
|
|
|
|
<section class="panel" id="expenses">
|
|
|
|
|
|
<h2 class="section-title">💰 花销 (<?= (int)$expenseSummary['count'] ?>)</h2>
|
|
|
|
|
|
|
|
|
|
|
|
<?php if (empty($expenses)): ?>
|
|
|
|
|
|
<p class="muted">还没有记账</p>
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
<div class="expense-list">
|
|
|
|
|
|
<?php foreach ($expenses as $ex):
|
|
|
|
|
|
$sym = $expenseSymbols[$ex['currency']] ?? '';
|
|
|
|
|
|
$splits = [];
|
|
|
|
|
|
foreach (($ex['splits'] ?? []) as $sp) {
|
|
|
|
|
|
$sname = (string)($sp['user_name'] ?? '');
|
|
|
|
|
|
if ($sname === '') $sname = '已注销';
|
|
|
|
|
|
$splits[] = $sname . ' ' . $sym . $money((float)$sp['share_amount']);
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
|
|
<div class="expense-row">
|
|
|
|
|
|
<div class="expense-main">
|
|
|
|
|
|
<span class="expense-cat"><?= e($ex['category']) ?></span>
|
|
|
|
|
|
<span class="expense-desc"><?= e($ex['description'] ?: $ex['category']) ?></span>
|
|
|
|
|
|
<span class="expense-amount"><?= e($sym) ?><?= $money((float)$ex['total_amount']) ?></span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="expense-sub">
|
|
|
|
|
|
付款:<?= e($ex['payer_name'] ?: '未知') ?>
|
|
|
|
|
|
<?php if (!empty($splits)): ?>
|
|
|
|
|
|
· 分摊:<?= e(implode(' / ', $splits)) ?>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<form method="post" action="<?= url('expenses/destroy') ?>" style="display:inline"
|
|
|
|
|
|
onsubmit="return confirm('删除这笔花销?');">
|
|
|
|
|
|
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
|
|
|
|
|
|
<input type="hidden" name="id" value="<?= (int)$ex['id'] ?>">
|
|
|
|
|
|
<button type="submit" class="comment-del">删除</button>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</div>
|
2026-09-23 14:59:02 +08:00
|
|
|
|
|
|
|
|
|
|
<div class="expense-total">
|
|
|
|
|
|
<span>总计(<?= (int)$expenseSummary['count'] ?> 笔)</span>
|
|
|
|
|
|
<strong>¥<?= $money($total) ?></strong>
|
|
|
|
|
|
</div>
|
2026-09-22 22:03:08 +08:00
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
<details class="inline-panel">
|
|
|
|
|
|
<summary>+ 记一笔花销</summary>
|
|
|
|
|
|
<form method="post" action="<?= url('expenses/store') ?>" class="form form-plain">
|
|
|
|
|
|
<input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
|
|
|
|
|
|
<input type="hidden" name="node_id" value="<?= (int)$node['id'] ?>">
|
|
|
|
|
|
|
|
|
|
|
|
<div class="form-row two-col">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label>金额 *</label>
|
|
|
|
|
|
<input type="text" name="total_amount" required placeholder="例如:268.50">
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label>币种</label>
|
|
|
|
|
|
<select name="currency">
|
|
|
|
|
|
<?php foreach ($currencies as $code => $label): ?>
|
|
|
|
|
|
<option value="<?= e($code) ?>"><?= e($label) ?></option>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="form-row two-col">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label>类别</label>
|
|
|
|
|
|
<select name="category">
|
|
|
|
|
|
<?php foreach ($categories as $cat): ?>
|
|
|
|
|
|
<option value="<?= e($cat) ?>"><?= e($cat) ?></option>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label>付款人 *</label>
|
|
|
|
|
|
<select name="payer_user_id" required>
|
|
|
|
|
|
<?php foreach ($familyUsers as $u): ?>
|
|
|
|
|
|
<option value="<?= (int)$u['id'] ?>"
|
|
|
|
|
|
<?= (int)$u['id'] === (int)$currentUserId ? ' selected' : '' ?>>
|
|
|
|
|
|
<?= e($u['name']) ?>
|
|
|
|
|
|
</option>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="form-row">
|
|
|
|
|
|
<label>说明</label>
|
|
|
|
|
|
<input type="text" name="description" maxlength="200" placeholder="例如:三人门票">
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="form-row">
|
|
|
|
|
|
<label>分摊人(默认全家平摊,可只勾选部分人)</label>
|
|
|
|
|
|
<div class="check-grid">
|
|
|
|
|
|
<?php foreach ($familyUsers as $u): ?>
|
|
|
|
|
|
<label class="checkbox-label">
|
|
|
|
|
|
<input type="checkbox" name="split_user_ids[]"
|
|
|
|
|
|
value="<?= (int)$u['id'] ?>" checked>
|
|
|
|
|
|
<span><?= e($u['name']) ?></span>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="form-actions">
|
|
|
|
|
|
<button type="submit" class="btn-primary">保存</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</details>
|
|
|
|
|
|
</section>
|