dd/app/Services/Tg/Hook/Mod/CacheTg.php
2026-01-17 12:57:57 +08:00

178 lines
5.1 KiB
PHP
Executable File

<?php
namespace App\Services\Tg\Hook\Mod;
use App\Models\ArticleSchema as ModelArticleSchema;
use App\Models\ArticleCache as ModelArticleCache;
use App\Models\ArticleCacheTime as ModelArticleCacheTime;
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\Services\TomTool\Flow;
//use App\Services\HttpQueue;
use App\Services\TomTool\TelegramVdb;
use App\Services\TomTool\ThrowableHandler;
use Illuminate\Database\QueryException;
use RuntimeException;
use App\Services\TomTool\HttpV2;
use App\Services\Cron\ArticleSchema as CronArticleSchema;
class Article extends Base {
private $oDog;
private $aUpdate;
public function __construct($aUpdate)
{
$this->oDog = new Dog(new ModelArticleSchema());
$this->oDog->_setDogName("articleSchema");
$this->oDog->_setStrField(["content"]);
$this->aUpdate = $aUpdate;
}
public function __call($sName, $aArg)
{
return $this->oDog->$sName($aArg[0]);
}
public function test_cron_saveAuto()
{
$r = ServiceArticleSchema::make()->cron_saveAuto();
return $r;
}
public function build_test_ttcp($aParam)
{
$oArticleCodeFirst = ModelArticleSchema::where("status", 1)->orderBy("id", "desc")->first();
$aArg["sArticleCode"] = $oArticleCodeFirst->code;
$aArg["sFromCode"] = 'ttcp';
$aArg["sFromName"] = '天天测评';
$aArg["sFromUrl"] = 'ttcp.loc';
$aArg["sFromGroup"] = 'vue_md_ceping';
$aParam["aArg"][1] = json_encode($aArg);
$r = $this->build_test($aParam);
}
public function build_test($aParam)
{
$aJson = $aParam["aArg"];
$sJson = implode(" ", $aJson);
$aJson = json_decode($sJson, true);
$sShell = $this->aUpdate["shell"] ?? '';
$aJson["isTest"] = true;
$url = $_ENV["APP_URL"]."/api/article/build";
$r = HttpV2::make($url)->enableJsonSend()->setData($aJson)->send();
$a = json_decode($r, true);
if ($sShell !== "cmd") {
$oTelegramVdb = TelegramVdb::make("master");
foreach ($a["aData"] as $aa) {
$oTelegramVdb->send($aa);
}
}
echo "标题:".$a["aData"]["title"] ?? "?";
echo "<br>";
echo $a["aData"]["content"] ?? "?";
exit;
}
public function build_test_case($aParam)
{
$aArg["sArticleCode"] = 'ffq_tg::20251028113221';
$aArg["sFromCode"] = 'ttcp';
$aArg["sFromName"] = '天天测评';
$aArg["sFromUrl"] = 'ttcp.loc';
$aArg["sFromGroup"] = 'vue_md_ceping';
return $this->toJson($aArg);
}
public function cmdReset($aParam)
{
$xId = $aParam["aArg"][1] ?? "first";
if ($xId == "?") {
return "#cmdRe [xId:first]";
}
if ($xId == "first") {
$oModelArticleSchema = ModelArticleSchema::where("status", 1)->orderBy("id", "desc")->first();
} else {
$oModelArticleSchema = ModelArticleSchema::where("status", 1)->where("id", $xId)->first();
}
$oModelArticleSchema->enable_sync = true;
$oModelArticleSchema->save();
$bool = ServiceArticleCmd::start($oModelArticleSchema->code)->reset();
return $bool;
}
public function cmdGet($aParam)
{
$xId = $aParam["aArg"][1] ?? "first";
if ($xId == "?") {
return "#cmdGet [xId:first]";
}
if ($xId == "first") {
$oModelArticleSchema = ModelArticleSchema::where("status", 1)->orderBy("id", "desc")->first();
} else {
$oModelArticleSchema = ModelArticleSchema::where("status", 1)->where("id", $xId)->first();
}
return json_decode($oModelArticleSchema->cmd, true);
}
public function schemaGet($aParam)
{
$xId = $aParam["aArg"][1] ?? "first";
if ($xId == "?") {
return "#schemaGet [xId:first]";
}
if ($xId == "first") {
$oModelArticleSchema = ModelArticleSchema::where("status", 1)->orderBy("id", "desc")->first();
} else {
$oModelArticleSchema = ModelArticleSchema::where("status", 1)->where("id", $xId)->first();
}
$aSchema = json_decode($oModelArticleSchema->schema, true);
$sMsg = json_encode($aSchema, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
return $sMsg;
}
public function cacheAdd($aParam)
{
$sFromGroupCode = $aParam["aOption"][1] ?? "ffq_tg_a";
$sContent = implode(' ', $aParam["aArg"]);
$r = ServiceArticleCacheTg::start()->add($sFromGroupCode, $sContent);
return $r;
}
// public function save($aParam)
// {
// $r = ServiceArticleSchema::make()->save();
//
// return $r;
// }
}