feat(platform-orders): 增加对账不一致筛选(回执总额≠已付金额)

This commit is contained in:
萝卜
2026-03-10 20:58:08 +00:00
parent 6800ee3d59
commit ca1c25e18d
4 changed files with 131 additions and 0 deletions

View File

@@ -136,6 +136,8 @@ class PlatformOrderController extends Controller
'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''), 'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''),
// 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪) // 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪)
'batch_mark_activated_24h' => (string) $request->query('batch_mark_activated_24h', ''), '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', ''), 'batch_synced_24h' => (string) $request->query('batch_synced_24h', ''),
// 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪) // 只看最近 24 小时批量“仅标记为已生效”过的订单(可治理追踪)
'batch_mark_activated_24h' => (string) $request->query('batch_mark_activated_24h', ''), '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 { } else {
$builder->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(meta, '$.batch_mark_activated.at')) >= ?", [$since]); $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");
}
}); });
} }

View File

@@ -82,6 +82,10 @@
<input type="checkbox" name="batch_mark_activated_24h" value="1" @checked(($filters['batch_mark_activated_24h'] ?? '') === '1')> <input type="checkbox" name="batch_mark_activated_24h" value="1" @checked(($filters['batch_mark_activated_24h'] ?? '') === '1')>
<span>最近24小时批量生效过</span> <span>最近24小时批量生效过</span>
</label> </label>
<label class="form-inline-row">
<input type="checkbox" name="reconcile_mismatch" value="1" @checked(($filters['reconcile_mismatch'] ?? '') === '1')>
<span>只看对账不一致(回执总额≠已付金额)</span>
</label>
<input type="text" name="keyword" placeholder="关键词:订单号/站点/订阅号" value="{{ $filters['keyword'] ?? '' }}"> <input type="text" name="keyword" placeholder="关键词:订单号/站点/订阅号" value="{{ $filters['keyword'] ?? '' }}">
<div> <div>
<button type="submit">应用筛选</button> <button type="submit">应用筛选</button>
@@ -176,6 +180,7 @@
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}"> <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'] ?? '' }}"> <input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}"> <input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
<label class="form-inline-row mb-8"> <label class="form-inline-row mb-8">
<input type="checkbox" name="include_meta" value="1"> <input type="checkbox" name="include_meta" value="1">
@@ -200,6 +205,7 @@
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}"> <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'] ?? '' }}"> <input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}"> <input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
<label class="muted form-inline-row mb-8"> <label class="muted form-inline-row mb-8">
<span>本次最多处理</span> <span>本次最多处理</span>
@@ -226,6 +232,7 @@
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}"> <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'] ?? '' }}"> <input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}"> <input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
<label class="muted form-inline-row mb-8"> <label class="muted form-inline-row mb-8">
<span>确认输入</span> <span>确认输入</span>
<input type="text" name="confirm" placeholder="YES" class="w-140"> <input type="text" name="confirm" placeholder="YES" class="w-140">
@@ -251,6 +258,7 @@
<input type="hidden" name="synced_only" value="{{ $filters['synced_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="sync_status" value="{{ $filters['sync_status'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}"> <input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
<label class="muted form-inline-row mb-8"> <label class="muted form-inline-row mb-8">
<span>本次最多处理</span> <span>本次最多处理</span>
@@ -293,6 +301,7 @@
<input type="hidden" name="batch_synced_24h" value="{{ $filters['batch_synced_24h'] ?? '' }}"> <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'] ?? '' }}"> <input type="hidden" name="batch_mark_activated_24h" value="{{ $filters['batch_mark_activated_24h'] ?? '' }}">
<input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}"> <input type="hidden" name="keyword" value="{{ $filters['keyword'] ?? '' }}">
<input type="hidden" name="reconcile_mismatch" value="{{ $filters['reconcile_mismatch'] ?? '' }}">
<button type="submit">清除当前筛选范围的失败标记</button> <button type="submit">清除当前筛选范围的失败标记</button>
</form> </form>

View File

@@ -0,0 +1,102 @@
<?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 AdminPlatformOrderReconcileMismatchFilterTest 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_reconcile_mismatch(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'reconcile_mismatch_test',
'name' => '对账不一致筛选测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
// 不一致paid_amount=10但 payment_summary.total_amount=9.99
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_RECON_MISMATCH_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_summary' => [
'count' => 1,
'total_amount' => 9.99,
'last_at' => now()->toDateTimeString(),
'last_amount' => 9.99,
'last_channel' => 'bank',
],
],
]);
// 一致paid_amount=10payment_summary.total_amount=10
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_RECON_MATCH_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' => [
'count' => 1,
'total_amount' => 10.00,
'last_at' => now()->toDateTimeString(),
'last_amount' => 10.00,
'last_channel' => 'bank',
],
],
]);
$this->get('/admin/platform-orders?reconcile_mismatch=1')
->assertOk()
->assertSee('PO_RECON_MISMATCH_0001')
->assertDontSee('PO_RECON_MATCH_0002');
}
}

View File

@@ -41,6 +41,7 @@ class AdminPlatformOrderTest extends TestCase
->assertSee('退款总额') ->assertSee('退款总额')
->assertSee('有回执订单 / 回执总额') ->assertSee('有回执订单 / 回执总额')
->assertSee('对账差额') ->assertSee('对账差额')
->assertSee('只看对账不一致')
->assertSee('快捷筛选') ->assertSee('快捷筛选')
->assertSee('待支付') ->assertSee('待支付')
->assertSee('待生效') ->assertSee('待生效')