dd/app/Http/Controllers/CronController.php
2025-11-14 17:30:27 +08:00

81 lines
2.1 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers;
//use Illuminate\Http\Request;
//use App\Models\ArticleList;
//use App\Services\Time;
//use voku\helper\AntiXSS;
//use App\Models\Tags;
//use App\Services\TomTool\Http;
use App\Models\Book as ModelBook;
use App\Models\BookOption as ModelBookOption;
use App\Services\Tg\Http as TGHttp;
class CronController
{
public $oTGHttp;
function __construct()
{
$this->oTGHttp = new TGHttp();
$this->oTGHttp->sApiToken = env('telegram_token');
$this->oTGHttp->sApiChatId = env('telegram_chatid');
}
public function index()
{
$h = date("H");
$i = date("i");
$s = date("s");
//// test
$k = $_GET["k"] ?? false;
$v = $_GET["v"] ?? false;
if ($k == "h") {
$h = $v;
} else if ($k == "i") {
$i = $v;
} else if ($k == "k") {
$s = $v;
}
// $h = "00";
//// test end
if ($h == "00" && $i== "00") {
$iFireWarningLine = ModelBookOption::_hit("fire_warning_line");
$sDateWarningLine = date("Y-m-d H:i:s", strtotime($iFireWarningLine."day"));
$oBook = ModelBook::whereDate("fire", "<=", $sDateWarningLine)->where("fire_close", 0)->get();
if (!$oBook->isEmpty()) {
$oDateNow = new \DateTime();
foreach ($oBook as $oBookRow) {
$oDateRag = new \DateTime($oBookRow->fire);
$iDiffDay = $oDateNow->diff($oDateRag)->days;
if ($oDateNow > $oDateRag) {
$iDiffDay = -$iDiffDay;
}
$sTgStr = "⚠️⚠️⚠️ {{ ".$oBookRow->rag." }} 还有 {{ ".$iDiffDay." }} 天到期 ⚠️⚠️⚠️";
$this->oTGHttp->sendToTG($sTgStr);
}
}
}
}
}