74 lines
1.8 KiB
PHP
Executable File
74 lines
1.8 KiB
PHP
Executable File
<?php
|
||
|
||
namespace App\Services\Tg\Hook\Mod;
|
||
use App\Models\Articles as ModelArticles;
|
||
use App\Models\Tags as ModelTags;
|
||
use App\Models\ArticleTags as ModelArticleTags;
|
||
use App\Services\Tg\Hook\Dog;
|
||
use App\Services\TagService;
|
||
|
||
class Articles extends Base {
|
||
|
||
private $oDog;
|
||
|
||
public function __construct($aUpdate = [])
|
||
{
|
||
$this->oDog = new Dog(new ModelArticles());
|
||
// $this->oDog->_setPrimaryKey("k"); // 可选,默认id
|
||
$this->oDog->_setDogName("articles"); // 必须
|
||
$this->oDog->_setStrField(["sContent"]);
|
||
}
|
||
|
||
public function __call($sName, $aArg)
|
||
{
|
||
return $this->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;
|
||
}
|
||
|
||
}
|