diff --git a/app/Http/Controllers/Web/HostController.php b/app/Http/Controllers/Web/HostController.php index d116418..d45fc57 100644 --- a/app/Http/Controllers/Web/HostController.php +++ b/app/Http/Controllers/Web/HostController.php @@ -23,23 +23,35 @@ public function index(): View public function renew(Host $host) { - if ($host->renew()) { - return back()->with('success', '续费成功,新的到期时间为:'.$host->next_due_at); + $price = $host->getRenewPrice(); + + if ($price > auth()->user()->balance) { + return back()->with('error', '余额不足,续费需要:' . $price . ' 元,您还需要充值:' . ($price - auth()->user()->balance) . ' 元'); } + if (!$host->isCycle()) { + return back()->with('error', '该主机不是周期性付费,无法续费。'); + } + + if ($host->renew()) { + return back()->with('success', '续费成功,新的到期时间为:' . $host->next_due_at . '。'); + } + + return back()->with('error', '续费失败,请检查是否有足够的余额。'); } /** * Remove the specified resource from storage. * - * @param Host $host + * @param Host $host + * * @return RedirectResponse */ public function destroy(Host $host): RedirectResponse { $host->safeDelete(); - return back()->with('success', '已添加到销毁队列。'); + return redirect()->route('hosts . index')->with('success', '已添加到删除队列。'); } } diff --git a/resources/views/hosts/index.blade.php b/resources/views/hosts/index.blade.php new file mode 100644 index 0000000..cd3edf3 --- /dev/null +++ b/resources/views/hosts/index.blade.php @@ -0,0 +1,87 @@ +@extends('layouts.app') + +@section('title', '主机') + +@section('content') +
更快捷的管理计费项目。更高级的管理请前往 "仪表盘"。
+ +ID | +模块 | +名称 | +月估算价格 | +状态 | +更新 / 创建 时间 | +操作 | + + + + @foreach ($hosts as $host) +
---|---|---|---|---|---|---|
+ {{ $host->id }} + | ++ {{ $host->module->name }} + | ++ {{ $host->name }} + | + +
+ @if ($host->managed_price !== null)
+ {{ $host->managed_price }} 元
+ @else
+ {{ $host->price }} 元
+ @endif
+ + @if($host->billing_cycle) + |
+
+ |
+
+
+ {{ $host->updated_at }}
+ + {{ $host->created_at }} + + |
+ + + + @if($host->billing_cycle) + + @endif + + + | +