PlatformOrder: add orderTypeLabel helper
This commit is contained in:
@@ -10,6 +10,20 @@ class PlatformOrder extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
public function orderTypeLabel(): string
|
||||||
|
{
|
||||||
|
$labels = [
|
||||||
|
'new_purchase' => '新购',
|
||||||
|
'renewal' => '续费',
|
||||||
|
'upgrade' => '升级',
|
||||||
|
'downgrade' => '降级',
|
||||||
|
];
|
||||||
|
|
||||||
|
$type = (string) ($this->order_type ?? '');
|
||||||
|
|
||||||
|
return (string) ($labels[$type] ?? $type);
|
||||||
|
}
|
||||||
|
|
||||||
public function receiptTotal(): float
|
public function receiptTotal(): float
|
||||||
{
|
{
|
||||||
// 优先读扁平字段 payment_summary.total_amount(更稳定、避免遍历 receipts)
|
// 优先读扁平字段 payment_summary.total_amount(更稳定、避免遍历 receipts)
|
||||||
|
|||||||
34
tests/Unit/PlatformOrderOrderTypeLabelTest.php
Normal file
34
tests/Unit/PlatformOrderOrderTypeLabelTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\Models\PlatformOrder;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class PlatformOrderOrderTypeLabelTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_order_type_label_should_map_known_types(): void
|
||||||
|
{
|
||||||
|
$o = new PlatformOrder();
|
||||||
|
|
||||||
|
$o->order_type = 'new_purchase';
|
||||||
|
$this->assertSame('新购', $o->orderTypeLabel());
|
||||||
|
|
||||||
|
$o->order_type = 'renewal';
|
||||||
|
$this->assertSame('续费', $o->orderTypeLabel());
|
||||||
|
|
||||||
|
$o->order_type = 'upgrade';
|
||||||
|
$this->assertSame('升级', $o->orderTypeLabel());
|
||||||
|
|
||||||
|
$o->order_type = 'downgrade';
|
||||||
|
$this->assertSame('降级', $o->orderTypeLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_order_type_label_should_fallback_to_code_when_unknown(): void
|
||||||
|
{
|
||||||
|
$o = new PlatformOrder();
|
||||||
|
$o->order_type = 'something_new';
|
||||||
|
|
||||||
|
$this->assertSame('something_new', $o->orderTypeLabel());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user