feat(platform-orders): 支持总台手工创建平台订单并进入闭环

This commit is contained in:
萝卜
2026-03-10 14:35:31 +00:00
parent 826c58085b
commit 3f809c8150
5 changed files with 304 additions and 1 deletions

View File

@@ -0,0 +1,107 @@
<?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 AdminPlatformOrderCreateTest 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_admin_can_open_create_platform_order_form(): void
{
$this->loginAsPlatformAdmin();
// 需要至少一个套餐供选择
Plan::query()->create([
'code' => 'create_order_plan_01',
'name' => '创建订单测试套餐',
'billing_cycle' => 'monthly',
'price' => 100,
'list_price' => 100,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$res = $this->get('/admin/platform-orders/create');
$res->assertOk();
$res->assertSee('新建平台订单');
$res->assertSee('站点');
$res->assertSee('套餐');
$res->assertSee('创建订单');
}
public function test_platform_admin_can_create_platform_order_and_see_it_in_show_page(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'create_order_plan_02',
'name' => '创建订单测试套餐2',
'billing_cycle' => 'monthly',
'price' => 199,
'list_price' => 199,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$res = $this->post('/admin/platform-orders', [
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_type' => 'new_purchase',
'quantity' => 2,
'discount_amount' => 10,
'payment_channel' => 'offline',
'remark' => '线下补单',
]);
$res->assertRedirect();
$order = PlatformOrder::query()->latest('id')->first();
$this->assertNotNull($order);
$this->assertSame($merchant->id, $order->merchant_id);
$this->assertSame($plan->id, $order->plan_id);
$this->assertSame('pending', $order->status);
$this->assertSame('unpaid', $order->payment_status);
$this->assertSame('offline', $order->payment_channel);
// 金额口径list_amount=price*quantitypayable=list-discount
$this->assertSame(398.0, (float) $order->list_amount);
$this->assertSame(10.0, (float) $order->discount_amount);
$this->assertSame(388.0, (float) $order->payable_amount);
$show = $this->get('/admin/platform-orders/' . $order->id);
$show->assertOk();
$show->assertSee($order->order_no);
$show->assertSee('平台订单详情');
$show->assertSee('待处理');
$show->assertSee('未支付');
}
public function test_guest_cannot_open_create_platform_order_form(): void
{
$this->seed();
$this->get('/admin/platform-orders/create')
->assertRedirect('/admin/login');
}
}