Plans: add publish toggle action and UI
This commit is contained in:
@@ -219,6 +219,28 @@ class PlanController extends Controller
|
||||
return redirect()->back()->with('success', '套餐状态已更新:' . ($this->statusLabels()[$plan->status] ?? $plan->status));
|
||||
}
|
||||
|
||||
public function setPublished(Request $request, Plan $plan): RedirectResponse
|
||||
{
|
||||
$this->ensurePlatformAdmin($request);
|
||||
|
||||
$data = $request->validate([
|
||||
'published' => ['required', Rule::in(['0', '1'])],
|
||||
]);
|
||||
|
||||
$published = (string) $data['published'] === '1';
|
||||
|
||||
if ($published) {
|
||||
// 最小治理:发布动作仅写 published_at,不改变 status(避免误把草稿/停用套餐误启用)。
|
||||
$plan->published_at = $plan->published_at ?? now();
|
||||
} else {
|
||||
$plan->published_at = null;
|
||||
}
|
||||
|
||||
$plan->save();
|
||||
|
||||
return redirect()->back()->with('success', $published ? '套餐已发布' : '套餐已取消发布');
|
||||
}
|
||||
|
||||
public function update(Request $request, Plan $plan): RedirectResponse
|
||||
{
|
||||
$this->ensurePlatformAdmin($request);
|
||||
|
||||
Reference in New Issue
Block a user