update
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Module\IPPool\IPPoolRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ModuleIPPoolController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public IPPoolRepositoryInterface $ipPoolRepository
|
||||
) {
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
$modules = $this->ipPoolRepository->filter(
|
||||
[
|
||||
'page' => $request->get('page') ?? 1
|
||||
]
|
||||
);
|
||||
$title = 'List all server ip pool';
|
||||
return view('admin.module.ippool.index', compact('modules', 'title'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$title = 'Add new server ip pool';
|
||||
return view('admin.module.ippool.add', compact('title'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$ipAddresses = explode(',', $data['ip_address']);
|
||||
$moduleNetworkId = $data['module_network_id'];
|
||||
|
||||
foreach ($ipAddresses as $ip) {
|
||||
$this->ipPoolRepository->create([
|
||||
'ip_address' => trim($ip),
|
||||
'module_network_id' => $moduleNetworkId,
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('module.ippool.index')->with('success', 'Add new server ip pool success');
|
||||
}
|
||||
|
||||
public function edit(int $id = 0)
|
||||
{
|
||||
$module = $this->ipPoolRepository->find($id);
|
||||
$title = 'Edit server ip pool';
|
||||
return view('admin.module.ippool.edit', compact('module', 'title'));
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id = 0)
|
||||
{
|
||||
$this->ipPoolRepository->update($id, $request->all());
|
||||
}
|
||||
|
||||
public function destroy(int $id = 0)
|
||||
{
|
||||
$this->ipPoolRepository->delete($id);
|
||||
return redirect()->route('module.ippool.index')->with('success', 'Delete server ip pool success');
|
||||
}
|
||||
}
|
||||
@@ -756,7 +756,7 @@ class ServiceController extends Controller
|
||||
], 422);
|
||||
}
|
||||
|
||||
$productId = htmlspecialchars(strip_tags(trim($request->product_id)), ENT_QUOTES, 'UTF-8');
|
||||
$productId = $request->product_id;
|
||||
$userId = $user->id;
|
||||
|
||||
$product = ModuleVmware::where('vmware_id', $productId)
|
||||
|
||||
@@ -117,14 +117,6 @@ class ProcessOrderPaymentJob implements ShouldQueue
|
||||
$successfulVMs = array_filter($vmCreationResults, fn($vm) => $vm['success']);
|
||||
$failedVMs = array_filter($vmCreationResults, fn($vm) => !$vm['success']);
|
||||
|
||||
Log::info("Kết quả tạo VM cho đơn hàng #{$this->order->order_num}", [
|
||||
'order_id' => $this->order->id,
|
||||
'total_vms' => count($vmCreationResults),
|
||||
'successful_vms' => count($successfulVMs),
|
||||
'failed_vms' => count($failedVMs),
|
||||
'vm_results' => $vmCreationResults
|
||||
]);
|
||||
|
||||
// Nếu tất cả VM được tạo thành công, tiến hành thanh toán
|
||||
if ($allVMsCreated && count($successfulVMs) > 0) {
|
||||
DB::beginTransaction();
|
||||
@@ -142,13 +134,6 @@ class ProcessOrderPaymentJob implements ShouldQueue
|
||||
|
||||
DB::commit();
|
||||
|
||||
Log::info("Thanh toán thành công cho đơn hàng #{$this->order->order_num}", [
|
||||
'order_id' => $this->order->id,
|
||||
'vm_results' => $vmCreationResults,
|
||||
'total_vms' => count($vmCreationResults),
|
||||
'successful_vms' => count($successfulVMs)
|
||||
]);
|
||||
|
||||
// Gửi thông báo thành công cho khách hàng
|
||||
$this->sendSuccessNotification($vmCreationResults);
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class IpPool extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'ip_address',
|
||||
'module_network_id',
|
||||
];
|
||||
|
||||
public function network()
|
||||
{
|
||||
return $this->belongsTo(ModuleNetwork::class, 'module_network_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,8 @@ use App\Repositories\Module\Datastore\DatastoreCachedRepository;
|
||||
use App\Repositories\Module\Datastore\DatastoreRepositoryInterface;
|
||||
use App\Repositories\Module\DnsServer\DnsServerCachedRepository;
|
||||
use App\Repositories\Module\DnsServer\DnsServerRepositoryInterface;
|
||||
use App\Repositories\Module\IPPool\IPPoolCachedRepository;
|
||||
use App\Repositories\Module\IPPool\IPPoolRepositoryInterface;
|
||||
use App\Repositories\Note\NoteCachedRepository;
|
||||
use App\Repositories\Note\NoteRepositoryInterface;
|
||||
use App\Repositories\Order\OrderCachedRepository;
|
||||
@@ -327,6 +329,12 @@ class RepositoryProvider extends ServiceProvider
|
||||
VPSRepositoryInterface::class,
|
||||
VPSCachedRepository::class
|
||||
);
|
||||
|
||||
//Module IP Pool
|
||||
$this->app->bind(
|
||||
IPPoolRepositoryInterface::class,
|
||||
IPPoolCachedRepository::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\IPPool;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class IPPoolCachedRepository extends BaseCachedRepository implements IPPoolRepositoryInterface
|
||||
{
|
||||
public function __construct(
|
||||
public IPPoolRepository $ipPoolRepository
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
public function getModel()
|
||||
{
|
||||
return $this->ipPoolRepository->getModel();
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'filterItem' => [
|
||||
'data' => $data,
|
||||
'relationships' => $relationships,
|
||||
'select' => $select,
|
||||
'withCount' => $withCount
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) {
|
||||
return $this->ipPoolRepository->filter($data, $relationships, $withCount, $select);
|
||||
});
|
||||
}
|
||||
public function findByName(string $name = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findByName' => [
|
||||
'name' => $name
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($name){
|
||||
return $this->ipPoolRepository->findByName($name);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Module\IPPool;
|
||||
|
||||
use App\Models\IPPool;
|
||||
use App\Repositories\BaseRepository;
|
||||
|
||||
class IPPoolRepository extends BaseRepository implements IPPoolRepositoryInterface
|
||||
{
|
||||
public function getModel()
|
||||
{
|
||||
return IPPool::class;
|
||||
}
|
||||
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
|
||||
{
|
||||
$model = $this->model->with($relationships)->select($select);
|
||||
if (isset($data['relations'])) {
|
||||
foreach ($data['relations'] as $key => $value) {
|
||||
$model = $model->whereHas($key, function ($query) use ($value) {
|
||||
if (isset($value['condition'])) {
|
||||
switch (strtoupper($value['condition'])) {
|
||||
case "IN":
|
||||
$query->whereIn($value['key'], $value['value']);
|
||||
break;
|
||||
case "NotIn":
|
||||
$query->whereNotIn($value['key'], $value['value']);
|
||||
break;
|
||||
default:
|
||||
$query->where($value['key'], $value['condition'], $value['value']);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$query->where($value['key'], $value['value']);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (count($withCount) > 0) {
|
||||
$model = $model->withCount($withCount);
|
||||
}
|
||||
if (isset($data['page'])) {
|
||||
return $model->paginate(15);
|
||||
}
|
||||
return $model->get();
|
||||
}
|
||||
public function findByName(string $name = '')
|
||||
{
|
||||
if (empty($name)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->where('name','LIKE',"%$name%")->first();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace App\Repositories\Module\IPPool;
|
||||
|
||||
use App\Repositories\BaseRepositoryInterface;
|
||||
|
||||
interface IPPoolRepositoryInterface extends BaseRepositoryInterface{
|
||||
public function filter(array $data = [],array $relationships = [],array $withCount = [],array $select = ['*']);
|
||||
public function findByName(string $name = '');
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user