feat(platform-orders): 摘要卡增加有退款/无退款订单数(含测试)
This commit is contained in:
@@ -294,6 +294,16 @@ class PlatformOrderController extends Controller
|
|||||||
->whereRaw("JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NULL")
|
->whereRaw("JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NULL")
|
||||||
->whereRaw("JSON_EXTRACT(meta, '$.payment_receipts[0].amount') IS NULL")
|
->whereRaw("JSON_EXTRACT(meta, '$.payment_receipts[0].amount') IS NULL")
|
||||||
->count(),
|
->count(),
|
||||||
|
'refund_orders' => (clone $baseQuery)
|
||||||
|
->where(function (Builder $q) {
|
||||||
|
$q->whereRaw("JSON_EXTRACT(meta, '$.refund_summary.total_amount') IS NOT NULL")
|
||||||
|
->orWhereRaw("JSON_EXTRACT(meta, '$.refund_receipts[0].amount') IS NOT NULL");
|
||||||
|
})
|
||||||
|
->count(),
|
||||||
|
'no_refund_orders' => (clone $baseQuery)
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.refund_summary.total_amount') IS NULL")
|
||||||
|
->whereRaw("JSON_EXTRACT(meta, '$.refund_receipts[0].amount') IS NULL")
|
||||||
|
->count(),
|
||||||
'total_receipt_amount' => $totalReceiptAmount,
|
'total_receipt_amount' => $totalReceiptAmount,
|
||||||
// 对账差额:回执总额 - 订单已付总额(当前筛选范围)
|
// 对账差额:回执总额 - 订单已付总额(当前筛选范围)
|
||||||
'reconciliation_delta' => (float) ($totalReceiptAmount - $totalPaidAmount),
|
'reconciliation_delta' => (float) ($totalReceiptAmount - $totalPaidAmount),
|
||||||
|
|||||||
@@ -154,6 +154,11 @@
|
|||||||
<div class="metric-number">¥{{ number_format((float) ($summaryStats['total_refunded_amount'] ?? 0), 2) }}</div>
|
<div class="metric-number">¥{{ number_format((float) ($summaryStats['total_refunded_amount'] ?? 0), 2) }}</div>
|
||||||
<div class="muted muted-xs">基于 meta.refund_summary.total_amount(缺省回退汇总)</div>
|
<div class="muted muted-xs">基于 meta.refund_summary.total_amount(缺省回退汇总)</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<h3>有退款订单 / 无退款订单</h3>
|
||||||
|
<div class="metric-number">{{ $summaryStats['refund_orders'] ?? 0 }} / {{ $summaryStats['no_refund_orders'] ?? 0 }}</div>
|
||||||
|
<div class="muted muted-xs">口径:refund_summary.total_amount 存在或 refund_receipts 有记录</div>
|
||||||
|
</div>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>有回执订单 / 回执总额</h3>
|
<h3>有回执订单 / 回执总额</h3>
|
||||||
<div class="metric-number">{{ $summaryStats['receipt_orders'] ?? 0 }} / ¥{{ number_format((float) ($summaryStats['total_receipt_amount'] ?? 0), 2) }}</div>
|
<div class="metric-number">{{ $summaryStats['receipt_orders'] ?? 0 }} / ¥{{ number_format((float) ($summaryStats['total_receipt_amount'] ?? 0), 2) }}</div>
|
||||||
|
|||||||
93
tests/Feature/AdminPlatformOrderRefundSummaryCardTest.php
Normal file
93
tests/Feature/AdminPlatformOrderRefundSummaryCardTest.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?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 AdminPlatformOrderRefundSummaryCardTest 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_page_shows_refund_orders_summary_card(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$merchant = Merchant::query()->firstOrFail();
|
||||||
|
$plan = Plan::query()->create([
|
||||||
|
'code' => 'refund_summary_card_test',
|
||||||
|
'name' => '退款摘要卡测试套餐',
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'price' => 10,
|
||||||
|
'list_price' => 10,
|
||||||
|
'status' => 'active',
|
||||||
|
'sort' => 10,
|
||||||
|
'published_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 有退款:summary
|
||||||
|
PlatformOrder::query()->create([
|
||||||
|
'merchant_id' => $merchant->id,
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'order_no' => 'PO_REFUND_CARD_HAS',
|
||||||
|
'order_type' => 'new_purchase',
|
||||||
|
'status' => 'activated',
|
||||||
|
'payment_status' => 'refunded',
|
||||||
|
'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,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 无退款
|
||||||
|
PlatformOrder::query()->create([
|
||||||
|
'merchant_id' => $merchant->id,
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'order_no' => 'PO_REFUND_CARD_NONE',
|
||||||
|
'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' => [],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->get('/admin/platform-orders')
|
||||||
|
->assertOk()
|
||||||
|
->assertSee('有退款订单 / 无退款订单')
|
||||||
|
->assertSee('1')
|
||||||
|
->assertSee('/')
|
||||||
|
->assertSee('1');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user