2021-06-05 09:26:32 +00:00
|
|
|
<?php
|
2021-11-11 15:19:16 +00:00
|
|
|
|
2021-06-05 09:26:32 +00:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2022-10-18 15:35:10 +00:00
|
|
|
use App\Models\PartnerDiscount;
|
2021-07-05 19:49:28 +00:00
|
|
|
use App\Models\UsefulLink;
|
2021-06-05 09:26:32 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2022-10-18 15:35:10 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2022-08-15 00:08:42 +00:00
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use Illuminate\Support\Facades\URL;
|
2021-06-05 09:26:32 +00:00
|
|
|
|
2021-11-11 16:16:25 +00:00
|
|
|
|
2021-06-05 09:26:32 +00:00
|
|
|
class HomeController extends Controller
|
|
|
|
{
|
2021-11-11 15:19:16 +00:00
|
|
|
const TIME_LEFT_BG_SUCCESS = "bg-success";
|
|
|
|
const TIME_LEFT_BG_WARNING = "bg-warning";
|
|
|
|
const TIME_LEFT_BG_DANGER = "bg-danger";
|
2021-10-27 05:48:00 +00:00
|
|
|
|
2021-06-05 09:26:32 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
2022-08-15 00:08:42 +00:00
|
|
|
public function callHome(){
|
2022-08-15 00:10:31 +00:00
|
|
|
if(Storage::exists("callHome")){return;}
|
2022-08-15 00:08:42 +00:00
|
|
|
Http::asForm()->post('https://market.controlpanel.gg/callhome.php', [
|
|
|
|
'id' => Hash::make(URL::current())
|
|
|
|
]);
|
2022-08-15 00:10:53 +00:00
|
|
|
Storage::put('callHome', 'This is only used to count the installations of cpgg.');
|
2022-08-15 00:08:42 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 07:13:52 +00:00
|
|
|
/**
|
2021-11-11 15:19:16 +00:00
|
|
|
* @description Get the Background Color for the Days-Left-Box in HomeView
|
|
|
|
*
|
2021-11-11 15:25:29 +00:00
|
|
|
* @param float $daysLeft
|
2021-11-11 15:19:16 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-11-11 15:25:29 +00:00
|
|
|
public function getTimeLeftBoxBackground(float $daysLeft): string
|
2021-10-27 06:41:07 +00:00
|
|
|
{
|
2021-11-11 15:25:29 +00:00
|
|
|
if ($daysLeft >= 15) {
|
2021-11-11 15:19:16 +00:00
|
|
|
return $this::TIME_LEFT_BG_SUCCESS;
|
|
|
|
}
|
2021-11-11 15:25:29 +00:00
|
|
|
if ($daysLeft <= 7) {
|
2021-11-11 15:19:16 +00:00
|
|
|
return $this::TIME_LEFT_BG_DANGER;
|
2021-10-27 06:41:07 +00:00
|
|
|
}
|
2021-11-11 15:19:16 +00:00
|
|
|
return $this::TIME_LEFT_BG_WARNING;
|
2021-10-27 06:41:07 +00:00
|
|
|
}
|
|
|
|
|
2021-11-11 15:19:16 +00:00
|
|
|
|
2021-11-08 06:38:29 +00:00
|
|
|
/**
|
2021-11-11 15:19:16 +00:00
|
|
|
* @description Set "hours", "days" or nothing behind the remaining time
|
|
|
|
*
|
2021-11-11 15:25:29 +00:00
|
|
|
* @param float $daysLeft
|
|
|
|
* @param float $hoursLeft
|
2021-11-11 15:19:16 +00:00
|
|
|
*
|
|
|
|
* @return string|void
|
|
|
|
*/
|
2021-11-11 15:25:29 +00:00
|
|
|
public function getTimeLeftBoxUnit(float $daysLeft, float $hoursLeft)
|
2021-11-08 06:38:29 +00:00
|
|
|
{
|
2021-12-13 10:47:35 +00:00
|
|
|
if ($daysLeft > 1) return __('days');
|
|
|
|
return $hoursLeft < 1 ? null : __("hours");
|
2021-11-08 06:38:29 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 07:13:52 +00:00
|
|
|
/**
|
2021-11-11 15:19:16 +00:00
|
|
|
* @description Get the Text for the Days-Left-Box in HomeView
|
|
|
|
*
|
2021-11-11 15:25:29 +00:00
|
|
|
* @param float $daysLeft
|
|
|
|
* @param float $hoursLeft
|
2021-11-11 15:19:16 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-11-11 15:25:29 +00:00
|
|
|
public function getTimeLeftBoxText(float $daysLeft, float $hoursLeft)
|
2021-10-27 06:41:07 +00:00
|
|
|
{
|
2021-11-12 18:47:13 +00:00
|
|
|
if ($daysLeft > 1) return strval(number_format($daysLeft, 0));
|
2021-12-13 10:47:35 +00:00
|
|
|
return ($hoursLeft < 1 ? __("You ran out of Credits") : strval($hoursLeft));
|
2021-10-27 06:41:07 +00:00
|
|
|
}
|
2021-10-27 05:48:00 +00:00
|
|
|
|
2021-06-06 18:17:52 +00:00
|
|
|
/** Show the application dashboard. */
|
2021-06-06 21:26:36 +00:00
|
|
|
public function index(Request $request)
|
2021-06-05 09:26:32 +00:00
|
|
|
{
|
2021-10-26 15:51:15 +00:00
|
|
|
$usage = Auth::user()->creditUsage();
|
|
|
|
$credits = Auth::user()->Credits();
|
2021-10-26 15:55:55 +00:00
|
|
|
$bg = "";
|
|
|
|
$boxText = "";
|
2021-10-26 14:53:53 +00:00
|
|
|
$unit = "";
|
2021-06-05 09:26:32 +00:00
|
|
|
|
2021-10-27 05:48:00 +00:00
|
|
|
/** Build our Time-Left-Box */
|
2021-11-11 15:19:16 +00:00
|
|
|
if ($credits > 0.01 and $usage > 0) {
|
|
|
|
$daysLeft = number_format(($credits * 30) / $usage, 2, '.', '');
|
|
|
|
$hoursLeft = number_format($credits / ($usage / 30 / 24), 2, '.', '');
|
2021-10-26 15:55:55 +00:00
|
|
|
|
2021-11-11 15:19:16 +00:00
|
|
|
$bg = $this->getTimeLeftBoxBackground($daysLeft);
|
|
|
|
$boxText = $this->getTimeLeftBoxText($daysLeft, $hoursLeft);
|
2021-12-13 10:47:35 +00:00
|
|
|
$unit = $daysLeft < 1 ? ($hoursLeft < 1 ? null : __("hours")) : __("days");
|
2021-10-26 14:18:16 +00:00
|
|
|
}
|
2021-10-27 07:13:52 +00:00
|
|
|
|
2022-08-15 00:08:42 +00:00
|
|
|
$this->callhome();
|
2021-10-27 06:41:07 +00:00
|
|
|
|
2021-10-26 15:55:55 +00:00
|
|
|
// RETURN ALL VALUES
|
2021-10-26 14:53:53 +00:00
|
|
|
return view('home')->with([
|
2021-12-28 19:05:03 +00:00
|
|
|
'usage' => $usage,
|
2021-10-26 17:26:41 +00:00
|
|
|
'credits' => $credits,
|
2021-10-26 14:53:53 +00:00
|
|
|
'useful_links' => UsefulLink::all()->sortBy('id'),
|
|
|
|
'bg' => $bg,
|
2021-10-27 07:13:52 +00:00
|
|
|
'boxText' => $boxText,
|
2022-10-18 15:35:10 +00:00
|
|
|
'unit' => $unit,
|
|
|
|
'numberOfReferrals' => DB::table('user_referrals')->where("referral_id","=",Auth::user()->id)->count(),
|
|
|
|
'partnerDiscount' => PartnerDiscount::where('user_id', Auth::user()->id)->first(),
|
|
|
|
'myDiscount' => PartnerDiscount::getDiscount()
|
2021-10-26 14:53:53 +00:00
|
|
|
]);
|
2021-10-26 15:55:55 +00:00
|
|
|
}
|
2021-10-26 14:53:53 +00:00
|
|
|
}
|