余额溢出和 POST 限制

This commit is contained in:
iVampireSP.com 2022-09-04 01:32:50 +08:00
parent 01bb962623
commit 39cd00571f
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 13 additions and 16 deletions

View File

@ -6,6 +6,7 @@
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Module\Module; use App\Models\Module\Module;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
class ModuleController extends Controller class ModuleController extends Controller
{ {
@ -36,6 +37,15 @@ public function call(Request $request, Module $module)
$method = Str::lower($request->method()); $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()); $response = $module->remoteRequest($method, $func, $request->all());

View File

@ -83,25 +83,10 @@ public function cost($price = null)
$price = abs($price); $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; $cache_key = 'user_drops_' . $this->user_id;
$drops = Cache::get($cache_key); $drops = Cache::get($cache_key);
// Log::debug($user); // Log::debug($user);
if ($price !== null) { if ($price !== null) {
@ -112,6 +97,8 @@ public function cost($price = null)
$this->price = $this->managed_price; $this->price = $this->managed_price;
} }
$amount = $price / Cache::get('drops_rate', 100) + 1;
// if drops <= price // if drops <= price
if ($drops < $this->price) { if ($drops < $this->price) {
try { try {