dd/app/Services/Tg/Hook/Mod/ArticleCache.php
2026-01-12 16:09:00 +08:00

74 lines
1.9 KiB
PHP
Executable File

<?php
namespace App\Services\Tg\Hook\Mod;
use App\Models\ArticleCache as ModelArticleCache;
use App\Services\Tg\Hook\Dog;
use App\Services\Article\CacheTg as ServiceArticleCacheTg;
use App\Services\Article\Schema as ServiceArticleSchema;
use App\Services\Article\Cmd as ServiceArticleCmd;
use App\Models\ArticleCacheTime as ModelArticleCacheTime;
use App\Services\TomTool\Flow;
use App\Services\TomTool\ThrowableHandler;
class ArticleCache extends Base {
public function __construct($aUpdate)
{
$this->oDog = new Dog(new ModelArticleCache());
$this->oDog->_setDogName("articleCache");
$this->oDog->_setJsonField(["content"]);
// $this->oDog->_setStrField(["content"]);
$this->aUpdate = $aUpdate;
}
public function __call($sName, $aArg)
{
return $this->oDog->$sName($aArg[0]);
}
public function save($aParam)
{
$r = ServiceArticleCacheTg::start()->saveToSchema();
return $r->getResult();
}
public function reCron()
{
$o = ModelArticleCacheTime::first();
$o->time = time() - 6000;
$o->save();
$o = ModelArticleCache::orderBy("id", "desc")->first();
$r = ModelArticleCache::where("code", $o->code)->update(["status" => 1]);
return $r;
}
public function show($aParam)
{
$xCode = $aParam["aArg"][0] ?? ":last";
$sCode = $xCode;
if ($xCode == "?") {
return "#show__[code:last]";
}
if ($xCode === ":last") {
$sCode = ModelArticleCache::orderBy("id", "desc")->first()?->code;
}
$aCache = ModelArticleCache::where("code", $sCode)->get()->toArray();
$a = [];
foreach ($aCache as $aCacheRow) {
$aContent = json_decode($aCacheRow['content'], true);
$a[] = $aContent;
}
return $this->toJson($a);
}
}