2022-03-05 16:02:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2022-05-16 06:43:33 +02:00
|
|
|
use App\Models\Home;
|
2022-03-05 16:58:25 +01:00
|
|
|
use App\Models\IPs;
|
2022-03-05 16:02:12 +01:00
|
|
|
use App\Models\Labels;
|
|
|
|
use App\Models\Pricing;
|
|
|
|
use App\Models\Reseller;
|
|
|
|
use Illuminate\Http\Request;
|
2022-03-05 16:58:25 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2022-03-05 16:02:12 +01:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class ResellerController extends Controller
|
|
|
|
{
|
|
|
|
public function index()
|
|
|
|
{
|
2022-07-19 07:55:10 +02:00
|
|
|
$resellers = Reseller::allResellerHosting();
|
2022-03-05 16:02:12 +01:00
|
|
|
return view('reseller.index', compact(['resellers']));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
{
|
2022-07-19 07:55:10 +02:00
|
|
|
return view('reseller.create');
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
|
|
|
'domain' => 'required|min:4',
|
2022-10-20 02:06:44 +02:00
|
|
|
'reseller_type' => 'required|string',
|
|
|
|
'disk' => 'integer',
|
|
|
|
'os_id' => 'integer',
|
|
|
|
'provider_id' => 'integer',
|
|
|
|
'location_id' => 'integer',
|
2022-03-05 16:02:12 +01:00
|
|
|
'price' => 'numeric',
|
2022-10-20 02:06:44 +02:00
|
|
|
'payment_term' => 'integer',
|
|
|
|
'was_promo' => 'integer',
|
|
|
|
'owned_since' => 'sometimes|nullable|date',
|
|
|
|
'accounts' => 'integer',
|
|
|
|
'domains' => 'integer',
|
|
|
|
'sub_domains' => 'integer',
|
|
|
|
'bandwidth' => 'integer',
|
|
|
|
'email' => 'integer',
|
|
|
|
'ftp' => 'integer',
|
|
|
|
'db' => 'integer',
|
|
|
|
'next_due_date' => 'required|date',
|
|
|
|
'label1' => 'sometimes|nullable|string',
|
|
|
|
'label2' => 'sometimes|nullable|string',
|
|
|
|
'label3' => 'sometimes|nullable|string',
|
|
|
|
'label4' => 'sometimes|nullable|string',
|
2022-03-05 16:02:12 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$reseller_id = Str::random(8);
|
|
|
|
|
|
|
|
$pricing = new Pricing();
|
2022-08-30 15:37:05 +02:00
|
|
|
$pricing->insertPricing(3, $reseller_id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-03-05 16:58:25 +01:00
|
|
|
if (!is_null($request->dedicated_ip)) {
|
2022-05-09 06:35:07 +02:00
|
|
|
IPs::insertIP($reseller_id, $request->dedicated_ip);
|
2022-03-05 16:58:25 +01:00
|
|
|
}
|
|
|
|
|
2022-05-09 06:35:07 +02:00
|
|
|
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $reseller_id);
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-05-09 06:35:07 +02:00
|
|
|
Reseller::create([
|
|
|
|
'id' => $reseller_id,
|
|
|
|
'main_domain' => $request->domain,
|
|
|
|
'accounts' => $request->accounts,
|
|
|
|
'reseller_type' => $request->reseller_type,
|
|
|
|
'provider_id' => $request->provider_id,
|
|
|
|
'location_id' => $request->location_id,
|
|
|
|
'disk' => $request->disk,
|
|
|
|
'disk_type' => 'GB',
|
|
|
|
'disk_as_gb' => $request->disk,
|
|
|
|
'owned_since' => $request->owned_since,
|
|
|
|
'bandwidth' => $request->bandwidth,
|
|
|
|
'was_promo' => $request->was_promo,
|
|
|
|
'domains_limit' => $request->domains,
|
|
|
|
'subdomains_limit' => $request->sub_domains,
|
|
|
|
'email_limit' => $request->email,
|
|
|
|
'ftp_limit' => $request->ftp,
|
|
|
|
'db_limit' => $request->db
|
|
|
|
]);
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-07-19 07:55:10 +02:00
|
|
|
Cache::forget("all_reseller");
|
2022-05-16 06:43:33 +02:00
|
|
|
Home::homePageCacheForget();
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('reseller.index')
|
|
|
|
->with('success', 'Reseller hosting created Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Reseller $reseller)
|
|
|
|
{
|
2022-09-22 05:20:23 +02:00
|
|
|
$reseller = Reseller::resellerHosting($reseller->id);
|
2022-07-19 07:55:10 +02:00
|
|
|
return view('reseller.show', compact(['reseller']));
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function edit(Reseller $reseller)
|
|
|
|
{
|
2022-09-22 05:20:23 +02:00
|
|
|
$reseller = Reseller::resellerHosting($reseller->id);
|
2022-07-19 07:55:10 +02:00
|
|
|
return view('reseller.edit', compact(['reseller']));
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function update(Request $request, Reseller $reseller)
|
|
|
|
{
|
|
|
|
$request->validate([
|
|
|
|
'domain' => 'required|min:4',
|
2022-10-20 02:06:44 +02:00
|
|
|
'reseller_type' => 'required|string',
|
|
|
|
'disk' => 'integer',
|
|
|
|
'os_id' => 'integer',
|
|
|
|
'provider_id' => 'integer',
|
|
|
|
'location_id' => 'integer',
|
2022-03-05 16:02:12 +01:00
|
|
|
'price' => 'numeric',
|
2022-10-20 02:06:44 +02:00
|
|
|
'payment_term' => 'integer',
|
|
|
|
'was_promo' => 'integer',
|
|
|
|
'owned_since' => 'sometimes|nullable|date',
|
|
|
|
'accounts' => 'integer',
|
|
|
|
'domains' => 'integer',
|
|
|
|
'sub_domains' => 'integer',
|
|
|
|
'bandwidth' => 'integer',
|
|
|
|
'email' => 'integer',
|
|
|
|
'ftp' => 'integer',
|
|
|
|
'db' => 'integer',
|
|
|
|
'next_due_date' => 'required|date',
|
|
|
|
'label1' => 'sometimes|nullable|string',
|
|
|
|
'label2' => 'sometimes|nullable|string',
|
|
|
|
'label3' => 'sometimes|nullable|string',
|
|
|
|
'label4' => 'sometimes|nullable|string',
|
2022-03-05 16:02:12 +01:00
|
|
|
]);
|
|
|
|
|
2022-10-20 02:06:44 +02:00
|
|
|
$reseller->update([
|
|
|
|
'main_domain' => $request->domain,
|
|
|
|
'reseller_type' => $request->reseller_type,
|
|
|
|
'provider_id' => $request->provider_id,
|
|
|
|
'location_id' => $request->location_id,
|
2022-10-31 06:00:43 +01:00
|
|
|
'accounts' => $request->accounts,
|
2022-10-20 02:06:44 +02:00
|
|
|
'disk' => $request->disk,
|
|
|
|
'disk_type' => 'GB',
|
|
|
|
'disk_as_gb' => $request->disk,
|
|
|
|
'owned_since' => $request->owned_since,
|
|
|
|
'bandwidth' => $request->bandwidth,
|
|
|
|
'was_promo' => $request->was_promo,
|
|
|
|
'domains_limit' => $request->domains,
|
|
|
|
'subdomains_limit' => $request->sub_domains,
|
|
|
|
'email_limit' => $request->email,
|
|
|
|
'ftp_limit' => $request->ftp,
|
|
|
|
'db_limit' => $request->db
|
|
|
|
]);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
|
|
|
$pricing = new Pricing();
|
2022-10-31 06:00:43 +01:00
|
|
|
$pricing->updatePricing($reseller->id, $request->currency, $request->price, $request->payment_term, $request->next_due_date);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-10-31 06:00:43 +01:00
|
|
|
Labels::deleteLabelsAssignedTo($reseller->id);
|
|
|
|
Labels::insertLabelsAssigned([$request->label1, $request->label2, $request->label3, $request->label4], $reseller->id);
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-10-31 06:00:43 +01:00
|
|
|
IPs::deleteIPsAssignedTo($reseller->id);
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-10-31 06:00:43 +01:00
|
|
|
if (!is_null($request->dedicated_ip)) {
|
|
|
|
IPs::insertIP($reseller->id, $request->dedicated_ip);
|
2022-03-05 16:58:25 +01:00
|
|
|
}
|
|
|
|
|
2022-10-31 06:00:43 +01:00
|
|
|
Cache::forget("all_reseller");
|
|
|
|
Cache::forget("reseller_hosting.{$reseller->id}");
|
|
|
|
Cache::forget("labels_for_service.{$reseller->id}");
|
2022-05-15 08:49:54 +02:00
|
|
|
|
2022-05-16 06:43:33 +02:00
|
|
|
Home::homePageCacheForget();
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('reseller.index')
|
|
|
|
->with('success', 'Reseller hosting updated Successfully.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(Reseller $reseller)
|
|
|
|
{
|
2022-11-09 05:18:25 +01:00
|
|
|
if ($reseller->delete()) {
|
|
|
|
$p = new Pricing();
|
|
|
|
$p->deletePricing($reseller->id);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-11-09 05:18:25 +01:00
|
|
|
Labels::deleteLabelsAssignedTo($reseller->id);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-11-09 05:18:25 +01:00
|
|
|
IPs::deleteIPsAssignedTo($reseller->id);
|
2022-03-05 16:02:12 +01:00
|
|
|
|
2022-11-09 05:18:25 +01:00
|
|
|
Cache::forget("all_reseller");
|
|
|
|
Cache::forget("reseller_hosting.$reseller->id");
|
|
|
|
Home::homePageCacheForget();
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-11-09 05:18:25 +01:00
|
|
|
return redirect()->route('reseller.index')
|
|
|
|
->with('success', 'Reseller hosting was deleted Successfully.');
|
|
|
|
}
|
2022-03-05 16:58:25 +01:00
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
return redirect()->route('reseller.index')
|
2022-11-09 05:18:25 +01:00
|
|
|
->with('error', 'Reseller was not deleted.');
|
|
|
|
|
2022-03-05 16:02:12 +01:00
|
|
|
}
|
|
|
|
}
|