66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Controllers\TomApi;
|
||
|
||
use Psr\Http\Message\ResponseInterface;
|
||
use Slim\Http\Response;
|
||
use Slim\Http\ServerRequest;
|
||
|
||
use App\Models\Huodong;
|
||
//use App\Models\TgStep;
|
||
|
||
final class HuodongController
|
||
{
|
||
|
||
public function findByDate(ServerRequest $request, Response $response, array $args)
|
||
{
|
||
|
||
$sFindDate = $args['date'];
|
||
|
||
$oHuodong = Huodong::where("start_date", "<=", $sFindDate)->where("end_date", ">=", $sFindDate)->first();
|
||
|
||
if ($oHuodong) {
|
||
echo json_encode($oHuodong);
|
||
}
|
||
|
||
exit;
|
||
|
||
}
|
||
|
||
public function dateHit(ServerRequest $request, Response $response, array $args)
|
||
{
|
||
|
||
$sDate = $args["date"] ?? date("Y-m-d");
|
||
|
||
// test
|
||
// $sDate = "2025-01-01";
|
||
|
||
$oHuodong = Huodong::where("start_date", "<=", $sDate)->where("end_date", ">=", $sDate)->first();
|
||
|
||
if ($oHuodong) {
|
||
|
||
$oHuodong->start_date_str = date("n月j日", strtotime($oHuodong->start_date));
|
||
$oHuodong->end_date_str = date("n月j日", strtotime($oHuodong->end_date));
|
||
|
||
$oHuodong->str = $oHuodong->title.":".$oHuodong->start_date_str."至".$oHuodong->end_date_str."期间,".$oHuodong->content;
|
||
|
||
$aReturn = [
|
||
"status" => 1,
|
||
"data" => $oHuodong
|
||
];
|
||
|
||
} else {
|
||
$aReturn = [
|
||
"status" => 0
|
||
];
|
||
}
|
||
|
||
echo json_encode($aReturn);
|
||
exit;
|
||
|
||
}
|
||
|
||
}
|