From 0299434ff5aeefee1973139d9f91ad477bb2ab6d Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Wed, 18 Jan 2023 00:16:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20/=20=E6=94=B9=E8=BF=9B=20?= =?UTF-8?q?=E5=85=85=E5=80=BC=E6=88=96=E6=89=A3=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/ModuleController.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/Http/Controllers/Admin/ModuleController.php b/app/Http/Controllers/Admin/ModuleController.php index bb817d8..f3b4205 100644 --- a/app/Http/Controllers/Admin/ModuleController.php +++ b/app/Http/Controllers/Admin/ModuleController.php @@ -6,6 +6,7 @@ use App\Models\Host; use App\Models\Module; use App\Models\ModuleAllow; +use App\Models\Transaction; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Str; @@ -72,6 +73,7 @@ private function rules(): array 'name' => 'required|string|max:255', 'url' => 'required|url', 'status' => 'required|string|in:up,down,maintenance', + 'balance' => 'required|numeric', 'wecom_key' => 'nullable|string|max:255', ]; } @@ -134,6 +136,24 @@ public function update(Request $request, Module $module): RedirectResponse $text = '模块更新成功'; + if ($request->filled('balance')) { + // 判断有无差异 + if ($module->balance != $request->input('balance')) { + // bc 获取差异 + $diff = bcsub($request->input('balance'), $module->balance, 4); + + // 充值或者扣费 + if ($diff > 0) { + $description = '管理员 ' . auth('admin')->user()->name . ' 充值 ' . $diff . ' 元'; + $module->charge($diff, 'console', $description); + } else { + $description = '管理员 ' . auth('admin')->user()->name . ' 扣除 ' . abs($diff) . ' 元'; + $module->reduce(abs($diff), $description, false); + } + } + } + + if ($request->input('reset_api_token')) { $text .= ', API Token 为 ' . $module->api_token . '。'; } else {