77 lines
1.8 KiB
PHP
77 lines
1.8 KiB
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\index\model;
|
|
|
|
use app\common\model\ArticleCategoryBaseModel;
|
|
use think\model\concern\SoftDelete;
|
|
|
|
/**
|
|
* 文章分类模型
|
|
* @mixin \think\Model
|
|
*/
|
|
class ArticleCategoryModel extends ArticleCategoryBaseModel
|
|
{
|
|
// 启用软删除
|
|
use SoftDelete;
|
|
// 软删除字段
|
|
protected $deleteTime = 'deleted_at';
|
|
|
|
// 关联文章
|
|
public function article()
|
|
{
|
|
return $this->hasMany(ArticleModel::class, 'category_id', 'id');
|
|
}
|
|
|
|
// 所属语言范围查询
|
|
public function scopeLanguage($query, $language)
|
|
{
|
|
$query->where('language_id', '=', $language);
|
|
}
|
|
|
|
// 所属唯一标识范围查询
|
|
public function scopeUniqueLabel($query, $unique_label)
|
|
{
|
|
if (is_array($unique_label)) {
|
|
$query->where('unique_label', 'IN', $unique_label);
|
|
return;
|
|
}
|
|
$query->where('unique_label', '=', $unique_label);
|
|
}
|
|
|
|
// 所属上级分类范围查询
|
|
public function scopeParent($query, $parent)
|
|
{
|
|
if (is_null($parent)) return;
|
|
$query->where('pid', '=', $parent);
|
|
}
|
|
|
|
// 所属上级分类范围查询
|
|
public function scopeParentChild($query, $parent)
|
|
{
|
|
if (is_array($parent)) {
|
|
$query->where('pid', 'IN', $parent);
|
|
return;
|
|
}
|
|
$query->where('pid', '=', $parent);
|
|
}
|
|
|
|
|
|
// 所属子分类范围查询
|
|
public function scopeChild($query, $id, $merge_self = false)
|
|
{
|
|
$query->where(function($q) use($id, $merge_self) {
|
|
$q->where('pid', '=', $id);
|
|
if ($merge_self) {
|
|
$q->whereOr('id', '=', $id);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 是否显示状态范围查询
|
|
public function scopeIsShow($query, bool $is_show)
|
|
{
|
|
$query->where('is_show', '=', (int)$is_show);
|
|
}
|
|
}
|