ldc-gen-game-web/app/Http/Controllers/Bo/Re7Controller.php

281 lines
6.7 KiB
PHP
Raw Permalink Normal View History

<?php
2026-10-02 12:09:46 +02:00
declare(strict_types=1);
2023-12-01 11:45:12 +01:00
namespace App\Http\Controllers\Bo;
use App\Http\Controllers\Controller;
2026-10-02 12:09:46 +02:00
use App\Lib\Discount;
2023-12-07 16:59:17 +01:00
use App\Mail\Won\DiscountWonMail;
2023-12-13 18:08:05 +01:00
use App\Mail\Won\PrizeIsSentMail;
2023-12-07 16:59:17 +01:00
use App\Mail\Won\PrizeWonMail;
2023-12-13 11:29:56 +01:00
use App\Mail\Won\WinningProofSubmitedMail;
2026-10-02 12:09:46 +02:00
use App\Models\Participation;
2023-12-05 18:41:58 +01:00
use App\Models\Prize;
use App\Models\Settings;
2026-10-02 12:09:46 +02:00
use App\Models\User;
use Closure;
2023-12-01 11:45:12 +01:00
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
2023-12-07 16:59:17 +01:00
use Illuminate\Http\Response;
use Illuminate\Mail\Mailables\Address;
2023-12-07 15:15:08 +01:00
use Illuminate\Support\Arr;
2023-08-24 12:59:51 +00:00
class Re7Controller extends Controller
{
2022-08-11 10:26:29 +02:00
/**
2023-12-01 11:45:12 +01:00
* Re7Controller
2022-08-11 10:26:29 +02:00
*/
2023-12-01 11:45:12 +01:00
public function __construct()
{
2026-10-02 12:09:46 +02:00
$this->middleware(function (Request $request, Closure $next) {
2023-12-01 11:45:12 +01:00
$this->authorize('fo.showRe7');
2026-10-02 12:09:46 +02:00
2023-12-01 11:45:12 +01:00
return $next($request);
});
}
2023-12-08 15:49:20 +01:00
/**
* Show Home page
*/
public function home(): View
{
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'theme::pages.home';
return view($view);
2023-12-08 15:49:20 +01:00
}
2023-12-05 12:33:25 +01:00
/**
* Show Teaser page
*/
public function teaser(): View
{
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'theme::pages.teaser';
return view($view);
2023-12-05 12:33:25 +01:00
}
2023-12-07 15:27:48 +01:00
/**
* Show Teaser page
*/
public function endGame(): View
{
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'theme::pages.end-game';
return view($view);
2023-12-07 15:27:48 +01:00
}
/**
* Show code input page
*/
public function participate(): View
{
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'theme::pages.participation.participate';
return view($view);
}
/**
* Show code input page
*/
public function participationExhausted(): View
{
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'theme::pages.participation.participation-exhausted';
return view($view);
}
2023-12-05 18:41:58 +01:00
// * -- Participation
2022-08-11 10:26:29 +02:00
/**
2023-12-05 18:41:58 +01:00
* Show prize page
2022-08-11 10:26:29 +02:00
*/
2023-12-05 18:41:58 +01:00
public function prize(Prize $prize): View
{
2023-12-13 11:36:10 +01:00
// * Fake participation model
$participationModel = new Participation();
$participationModel = 9999999;
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'theme::pages.participation.won';
return view($view, [
'prizeModel' => $prize,
'participationModel' => $participationModel,
2023-12-05 18:41:58 +01:00
]);
}
2022-08-11 10:26:29 +02:00
/**
2023-12-05 18:41:58 +01:00
* Show discount page
2022-08-11 10:26:29 +02:00
*/
2023-12-07 16:59:17 +01:00
public function discount(): View
{
2026-10-02 12:09:46 +02:00
/** @var Settings */
$settings = resolve(Settings::class);
/** @var Discount */
2023-12-07 15:15:08 +01:00
$discount = Arr::get(
$settings->web_coupons,
$this->getRandomWeightedElementIndex($settings->web_coupons)
);
2026-10-02 12:09:46 +02:00
if (! $settings->discounts_activated) {
return abort(404);
}
2023-12-12 14:56:12 +01:00
$mesBrDiscount = new Discount();
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'theme::pages.participation.won';
return view($view, ['discount' => $discount, 'mesBrDiscount' => $mesBrDiscount]);
}
2022-08-11 10:26:29 +02:00
/**
2023-12-05 18:41:58 +01:00
* Show loose page
2022-08-11 10:26:29 +02:00
*/
2023-12-05 18:41:58 +01:00
public function loose(): View
{
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'theme::pages.home';
return view($view);
}
2023-12-05 18:41:58 +01:00
// * -- END Participation
2022-08-11 10:26:29 +02:00
/**
2023-12-13 18:08:05 +01:00
* View won prize mail
2023-12-07 16:59:17 +01:00
*/
public function mailPrize(Prize $prize): View
{
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'back::pages.re7-preview-mail';
return view($view, [
2023-12-07 16:59:17 +01:00
'render_url' => route('re7.mail-print', [
2026-10-02 12:09:46 +02:00
'type' => 'prize',
'prize' => $prize,
]),
2023-12-07 16:59:17 +01:00
]);
}
/**
* View won discount mail
2022-08-11 10:26:29 +02:00
*/
2023-12-07 16:59:17 +01:00
public function mailDiscount(): View
{
2026-10-02 12:09:46 +02:00
/** @var Settings */
$settings = resolve(Settings::class);
if (! $settings->discounts_activated) {
return abort(404);
}
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'back::pages.re7-preview-mail';
return view($view, [
2023-12-07 16:59:17 +01:00
'render_url' => route('re7.mail-print', [
2026-10-02 12:09:46 +02:00
'type' => 'discount',
]),
2023-12-07 16:59:17 +01:00
]);
}
2023-12-13 11:29:56 +01:00
/**
* View proof mail received mail
*/
public function mailProofReceived(): View
{
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'back::pages.re7-preview-mail';
return view($view, [
2023-12-13 11:29:56 +01:00
'render_url' => route('re7.mail-print', [
2026-10-02 12:09:46 +02:00
'type' => 'proof',
]),
2023-12-13 11:29:56 +01:00
]);
}
2023-12-13 18:08:05 +01:00
/**
* View sent prize mail
*/
public function mailPrizeSent(): View
{
2026-10-02 12:09:46 +02:00
/** @var view-string $view */
$view = 'back::pages.re7-preview-mail';
return view($view, [
2023-12-13 18:08:05 +01:00
'render_url' => route('re7.mail-print', [
2026-10-02 12:09:46 +02:00
'type' => 'prize-sent',
]),
2023-12-13 18:08:05 +01:00
]);
}
2022-08-11 10:26:29 +02:00
/**
2023-12-07 16:59:17 +01:00
* Print a specific mail
2022-08-11 10:26:29 +02:00
*/
2026-10-02 12:09:46 +02:00
public function mailPrint(string $type, ?Prize $prize = null): Response
{
2026-10-02 12:09:46 +02:00
/** @var User */
2023-12-07 16:59:17 +01:00
$user = auth('backend')->user();
2026-10-02 12:09:46 +02:00
/** @var Settings */
$settings = resolve(Settings::class);
2023-12-07 16:59:17 +01:00
switch ($type) {
case 'discount':
2026-10-02 12:09:46 +02:00
/** @var Discount */
2023-12-07 16:59:17 +01:00
$discount = Arr::get(
$settings->web_coupons,
$this->getRandomWeightedElementIndex($settings->web_coupons)
);
2026-10-02 12:09:46 +02:00
return response(new DiscountWonMail(
2023-12-07 16:59:17 +01:00
new Address(
$user->email,
$user->first_name
),
$settings->name,
$discount,
config('app.url'),
$settings->company,
2026-10-02 12:09:46 +02:00
)->render());
2023-12-07 16:59:17 +01:00
case 'prize':
2026-10-02 12:09:46 +02:00
return response(new PrizeWonMail(
2023-12-07 16:59:17 +01:00
new Address(
$user->email,
$user->first_name
),
$settings->name,
$prize,
config('app.url'),
$settings->company,
2026-10-02 12:09:46 +02:00
)->render());
2023-12-13 18:08:05 +01:00
case 'prize-sent':
2026-10-02 12:09:46 +02:00
return response(new PrizeIsSentMail(
2023-12-13 18:08:05 +01:00
new Address(
$user->email,
$user->first_name
),
$settings->name,
$settings->company,
2026-10-02 12:09:46 +02:00
)->render());
2023-12-13 11:29:56 +01:00
case 'proof':
2026-10-02 12:09:46 +02:00
return response(new WinningProofSubmitedMail(
2023-12-13 11:29:56 +01:00
new Address(
$user->email,
$user->first_name
),
$settings->name,
$settings->company,
2026-10-02 12:09:46 +02:00
)->render());
2023-12-07 16:59:17 +01:00
default:
return response('', 404);
2026-10-02 12:09:46 +02:00
} // end switch
}
}