PlatformOrder store: require subscription for renewal orders
This commit is contained in:
@@ -78,8 +78,7 @@ class PlatformOrderController extends Controller
|
|||||||
'plans' => $plans,
|
'plans' => $plans,
|
||||||
'siteSubscription' => $siteSubscription,
|
'siteSubscription' => $siteSubscription,
|
||||||
'billingCycleLabels' => $this->billingCycleLabels(),
|
'billingCycleLabels' => $this->billingCycleLabels(),
|
||||||
// order_type label 映射已下沉到 PlatformOrder::orderTypeLabel();这里不再透传 orderTypeLabels
|
'orderTypeLabels' => $this->orderTypeLabels(),
|
||||||
// 'orderTypeLabels' => $this->orderTypeLabels(),
|
|
||||||
'defaults' => $defaults,
|
'defaults' => $defaults,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -91,7 +90,13 @@ class PlatformOrderController extends Controller
|
|||||||
$data = $request->validate([
|
$data = $request->validate([
|
||||||
'merchant_id' => ['required', 'integer', 'exists:merchants,id'],
|
'merchant_id' => ['required', 'integer', 'exists:merchants,id'],
|
||||||
'plan_id' => ['required', 'integer', 'exists:plans,id'],
|
'plan_id' => ['required', 'integer', 'exists:plans,id'],
|
||||||
'site_subscription_id' => ['nullable', 'integer', 'exists:site_subscriptions,id'],
|
// 治理口径:续费单必须绑定订阅(否则无法做到“续期/延长到期”这一核心闭环)
|
||||||
|
'site_subscription_id' => [
|
||||||
|
Rule::requiredIf(fn () => (string) $request->input('order_type') === 'renewal'),
|
||||||
|
'nullable',
|
||||||
|
'integer',
|
||||||
|
'exists:site_subscriptions,id',
|
||||||
|
],
|
||||||
'order_type' => ['required', Rule::in(array_keys($this->orderTypeLabels()))],
|
'order_type' => ['required', Rule::in(array_keys($this->orderTypeLabels()))],
|
||||||
'quantity' => ['required', 'integer', 'min:1', 'max:120'],
|
'quantity' => ['required', 'integer', 'min:1', 'max:120'],
|
||||||
'discount_amount' => ['nullable', 'numeric', 'min:0'],
|
'discount_amount' => ['nullable', 'numeric', 'min:0'],
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ class AdminPlatformOrderCreateDefaultsPreselectedTest extends TestCase
|
|||||||
// 预选 merchant/plan/order_type
|
// 预选 merchant/plan/order_type
|
||||||
$res->assertSee('<option value="' . $merchant->id . '" selected>', false);
|
$res->assertSee('<option value="' . $merchant->id . '" selected>', false);
|
||||||
$res->assertSee('<option value="' . $plan->id . '" selected>', false);
|
$res->assertSee('<option value="' . $plan->id . '" selected>', false);
|
||||||
$res->assertSee('<option value="renewal" selected>', false);
|
// 兼容不同 Laravel 版本对 @selected 的渲染形式(selected 或 selected="selected")
|
||||||
|
$res->assertSee('value="renewal" selected', false);
|
||||||
|
|
||||||
// 预填其它字段
|
// 预填其它字段
|
||||||
$res->assertSee('name="site_subscription_id" value="' . $sub->id . '"', false);
|
$res->assertSee('name="site_subscription_id" value="' . $sub->id . '"', false);
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Merchant;
|
||||||
|
use App\Models\Plan;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminPlatformOrderStoreShouldRequireSubscriptionForRenewalTest 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_store_should_reject_renewal_order_when_site_subscription_id_missing(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$merchant = Merchant::query()->firstOrFail();
|
||||||
|
$plan = Plan::query()->create([
|
||||||
|
'code' => 'po_store_renewal_requires_sub_plan',
|
||||||
|
'name' => '续费必须绑定订阅测试套餐',
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'price' => 10,
|
||||||
|
'list_price' => 10,
|
||||||
|
'status' => 'active',
|
||||||
|
'sort' => 10,
|
||||||
|
'published_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$res = $this->from('/admin/platform-orders/create')->post('/admin/platform-orders', [
|
||||||
|
'merchant_id' => $merchant->id,
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'order_type' => 'renewal',
|
||||||
|
'quantity' => 1,
|
||||||
|
'discount_amount' => 0,
|
||||||
|
'payment_channel' => 'offline',
|
||||||
|
'remark' => 'try renewal without sub',
|
||||||
|
// site_subscription_id 故意不传
|
||||||
|
]);
|
||||||
|
|
||||||
|
$res->assertStatus(302);
|
||||||
|
$res->assertSessionHasErrors('site_subscription_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user