From ca1c25e18de75387697bda8bc56630fc32a6150c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 10 Mar 2026 20:58:08 +0000 Subject: [PATCH] =?UTF-8?q?feat(platform-orders):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E8=B4=A6=E4=B8=8D=E4=B8=80=E8=87=B4=E7=AD=9B=E9=80=89?= =?UTF-8?q?=EF=BC=88=E5=9B=9E=E6=89=A7=E6=80=BB=E9=A2=9D=E2=89=A0=E5=B7=B2?= =?UTF-8?q?=E4=BB=98=E9=87=91=E9=A2=9D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformOrderController.php | 19 ++++ .../admin/platform_orders/index.blade.php | 9 ++ ...atformOrderReconcileMismatchFilterTest.php | 102 ++++++++++++++++++ tests/Feature/AdminPlatformOrderTest.php | 1 + 4 files changed, 131 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderReconcileMismatchFilterTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 1c3ce10..ca25f0b 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -136,6 +136,8 @@ class PlatformOrderController extends Controller 'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''), // 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪) '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', ''), ]; @@ -558,6 +560,8 @@ class PlatformOrderController extends Controller 'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''), // 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪) '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', ''), ]; @@ -1062,6 +1066,21 @@ class PlatformOrderController extends Controller } else { $builder->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_mark_activated.at')) >= ?", [$since]); } + }) + ->when(($filters['reconcile_mismatch'] ?? '') !== '', function (Builder $builder) { + // 只看“对账不一致”的订单(粗版):支付回执总额(优先 payment_summary.total_amount)与订单 paid_amount 不一致 + // 注意:该筛选需要读取 JSON 字段,MySQL/SQLite 写法略有差异。 + $driver = $builder->getQuery()->getConnection()->getDriverName(); + + if ($driver === 'sqlite') { + // sqlite 下 JSON_EXTRACT 直接返回标量(数值或字符串),这里用“按分”取整避免浮点误差导致 0.01 边界不稳定 + $builder->whereRaw("JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NOT NULL") + ->whereRaw("ABS(ROUND(CAST(JSON_EXTRACT(meta, '$.payment_summary.total_amount') AS REAL) * 100) - ROUND(paid_amount * 100)) >= 1"); + } else { + // MySQL 下 JSON_EXTRACT 返回 JSON,需要 JSON_UNQUOTE 再 cast;同样按分取整避免浮点误差 + $builder->whereRaw("JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NOT NULL") + ->whereRaw("ABS(ROUND(CAST(JSON_UNQUOTE(JSON_EXTRACT(meta, '$.payment_summary.total_amount')) AS DECIMAL(12,2)) * 100) - ROUND(paid_amount * 100)) >= 1"); + } }); } diff --git a/resources/views/admin/platform_orders/index.blade.php b/resources/views/admin/platform_orders/index.blade.php index 52152a2..07d6512 100644 --- a/resources/views/admin/platform_orders/index.blade.php +++ b/resources/views/admin/platform_orders/index.blade.php @@ -82,6 +82,10 @@ 最近24小时批量生效过 +
@@ -176,6 +180,7 @@ +