platform orders: bmpa receipt mismatch safety valve uses configured tolerance
This commit is contained in:
@@ -1240,7 +1240,11 @@ class PlatformOrderController extends Controller
|
|||||||
$receiptCents = (int) round($receiptTotal * 100);
|
$receiptCents = (int) round($receiptTotal * 100);
|
||||||
$expectedCents = (int) round($expectedPaid * 100);
|
$expectedCents = (int) round($expectedPaid * 100);
|
||||||
|
|
||||||
if (abs($receiptCents - $expectedCents) >= 1) {
|
$tol = (float) config('saasshop.amounts.tolerance', 0.01);
|
||||||
|
$tolCents = (int) round($tol * 100);
|
||||||
|
$tolCents = max(1, $tolCents);
|
||||||
|
|
||||||
|
if (abs($receiptCents - $expectedCents) >= $tolCents) {
|
||||||
throw new \InvalidArgumentException('订单回执总额与应付金额不一致,不允许批量推进,请先修正回执/金额后再处理。');
|
throw new \InvalidArgumentException('订单回执总额与应付金额不一致,不允许批量推进,请先修正回执/金额后再处理。');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 AdminPlatformOrderBatchMarkPaidAndActivateToleranceConfigTest 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_batch_mark_paid_and_activate_uses_configured_tolerance_for_receipt_mismatch_safety_valve(): void
|
||||||
|
{
|
||||||
|
// 将容差放大到 0.05(5 分),以验证 safety valve 使用配置,而不是硬编码 0.01(1 分)
|
||||||
|
config()->set('saasshop.amounts.tolerance', 0.05);
|
||||||
|
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$merchant = Merchant::query()->firstOrFail();
|
||||||
|
$plan = Plan::query()->create([
|
||||||
|
'code' => 'bmpa_tol_test_plan',
|
||||||
|
'name' => 'BMPA 容差配置测试套餐',
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'price' => 10,
|
||||||
|
'list_price' => 10,
|
||||||
|
'status' => 'active',
|
||||||
|
'sort' => 10,
|
||||||
|
'published_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 应付 10.00,回执 10.02(差 2 分)
|
||||||
|
// 如果容差=5 分,则允许通过,不应写入 batch_mark_paid_and_activate_error
|
||||||
|
$order = PlatformOrder::query()->create([
|
||||||
|
'merchant_id' => $merchant->id,
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'order_no' => 'PO_BMPA_TOL_0001',
|
||||||
|
'order_type' => 'new_purchase',
|
||||||
|
'status' => 'pending',
|
||||||
|
'payment_status' => 'unpaid',
|
||||||
|
'plan_name' => $plan->name,
|
||||||
|
'billing_cycle' => $plan->billing_cycle,
|
||||||
|
'period_months' => 1,
|
||||||
|
'quantity' => 1,
|
||||||
|
'payable_amount' => 10,
|
||||||
|
'paid_amount' => 0,
|
||||||
|
'placed_at' => now(),
|
||||||
|
'meta' => [
|
||||||
|
'payment_receipts' => [
|
||||||
|
[
|
||||||
|
'type' => 'manual',
|
||||||
|
'channel' => 'test',
|
||||||
|
'amount' => 10.02,
|
||||||
|
'paid_at' => now()->toDateTimeString(),
|
||||||
|
'note' => '回执略微偏差',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'payment_summary' => [
|
||||||
|
'count' => 1,
|
||||||
|
'total_amount' => 10.02,
|
||||||
|
'last_at' => now()->toDateTimeString(),
|
||||||
|
'last_amount' => 10.02,
|
||||||
|
'last_channel' => 'test',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->post('/admin/platform-orders/batch-mark-paid-and-activate', [
|
||||||
|
'scope' => 'filtered',
|
||||||
|
'status' => 'pending',
|
||||||
|
'payment_status' => 'unpaid',
|
||||||
|
'limit' => 50,
|
||||||
|
])->assertRedirect();
|
||||||
|
|
||||||
|
$order->refresh();
|
||||||
|
|
||||||
|
$this->assertEmpty(data_get($order->meta, 'batch_mark_paid_and_activate_error.message'));
|
||||||
|
$this->assertSame('paid', $order->payment_status);
|
||||||
|
$this->assertSame('activated', $order->status);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user