From 39cd00571fbef6d8ed9bf7ebab72bf42756b1ed6 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Sun, 4 Sep 2022 01:32:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=99=E9=A2=9D=E6=BA=A2=E5=87=BA=E5=92=8C?= =?UTF-8?q?=20POST=20=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Remote/ModuleController.php | 12 +++++++++++- app/Models/Host.php | 17 ++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Remote/ModuleController.php b/app/Http/Controllers/Remote/ModuleController.php index 8f44cc7..78a6051 100644 --- a/app/Http/Controllers/Remote/ModuleController.php +++ b/app/Http/Controllers/Remote/ModuleController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use App\Models\Module\Module; use App\Http\Controllers\Controller; +use Illuminate\Support\Facades\Cache; class ModuleController extends Controller { @@ -29,13 +30,22 @@ public function call(Request $request, Module $module) // 过滤除了 "/" 以外的特殊字符 $func = preg_replace('/[^a-zA-Z0-9\/]/', '', $func); - + // dd($func); $method = Str::lower($request->method()); + // 如果 method 为 post, 检查用户余额 + if ($method == 'post') { + $user = auth('sanctum')->user(); + + if ($user->balance < 1) { + return $this->error('余额小于 1, 无法使用 POST 请求。'); + } + } + $response = $module->remoteRequest($method, $func, $request->all()); diff --git a/app/Models/Host.php b/app/Models/Host.php index ddbdfaa..310b7f9 100644 --- a/app/Models/Host.php +++ b/app/Models/Host.php @@ -83,25 +83,10 @@ public function cost($price = null) $price = abs($price); - - if ($this->user->balance < 10) { - $amount = 1; - } else if ($this->user->balance < 100) { - $amount = 10; - } else if ($this->user->balance < 1000) { - $amount = 100; - } else if ($this->user->balance < 10000) { - $amount = 1000; - } else { - $amount = 10000; - } - $cache_key = 'user_drops_' . $this->user_id; $drops = Cache::get($cache_key); - - // Log::debug($user); if ($price !== null) { @@ -112,6 +97,8 @@ public function cost($price = null) $this->price = $this->managed_price; } + $amount = $price / Cache::get('drops_rate', 100) + 1; + // if drops <= price if ($drops < $this->price) { try {