feat(plans): 空库一键初始化默认套餐(带护栏与测试)
This commit is contained in:
@@ -228,6 +228,49 @@ class PlanController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
public function seedDefaults(Request $request): RedirectResponse
|
||||
{
|
||||
$this->ensurePlatformAdmin($request);
|
||||
|
||||
// 安全护栏:仅当当前库没有任何套餐时才允许一键初始化
|
||||
$existingCount = Plan::query()->count();
|
||||
if ($existingCount > 0) {
|
||||
return redirect()->back()->with('error', '当前已有套餐(' . $existingCount . ' 条),为避免污染运营数据,已阻止一键初始化。');
|
||||
}
|
||||
|
||||
$now = now();
|
||||
$defaults = [
|
||||
[
|
||||
'code' => 'starter_monthly',
|
||||
'name' => '基础版(月付)',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 99,
|
||||
'list_price' => 129,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'description' => '适合刚开站的试运营阶段,可用于 Demo 场景。',
|
||||
'published_at' => $now,
|
||||
],
|
||||
[
|
||||
'code' => 'pro_yearly',
|
||||
'name' => '专业版(年付)',
|
||||
'billing_cycle' => 'yearly',
|
||||
'price' => 1999,
|
||||
'list_price' => 2599,
|
||||
'status' => 'active',
|
||||
'sort' => 20,
|
||||
'description' => '面向成长型站点,后续搭配授权项配置。',
|
||||
'published_at' => $now,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($defaults as $row) {
|
||||
Plan::query()->create($row);
|
||||
}
|
||||
|
||||
return redirect('/admin/plans')->with('success', '已初始化默认套餐:' . count($defaults) . ' 条。');
|
||||
}
|
||||
|
||||
protected function statusLabels(): array
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user