feat(platform-orders): 列表/导出回执数优先读 payment_summary.count(含测试)

This commit is contained in:
萝卜
2026-03-11 00:33:02 +00:00
parent 80b218bbfb
commit cc6835e19c
3 changed files with 78 additions and 3 deletions

View File

@@ -678,8 +678,9 @@ class PlatformOrderController extends Controller
} }
$receipts = (array) (data_get($order->meta, 'payment_receipts', []) ?? []); $receipts = (array) (data_get($order->meta, 'payment_receipts', []) ?? []);
$receiptCount = count($receipts); $receiptSummaryCount = data_get($order->meta, 'payment_summary.count');
$latestReceipt = $receiptCount > 0 ? end($receipts) : null; $receiptCount = $receiptSummaryCount !== null ? (int) $receiptSummaryCount : count($receipts);
$latestReceipt = count($receipts) > 0 ? end($receipts) : null;
$refunds = (array) (data_get($order->meta, 'refund_receipts', []) ?? []); $refunds = (array) (data_get($order->meta, 'refund_receipts', []) ?? []);
$refundSummaryCount = data_get($order->meta, 'refund_summary.count'); $refundSummaryCount = data_get($order->meta, 'refund_summary.count');

View File

@@ -574,7 +574,9 @@
</td> </td>
<td> <td>
@php @php
$receiptCount = count((array) (data_get($order->meta, 'payment_receipts', []) ?? [])); $receipts = (array) (data_get($order->meta, 'payment_receipts', []) ?? []);
$receiptSummaryCount = data_get($order->meta, 'payment_summary.count');
$receiptCount = $receiptSummaryCount !== null ? (int) $receiptSummaryCount : count($receipts);
@endphp @endphp
@if($receiptCount > 0) @if($receiptCount > 0)
<a href="/admin/platform-orders/{{ $order->id }}" class="muted">{{ $receiptCount }}</a> <a href="/admin/platform-orders/{{ $order->id }}" class="muted">{{ $receiptCount }}</a>

View File

@@ -0,0 +1,72 @@
<?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 AdminPlatformOrderReceiptSummaryRowColumnsTest 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_platform_orders_row_receipt_count_prefers_payment_summary_when_receipts_missing(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'receipt_row_summary_test',
'name' => '回执行级摘要测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_RECEIPT_ROW_SUMMARY_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' => [
// 故意不给 payment_receipts验证列表能从 payment_summary 读到回执数
'payment_summary' => [
'count' => 101,
'total_amount' => 10.00,
],
],
]);
$this->get('/admin/platform-orders')
->assertOk()
->assertSee('PO_RECEIPT_ROW_SUMMARY_0001')
->assertSee('101')
->assertSee('¥10.00');
}
}