余额溢出和 POST 限制
This commit is contained in:
parent
01bb962623
commit
39cd00571f
@ -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());
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user