Update source into github
This commit is contained in:
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\frontend;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\VirtualMachine\Action\RemoveVirtualMachine;
|
||||
use App\Jobs\VirtualMachine\Action\VMJobs;
|
||||
use App\Jobs\VirtualMachine\Snapshot\CreateSnapshot;
|
||||
use App\Jobs\VirtualMachine\Snapshot\RemoveSnapshot;
|
||||
use App\Jobs\VirtualMachine\Snapshot\RevertSnapshot;
|
||||
use App\Models\InvoiceItem;
|
||||
use App\Models\ModuleHosting;
|
||||
use App\Models\ModuleSnapshotLimit;
|
||||
use App\Models\ModuleVmware;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class ManagerService extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$title = "Dịch vụ của tôi";
|
||||
|
||||
return view("frontend.service", [
|
||||
'title' => $title,
|
||||
'breadcrumbs' => $this->crums->add(__('Dashboard'), route('home'))->add(__('Dịch vụ của tôi')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
|
||||
$validator = Validator::make($request->all(),
|
||||
[
|
||||
'type' => 'required',
|
||||
'product' => 'required'
|
||||
],
|
||||
[
|
||||
'type' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
],
|
||||
'product' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
]
|
||||
]
|
||||
);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator);
|
||||
}
|
||||
|
||||
$product = null;
|
||||
$information = null;
|
||||
$addon = [];
|
||||
$view = "";
|
||||
switch ($request->type) {
|
||||
case 3:
|
||||
$product = ModuleHosting::with('Server')->find($request->product);
|
||||
$information = InvoiceItem::where('relid', $product->id)
|
||||
->where('type_id', 3)
|
||||
->where('invoice_type', 1)
|
||||
->first()
|
||||
->GetItemProduct();
|
||||
$view = "frontend.service.hosting";
|
||||
break;
|
||||
case 4:
|
||||
$product = ModuleVmware::with('IpAddress.Host')->find($request->product);
|
||||
$information = InvoiceItem::where('relid', $product->id)
|
||||
->where('type_id', 4)
|
||||
->where('invoice_type', 1)
|
||||
->first()
|
||||
->GetItemProduct();
|
||||
$AllOn = InvoiceItem::whereHas('OrderItem', function ($query) {
|
||||
$query->where('status', 1);
|
||||
})
|
||||
->where('parent_id', $product->id)
|
||||
->where('type_id', 1)
|
||||
->get();
|
||||
|
||||
foreach ($AllOn as $item) {
|
||||
|
||||
$itemData = $item->GetItemProduct();
|
||||
|
||||
$price = 0;
|
||||
|
||||
switch ($item->billing) {
|
||||
case 2:
|
||||
$price = $item->amount / 1;
|
||||
break;
|
||||
case 3:
|
||||
$price = $item->amount / 3;
|
||||
break;
|
||||
case 4:
|
||||
$price = $item->amount / 6;
|
||||
break;
|
||||
case 5:
|
||||
$price = $item->amount / 12;
|
||||
break;
|
||||
}
|
||||
if (array_key_exists(strtolower($itemData->name), $addon)) {
|
||||
$addon[strtolower($itemData->name)] += $price / $itemData->price;
|
||||
} else {
|
||||
$addon[strtolower($itemData->name)] = $price / $itemData->price;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$view = "frontend.service.vmware";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$product) {
|
||||
return back()->withErrors("Không tìm thấy thông tin dữ liệu");
|
||||
}
|
||||
|
||||
$title = "Thông tin chi tiết dịch vụ";
|
||||
|
||||
return view($view, compact('title', 'product', 'information', 'addon'));
|
||||
}
|
||||
|
||||
public function reinstall(Request $request)
|
||||
{
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'userid' => 'numeric|required',
|
||||
'type' => 'numeric|required',
|
||||
'product' => 'numeric|required',
|
||||
'action' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator);
|
||||
}
|
||||
|
||||
$product = ModuleVmware::find($request->product);
|
||||
|
||||
if (!$product) {
|
||||
return back()->withErrors("Không tìm thấy thông tin dịch vụ");
|
||||
}
|
||||
$product->update([
|
||||
'status' => 3
|
||||
]);
|
||||
$jobs = new RemoveVirtualMachine($product->id);
|
||||
|
||||
dispatch($jobs)->delay(now()->addSeconds(5));
|
||||
|
||||
return back()->with('success', 'The system has received the information. Please wait a second');
|
||||
}
|
||||
|
||||
public function action(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'product' => 'numeric|required',
|
||||
'userid' => 'numeric|required',
|
||||
'action' => 'required'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['error' => true, 'message' => $validator]);
|
||||
}
|
||||
|
||||
$jobs = new VMJobs($request->product, $request->action);
|
||||
|
||||
$this->dispatch($jobs);
|
||||
|
||||
}
|
||||
|
||||
public function snapshot(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(),
|
||||
[
|
||||
'product' => 'numeric|required|not__in:0',
|
||||
'userid' => 'numeric|required|not__in:0',
|
||||
'action' => 'required'
|
||||
],
|
||||
[
|
||||
'product' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
],
|
||||
'userid' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
],
|
||||
'action' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
],
|
||||
]
|
||||
);
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['error' => true, 'message' => $validator->getMessageBag()]);
|
||||
}
|
||||
|
||||
|
||||
$jobs = null;
|
||||
|
||||
switch ($request->action) {
|
||||
case "Create":
|
||||
$SnapshotLimited = ModuleSnapshotLimit::where('customer_id', $request->userid)->first();
|
||||
|
||||
if ($SnapshotLimited->used == $SnapshotLimited->limit) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => "Đã đạt giới hạn số lượng Snapshot. Vui lòng liên hệ quản trị viên để nâng cấp!"
|
||||
]);
|
||||
}
|
||||
$jobs = new CreateSnapshot($request->product);
|
||||
break;
|
||||
case "Revert":
|
||||
$validator = Validator::make($request->all(),
|
||||
[
|
||||
'snap' => 'numeric|required|not__in:0',
|
||||
],
|
||||
[
|
||||
'snap' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
]
|
||||
]
|
||||
);
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['error' => true, 'message' => $validator->getMessageBag()]);
|
||||
}
|
||||
$jobs = new RevertSnapshot($request->product, $request->snap);
|
||||
break;
|
||||
case "Remove":
|
||||
$validator = Validator::make($request->all(),
|
||||
[
|
||||
'snap' => 'numeric|required|not__in:0',
|
||||
],
|
||||
[
|
||||
'snap' => [
|
||||
'required' => 'Yêu cầu không hợp lệ'
|
||||
]
|
||||
]
|
||||
);
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['error' => true, 'message' => $validator->getMessageBag()]);
|
||||
}
|
||||
$jobs = new RemoveSnapshot($request->product, $request->snap);
|
||||
break;
|
||||
}
|
||||
$this->dispatch($jobs);
|
||||
|
||||
}
|
||||
|
||||
public function console(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'product' => 'required|not__in:0'
|
||||
], ['product.required' => 'Yêu cầu không hợp lệ']);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator);
|
||||
}
|
||||
$product = ModuleVmware::find($request->product);
|
||||
if (!$product) {
|
||||
return back()->withErrors('Yêu cầu không hợp lệ');
|
||||
}
|
||||
$title = "Console for #" . $product->name;
|
||||
return view('frontend.service.console', compact('product', 'title'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user