From d2e12a3d79797a7fd716fb624a61b0c967b97b71 Mon Sep 17 00:00:00 2001 From: hellcat Date: Thu, 9 Apr 2026 18:57:06 +0800 Subject: [PATCH] no message --- src/Services/Tg/Hook/Dog.php | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/src/Services/Tg/Hook/Dog.php b/src/Services/Tg/Hook/Dog.php index 479615c79..7a2c4f5b1 100644 --- a/src/Services/Tg/Hook/Dog.php +++ b/src/Services/Tg/Hook/Dog.php @@ -441,6 +441,56 @@ class Dog extends Mod\Base { return $iLimit; } + public function last() + { + $iLastId = $this->oModelSelf->orderBy("id", "desc")->first()?->id; + + $aParam = []; + $aParam["aOption"][1] = "id"; + $aParam["aArg"][1] = $iLastId; + + return $this->find($aParam); + } + + public function hitRaw($aParam) + { + $xId = $aParam["aArg"][1] ?? false; + $sField = $aParam["aOption"][1] ?? false; + + if (!$xId) { + return "需要id"; + } + + if (!$sField) { + return "需要field"; + } + + if ($xId == "?") { + return "#hitRaw__[field] [id]"; + } + + $sContent = $this->oModelSelf->where("id", $xId)->first()?->{$sField}; + + return $sContent; + } + + public function findRaw($aParam) + { + $xId = $aParam["aArg"][1] ?? false; + + if (!$xId) { + return "需要id"; + } + + if ($xId == "?") { + return "#findRaw [id]"; + } + + $aData = $this->oModelSelf->where("id", $xId)->first()->toArray(); + + return $this->toJson($aData); + } + public function find($aParam) { $sField = $aParam["aOption"][1] ?? $this->sPrimaryKey; @@ -538,6 +588,9 @@ class Dog extends Mod\Base { public function toJson($aData) { + if (is_string($aData)) { + return $aData; + } if ($this->aMsg && !is_string($aData)) { if (is_object($aData)) { @@ -648,6 +701,38 @@ class Dog extends Mod\Base { return $this->set($aParam); } + public function jsonSet($aParam) + { + $iId = $aParam["aOption"][1] ?? ""; + $sField = $aParam["aOption"][2] ?? ""; + $aJson = $aParam["aArg"]; + $sJson = implode(" ", $aJson); + $aJson = json_decode($sJson, true); + + if ($sJson == "?") { + return "#jsonSet__[id]__[field] [json]"; + } + + if (!$iId || !$sField || !$sJson) { + return "参数不足"; + } + + $oModelSelf = $this->oModelSelf->where("id", $iId)->first(); + + if (!$oModelSelf) { + return "没有这个"; + } + + $oModelSelf->$sField = $aJson; + $oModelSelf->save(); + + $aParam = []; + $aParam["aOption"][1] = "id"; + $aParam["aArg"][1] = $iId; + + return $this->find($aParam); + } + public function arrUnset($aParam) { $aParam["sCmd"] = "unset";