审计追溯:手动修正退款状态记录快照并在详情展示

This commit is contained in:
萝卜
2026-03-11 05:42:24 +00:00
parent 8cb0368a10
commit 09981f9933
3 changed files with 103 additions and 0 deletions

View File

@@ -611,6 +611,10 @@ class PlatformOrderController extends Controller
'at' => $now->toDateTimeString(), 'at' => $now->toDateTimeString(),
'admin_id' => $admin->id, 'admin_id' => $admin->id,
'note' => '手动标记为已退款(仅修正支付状态,不自动写退款回执)', 'note' => '手动标记为已退款(仅修正支付状态,不自动写退款回执)',
'snapshot' => [
'paid_amount' => $paidAmount,
'refund_total' => $refundTotal,
],
]; ];
data_set($meta, 'audit', $audit); data_set($meta, 'audit', $audit);
@@ -654,6 +658,10 @@ class PlatformOrderController extends Controller
'at' => $now->toDateTimeString(), 'at' => $now->toDateTimeString(),
'admin_id' => $admin->id, 'admin_id' => $admin->id,
'note' => '手动标记为部分退款(仅修正支付状态,不自动写退款回执)', 'note' => '手动标记为部分退款(仅修正支付状态,不自动写退款回执)',
'snapshot' => [
'paid_amount' => $paidAmount,
'refund_total' => $refundTotal,
],
]; ];
data_set($meta, 'audit', $audit); data_set($meta, 'audit', $audit);
@@ -692,6 +700,10 @@ class PlatformOrderController extends Controller
'at' => $now->toDateTimeString(), 'at' => $now->toDateTimeString(),
'admin_id' => $admin->id, 'admin_id' => $admin->id,
'note' => '手动标记为已支付(仅修正支付状态,不自动写回执/退款回执)', 'note' => '手动标记为已支付(仅修正支付状态,不自动写回执/退款回执)',
'snapshot' => [
'paid_amount' => $paidAmount,
'refund_total' => (float) $this->refundTotalForOrder($order),
],
]; ];
data_set($meta, 'audit', $audit); data_set($meta, 'audit', $audit);

View File

@@ -432,16 +432,29 @@
<th style="width:120px;">范围</th> <th style="width:120px;">范围</th>
<th style="width:200px;">时间</th> <th style="width:200px;">时间</th>
<th style="width:100px;">管理员</th> <th style="width:100px;">管理员</th>
<th style="width:180px;">快照</th>
<th>备注</th> <th>备注</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($auditItems as $item) @foreach($auditItems as $item)
@php
$snap = (array) (data_get($item, 'snapshot', []) ?? []);
$snapPaid = data_get($snap, 'paid_amount');
$snapRefund = data_get($snap, 'refund_total');
@endphp
<tr> <tr>
<td>{{ $auditActionLabels[data_get($item, 'action')] ?? (data_get($item, 'action') ?: '-') }}</td> <td>{{ $auditActionLabels[data_get($item, 'action')] ?? (data_get($item, 'action') ?: '-') }}</td>
<td>{{ data_get($item, 'scope') ?: '-' }}</td> <td>{{ data_get($item, 'scope') ?: '-' }}</td>
<td>{{ data_get($item, 'at') ?: '-' }}</td> <td>{{ data_get($item, 'at') ?: '-' }}</td>
<td>{{ data_get($item, 'admin_id') ?: '-' }}</td> <td>{{ data_get($item, 'admin_id') ?: '-' }}</td>
<td class="muted">
@if($snapPaid !== null || $snapRefund !== null)
paid=¥{{ number_format((float) ($snapPaid ?? 0), 2) }}refund=¥{{ number_format((float) ($snapRefund ?? 0), 2) }}
@else
-
@endif
</td>
<td class="muted">{{ data_get($item, 'note') ?: '' }}</td> <td class="muted">{{ data_get($item, 'note') ?: '' }}</td>
</tr> </tr>
@endforeach @endforeach

View File

@@ -0,0 +1,78 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderAuditSnapshotTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_mark_refunded_will_write_audit_snapshot_and_show_page_can_render_it(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'audit_snapshot_plan_01',
'name' => '审计快照测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_AUDIT_SNAPSHOT_0001',
'order_type' => 'new_purchase',
'status' => 'activated',
'payment_status' => 'paid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'paid_at' => now(),
'activated_at' => now(),
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
],
],
]);
$this->post('/admin/platform-orders/' . $order->id . '/mark-refunded')
->assertRedirect();
$order->refresh();
$this->assertSame(10.0, (float) data_get($order->meta, 'audit.0.snapshot.paid_amount'));
$this->assertSame(10.0, (float) data_get($order->meta, 'audit.0.snapshot.refund_total'));
$this->get('/admin/platform-orders/' . $order->id)
->assertOk()
->assertSee('paid=¥10.00')
->assertSee('refund=¥10.00');
}
}