platform_orders index: compact view money format hides trailing .00
This commit is contained in:
@@ -28,6 +28,17 @@
|
||||
? $incomingBackForLinks
|
||||
: '';
|
||||
|
||||
// 金额展示:精简视图尽量更短(整数不显示 .00),full 视图保持两位小数(便于对账)
|
||||
$formatMoneyCompact = function ($amount) {
|
||||
$v = (float) $amount;
|
||||
$rounded = round($v, 2);
|
||||
if (abs($rounded - round($rounded)) < 0.00001) {
|
||||
return (string) ((int) round($rounded));
|
||||
}
|
||||
|
||||
return number_format($rounded, 2, '.', '');
|
||||
};
|
||||
|
||||
// 安全版“保留当前 query 并覆盖字段”的链接构造器:
|
||||
// - 强制使用站内相对路径(不包含域名)
|
||||
// - back 仅保留安全值(否则移除),避免 `{!! !!}` 输出时发生属性注入
|
||||
@@ -1074,8 +1085,20 @@
|
||||
</div>
|
||||
@endif
|
||||
</td>
|
||||
<td>¥{{ number_format((float) $order->payable_amount, 2) }}</td>
|
||||
<td>¥{{ number_format((float) $order->paid_amount, 2) }}</td>
|
||||
<td>
|
||||
@if($isFullView)
|
||||
¥{{ number_format((float) $order->payable_amount, 2) }}
|
||||
@else
|
||||
¥{{ $formatMoneyCompact($order->payable_amount) }}
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if($isFullView)
|
||||
¥{{ number_format((float) $order->paid_amount, 2) }}
|
||||
@else
|
||||
¥{{ $formatMoneyCompact($order->paid_amount) }}
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@if($isFullView)
|
||||
{{ optional($order->placed_at)->format('Y-m-d H:i:s') ?: '-' }}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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 AdminPlatformOrderIndexCompactViewMoneyFormatTest 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_compact_view_money_hides_trailing_zeros_but_full_view_keeps_two_decimals(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'po_index_compact_money_format_plan',
|
||||
'name' => '平台订单列表金额格式测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_INDEX_MONEY_FORMAT_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.00,
|
||||
'paid_amount' => 9.50,
|
||||
'placed_at' => now(),
|
||||
'paid_at' => now(),
|
||||
'activated_at' => now(),
|
||||
'meta' => [],
|
||||
]);
|
||||
|
||||
// 精简视图:整数不显示 .00
|
||||
$this->get('/admin/platform-orders')
|
||||
->assertOk()
|
||||
->assertSee('¥10', false)
|
||||
->assertDontSee('¥10.00', false);
|
||||
|
||||
// full 视图:保持两位小数
|
||||
$this->get('/admin/platform-orders?view=full')
|
||||
->assertOk()
|
||||
->assertSee('¥10.00', false)
|
||||
->assertSee('¥9.50', false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user