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

111 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers\Fo;
use App\Http\Controllers\Controller;
use App\Models\Settings;
use App\Models\Reduction;
2023-08-24 12:59:51 +00:00
class Re7Controller extends Controller
{
2022-08-11 10:26:29 +02:00
/**
* index
2023-08-24 12:59:51 +00:00
*
2022-08-11 10:26:29 +02:00
* @return \Illuminate\View\View
*/
public function index()
{
return view('re7');
}
2022-08-11 10:26:29 +02:00
/**
* teaser
2023-08-24 12:59:51 +00:00
*
2022-08-11 10:26:29 +02:00
* @return \Illuminate\View\View
*/
public function teaser()
{
$settings = app(Settings::class)
->select('start_date', 'end_date', 'activated_teaser', 'teaser_end_activity')->first();
2023-11-21 12:28:09 +01:00
return view('theme::fo.teaser', compact('settings'));
}
2022-08-11 10:26:29 +02:00
/**
* prizeMail
2023-08-24 12:59:51 +00:00
*
2022-08-11 10:26:29 +02:00
* @return \Illuminate\View\View
*/
public function prizeMail()
{
2023-11-21 12:28:09 +01:00
return view('theme::fo.prize-mail');
}
2022-08-11 10:26:29 +02:00
/**
* reductionMail
2023-08-24 12:59:51 +00:00
*
2022-08-11 10:26:29 +02:00
* @return \Illuminate\View\View
*/
public function reductionMail()
{
2023-11-21 12:28:09 +01:00
return view('theme::fo.reduction-mail');
}
2022-08-11 10:26:29 +02:00
/**
* br
2023-08-24 12:59:51 +00:00
*
2022-08-11 10:26:29 +02:00
* @return \Illuminate\View\View
*/
public function br()
{
$settings = app(Settings::class);
2021-08-18 17:08:02 +02:00
$coupon = $this->getRandomCoupon($settings);
$crmCoupon = new Reduction();
2023-11-21 12:28:09 +01:00
return view('theme::fo.reduction', compact('coupon', 'crmCoupon'));
}
2022-08-11 10:26:29 +02:00
/**
* gain 1
2023-08-24 12:59:51 +00:00
*
2022-08-11 10:26:29 +02:00
* @return \Illuminate\View\View
*/
public function gain1()
{
2023-11-21 12:28:09 +01:00
return view('theme::fo.gain1');
}
2022-08-11 10:26:29 +02:00
/**
* gain 2
2023-08-24 12:59:51 +00:00
*
2022-08-11 10:26:29 +02:00
* @return \Illuminate\View\View
*/
public function gain2()
{
2023-11-21 12:28:09 +01:00
return view('theme::fo.gain2');
}
2022-08-11 10:26:29 +02:00
/**
* getRandomCoupon
2023-08-24 12:59:51 +00:00
*
2022-08-11 10:26:29 +02:00
* @param App\Models\Settings $settings
* @return string
*/
private function getRandomCoupon(Settings $settings)
2021-08-18 17:08:02 +02:00
{
$webCoupons = json_decode($settings->web_coupons);
if (count($webCoupons) > 1) {
$lots = [];
2021-08-18 17:08:02 +02:00
foreach ($webCoupons as $webCoupon) {
$lots[] = $webCoupon;
2021-08-18 17:08:02 +02:00
}
foreach ($lots as $lot) {
for ($i = 0; $i < $lot->percentage; $i++) {
$tmp[] = $lot;
2021-08-18 17:08:02 +02:00
}
}
shuffle($tmp);
return $tmp[0];
} else {
return $webCoupons[0];
}
}
}