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

95 lines
2.4 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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"][1] ?? ":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["id:".$aCacheRow['id']] = $aContent;
}
return $this->toJson($a);
}
public function echo($aParam)
{
$iId = $aParam["aArg"][1] ?? "";
if ($iId === "?") {
return "#show__[id]show()获取id";
}
if (!$iId) {
return "id必须";
}
$oCache = ModelArticleCache::where("id", $iId)->first();
if (!$oCache) {
return "没找到";
}
return $oCache->content;
}
}