改进 计费规则,改为模块需要创建计费项目时才要求余额。
This commit is contained in:
parent
5b0a892241
commit
a77e37bb31
@ -3,8 +3,8 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
// use Exception;
|
||||
// use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
|
@ -3,10 +3,12 @@
|
||||
namespace App\Http\Controllers\Remote\Host;
|
||||
|
||||
use App\Models\Host;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
// use Illuminate\Support\Facades\Log;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Exceptions\User\BalanceNotEnoughException;
|
||||
|
||||
class HostController extends Controller
|
||||
{
|
||||
@ -36,6 +38,13 @@ public function store(Request $request)
|
||||
'user_id' => 'required|integer|exists:users,id',
|
||||
]);
|
||||
|
||||
//
|
||||
$user = User::findOrFail($request->user_id);
|
||||
|
||||
if ($user->balance <= 1) {
|
||||
throw new BalanceNotEnoughException("余额不足,无法开设新的计费项目。");
|
||||
}
|
||||
|
||||
// 如果没有 name,则随机
|
||||
$name = $request->input('name', Str::random(10));
|
||||
|
||||
@ -43,7 +52,7 @@ public function store(Request $request)
|
||||
'name' => $name,
|
||||
'status' => $request->status,
|
||||
'price' => $request->price,
|
||||
'user_id' => $request->user_id,
|
||||
'user_id' => $user->id,
|
||||
'module_id' => auth('remote')->id()
|
||||
];
|
||||
|
||||
|
@ -53,13 +53,13 @@ public function call(Request $request, Module $module)
|
||||
$method = Str::lower($request->method());
|
||||
|
||||
// 如果 method 为 post, 检查用户余额
|
||||
if ($method == 'post') {
|
||||
$user = auth('api')->user();
|
||||
// if ($method == 'post') {
|
||||
// $user = auth('api')->user();
|
||||
|
||||
if ($user->balance < 1) {
|
||||
return $this->error('账户余额不足,请保证账户余额至少有 1 元。');
|
||||
}
|
||||
}
|
||||
// if ($user->balance < 1) {
|
||||
// return $this->error('账户余额不足,请保证账户余额至少有 1 元。');
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
$response = $module->remoteRequest($method, $path, $request->all());
|
||||
|
@ -23,9 +23,9 @@ public function update(Request $request, Host $host)
|
||||
$user = $request->user();
|
||||
if ($host->user_id == $user->id) {
|
||||
|
||||
if ($user->balance < 1) {
|
||||
return $this->error('余额不足');
|
||||
}
|
||||
// if ($user->balance < 1) {
|
||||
// return $this->error('余额不足');
|
||||
// }
|
||||
|
||||
$host->update([
|
||||
'status' => 'running'
|
||||
|
Loading…
Reference in New Issue
Block a user