280 lines
6.7 KiB
PHP
280 lines
6.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Lib\Discount;
|
|
use App\Mail\Won\DiscountWonMail;
|
|
use App\Mail\Won\PrizeIsSentMail;
|
|
use App\Mail\Won\PrizeWonMail;
|
|
use App\Mail\Won\WinningProofSubmitedMail;
|
|
use App\Models\Participation;
|
|
use App\Models\Prize;
|
|
use App\Models\Settings;
|
|
use App\Models\User;
|
|
use Closure;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Mail\Mailables\Address;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class Re7Controller extends Controller
|
|
{
|
|
/**
|
|
* Re7Controller
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware(function (Request $request, Closure $next) {
|
|
$this->authorize('fo.showRe7');
|
|
|
|
return $next($request);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Show Home page
|
|
*/
|
|
public function home(): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'theme::pages.home';
|
|
|
|
return view($view);
|
|
}
|
|
|
|
/**
|
|
* Show Teaser page
|
|
*/
|
|
public function teaser(): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'theme::pages.teaser';
|
|
|
|
return view($view);
|
|
}
|
|
|
|
/**
|
|
* Show Teaser page
|
|
*/
|
|
public function endGame(): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'theme::pages.end-game';
|
|
|
|
return view($view);
|
|
}
|
|
|
|
/**
|
|
* Show code input page
|
|
*/
|
|
public function participate(): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'theme::pages.participation.participate';
|
|
|
|
return view($view);
|
|
}
|
|
|
|
/**
|
|
* Show code input page
|
|
*/
|
|
public function participationExhausted(): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'theme::pages.participation.participation-exhausted';
|
|
|
|
return view($view);
|
|
}
|
|
|
|
// * -- Participation
|
|
|
|
/**
|
|
* Show prize page
|
|
*/
|
|
public function prize(Prize $prize): View
|
|
{
|
|
// * Fake participation model
|
|
$participationModel = new Participation();
|
|
$participationModel = 9999999;
|
|
|
|
/** @var view-string $view */
|
|
$view = 'theme::pages.participation.won';
|
|
|
|
return view($view, [
|
|
'prizeModel' => $prize,
|
|
'participationModel' => $participationModel,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show discount page
|
|
*/
|
|
public function discount(): View
|
|
{
|
|
/** @var Settings */
|
|
$settings = resolve(Settings::class);
|
|
/** @var Discount */
|
|
$discount = Arr::get(
|
|
$settings->web_coupons,
|
|
$this->getRandomWeightedElementIndex($settings->web_coupons)
|
|
);
|
|
|
|
if (! $settings->discounts_activated) {
|
|
return abort(404);
|
|
}
|
|
|
|
$mesBrDiscount = new Discount();
|
|
|
|
/** @var view-string $view */
|
|
$view = 'theme::pages.participation.won';
|
|
|
|
return view($view, ['discount' => $discount, 'mesBrDiscount' => $mesBrDiscount]);
|
|
}
|
|
|
|
/**
|
|
* Show loose page
|
|
*/
|
|
public function loose(): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'theme::pages.home';
|
|
|
|
return view($view);
|
|
}
|
|
|
|
// * -- END Participation
|
|
|
|
/**
|
|
* View won prize mail
|
|
*/
|
|
public function mailPrize(Prize $prize): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'back::pages.re7-preview-mail';
|
|
|
|
return view($view, [
|
|
'render_url' => route('re7.mail-print', [
|
|
'type' => 'prize',
|
|
'prize' => $prize,
|
|
]),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* View won discount mail
|
|
*/
|
|
public function mailDiscount(): View
|
|
{
|
|
/** @var Settings */
|
|
$settings = resolve(Settings::class);
|
|
if (! $settings->discounts_activated) {
|
|
return abort(404);
|
|
}
|
|
|
|
/** @var view-string $view */
|
|
$view = 'back::pages.re7-preview-mail';
|
|
|
|
return view($view, [
|
|
'render_url' => route('re7.mail-print', [
|
|
'type' => 'discount',
|
|
]),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* View proof mail received mail
|
|
*/
|
|
public function mailProofReceived(): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'back::pages.re7-preview-mail';
|
|
|
|
return view($view, [
|
|
'render_url' => route('re7.mail-print', [
|
|
'type' => 'proof',
|
|
]),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* View sent prize mail
|
|
*/
|
|
public function mailPrizeSent(): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'back::pages.re7-preview-mail';
|
|
|
|
return view($view, [
|
|
'render_url' => route('re7.mail-print', [
|
|
'type' => 'prize-sent',
|
|
]),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Print a specific mail
|
|
*/
|
|
public function mailPrint(string $type, ?Prize $prize = null): Response
|
|
{
|
|
/** @var User */
|
|
$user = auth('backend')->user();
|
|
|
|
/** @var Settings */
|
|
$settings = resolve(Settings::class);
|
|
|
|
switch ($type) {
|
|
case 'discount':
|
|
/** @var Discount */
|
|
$discount = Arr::get(
|
|
$settings->web_coupons,
|
|
$this->getRandomWeightedElementIndex($settings->web_coupons)
|
|
);
|
|
|
|
return response(new DiscountWonMail(
|
|
new Address(
|
|
$user->email,
|
|
$user->first_name
|
|
),
|
|
$settings->name,
|
|
$discount,
|
|
config('app.url'),
|
|
$settings->company,
|
|
)->render());
|
|
case 'prize':
|
|
return response(new PrizeWonMail(
|
|
new Address(
|
|
$user->email,
|
|
$user->first_name
|
|
),
|
|
$settings->name,
|
|
$prize,
|
|
config('app.url'),
|
|
$settings->company,
|
|
)->render());
|
|
case 'prize-sent':
|
|
return response(new PrizeIsSentMail(
|
|
new Address(
|
|
$user->email,
|
|
$user->first_name
|
|
),
|
|
$settings->name,
|
|
$settings->company,
|
|
)->render());
|
|
case 'proof':
|
|
return response(new WinningProofSubmitedMail(
|
|
new Address(
|
|
$user->email,
|
|
$user->first_name
|
|
),
|
|
$settings->name,
|
|
$settings->company,
|
|
)->render());
|
|
default:
|
|
return response('', 404);
|
|
} // end switch
|
|
}
|
|
}
|