feat(platform-orders): 增加回执状态筛选(有回执/无回执)
This commit is contained in:
@@ -138,6 +138,8 @@ class PlatformOrderController extends Controller
|
||||
'batch_mark_activated_24h' => (string) $request->query('batch_mark_activated_24h', ''),
|
||||
// 只看“对账不一致”的订单(粗版):meta.payment_summary.total_amount 与 paid_amount 不一致
|
||||
'reconcile_mismatch' => (string) $request->query('reconcile_mismatch', ''),
|
||||
// 支付回执筛选:has(有回执)/none(无回执)
|
||||
'receipt_status' => trim((string) $request->query('receipt_status', '')),
|
||||
];
|
||||
|
||||
|
||||
@@ -571,6 +573,8 @@ class PlatformOrderController extends Controller
|
||||
'batch_mark_activated_24h' => (string) $request->query('batch_mark_activated_24h', ''),
|
||||
// 只看“对账不一致”的订单(粗版):meta.payment_summary.total_amount 与 paid_amount 不一致
|
||||
'reconcile_mismatch' => (string) $request->query('reconcile_mismatch', ''),
|
||||
// 支付回执筛选:has(有回执)/none(无回执)
|
||||
'receipt_status' => trim((string) $request->query('receipt_status', '')),
|
||||
];
|
||||
|
||||
|
||||
@@ -1115,6 +1119,22 @@ class PlatformOrderController extends Controller
|
||||
// total_cents = (payment_summary.total_amount 存在 ? summary*100 : SUM(payment_receipts[].amount)*100)
|
||||
$builder->whereRaw("ABS(ROUND((CASE WHEN JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NOT NULL THEN CAST(JSON_UNQUOTE(JSON_EXTRACT(meta, '$.payment_summary.total_amount')) AS DECIMAL(12,2)) ELSE (SELECT IFNULL(SUM(j.amount), 0) FROM JSON_TABLE(meta, '$.payment_receipts[*]' COLUMNS(amount DECIMAL(12,2) PATH '$.amount')) j) END) * 100) - ROUND(paid_amount * 100)) >= 1");
|
||||
}
|
||||
})
|
||||
->when(($filters['receipt_status'] ?? '') !== '', function (Builder $builder) use ($filters) {
|
||||
// 支付回执筛选:
|
||||
// - has:有回执(payment_summary.total_amount 存在 或 payment_receipts[0].amount 存在)
|
||||
// - none:无回执(两者都不存在)
|
||||
$status = (string) ($filters['receipt_status'] ?? '');
|
||||
|
||||
if ($status === 'has') {
|
||||
$builder->where(function (Builder $q) {
|
||||
$q->whereRaw("JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NOT NULL")
|
||||
->orWhereRaw("JSON_EXTRACT(meta, '$.payment_receipts[0].amount') IS NOT NULL");
|
||||
});
|
||||
} elseif ($status === 'none') {
|
||||
$builder->whereRaw("JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NULL")
|
||||
->whereRaw("JSON_EXTRACT(meta, '$.payment_receipts[0].amount') IS NULL");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,11 @@
|
||||
<option value="synced" @selected(($filters['sync_status'] ?? '') === 'synced')>已同步</option>
|
||||
<option value="failed" @selected(($filters['sync_status'] ?? '') === 'failed')>同步失败</option>
|
||||
</select>
|
||||
<select name="receipt_status">
|
||||
<option value="">全部回执状态</option>
|
||||
<option value="has" @selected(($filters['receipt_status'] ?? '') === 'has')>有回执</option>
|
||||
<option value="none" @selected(($filters['receipt_status'] ?? '') === 'none')>无回执</option>
|
||||
</select>
|
||||
|
||||
<input type="number" name="site_subscription_id" placeholder="订阅ID(可选)" value="{{ $filters['site_subscription_id'] ?? '' }}" class="w-140">
|
||||
<label class="form-inline-row">
|
||||
@@ -178,6 +183,7 @@
|
||||
<input type="hidden" name="fail_only" value="{{ $filters['fail_only'] ?? '' }}">
|
||||
<input type="hidden" name="synced_only" value="{{ $filters['synced_only'] ?? '' }}">
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
<input type="hidden" name="receipt_status" value="{{ $filters['receipt_status'] ?? '' }}">
|
||||
<input type="hidden" name="syncable_only" value="{{ $filters['syncable_only'] ?? '' }}">
|
||||
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}">
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
@@ -203,6 +209,7 @@
|
||||
<input type="hidden" name="fail_only" value="{{ $filters['fail_only'] ?? '' }}">
|
||||
<input type="hidden" name="synced_only" value="{{ $filters['synced_only'] ?? '' }}">
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
<input type="hidden" name="receipt_status" value="{{ $filters['receipt_status'] ?? '' }}">
|
||||
<input type="hidden" name="syncable_only" value="{{ $filters['syncable_only'] ?? '' }}">
|
||||
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}">
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
@@ -230,6 +237,7 @@
|
||||
<input type="hidden" name="fail_only" value="{{ $filters['fail_only'] ?? '' }}">
|
||||
<input type="hidden" name="synced_only" value="{{ $filters['synced_only'] ?? '' }}">
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
<input type="hidden" name="receipt_status" value="{{ $filters['receipt_status'] ?? '' }}">
|
||||
<input type="hidden" name="syncable_only" value="{{ $filters['syncable_only'] ?? '' }}">
|
||||
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}">
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
@@ -299,6 +307,7 @@
|
||||
<input type="hidden" name="fail_only" value="{{ $filters['fail_only'] ?? '' }}">
|
||||
<input type="hidden" name="synced_only" value="{{ $filters['synced_only'] ?? '' }}">
|
||||
<input type="hidden" name="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
|
||||
<input type="hidden" name="receipt_status" value="{{ $filters['receipt_status'] ?? '' }}">
|
||||
<input type="hidden" name="syncable_only" value="{{ $filters['syncable_only'] ?? '' }}">
|
||||
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}">
|
||||
<input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
|
||||
|
||||
122
tests/Feature/AdminPlatformOrderReceiptStatusFilterTest.php
Normal file
122
tests/Feature/AdminPlatformOrderReceiptStatusFilterTest.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?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 AdminPlatformOrderReceiptStatusFilterTest 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_can_filter_by_receipt_status_has_and_none(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'receipt_status_filter_test',
|
||||
'name' => '回执状态筛选测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
// 有回执:仅 receipts
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_RECEIPT_HAS_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' => [
|
||||
['amount' => 10.00, 'paid_at' => now()->toDateTimeString()],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
// 有回执:summary
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_RECEIPT_HAS_0002',
|
||||
'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_summary' => [
|
||||
'total_amount' => 10.00,
|
||||
'count' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
// 无回执:两者都没有
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_RECEIPT_NONE_0003',
|
||||
'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?receipt_status=has')
|
||||
->assertOk()
|
||||
->assertSee('PO_RECEIPT_HAS_0001')
|
||||
->assertSee('PO_RECEIPT_HAS_0002')
|
||||
->assertDontSee('PO_RECEIPT_NONE_0003');
|
||||
|
||||
$this->get('/admin/platform-orders?receipt_status=none')
|
||||
->assertOk()
|
||||
->assertSee('PO_RECEIPT_NONE_0003')
|
||||
->assertDontSee('PO_RECEIPT_HAS_0001')
|
||||
->assertDontSee('PO_RECEIPT_HAS_0002');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user