改进 创建主机

This commit is contained in:
iVampireSP.com 2023-03-08 08:39:54 +08:00
parent 1830891c62
commit d14318e6c7
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -13,8 +13,6 @@
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
// use App\Models\User;
class HostController extends Controller
{
/**
@ -47,8 +45,8 @@ public function store(Request $request): Response|JsonResponse
$user = (new User)->findOrFail($request->input('user_id'));
if ($request->input('price') > 0) {
if ($request->billing_cycle === 'hourly') {
if (! $user->hasBalance(1)) {
if ($request->input('billing_cycle', 'hourly') === 'hourly') {
if (! $user->hasBalance("1")) {
return $this->error('此用户余额不足,无法开设计费项目。');
}
} else {
@ -63,7 +61,6 @@ public function store(Request $request): Response|JsonResponse
$data = [
'name' => $name,
'user_id' => $user->id,
'module_id' => auth('module')->id(),
'price' => $request->input('price'),
'managed_price' => $request->input('managed_price'),
@ -72,7 +69,7 @@ public function store(Request $request): Response|JsonResponse
'trial_ends_at' => $request->input('trial_ends_at'),
];
$host = (new Host)->create($data);
$host = $user->hosts()->create($data);
$host['host_id'] = $host->id;