fuc/src/Controllers/FrontController.php
2025-02-23 13:30:57 +08:00

145 lines
4.2 KiB
PHP
Executable File

<?php
declare(strict_types=1);
namespace App\Controllers;
use App\Services\Auth;
use Psr\Http\Message\ResponseInterface;
use Slim\Http\Response;
use Slim\Http\ServerRequest;
use Smarty\Exception as SmartyException;
use App\Services\Auth as AuthService;
use App\Models\Product;
use App\Models\Config;
use App\Models\UserCoupon;
final class FrontController extends BaseController
{
/**
* @throws SmartyException
*/
public function index(ServerRequest $request, Response $response, array $args): ResponseInterface
{
$sAffCode = $this->antiXss->xss_clean($args['code']);
if ($sAffCode) {
setcookie('affCode', $sAffCode, (time() + (86400 * 1)), "/");
}
$user = AuthService::getUser();
$taocan = (new Product())->where('status', '1')
->where('type_by_time', '30')
->orderBy('price')
->get();
foreach ($taocan as $taocanTmp) {
$taocanTmp->content = json_decode($taocanTmp->content);
$taocanTmp->price = (int) $taocanTmp->price;
}
return $response->write(
$this->view()
->assign('is_login', $user->isLogin)
->assign('taocan', $taocan)
->fetch('front/index.tpl')
);
}
public function sales(ServerRequest $request, Response $response, array $args): ResponseInterface
{
$user = AuthService::getUser();
$coupons = (new UserCoupon())->where("front_show", 1)->orderBy('id', 'desc')->get();
foreach ($coupons as $couponsTmp) {
if (empty($couponsTmp->expire_time)) {
$couponsTmp->expire_time = "无时间限制";
} else {
$couponsTmp->expire_time = '至'.date('Y-m-d', $couponsTmp->expire_time);
}
}
return $response->write(
$this->view()
->assign('is_login', $user->isLogin)
->assign('coupons', $coupons)
->assign('year', date("Y"))
->fetch('front/sales.tpl')
);
}
public function aff(ServerRequest $request, Response $response, array $args): ResponseInterface
{
$user = AuthService::getUser();
$invite_reward_rate = Config::obtain('invite_reward_rate') * 100;
return $response->write(
$this->view()
->assign('is_login', $user->isLogin)
->assign('invite_reward_rate', $invite_reward_rate)
->fetch('front/aff.tpl')
);
}
public function faq(ServerRequest $request, Response $response, array $args): ResponseInterface
{
$user = AuthService::getUser();
return $response->write(
$this->view()
->assign('is_login', $user->isLogin)
->fetch('front/faq.tpl')
);
}
/**
* @throws SmartyException
*/
public function tos(ServerRequest $request, Response $response, array $args): ResponseInterface
{
return $response->write($this->view()->fetch('tos.tpl'));
}
/**
* @throws SmartyException
*/
public function staff(ServerRequest $request, Response $response, array $args): ResponseInterface
{
$user = Auth::getUser();
if (! $user->isLogin) {
return $response->withStatus(404)->write($this->view()->fetch('404.tpl'));
}
return $response->write($this->view()->fetch('staff.tpl'));
}
/**
* @throws SmartyException
*/
public function notFound(ServerRequest $request, Response $response, array $args): ResponseInterface
{
return $response->write($this->view()->fetch('404.tpl'));
}
/**
* @throws SmartyException
*/
public function methodNotAllowed(ServerRequest $request, Response $response, array $args): ResponseInterface
{
return $response->write($this->view()->fetch('405.tpl'));
}
/**
* @throws SmartyException
*/
public function internalServerError(ServerRequest $request, Response $response, array $args): ResponseInterface
{
return $response->write($this->view()->fetch('500.tpl'));
}
}