no message
This commit is contained in:
parent
1539b79b50
commit
73abd9873e
12
app/Models/ArticleTags.php
Executable file
12
app/Models/ArticleTags.php
Executable file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ArticleTags extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
public $timestamps = false;
|
||||
protected $table = 'article_tag';
|
||||
}
|
||||
@ -2,7 +2,10 @@
|
||||
|
||||
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 {
|
||||
|
||||
@ -20,4 +23,50 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
24
app/Services/Tg/Hook/Mod/Tags.php
Executable file
24
app/Services/Tg/Hook/Mod/Tags.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Tg\Hook\Mod;
|
||||
use App\Models\Tags as ModelTags;
|
||||
use App\Services\Tg\Hook\Dog;
|
||||
use App\Services\TagService;
|
||||
|
||||
class Tags extends Base {
|
||||
|
||||
private $oDog;
|
||||
|
||||
public function __construct($aUpdate = [])
|
||||
{
|
||||
$this->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]);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user