From 6f6b5869642e876029715d202cf3c034cc192954 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Mon, 13 Feb 2023 02:42:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Web/HostController.php | 20 ++++- resources/views/hosts/index.blade.php | 87 +++++++++++++++++++++ resources/views/layouts/app.blade.php | 7 +- routes/web.php | 6 ++ 4 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 resources/views/hosts/index.blade.php 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') +

主机管理

+

更快捷的管理计费项目。更高级的管理请前往 "仪表盘"。

+ +
+ + + + + + + + + + + + + @foreach ($hosts as $host) + + + + + + + + + + + @endforeach + +
ID模块名称月估算价格状态更新 / 创建 时间操作
+ {{ $host->id }} + + {{ $host->module->name }} + + {{ $host->name }} + + @if ($host->managed_price !== null) + {{ $host->managed_price }} 元 + @else + {{ $host->price }} 元 + @endif +
+ @if($host->billing_cycle) + + 到期时间:{{ $host->next_due_at }} + @endif +
+ + + + {{ $host->updated_at }} +
+ {{ $host->created_at }} +
+
+
+ @csrf + @method('DELETE') + + +
+ + @if($host->billing_cycle) +
+ @csrf + + +
+ @endif + + +
+
+ + {{-- 分页 --}} + {{ $hosts->links() }} + +@endsection diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 39e38eb..848706c 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -40,10 +40,13 @@ @auth('web')