From 73abd9873e17c89fc8399f046b2044913b6fa6b8 Mon Sep 17 00:00:00 2001 From: hellcat Date: Fri, 13 Mar 2026 17:34:31 +0800 Subject: [PATCH] no message --- app/Models/ArticleTags.php | 12 +++++++ app/Services/Tg/Hook/Mod/Articles.php | 49 +++++++++++++++++++++++++++ app/Services/Tg/Hook/Mod/Tags.php | 24 +++++++++++++ 3 files changed, 85 insertions(+) create mode 100755 app/Models/ArticleTags.php create mode 100755 app/Services/Tg/Hook/Mod/Tags.php diff --git a/app/Models/ArticleTags.php b/app/Models/ArticleTags.php new file mode 100755 index 00000000..c014c9b3 --- /dev/null +++ b/app/Models/ArticleTags.php @@ -0,0 +1,12 @@ +oDog->$sName($aArg[0]); } + public function setTag($aParam) + { + $iArticleId = $aParam["aOption"][1] ?? 0; + $aTag = $aParam["aArg"] ?? []; + + if (!$aTag) { + return "需要tag"; + } + + if ($aParam["aArg"][1] == "?") { + return "#setTag__[articleId] [aTag]"; + } + + $oArticle = ModelArticles::where("id", $iArticleId)->first(); + + (new TagService())->syncArticleTagsByName($oArticle, $aTag); + + return "ok"; + } + + public function unsetTag($aParam) + { + $iArticleId = $aParam["aOption"][1] ?? 0; + $sTag = $aParam["aArg"][1] ?? ''; + + if ($sTag == "?") { + return "#unsetTag__[articleId] [sTag]"; + } + + $iTagId = ModelTags::where("sName", $sTag)->first()?->id; + + if (!$iTagId) { + return "没有{$sTag}这个tag"; + } + + $iDeleted = ModelArticleTags::where("iArticleId", $iArticleId) + ->where("iTagId", $iTagId) + ->delete(); + + if (!$iDeleted) { + return "article里没有这个tag"; + } + + return $iDeleted; + } + } diff --git a/app/Services/Tg/Hook/Mod/Tags.php b/app/Services/Tg/Hook/Mod/Tags.php new file mode 100755 index 00000000..be20e7f6 --- /dev/null +++ b/app/Services/Tg/Hook/Mod/Tags.php @@ -0,0 +1,24 @@ +oDog = new Dog(new ModelTags()); +// $this->oDog->_setPrimaryKey("k"); // 可选,默认id + $this->oDog->_setDogName("tags"); // 必须 + } + + public function __call($sName, $aArg) + { + return $this->oDog->$sName($aArg[0]); + } + +}